unofficial mirror of emacs-devel@gnu.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

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 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).