summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChaos Eternal <chaos@shlug.org>2017-01-12 13:50:44 +0800
committerChaos Eternal <chaos@shlug.org>2017-01-13 12:02:33 +0800
commit1518f0c9ab370327c053faa6c0c1b5571b68eb5e (patch)
tree6d37c24596a02f5ff2442f395b7f1012897e86ed
parent6893f692259c0241049bf614147160c44dd4ba3e (diff)
downloadgeiser-guile-1518f0c9ab370327c053faa6c0c1b5571b68eb5e.tar.gz
geiser-guile-1518f0c9ab370327c053faa6c0c1b5571b68eb5e.tar.bz2
Make eval-last-sexp-to-buffer customizable
-rw-r--r--elisp/geiser-mode.el30
1 files changed, 25 insertions, 5 deletions
diff --git a/elisp/geiser-mode.el b/elisp/geiser-mode.el
index d0f184e..dd453b3 100644
--- a/elisp/geiser-mode.el
+++ b/elisp/geiser-mode.el
@@ -62,6 +62,16 @@ active when `geiser-mode' is activated in a buffer."
:group 'geiser-mode
:type 'boolean)
+(geiser-custom--defcustom geiser-mode-eval-last-sexp-to-buffer nil
+ "Whether `eval-last-sexp' prints results to buffer"
+ :group 'geiser-mode
+ :type 'boolean)
+
+(geiser-custom--defcustom geiser-mode-eval-to-buffer-prefix ""
+ "When `geiser-mode-eval-last-sexp-to-buffer', the prefix string which will prepend to results"
+ :group 'geiser-mode
+ :type 'string)
+
;;; Evaluation commands:
@@ -132,17 +142,27 @@ With prefix, goes to the REPL buffer afterwards (as
(defun geiser-eval-last-sexp (print-to-buffer-p)
"Eval the previous sexp in the Geiser REPL.
-With a prefix, print the result of the evaluation to the buffer."
+With a prefix, revert the effect of `geiser-mode-eval-last-sexp-to-buffer' "
(interactive "P")
(let* ((ret (geiser-eval-region (save-excursion (backward-sexp) (point))
(point)
nil
t
print-to-buffer-p))
- (str (geiser-eval--retort-result-str ret (when print-to-buffer-p ""))))
- (when (and print-to-buffer-p (not (string= "" str)))
- (push-mark)
- (insert str))))
+ (err (geiser-eval--retort-error ret))
+ (will-eval-to-buffer (if print-to-buffer-p
+ (not 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)
+ ((string= "" str))
+ (err (insert
+ (format "\n%sERROR:%s\n" geiser-mode-eval-to-buffer-prefix
+ (geiser-eval--error-str err))))
+ (t (progn
+ (push-mark)
+ (insert
+ (format "\n%s%s\n" geiser-mode-eval-to-buffer-prefix str)))))))
(defun geiser-compile-definition (&optional and-go)
"Compile the current definition in the Geiser REPL.