unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] pp-macroexpand-last-sexp (resend)
@ 2007-11-30 12:48 Johannes Weiner
  0 siblings, 0 replies; only message in thread
From: Johannes Weiner @ 2007-11-30 12:48 UTC (permalink / raw)
  To: emacs-devel; +Cc: Randal Schwartz

Hi,

some months ago I already sent this in but did not get any feedback so
far, so here it is again.  Original author of pp.el CC'd.

This patch extend pp.el to support pretty prenting of macroexpanded
expressions.

With pp-macroexpand-last-sexp bound to a key, you can have a
pretty-printed macroexpansion of an expression you are editing at an
instant!

I am bad at advertising.  Here's the code :)

	Hannes

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 01af702..989f875 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,12 @@
+2007-11-30  Johannes Weiner <hannes@saeurebad.de>
+
+	* emacs-lisp/pp.el (pp-display-expression)
+	(pp-macroexpand-expression, pp-macroexpand-last-sexp) New
+	functions.
+	(pp-eval-expression): Use pp-display-expression.
+	(pp-last-sexp): Remove direct pretty-printing, just return sexp.
+	(pp-eval-last-sexp): Use pp-last-sexp and pp-eval-expression.
+
 2007-11-30  Martin Rudalics  <rudalics@gmx.at>
 
 	* longlines.el (longlines-show-hard-newlines): Remove handling of
diff --git a/lisp/emacs-lisp/pp.el b/lisp/emacs-lisp/pp.el
index a5cefff..ab8b037 100644
--- a/lisp/emacs-lisp/pp.el
+++ b/lisp/emacs-lisp/pp.el
@@ -97,14 +97,10 @@ Output stream is STREAM, or value of `standard-output' (which see)."
   (princ (pp-to-string object) (or stream standard-output)))
 
 ;;;###autoload
-(defun pp-eval-expression (expression)
-  "Evaluate EXPRESSION and pretty-print its value.
-Also add the value to the front of the list in the variable `values'."
-  (interactive
-   (list (read-from-minibuffer "Eval: " nil read-expression-map t
-			       'read-expression-history)))
-  (message "Evaluating...")
-  (setq values (cons (eval expression) values))
+(defun pp-display-expression (expression out-buffer-name)
+  "Prettify and display EXPRESSION in an appropriate way,
+depending on its printed length.  If a temporary buffer is needed
+for representation, it will be named after OUT-BUFFER-NAME."
   (let* ((old-show-function temp-buffer-show-function)
 	 ;; Use this function to display the buffer.
 	 ;; This function either decides not to display it at all
@@ -128,23 +124,37 @@ Also add the value to the front of the list in the variable `values'."
 			   (select-window window)
 			   (run-hooks 'temp-buffer-show-hook))
 		       (select-window old-selected)
-		       (message "Evaluating...done.  \
-See buffer *Pp Eval Output*.")))
+		       (message "See buffer %s." out-buffer-name)))
 		 (message "%s" (buffer-substring (point-min) (point)))
 		 ))))))
-    (with-output-to-temp-buffer "*Pp Eval Output*"
-      (pp (car values))
+    (with-output-to-temp-buffer out-buffer-name
+      (pp expression)
       (with-current-buffer standard-output
 	(emacs-lisp-mode)
 	(setq buffer-read-only nil)
 	(set (make-local-variable 'font-lock-verbose) nil)))))
 
 ;;;###autoload
-(defun pp-eval-last-sexp (arg)
-  "Run `pp-eval-expression' on sexp before point (which see).
-With argument, pretty-print output into current buffer.
-Ignores leading comment characters."
-  (interactive "P")
+(defun pp-eval-expression (expression)
+  "Evaluate EXPRESSION and pretty-print its value.
+Also add the value to the front of the list in the variable `values'."
+  (interactive
+   (list (read-from-minibuffer "Eval: " nil read-expression-map t
+			       'read-expression-history)))
+  (message "Evaluating...")
+  (setq values (cons (eval expression) values))
+  (pp-display-expression (car values) "*Pp Eval Output*"))
+
+;;;###autoload
+(defun pp-macroexpand-expression (expression)
+  "Macroexpand EXPRESSION and pretty-print its value."
+  (interactive
+   (list (read-from-minibuffer "Macroexpand: " nil read-expression-map t
+			       'read-expression-history)))
+  (pp-display-expression (macroexpand expression) "*Pp Macroexpand Output*"))
+
+(defun pp-last-sexp ()
+  "Read sexp before point.  Ignores leading comment characters."
   (let ((stab (syntax-table)) (pt (point)) start exp)
     (set-syntax-table emacs-lisp-mode-syntax-table)
     (save-excursion
@@ -160,9 +170,27 @@ Ignores leading comment characters."
 	    (setq exp (read exp)))
 	(setq exp (read (current-buffer)))))
     (set-syntax-table stab)
-    (if arg
-	(insert (pp-to-string (eval exp)))
-      (pp-eval-expression exp))))
+    exp))
+
+;;;###autoload
+(defun pp-eval-last-sexp (arg)
+  "Run `pp-eval-expression' on sexp before point (which see).
+With argument, pretty-print output into current buffer.
+Ignores leading comment characters."
+  (interactive "P")
+  (if arg
+      (insert (pp-to-string (eval (pp-last-sexp))))
+    (pp-eval-expression (pp-last-sexp))))
+
+;;;###autoload
+(defun pp-macroexpand-last-sexp (arg)
+  "Run `pp-macroexpand-expression' on sexp before point (which see).
+With argument, pretty-print output into current buffer.
+Ignores leading comment characters."
+  (interactive "P")
+  (if arg
+      (insert (pp-to-string (macroexpand (pp-last-sexp))))
+    (pp-macroexpand-expression (pp-last-sexp))))
 
 ;;; Test cases for quote
 ;; (pp-eval-expression ''(quote quote))

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2007-11-30 12:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-30 12:48 [PATCH] pp-macroexpand-last-sexp (resend) Johannes Weiner

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).