From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Johannes Weiner Newsgroups: gmane.emacs.devel Subject: [PATCH] Extract last-sexp from eval-last-sexp-1 Date: Mon, 20 Aug 2007 00:08:06 +0200 Message-ID: <20070819220806.GA14139@saeurebad.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Qxx1br4bt0+wmkIi" X-Trace: sea.gmane.org 1187561303 5914 80.91.229.12 (19 Aug 2007 22:08:23 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 19 Aug 2007 22:08:23 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Aug 20 00:08:21 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IMswW-0007Mq-Kw for ged-emacs-devel@m.gmane.org; Mon, 20 Aug 2007 00:08:20 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IMswW-0007Ex-Ty for ged-emacs-devel@m.gmane.org; Sun, 19 Aug 2007 18:08:20 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IMswS-0007EZ-PT for emacs-devel@gnu.org; Sun, 19 Aug 2007 18:08:16 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IMswR-0007EA-MT for emacs-devel@gnu.org; Sun, 19 Aug 2007 18:08:16 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IMswR-0007E7-Jk for emacs-devel@gnu.org; Sun, 19 Aug 2007 18:08:15 -0400 Original-Received: from saeurebad.de ([85.214.36.134]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IMswP-0005sP-WA for emacs-devel@gnu.org; Sun, 19 Aug 2007 18:08:14 -0400 Original-Received: by saeurebad.de (Postfix, from userid 1000) id BC8EF2F03B2; Mon, 20 Aug 2007 00:08:06 +0200 (CEST) Mail-Followup-To: emacs-devel@gnu.org Content-Disposition: inline User-Agent: Mutt/1.5.16 (2007-06-11) X-Detected-Kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:76775 Archived-At: --Qxx1br4bt0+wmkIi Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --Qxx1br4bt0+wmkIi Content-Type: text/x-diff; charset=us-ascii Content-Disposition: inline; filename="emacs-extract-last-sexp.patch" 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)) --Qxx1br4bt0+wmkIi Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --Qxx1br4bt0+wmkIi--