summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2009-05-03 01:22:01 +0200
committerJose Antonio Ortega Ruiz <jao@gnu.org>2009-05-03 01:22:01 +0200
commita63280cd55b342046966f95943ca9a45b2870c07 (patch)
tree25b827e6006563a52af7128ae02760221e0b0eab
parentd485cecc04bbdd3fff177b3c179ca1fd1dbc9500 (diff)
downloadgeiser-a63280cd55b342046966f95943ca9a45b2870c07.tar.gz
geiser-a63280cd55b342046966f95943ca9a45b2870c07.tar.bz2
Wrapping arbitrary regions with a begin block before evaluation/expansion.
-rw-r--r--elisp/geiser-debug.el28
-rw-r--r--elisp/geiser-mode.el33
2 files changed, 42 insertions, 19 deletions
diff --git a/elisp/geiser-debug.el b/elisp/geiser-debug.el
index c8fb3f4..0573716 100644
--- a/elisp/geiser-debug.el
+++ b/elisp/geiser-debug.el
@@ -91,28 +91,36 @@
(insert "In expression:\n"))
(insert (format "%s%s\n" (make-string offset ?\ ) description))))
-(defun geiser-debug--send-region (compile start end and-go)
+(defsubst geiser-debug--wrap-region (str)
+ (format "(begin %s)" str))
+
+(defun geiser-debug--unwrap (str)
+ (if (string-match "(begin[ \t\n\v\r]+\\(.+\\)*)" str)
+ (match-string 1 str)
+ str))
+
+(defun geiser-debug--send-region (compile start end and-go wrap)
(let* ((str (buffer-substring-no-properties start end))
- (code `(,(if compile :comp :eval) (:scm ,str)))
+ (wrapped (if wrap (geiser-debug--wrap-region str) str))
+ (code `(,(if compile :comp :eval) (:scm ,wrapped)))
(ret (geiser-eval--send/wait code))
(err (geiser-eval--retort-error ret)))
- (when and-go
- (switch-to-geiser)
- (push-mark)
- (goto-char (point-max)))
+ (when and-go (funcall and-go))
(when (not err) (message (format "=> %s" (geiser-eval--retort-result ret))))
(geiser-debug--display-retort str ret)))
-(defun geiser-debug--expand-region (start end all)
+(defun geiser-debug--expand-region (start end all wrap)
(let* ((str (buffer-substring-no-properties start end))
- (code `(:eval ((:ge macroexpand) (quote (:scm ,str)) ,(if all :t :f))))
+ (wrapped (if wrap (geiser-debug--wrap-region str) str))
+ (code `(:eval ((:ge macroexpand) (quote (:scm ,wrapped)) ,(if all :t :f))))
(ret (geiser-eval--send/wait code))
- (err (geiser-eval--retort-error ret)))
+ (err (geiser-eval--retort-error ret))
+ (result (geiser-eval--retort-result ret)))
(if err
(geiser-debug--display-retort str ret)
(geiser-debug--with-buffer
(erase-buffer)
- (insert (format "%s" (geiser-eval--retort-result ret)))
+ (insert (format "%s" (if wrap (geiser-debug--unwrap result) result)))
(goto-char (point-min)))
(geiser-debug--pop-to-buffer))))
diff --git a/elisp/geiser-mode.el b/elisp/geiser-mode.el
index d63d43a..045f5a9 100644
--- a/elisp/geiser-mode.el
+++ b/elisp/geiser-mode.el
@@ -61,12 +61,21 @@
;;; Evaluation commands:
-(defun geiser-eval-region (start end &optional and-go)
+(defun geiser--go-to-repl ()
+ (switch-to-geiser)
+ (push-mark)
+ (goto-char (point-max)))
+
+(defun geiser-eval-region (start end &optional and-go raw)
"Eval the current region in the Geiser REPL.
With prefix, goes to the REPL buffer afterwards (as
`geiser-eval-region-and-go')"
(interactive "rP")
- (geiser-debug--send-region nil start end and-go))
+ (geiser-debug--send-region nil
+ start
+ end
+ (and and-go 'geiser-go-to-repl)
+ (not raw)))
(defun geiser-eval-region-and-go (start end)
"Eval the current region in the Geiser REPL and visit it afterwads."
@@ -82,7 +91,7 @@ With prefix, goes to the REPL buffer afterwards (as
(end-of-defun)
(let ((end (point)))
(beginning-of-defun)
- (geiser-eval-region (point) end and-go))))
+ (geiser-eval-region (point) end and-go t))))
(defun geiser-eval-definition-and-go ()
"Eval the current definition in the Geiser REPL and visit it afterwads."
@@ -92,7 +101,10 @@ With prefix, goes to the REPL buffer afterwards (as
(defun geiser-eval-last-sexp ()
"Eval the previous sexp in the Geiser REPL."
(interactive)
- (geiser-eval-region (save-excursion (backward-sexp) (point)) (point)))
+ (geiser-eval-region (save-excursion (backward-sexp) (point))
+ (point)
+ nil
+ t))
(defun geiser-compile-definition (&optional and-go)
"Compile the current definition in the Geiser REPL.
@@ -103,18 +115,18 @@ With prefix, goes to the REPL buffer afterwards (as
(end-of-defun)
(let ((end (point)))
(beginning-of-defun)
- (geiser-debug--send-region t (point) end and-go))))
+ (geiser-debug--send-region t (point) end and-go t))))
(defun geiser-compile-definition-and-go ()
"Compile the current definition in the Geiser REPL and visit it afterwads."
(interactive)
(geiser-compile-definition t))
-(defun geiser-expand-region (start end &optional all)
+(defun geiser-expand-region (start end &optional all raw)
"Macro-expand the current region and display it in a buffer.
With prefix, recursively macro-expand the resulting expression."
(interactive "rP")
- (geiser-debug--expand-region start end all))
+ (geiser-debug--expand-region start end all (not raw)))
(defun geiser-expand-definition (&optional all)
"Macro-expand the current definition.
@@ -124,13 +136,16 @@ With prefix, recursively macro-expand the resulting expression."
(end-of-defun)
(let ((end (point)))
(beginning-of-defun)
- (geiser-expand-region (point) end all))))
+ (geiser-expand-region (point) end all t))))
(defun geiser-expand-last-sexp (&optional all)
"Macro-expand the previous sexp.
With prefix, recursively macro-expand the resulting expression."
(interactive "P")
- (geiser-expand-region (save-excursion (backward-sexp) (point)) (point) all))
+ (geiser-expand-region (save-excursion (backward-sexp) (point))
+ (point)
+ all
+ t))
(defun geiser-set-scheme ()
"Associates current buffer with a given Scheme implementation."