summaryrefslogtreecommitdiff
path: root/elisp
diff options
context:
space:
mode:
authorDiogo F. S. Ramos <diogofsr@gmail.com>2013-04-11 18:56:30 -0300
committerJose Antonio Ortega Ruiz <jao@gnu.org>2013-04-12 00:17:00 +0200
commit2ebc1225b929d2a3c3b25fbd7596adb4d49915f0 (patch)
tree1c052ad067b05d3d17a0943699a9a61faecd48e6 /elisp
parent246175eadf22a2ab7121be68d37d01f320ddb44a (diff)
downloadgeiser-chez-2ebc1225b929d2a3c3b25fbd7596adb4d49915f0.tar.gz
geiser-chez-2ebc1225b929d2a3c3b25fbd7596adb4d49915f0.tar.bz2
Evaluate last expression to buffer with a prefix
Use a prefix before pressing C-x C-e to print the result of evaluating the expression before mark to the current buffer.
Diffstat (limited to 'elisp')
-rw-r--r--elisp/geiser-debug.el6
-rw-r--r--elisp/geiser-eval.el10
-rw-r--r--elisp/geiser-mode.el24
3 files changed, 30 insertions, 10 deletions
diff --git a/elisp/geiser-debug.el b/elisp/geiser-debug.el
index c35f577..184d9c8 100644
--- a/elisp/geiser-debug.el
+++ b/elisp/geiser-debug.el
@@ -172,9 +172,9 @@ buffer.")
(when (not err)
(save-excursion
(goto-char (/ (+ end start) 2))
- (geiser-autodoc--clean-cache))
- (message "%s" res))
- (geiser-debug--display-retort (geiser-syntax--scheme-str str) ret res)))
+ (geiser-autodoc--clean-cache)))
+ (geiser-debug--display-retort (geiser-syntax--scheme-str str) ret res)
+ ret))
(defun geiser-debug--expand-region (start end all wrap)
(let* ((str (buffer-substring-no-properties start end))
diff --git a/elisp/geiser-eval.el b/elisp/geiser-eval.el
index dd0e45d..5d61580 100644
--- a/elisp/geiser-eval.el
+++ b/elisp/geiser-eval.el
@@ -173,6 +173,16 @@ module-exports, autodoc, callers, callees and generic-methods.")
(concat "=> " (mapconcat 'identity values "\n=> "))
"(No value)")))
+(defun geiser-eval--retort-result-list (ret)
+ "Return the list of results."
+ (cdr (assoc 'result ret)))
+
+(defun geiser-eval--retort-result-to-buffer (ret)
+ "Return a string formated for printing to buffer."
+ (mapconcat 'identity
+ (geiser-eval--retort-result-list ret)
+ "\n"))
+
(defsubst geiser-eval--retort-output (ret) (cdr (assoc 'output ret)))
(defsubst geiser-eval--retort-error (ret) (cdr (assoc 'error ret)))
diff --git a/elisp/geiser-mode.el b/elisp/geiser-mode.el
index b66f4a2..a47a92b 100644
--- a/elisp/geiser-mode.el
+++ b/elisp/geiser-mode.el
@@ -107,13 +107,23 @@ With prefix, goes to the REPL buffer afterwards (as
(interactive)
(geiser-eval-definition t))
-(defun geiser-eval-last-sexp ()
- "Eval the previous sexp in the Geiser REPL."
- (interactive)
- (geiser-eval-region (save-excursion (backward-sexp) (point))
- (point)
- nil
- t))
+(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."
+ (interactive "P")
+ (let ((ret (geiser-eval-region (save-excursion (backward-sexp) (point))
+ (point)
+ nil
+ t)))
+ (if print-to-buffer-p
+ (let ((str (geiser-eval--retort-result-to-buffer ret)))
+ ;; It's possible that a procedure returns nothing, so we
+ ;; don't want to `push-mark' if it's not necessary
+ (unless (string= "" str)
+ (push-mark)
+ (insert str)))
+ (message "%s" (geiser-eval--retort-result-str ret)))))
(defun geiser-compile-definition (&optional and-go)
"Compile the current definition in the Geiser REPL.