]> git.eshelyaron.com Git - emacs.git/commitdiff
Make `C-x C-e' work more like `C-M-x' on defvar etc
authorLars Ingebrigtsen <larsi@gnus.org>
Thu, 15 Oct 2020 14:26:40 +0000 (16:26 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Thu, 15 Oct 2020 14:26:45 +0000 (16:26 +0200)
* 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
etc/NEWS
lisp/emacs-lisp/pp.el
lisp/progmodes/elisp-mode.el

index 573b7ad71a2b07d13168fffd79602748383a74b8..3e09f243226bd615a7306b7c59931743365a2393 100644 (file)
@@ -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,
index 6b9105f577a2d5ed5f2c868ea55790a79a0a780f..97e2e6f1d350ee681edb95b02b101c8aac25a6fa 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -180,6 +180,12 @@ file during parsing" and dropping out of the minibuffer.  The user
 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
index 3df7b0e368e3628b76a5e93a38457d0d73757120..eb2ee94be3b14a33f557566e5233ee11d261be76 100644 (file)
@@ -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)
index b4803687b5a5a2b7397eae0699f820f30bd1877c..dbbb1274faab0479c29816cfcb2e966414bc9651 100644 (file)
@@ -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,