all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] Extract last-sexp from eval-last-sexp-1
@ 2007-08-19 22:08 Johannes Weiner
  2007-08-20  1:31 ` [PATCH] Interactive macro expansion added Johannes Weiner
  0 siblings, 1 reply; 10+ messages in thread
From: Johannes Weiner @ 2007-08-19 22:08 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 290 bytes --]

Hi Emacs-hackers,

here is a patch that extracts last-sexp from already existing code so that one
can use last-sexp for other purposes too.

Note: I ripped out the let-binding of `stap' in the original code because it
looked stale. Please correct me if I am wrong.

Thank you all!

	Hannes

[-- Attachment #2: emacs-extract-last-sexp.patch --]
[-- Type: text/x-diff, Size: 3937 bytes --]

diff -Naur emacs.orig/lisp/emacs-lisp/lisp-mode.el emacs/lisp/emacs-lisp/lisp-mode.el
--- emacs.orig/lisp/emacs-lisp/lisp-mode.el	2007-08-20 00:00:43.000000000 +0200
+++ emacs/lisp/emacs-lisp/lisp-mode.el	2007-08-20 00:00:58.000000000 +0200
@@ -538,63 +538,63 @@
 	      (= (car (read-from-string string)) char)
 	      string))))
 
+(defun last-sexp ()
+  "Return sexp before the point."
+  (let ((opoint (point))
+	ignore-quotes
+	expr)
+    (save-excursion
+      (with-syntax-table emacs-lisp-mode-syntax-table
+	;; If this sexp appears to be enclosed in `...'
+	;; then ignore the surrounding quotes.
+	(setq ignore-quotes
+	      (or (eq (following-char) ?\')
+		  (eq (preceding-char) ?\')))
+	(forward-sexp -1)
+	;; If we were after `?\e' (or similar case),
+	;; use the whole thing, not just the `e'.
+	(when (eq (preceding-char) ?\\)
+	  (forward-char -1)
+	  (when (eq (preceding-char) ??)
+	    (forward-char -1)))
+	
+	;; Skip over `#N='s.
+	(when (eq (preceding-char) ?=)
+	  (let (labeled-p)
+	    (save-excursion
+	      (skip-chars-backward "0-9#=")
+	      (setq labeled-p (looking-at "\\(#[0-9]+=\\)+")))
+	    (when labeled-p
+	      (forward-sexp -1))))
+	
+	(save-restriction
+	  ;; vladimir@cs.ualberta.ca 30-Jul-1997: skip ` in
+	  ;; `variable' so that the value is returned, not the
+	  ;; name
+	  (if (and ignore-quotes
+		   (eq (following-char) ?`))
+	      (forward-char))
+	  (narrow-to-region (point-min) opoint)
+	  (setq expr (read (current-buffer)))
+	  ;; If it's an (interactive ...) form, it's more
+	  ;; useful to show how an interactive call would
+	  ;; use it.
+	  (and (consp expr)
+	       (eq (car expr) 'interactive)
+	       (setq expr
+		     (list 'call-interactively
+			   (list 'quote
+				 (list 'lambda
+				       '(&rest args)
+				       expr
+				       'args)))))
+	  expr)))))
 
 (defun eval-last-sexp-1 (eval-last-sexp-arg-internal)
   "Evaluate sexp before point; print value in minibuffer.
 With argument, print output into current buffer."
   (let ((standard-output (if eval-last-sexp-arg-internal (current-buffer) t)))
-    (let ((value
-	   (eval (let ((stab (syntax-table))
-		       (opoint (point))
-		       ignore-quotes
-		       expr)
-		   (save-excursion
-		     (with-syntax-table emacs-lisp-mode-syntax-table
-		       ;; If this sexp appears to be enclosed in `...'
-		       ;; then ignore the surrounding quotes.
-		       (setq ignore-quotes
-			     (or (eq (following-char) ?\')
-				 (eq (preceding-char) ?\')))
-		       (forward-sexp -1)
-		       ;; If we were after `?\e' (or similar case),
-		       ;; use the whole thing, not just the `e'.
-		       (when (eq (preceding-char) ?\\)
-			 (forward-char -1)
-			 (when (eq (preceding-char) ??)
-			   (forward-char -1)))
-
-		       ;; Skip over `#N='s.
-		       (when (eq (preceding-char) ?=)
-			 (let (labeled-p)
-			   (save-excursion
-			     (skip-chars-backward "0-9#=")
-			     (setq labeled-p (looking-at "\\(#[0-9]+=\\)+")))
-			   (when labeled-p
-			     (forward-sexp -1))))
-
-		       (save-restriction
-			 ;; vladimir@cs.ualberta.ca 30-Jul-1997: skip ` in
-			 ;; `variable' so that the value is returned, not the
-			 ;; name
-			 (if (and ignore-quotes
-				  (eq (following-char) ?`))
-			     (forward-char))
-			 (narrow-to-region (point-min) opoint)
-			 (setq expr (read (current-buffer)))
-			 ;; If it's an (interactive ...) form, it's more
-			 ;; useful to show how an interactive call would
-			 ;; use it.
-			 (and (consp expr)
-			      (eq (car expr) 'interactive)
-			      (setq expr
-				    (list 'call-interactively
-					  (list 'quote
-						(list 'lambda
-						      '(&rest args)
-						      expr
-						      'args)))))
-			 expr)))))))
-      (eval-last-sexp-print-value value))))
+    (eval-last-sexp-print-value (eval (last-sexp)))))
 
 (defun eval-last-sexp-print-value (value)
   (let ((unabbreviated (let ((print-length nil) (print-level nil))

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Interactive macro expansion added
  2007-08-19 22:08 [PATCH] Extract last-sexp from eval-last-sexp-1 Johannes Weiner
@ 2007-08-20  1:31 ` Johannes Weiner
  2007-08-20 15:25   ` [PATCH] pp-macroexpansion Johannes Weiner
  2007-08-20 18:30   ` [PATCH] Interactive macro expansion added Richard Stallman
  0 siblings, 2 replies; 10+ messages in thread
From: Johannes Weiner @ 2007-08-20  1:31 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 706 bytes --]

Hi,

On Mon, Aug 20, 2007 at 12:08:06AM +0200, Johannes Weiner wrote:
> Hi Emacs-hackers,
> 
> here is a patch that extracts last-sexp from already existing code so that one
> can use last-sexp for other purposes too.

My real goals where of course, interactive macro expansion while editing lisp
code. So I implemented that also.  The result is now a more generalized
operation functionality on the sexp before point.

I promise to write documentation for the rest of the new functions if the
actual code is agreed upon.

> Note: I ripped out the let-binding of `stap' in the original code because it
> looked stale. Please correct me if I am wrong.

The old patch is superseeded by the new one.

	Hannes

[-- Attachment #2: emacs-lisp-mode-interactive-macroexpand.patch --]
[-- Type: text/x-diff, Size: 7829 bytes --]

diff -Naur emacs.orig/lisp/emacs-lisp/lisp-mode.el emacs/lisp/emacs-lisp/lisp-mode.el
--- emacs.orig/lisp/emacs-lisp/lisp-mode.el	2007-08-20 00:00:43.000000000 +0200
+++ emacs/lisp/emacs-lisp/lisp-mode.el	2007-08-20 03:18:27.000000000 +0200
@@ -444,6 +444,23 @@
 Entry to this mode calls the value of `lisp-interaction-mode-hook'
 if that value is non-nil.")
 
+(defun eval-last-sexp-and-print-1 (&optional expand-only)
+  "Evaluates or expands sexp before point, depending on `expand-only'.
+The value is printed into the current buffer.
+
+If `eval-expression-debug-on-error' is non-nil, which is the
+default, this command arranges for all errors to enter the
+debugger.
+
+Note that printing the result is controlled by the variables
+`eval-expression-print-length' and `eval-expression-print-level'."
+  (let ((standard-output (current-buffer)))
+    (terpri)
+    (if expand-only
+	(macroexpand-last-sexp t)
+      (eval-last-sexp t))
+    (terpri)))
+
 (defun eval-print-last-sexp ()
   "Evaluate sexp before point; print value into current buffer.
 
@@ -454,11 +471,19 @@
 `eval-expression-print-length' and `eval-expression-print-level',
 which see."
   (interactive)
-  (let ((standard-output (current-buffer)))
-    (terpri)
-    (eval-last-sexp t)
-    (terpri)))
+  (eval-last-sexp-and-print-1))
 
+(defun macroexpand-print-last-sexp ()
+  "Macroexpand sexp before point; print value into current buffer.
+
+If `eval-expression-debug-on-error' is non-nil, which is the
+default, this command arranges for all errors to enter the
+debugger.
+
+Note that printing the result is controlled by the variables
+`eval-expression-print-length' and `eval-expression-print-level'."
+  (interactive)
+  (eval-last-sexp-and-print-1 t))
 
 (defun last-sexp-setup-props (beg end value alt1 alt2)
   "Set up text properties for the output of `eval-last-sexp-1'.
@@ -538,65 +563,59 @@
 	      (= (car (read-from-string string)) char)
 	      string))))
 
+(defun last-sexp ()
+  "Return sexp before the point."
+  (let ((opoint (point))
+	ignore-quotes
+	expr)
+    (save-excursion
+      (with-syntax-table emacs-lisp-mode-syntax-table
+	;; If this sexp appears to be enclosed in `...'
+	;; then ignore the surrounding quotes.
+	(setq ignore-quotes
+	      (or (eq (following-char) ?\')
+		  (eq (preceding-char) ?\')))
+	(forward-sexp -1)
+	;; If we were after `?\e' (or similar case),
+	;; use the whole thing, not just the `e'.
+	(when (eq (preceding-char) ?\\)
+	  (forward-char -1)
+	  (when (eq (preceding-char) ??)
+	    (forward-char -1)))
+	
+	;; Skip over `#N='s.
+	(when (eq (preceding-char) ?=)
+	  (let (labeled-p)
+	    (save-excursion
+	      (skip-chars-backward "0-9#=")
+	      (setq labeled-p (looking-at "\\(#[0-9]+=\\)+")))
+	    (when labeled-p
+	      (forward-sexp -1))))
+	
+	(save-restriction
+	  ;; vladimir@cs.ualberta.ca 30-Jul-1997: skip ` in
+	  ;; `variable' so that the value is returned, not the
+	  ;; name
+	  (if (and ignore-quotes
+		   (eq (following-char) ?`))
+	      (forward-char))
+	  (narrow-to-region (point-min) opoint)
+	  (setq expr (read (current-buffer)))
+	  ;; If it's an (interactive ...) form, it's more
+	  ;; useful to show how an interactive call would
+	  ;; use it.
+	  (and (consp expr)
+	       (eq (car expr) 'interactive)
+	       (setq expr
+		     (list 'call-interactively
+			   (list 'quote
+				 (list 'lambda
+				       '(&rest args)
+				       expr
+				       'args)))))
+	  expr)))))
 
-(defun eval-last-sexp-1 (eval-last-sexp-arg-internal)
-  "Evaluate sexp before point; print value in minibuffer.
-With argument, print output into current buffer."
-  (let ((standard-output (if eval-last-sexp-arg-internal (current-buffer) t)))
-    (let ((value
-	   (eval (let ((stab (syntax-table))
-		       (opoint (point))
-		       ignore-quotes
-		       expr)
-		   (save-excursion
-		     (with-syntax-table emacs-lisp-mode-syntax-table
-		       ;; If this sexp appears to be enclosed in `...'
-		       ;; then ignore the surrounding quotes.
-		       (setq ignore-quotes
-			     (or (eq (following-char) ?\')
-				 (eq (preceding-char) ?\')))
-		       (forward-sexp -1)
-		       ;; If we were after `?\e' (or similar case),
-		       ;; use the whole thing, not just the `e'.
-		       (when (eq (preceding-char) ?\\)
-			 (forward-char -1)
-			 (when (eq (preceding-char) ??)
-			   (forward-char -1)))
-
-		       ;; Skip over `#N='s.
-		       (when (eq (preceding-char) ?=)
-			 (let (labeled-p)
-			   (save-excursion
-			     (skip-chars-backward "0-9#=")
-			     (setq labeled-p (looking-at "\\(#[0-9]+=\\)+")))
-			   (when labeled-p
-			     (forward-sexp -1))))
-
-		       (save-restriction
-			 ;; vladimir@cs.ualberta.ca 30-Jul-1997: skip ` in
-			 ;; `variable' so that the value is returned, not the
-			 ;; name
-			 (if (and ignore-quotes
-				  (eq (following-char) ?`))
-			     (forward-char))
-			 (narrow-to-region (point-min) opoint)
-			 (setq expr (read (current-buffer)))
-			 ;; If it's an (interactive ...) form, it's more
-			 ;; useful to show how an interactive call would
-			 ;; use it.
-			 (and (consp expr)
-			      (eq (car expr) 'interactive)
-			      (setq expr
-				    (list 'call-interactively
-					  (list 'quote
-						(list 'lambda
-						      '(&rest args)
-						      expr
-						      'args)))))
-			 expr)))))))
-      (eval-last-sexp-print-value value))))
-
-(defun eval-last-sexp-print-value (value)
+(defun operate-on-last-sexp-print-value (value)
   (let ((unabbreviated (let ((print-length nil) (print-level nil))
 			 (prin1-to-string value)))
 	(print-length eval-expression-print-length)
@@ -618,8 +637,25 @@
 			       (buffer-substring-no-properties beg end))
 	))))
 
+(defun operate-on-last-sexp-1 (operation operate-on-last-sexp-arg-internal)
+  (let ((standard-output (if operate-on-last-sexp-arg-internal
+			     (current-buffer)
+			   t)))
+    (operate-on-last-sexp-print-value (funcall operation (last-sexp)))))
 
-(defvar eval-last-sexp-fake-value (make-symbol "t"))
+(defvar operate-on-last-sexp-fake-value (make-symbol "t"))
+
+(defun operate-on-last-sexp (operation operate-on-last-sexp-arg-internal)
+  (if (null eval-expression-debug-on-error)
+      (operate-on-last-sexp-1 operation operate-on-last-sexp-arg-internal)
+    (let ((value
+	   (let ((debug-on-error operate-on-last-sexp-fake-value))
+	     (cons (operate-on-last-sexp-1 operation
+					   operate-on-last-sexp-arg-internal)
+		   debug-on-error))))
+      (unless (eq (cdr value) operate-on-last-sexp-fake-value)
+	(setq debug-on-error (cdr value)))
+      (car value))))
 
 (defun eval-last-sexp (eval-last-sexp-arg-internal)
   "Evaluate sexp before point; print value in minibuffer.
@@ -628,15 +664,16 @@
 If `eval-expression-debug-on-error' is non-nil, which is the default,
 this command arranges for all errors to enter the debugger."
   (interactive "P")
-  (if (null eval-expression-debug-on-error)
-      (eval-last-sexp-1 eval-last-sexp-arg-internal)
-    (let ((value
-	   (let ((debug-on-error eval-last-sexp-fake-value))
-	     (cons (eval-last-sexp-1 eval-last-sexp-arg-internal)
-		   debug-on-error))))
-      (unless (eq (cdr value) eval-last-sexp-fake-value)
-	(setq debug-on-error (cdr value)))
-      (car value))))
+  (operate-on-last-sexp 'eval eval-last-sexp-arg-internal))
+
+(defun macroexpand-last-sexp (macroexpand-last-sexp-arg-internal)
+  "Macroexpand sexp before point; print expansion in minibuffer.
+Interactively, with prefix argument, print expansion into current buffer.
+
+If `eval-expression-debug-on-error' is non-nil, which is the default,
+this command arranges for all errors to enter the debugger."
+  (interactive "P")
+  (operate-on-last-sexp 'macroexpand macroexpand-last-sexp-arg-internal))
 
 (defun eval-defun-1 (form)
   "Treat some expressions specially.

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH] pp-macroexpansion
  2007-08-20  1:31 ` [PATCH] Interactive macro expansion added Johannes Weiner
@ 2007-08-20 15:25   ` Johannes Weiner
  2007-08-20 18:30   ` [PATCH] Interactive macro expansion added Richard Stallman
  1 sibling, 0 replies; 10+ messages in thread
From: Johannes Weiner @ 2007-08-20 15:25 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 849 bytes --]

Hi again,

On Mon, Aug 20, 2007 at 03:31:26AM +0200, Johannes Weiner wrote:
> > here is a patch that extracts last-sexp from already existing code so that one
> > can use last-sexp for other purposes too.
> 
> My real goals where of course, interactive macro expansion while editing lisp
> code. So I implemented that also.  The result is now a more generalized
> operation functionality on the sexp before point.
 
I realized now that macroexpansion really should not be done without
pretty-printing, the resulting forms are unreadable when they are more than
just a setf -> setq expansion.

So please forget about the above patches, here is one that extends the code in
pp.el by `pp-macroexpand-expression' and `pp-macroexpand-last-sexp'.
The code is now a lot shorter, more readable and the results more usable.

Diff attached, have fun!
	Hannes

[-- Attachment #2: emacs-pp-macroexpand-last-sexp.patch --]
[-- Type: text/x-diff, Size: 3907 bytes --]

diff -Naur emacs.orig/lisp/emacs-lisp/pp.el emacs/lisp/emacs-lisp/pp.el
--- emacs.orig/lisp/emacs-lisp/pp.el	2007-08-20 16:51:28.000000000 +0200
+++ emacs/lisp/emacs-lisp/pp.el	2007-08-20 17:18:48.000000000 +0200
@@ -97,14 +97,10 @@
   (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 @@
 			   (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 @@
 	    (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))

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Interactive macro expansion added
  2007-08-20  1:31 ` [PATCH] Interactive macro expansion added Johannes Weiner
  2007-08-20 15:25   ` [PATCH] pp-macroexpansion Johannes Weiner
@ 2007-08-20 18:30   ` Richard Stallman
  2007-09-09  0:50     ` Johannes Weiner
  1 sibling, 1 reply; 10+ messages in thread
From: Richard Stallman @ 2007-08-20 18:30 UTC (permalink / raw)
  To: Johannes Weiner; +Cc: emacs-devel

This is a much bigger patch, and we would need legal papers before we
could install it.  I will send you another msg to ask for them.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Interactive macro expansion added
  2007-08-20 18:30   ` [PATCH] Interactive macro expansion added Richard Stallman
@ 2007-09-09  0:50     ` Johannes Weiner
  2007-09-09 20:06       ` Richard Stallman
  0 siblings, 1 reply; 10+ messages in thread
From: Johannes Weiner @ 2007-09-09  0:50 UTC (permalink / raw)
  To: Richard Stallman; +Cc: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 347 bytes --]

Hi,

On Mon, Aug 20, 2007 at 02:30:46PM -0400, Richard Stallman wrote:
> This is a much bigger patch, and we would need legal papers before we
> could install it.  I will send you another msg to ask for them.

My legal papers arrived. The browse-url patch for elinks support already got
in.  Can this patch get merged now too?

Thank you,
	Hannes

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Interactive macro expansion added
  2007-09-09  0:50     ` Johannes Weiner
@ 2007-09-09 20:06       ` Richard Stallman
  2007-09-10  0:46         ` Johannes Weiner
  0 siblings, 1 reply; 10+ messages in thread
From: Richard Stallman @ 2007-09-09 20:06 UTC (permalink / raw)
  To: Johannes Weiner; +Cc: emacs-devel

    My legal papers arrived. The browse-url patch for elinks support already got
    in.  Can this patch get merged now too?

Please send your patch and its change log entry again,
plus NEWS entry if it needs one, and we can install it.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Interactive macro expansion added
  2007-09-09 20:06       ` Richard Stallman
@ 2007-09-10  0:46         ` Johannes Weiner
  2007-09-10 16:53           ` Richard Stallman
  2007-09-10 18:55           ` David Hansen
  0 siblings, 2 replies; 10+ messages in thread
From: Johannes Weiner @ 2007-09-10  0:46 UTC (permalink / raw)
  To: Richard Stallman; +Cc: emacs-devel


[-- Attachment #1.1.1: Type: text/plain, Size: 372 bytes --]

Hi,

On Sun, Sep 09, 2007 at 04:06:17PM -0400, Richard Stallman wrote:
>     My legal papers arrived. The browse-url patch for elinks support already got
>     in.  Can this patch get merged now too?
> 
> Please send your patch and its change log entry again,
> plus NEWS entry if it needs one, and we can install it.

Alright, unified diff attached.

	Hannes

[-- Attachment #1.1.2: emacs-pp-macroexpand-last-sexp-r1.patch --]
[-- Type: text/x-diff, Size: 5484 bytes --]

diff -Naur emacs.orig/etc/NEWS emacs/etc/NEWS
--- emacs.orig/etc/NEWS	2007-09-10 02:29:43.000000000 +0200
+++ emacs/etc/NEWS	2007-09-10 02:44:36.000000000 +0200
@@ -181,6 +181,9 @@
 
 *** The variable `fortran-line-length' can change the fixed-form line-length.
 
+*** The new command `pp-macroexpand-last-sexp' pretty-prints the
+macroexpansion of the s-expression before point.
+
 ** Miscellaneous
 
 *** comint-mode uses `start-file-process' now (see Lisp Changes).
@@ -319,6 +322,9 @@
 ** The interactive-form of a function can be added post-facto via the
 `interactive-form' symbol property.  Mostly useful to add complex interactive
 forms to subroutines.
+
+** The new function `pp-macroexpand-expression' pretty-prints the
+macroexpansion of an s-expression.
 \f
 * New Packages for Lisp Programming in Emacs 23.1
 
diff -Naur emacs.orig/lisp/ChangeLog emacs/lisp/ChangeLog
--- emacs.orig/lisp/ChangeLog	2007-09-10 02:29:44.000000000 +0200
+++ emacs/lisp/ChangeLog	2007-09-10 02:29:15.000000000 +0200
@@ -1,3 +1,11 @@
+2007-09-10  Johannes Weiner  <hannes@saeurebad.de>
+
+	* emacs-lisp/pp.el (pp-display-expression)
+	(pp-macroexpand-expression, pp-last-sexp)
+	(pp-macroexpand-last-sexp): New functions.
+	(pp-eval-expression): Use extracted pp-display-expression.
+	(pp-eval-last-sexp): Use extracted pp-last-sexp.
+
 2007-09-05  Glenn Morris  <rgm@gnu.org>
 
 	* cus-edit.el (custom-buffer-create-internal): Check tool-bar-mode
diff -Naur emacs.orig/lisp/emacs-lisp/pp.el emacs/lisp/emacs-lisp/pp.el
--- emacs.orig/lisp/emacs-lisp/pp.el	2007-09-10 02:29:44.000000000 +0200
+++ emacs/lisp/emacs-lisp/pp.el	2007-09-10 02:15:27.000000000 +0200
@@ -97,14 +97,10 @@
   (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 @@
 			   (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 @@
 	    (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))

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Interactive macro expansion added
  2007-09-10  0:46         ` Johannes Weiner
@ 2007-09-10 16:53           ` Richard Stallman
  2007-09-10 18:55           ` David Hansen
  1 sibling, 0 replies; 10+ messages in thread
From: Richard Stallman @ 2007-09-10 16:53 UTC (permalink / raw)
  To: Johannes Weiner; +Cc: emacs-devel

People will give feedback on your patch, and if it looks ready
for installation, someone will install it.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Interactive macro expansion added
  2007-09-10  0:46         ` Johannes Weiner
  2007-09-10 16:53           ` Richard Stallman
@ 2007-09-10 18:55           ` David Hansen
  2007-09-11 10:15             ` Johannes Weiner
  1 sibling, 1 reply; 10+ messages in thread
From: David Hansen @ 2007-09-10 18:55 UTC (permalink / raw)
  To: emacs-devel

On Mon, 10 Sep 2007 02:46:32 +0200 Johannes Weiner wrote:

> +*** The new command `pp-macroexpand-last-sexp' pretty-prints the
> +macroexpansion of the s-expression before point.
> +

Some time ago I wrote something similar but the output of the
macroexpansion is displayed in a separate buffer (similar how it works
in the slime package, in case you know it).  If you are interested it's
in the gnu.emacs.sources archive or I can send it / post it here.

David

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Interactive macro expansion added
  2007-09-10 18:55           ` David Hansen
@ 2007-09-11 10:15             ` Johannes Weiner
  0 siblings, 0 replies; 10+ messages in thread
From: Johannes Weiner @ 2007-09-11 10:15 UTC (permalink / raw)
  To: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 738 bytes --]

Hi David,

On Mon, Sep 10, 2007 at 08:55:16PM +0200, David Hansen wrote:
> > +*** The new command `pp-macroexpand-last-sexp' pretty-prints the
> > +macroexpansion of the s-expression before point.
> > +
> 
> Some time ago I wrote something similar but the output of the
> macroexpansion is displayed in a separate buffer (similar how it works
> in the slime package, in case you know it).  If you are interested it's
> in the gnu.emacs.sources archive or I can send it / post it here.

Have a look at pp-display-expression (in the sources with this patch applied)
or at pp-eval-expression in the vanilla sources.  The expansion is printed
into a separate buffer if the expression is too long for the minibuffer.

	Hannes

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2007-09-11 10:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-19 22:08 [PATCH] Extract last-sexp from eval-last-sexp-1 Johannes Weiner
2007-08-20  1:31 ` [PATCH] Interactive macro expansion added Johannes Weiner
2007-08-20 15:25   ` [PATCH] pp-macroexpansion Johannes Weiner
2007-08-20 18:30   ` [PATCH] Interactive macro expansion added Richard Stallman
2007-09-09  0:50     ` Johannes Weiner
2007-09-09 20:06       ` Richard Stallman
2007-09-10  0:46         ` Johannes Weiner
2007-09-10 16:53           ` Richard Stallman
2007-09-10 18:55           ` David Hansen
2007-09-11 10:15             ` Johannes Weiner

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.