summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2009-03-01 20:40:22 +0100
committerJose Antonio Ortega Ruiz <jao@gnu.org>2009-03-01 20:40:22 +0100
commit28e79842fd87689187834a2c4186b5e2ac294fe6 (patch)
tree6ef1349dea39bb9688c7a4a2e95969ef7fece7c9
parentc5d4a2b6670a9f3ce8b357ef5f4cab72eb211102 (diff)
downloadgeiser-chez-28e79842fd87689187834a2c4186b5e2ac294fe6.tar.gz
geiser-chez-28e79842fd87689187834a2c4186b5e2ac294fe6.tar.bz2
Macro-expand commands.
-rw-r--r--README55
-rw-r--r--elisp/geiser-debug.el13
-rw-r--r--elisp/geiser-mode.el27
-rw-r--r--scheme/guile/geiser/emacs.scm5
4 files changed, 72 insertions, 28 deletions
diff --git a/README b/README
index 18e59c6..0300dfa 100644
--- a/README
+++ b/README
@@ -17,31 +17,36 @@
*** In Scheme buffers:
- |---------+-------------------------------------------------|
- | C-cC-z | Switch to REPL |
- |---------+-------------------------------------------------|
- | M-. | Edit symbol at point |
- | M-, | Go back to where M-. was last invoked |
- | C-cC-em | Ask for a module and open its file |
- |---------+-------------------------------------------------|
- | C-M-x | Eval definition around point |
- | C-cM-e | Eval definition around point and switch to REPL |
- | C-xC-e | Eval sexp before point |
- | C-cC-r | Eval region |
- | C-cM-r | Eval region and switch to REPL |
- |---------+-------------------------------------------------|
- | C-cC-k | Compile and load current file |
- | C-cC-l | Load current file |
- |---------+-------------------------------------------------|
- | C-cC-dd | See documentation for symbol at point |
- | C-cC-dm | See module documentation |
- | C-cC-da | Toggle autodoc mode |
- |---------+-------------------------------------------------|
- | M-TAB | Complete symbol at point |
- | C-. | Complete module name at point |
- | TAB | Complete symbol at point or indent |
- | | (If `geiser-mode-smart-tab-p' is t) |
- |---------+-------------------------------------------------|
+ |------------------+-------------------------------------------------|
+ | C-cC-z | Switch to REPL |
+ |------------------+-------------------------------------------------|
+ | M-. | Edit symbol at point |
+ | M-, | Go back to where M-. was last invoked |
+ | C-cC-em | Ask for a module and open its file |
+ |------------------+-------------------------------------------------|
+ | C-M-x | Eval definition around point |
+ | C-cM-e | Eval definition around point and switch to REPL |
+ | C-xC-e | Eval sexp before point |
+ | C-cC-r | Eval region |
+ | C-cM-r | Eval region and switch to REPL |
+ |------------------+-------------------------------------------------|
+ | C-cC-xx | Macro-expand definition around point |
+ | C-cC-xe | Macro-expand sexp before point |
+ | C-cC-xr | Marcro-expand region |
+ | C-uC-cC-x[x,e,r] | (With prefix, macro expansions are recursive) |
+ |------------------+-------------------------------------------------|
+ | C-cC-k | Compile and load current file |
+ | C-cC-l | Load current file |
+ |------------------+-------------------------------------------------|
+ | C-cC-dd | See documentation for symbol at point |
+ | C-cC-dm | See module documentation |
+ | C-cC-da | Toggle autodoc mode |
+ |------------------+-------------------------------------------------|
+ | M-TAB | Complete symbol at point |
+ | C-. | Complete module name at point |
+ | TAB | Complete symbol at point or indent |
+ | | (If `geiser-mode-smart-tab-p' is t) |
+ |------------------+-------------------------------------------------|
*** In the REPL
diff --git a/elisp/geiser-debug.el b/elisp/geiser-debug.el
index 6393e7e..0bc3f85 100644
--- a/elisp/geiser-debug.el
+++ b/elisp/geiser-debug.el
@@ -106,6 +106,19 @@
(message (format "=> %s" (geiser-eval--retort-result ret)))
(geiser-debug--display-retort str ret))))
+(defun geiser-debug--expand-region (start end all)
+ (let* ((str (buffer-substring-no-properties start end))
+ (code `(:eval ((:ge macroexpand) (quote (:scm ,str)) ,(if all :t :f))))
+ (ret (geiser-eval--send/wait code))
+ (err (geiser-eval--retort-error ret)))
+ (if err
+ (geiser-debug--display-retort str ret)
+ (geiser-debug--with-buffer
+ (erase-buffer)
+ (insert (format "%s" (geiser-eval--retort-result ret)))
+ (goto-char (point-min)))
+ (geiser-debug--pop-to-buffer))))
+
(provide 'geiser-debug)
;;; geiser-debug.el ends here
diff --git a/elisp/geiser-mode.el b/elisp/geiser-mode.el
index fbbcff4..6a3df40 100644
--- a/elisp/geiser-mode.el
+++ b/elisp/geiser-mode.el
@@ -108,6 +108,28 @@ With prefix, goes to the REPL buffer afterwards (as
(interactive)
(geiser-compile-definition t))
+(defun geiser-expand-region (start end &optional all)
+ "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))
+
+(defun geiser-expand-definition (&optional all)
+ "Macro-expand the current definition.
+With prefix, recursively macro-expand the resulting expression."
+ (interactive "P")
+ (save-excursion
+ (end-of-defun)
+ (let ((end (point)))
+ (beginning-of-defun)
+ (geiser-expand-region (point) end all))))
+
+(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 mode:
@@ -166,8 +188,9 @@ interacting with the Geiser REPL is at your disposal.
(geiser-mode--triple-chord ?e ?m 'geiser-edit-module)
-(define-key geiser-mode-map "\C-c\C-t" 'geiser-trace-procedure)
-(define-key geiser-mode-map "\C-c\C-x" 'geiser-expand-current-form)
+(geiser-mode--triple-chord ?x ?e 'geiser-expand-last-sexp)
+(geiser-mode--triple-chord ?x ?r 'geiser-expand-region)
+(geiser-mode--triple-chord ?x ?x 'geiser-expand-definition)
(provide 'geiser-mode)
diff --git a/scheme/guile/geiser/emacs.scm b/scheme/guile/geiser/emacs.scm
index 66320ec..f2f3d45 100644
--- a/scheme/guile/geiser/emacs.scm
+++ b/scheme/guile/geiser/emacs.scm
@@ -41,6 +41,7 @@
#:use-module (system base compile)
#:use-module (system vm program)
#:use-module (ice-9 debugger utils)
+ #:use-module (ice-9 pretty-print)
#:use-module ((geiser introspection) :renamer (symbol-prefix-proc 'ge:)))
(define (make-result result output)
@@ -144,6 +145,8 @@
(define (ge:macroexpand form . all)
(let ((all (and (not (null? all)) (car all))))
- ((if all macroexpand macroexpand-1) form)))
+ (with-output-to-string
+ (lambda ()
+ (pretty-print ((if all macroexpand macroexpand-1) form))))))
;;; emacs.scm ends here