changeset 82486:6499a8de7fcb

preceding-sexp
author Vinicius Jose Latorre <viniciusjl@ig.com.br>
date Mon, 20 Aug 2007 15:53:09 +0000
parents 5c73856d6050
children c51f2772210a
files lisp/ChangeLog lisp/emacs-lisp/lisp-mode.el
diffstat 2 files changed, 60 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Mon Aug 20 12:26:40 2007 +0000
+++ b/lisp/ChangeLog	Mon Aug 20 15:53:09 2007 +0000
@@ -1,3 +1,9 @@
+2007-08-20  Johannes Weiner  <hannes@saeurebad.de>  (tiny change)
+
+	* emacs-lisp/lisp-mode.el (preceding-sexp): New fun, the code was
+	extracted from `eval-last-sexp-1'.
+	(eval-last-sexp-1): Call `preceding-sexp'.
+
 2007-08-20  Thien-Thi Nguyen  <ttn@gnuvola.org>
 
 	* vc-rcs.el (vc-rcs-annotate-command):
--- a/lisp/emacs-lisp/lisp-mode.el	Mon Aug 20 12:26:40 2007 +0000
+++ b/lisp/emacs-lisp/lisp-mode.el	Mon Aug 20 15:53:09 2007 +0000
@@ -539,62 +539,65 @@
 	      string))))
 
 
+(defun preceding-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)))
+    (eval-last-sexp-print-value (eval (preceding-sexp)))))
 
-		       ;; 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)
   (let ((unabbreviated (let ((print-length nil) (print-level nil))