summaryrefslogtreecommitdiff
path: root/elisp/geiser-mode.el
diff options
context:
space:
mode:
authorChaos Eternal <chaos@shlug.org>2017-08-20 22:23:38 +0800
committerJose Antonio Ortega Ruiz <jao@gnu.org>2017-08-28 02:54:04 +0200
commite1b9f87e535a43d04a5572bed820f029213c5b13 (patch)
tree00793aa8cd7596cb0a1c1647b8307f7137193d92 /elisp/geiser-mode.el
parentf9ce0b6c1a4d6a84ffafe6626d79bceab0ad8f7f (diff)
downloadgeiser-e1b9f87e535a43d04a5572bed820f029213c5b13.tar.gz
geiser-e1b9f87e535a43d04a5572bed820f029213c5b13.tar.bz2
Add geiser-mode-eval-to-buffer-transformer
geiser-mode-eval-to-buffer-transformer will take 2 argments: errstring and result when eval-to-buffer, the result will be transformed by this procedure e.g. (setq geiser-mode-eval-to-buffer-transformer (lambda (estring x) (let ((l (length x)) (p (seq-position x ?\n))) (if (and p (< (+ 1 p) l)) (format "\n#| %s%s\n |#" estring x) (format ";;=> %s%s" estring x)))))
Diffstat (limited to 'elisp/geiser-mode.el')
-rw-r--r--elisp/geiser-mode.el20
1 files changed, 16 insertions, 4 deletions
diff --git a/elisp/geiser-mode.el b/elisp/geiser-mode.el
index 0d00662..927a9b9 100644
--- a/elisp/geiser-mode.el
+++ b/elisp/geiser-mode.el
@@ -72,6 +72,16 @@ active when `geiser-mode' is activated in a buffer."
:group 'geiser-mode
:type 'string)
+(geiser-custom--defcustom geiser-mode-eval-to-buffer-transformer nil
+ "When `geiser-mode-eval-last-sexp-to-buffer', the result will be transformed using this function
+default behavior is just prepend with `geiser-mode-eval-to-buffer-prefix'
+takes two arguments: `msg' and `is-error?'
+`msg' is the result string going to be transformed,
+`is-error?' is a bool indicate whether the result is an error msg
+"
+ :group 'geiser-mode
+ :type 'function)
+
;;; Evaluation commands:
@@ -149,6 +159,10 @@ With a prefix, revert the effect of `geiser-mode-eval-last-sexp-to-buffer' "
(setq bosexp (point))
(forward-sexp)
(point)))
+ (ret-transformer (or geiser-mode-eval-to-buffer-transformer
+ (lambda (msg is-error?)
+ (format "%s%s%s" geiser-mode-eval-to-buffer-prefix
+ (if is-error? "ERROR" "") msg))))
(ret (save-excursion
(geiser-eval-region bosexp ;beginning of sexp
eosexp ;end of sexp
@@ -161,12 +175,10 @@ With a prefix, revert the effect of `geiser-mode-eval-last-sexp-to-buffer' "
geiser-mode-eval-last-sexp-to-buffer))
(str (geiser-eval--retort-result-str ret (when will-eval-to-buffer ""))))
(cond ((not will-eval-to-buffer) str)
- (err (insert (format "%sERROR:%s"
- geiser-mode-eval-to-buffer-prefix
- (geiser-eval--error-str err))))
+ (err (insert (funcall ret-transformer (geiser-eval--error-str err) t)))
((string= "" str))
(t (push-mark)
- (insert (format "%s%s" geiser-mode-eval-to-buffer-prefix str))))))
+ (insert (funcall ret-transformer str nil))))))
(defun geiser-compile-definition (&optional and-go)
"Compile the current definition in the Geiser REPL.