diff options
author | Chaos Eternal <chaos@shlug.org> | 2017-01-12 13:50:44 +0800 |
---|---|---|
committer | Chaos Eternal <chaos@shlug.org> | 2017-01-13 12:02:33 +0800 |
commit | a5794ca23e671848abae26536693360bff186b02 (patch) | |
tree | 7ed725ca4c4c67345903ed13d40b2599c25dc676 | |
parent | 335bae6189928f4fcdaa56a34ddb68917cb8abaa (diff) | |
download | geiser-a5794ca23e671848abae26536693360bff186b02.tar.gz geiser-a5794ca23e671848abae26536693360bff186b02.tar.bz2 |
Make eval-last-sexp-to-buffer customizable
-rw-r--r-- | elisp/geiser-mode.el | 30 |
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. |