From cb6dbc1528f332abde8569dc5f9bda20f8137d7f Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Sun, 1 Mar 2009 20:40:22 +0100 Subject: Macro-expand commands. --- elisp/geiser-debug.el | 13 +++++++++++++ elisp/geiser-mode.el | 27 +++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) (limited to 'elisp') 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) -- cgit v1.2.3