emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master c6ecf64: Make `C-x C-e' work more like `C-M-x' on defvar etc


From: Lars Ingebrigtsen
Subject: master c6ecf64: Make `C-x C-e' work more like `C-M-x' on defvar etc
Date: Thu, 15 Oct 2020 10:26:53 -0400 (EDT)

branch: master
commit c6ecf6428e8d4848a633782ed0605ddbacfcebee
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Make `C-x C-e' work more like `C-M-x' on defvar etc
    
    * doc/emacs/building.texi (Lisp Eval): Document it.
    
    * lisp/emacs-lisp/pp.el (pp-eval-last-sexp): Ditto.
    
    * lisp/progmodes/elisp-mode.el (elisp--eval-last-sexp): Work more
    like `eval-defun': Re-evaluate defvar/defcustom/defface forms.
---
 doc/emacs/building.texi      | 23 ++++++++++++++---------
 etc/NEWS                     |  6 ++++++
 lisp/emacs-lisp/pp.el        |  7 +++++--
 lisp/progmodes/elisp-mode.el |  7 ++++++-
 4 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/doc/emacs/building.texi b/doc/emacs/building.texi
index 573b7ad..3e09f24 100644
--- a/doc/emacs/building.texi
+++ b/doc/emacs/building.texi
@@ -1672,21 +1672,26 @@ abbreviation of the output according to the variables
 argument of @code{-1} overrides the effect of
 @code{eval-expression-print-length}.
 
+ @kbd{C-x C-e} (@code{eval-last-sexp}) treats @code{defvar}
+expressions specially.  Normally, evaluating a @code{defvar}
+expression does nothing if the variable it defines already has a
+value.  But this command unconditionally resets the variable to the
+initial value specified by the @code{defvar}; this is convenient for
+debugging Emacs Lisp programs.  @code{defcustom} and @code{defface}
+expressions are treated similarly.  Note the other commands documented
+in this section, except @code{eval-defun}, do not have this special
+feature.
+
 @kindex C-M-x @r{(Emacs Lisp mode)}
 @findex eval-defun
   The @code{eval-defun} command is bound to @kbd{C-M-x} in Emacs Lisp
 mode.  It evaluates the top-level Lisp expression containing or
 following point, and prints the value in the echo area.  In this
 context, a top-level expression is referred to as a ``defun'', but it
-need not be an actual @code{defun} (function definition).  In
-particular, this command treats @code{defvar} expressions specially.
-Normally, evaluating a @code{defvar} expression does nothing if the
-variable it defines already has a value.  But this command
-unconditionally resets the variable to the initial value specified by
-the @code{defvar}; this is convenient for debugging Emacs Lisp
-programs.  @code{defcustom} and @code{defface} expressions are treated
-similarly.  Note that the other commands documented in this section do
-not have this special feature.
+need not be an actual @code{defun} (function definition).
+
+ This command handles @code{defvar}/@code{defcustom}/@code{defface}
+forms the same way that @code{eval-last-sexp} does.
 
   With a prefix argument, @kbd{C-M-x} instruments the function
 definition for Edebug, the Emacs Lisp Debugger.  @xref{Instrumenting,
diff --git a/etc/NEWS b/etc/NEWS
index 6b9105f..97e2e6f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -181,6 +181,12 @@ would have to type 'M-: M-p' to edit and redo the 
expression.  Now
 Emacs will echo the message and allow the user to continue editing.
 
 +++
+** 'eval-last-sexp' now handles 'defvar'/'defcustom'/'defface' specially.
+This command would previously not redefine values defined by these
+forms, but this command has now been changed to work more like
+'eval-defun', and reset the values as specified.
+
++++
 ** New command 'undo-redo'.
 It undoes previous undo commands, but doesn't record itself as an
 undoable command.
diff --git a/lisp/emacs-lisp/pp.el b/lisp/emacs-lisp/pp.el
index 3df7b0e..eb2ee94 100644
--- a/lisp/emacs-lisp/pp.el
+++ b/lisp/emacs-lisp/pp.el
@@ -164,8 +164,11 @@ With argument, pretty-print output into current buffer.
 Ignores leading comment characters."
   (interactive "P")
   (if arg
-      (insert (pp-to-string (eval (pp-last-sexp) lexical-binding)))
-    (pp-eval-expression (pp-last-sexp))))
+      (insert (pp-to-string (eval (elisp--eval-defun-1
+                                   (macroexpand (pp-last-sexp)))
+                                  lexical-binding)))
+    (pp-eval-expression (elisp--eval-defun-1
+                         (macroexpand (pp-last-sexp))))))
 
 ;;;###autoload
 (defun pp-macroexpand-last-sexp (arg)
diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index b480368..dbbb127 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -1190,7 +1190,8 @@ character)."
     ;; Setup the lexical environment if lexical-binding is enabled.
     (elisp--eval-last-sexp-print-value
      (eval (macroexpand-all
-            (eval-sexp-add-defvars (elisp--preceding-sexp)))
+            (eval-sexp-add-defvars
+             (elisp--eval-defun-1 (macroexpand (elisp--preceding-sexp)))))
            lexical-binding)
      (if insert-value (current-buffer) t) no-truncate char-print-limit)))
 
@@ -1246,6 +1247,10 @@ POS specifies the starting position where EXP was found 
and defaults to point."
 Interactively, with a non `-' prefix argument, print output into
 current buffer.
 
+This commands handles `defvar', `defcustom' and `defface' the
+same way that `eval-defun' does.  See the doc string of that
+function for details.
+
 Normally, this function truncates long output according to the
 value of the variables `eval-expression-print-length' and
 `eval-expression-print-level'.  With a prefix argument of zero,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]