bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#58396: bug#58148: 29.0.50; Wrong number of arguments in keymap-set--


From: Jens Schmidt
Subject: bug#58396: bug#58148: 29.0.50; Wrong number of arguments in keymap-set--anon-cmacro
Date: Sat, 30 Sep 2023 20:44:55 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> +                  (let ((inhibit-message t)     ;[1]
>> +                        (warning-minimum-log-level :emergency))
>>                      (advice-add 'macroexpand :around macroexpand-advice)
>> -                    (macroexpand-all sexp))
>> +                    (condition-case nil         ;[3]
>> +                        (macroexpand-all sexp)
>> +                      (t sexp)))
>
> This `t` catches more than errors.  Better replace it with `error`.

Done plus Eli's comments from that other branch.

>> -                  (let ((warning-minimum-log-level :emergency))
>> +                  (let ((inhibit-message t)                  ;[1]
>> +                        (macroexp-inhibit-compiler-macros t) ;[2]
>> +                        (warning-minimum-log-level :emergency))
>>                      (advice-add 'macroexpand-1 :around macroexpand-advice)
>> -                    (macroexpand-all sexp elisp--local-macroenv))
>> +                    (condition-case nil         ;[3]
>> +                        (macroexpand-all sexp elisp--local-macroenv)
>> +                      (t sexp)))
>
> What kind of errors are we expecting to catch with this
> `condition-case`?  The pre-existing advice is supposed to catch macro
> expansion errors, and the new let-binding is supposed to catch
> compiler-macro errors, so it seems to me there aren't any *expected*
> errors left.  If so, better remove this `condition-case` (or replace it
> with `with-demoted-errors`) since all it has left to do is to hide any
> real coding error that may come up and that we'd like to be told about.

Done.

FWIW, bug#60081 can also be merged into this one.  (The other bugs that
Zehao mentions in her/his last post are either merged already or
typos/not related to this bug.)  Technically, I should be able to merge
that bug (after having been pointed to admin/notes/bugtracker), but is
it OK for me (as a "plain user") to do so?  Or should someone with more
authority do that?

Thanks.

>From f4184086081b9cf94e87848d33b527c35f78ffdf Mon Sep 17 00:00:00 2001
From: Jens Schmidt <jschmidt4gnu@vodafonemail.de>
Date: Tue, 26 Sep 2023 22:26:15 +0200
Subject: [PATCH] Silence macro expansion during completion at point

To keep risk in the current release branch low, do not avoid compiler
macros as suggested by Stefan in the bug, but rather suppress all errors.

* lisp/progmodes/elisp-mode.el (elisp--local-variables): Silence
messages.  Suppress all errors during macro expansion.  (Bug#58148)

Do not merge to master.
---
 lisp/progmodes/elisp-mode.el | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index bd3916ce108..354d98c50dc 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -447,9 +447,14 @@ elisp--local-variables
                                      (error form))))
              (sexp
               (unwind-protect
-                  (let ((warning-minimum-log-level :emergency))
+                  ;; Silence any macro expansion errors when
+                  ;; attempting completion at point (bug#58148).
+                  (let ((inhibit-message t)
+                        (warning-minimum-log-level :emergency))
                     (advice-add 'macroexpand :around macroexpand-advice)
-                    (macroexpand-all sexp))
+                    (condition-case nil
+                        (macroexpand-all sexp)
+                      (error sexp)))
                 (advice-remove 'macroexpand macroexpand-advice)))
              (vars (elisp--local-variables-1 nil sexp)))
         (delq nil
-- 
2.30.2

>From cc954764667e23ecc19ae9cc3fb89956a32289ce Mon Sep 17 00:00:00 2001
From: Jens Schmidt <jschmidt4gnu@vodafonemail.de>
Date: Fri, 29 Sep 2023 22:04:43 +0200
Subject: [PATCH] Silence macro expansion during completion at point

* lisp/emacs-lisp/macroexp.el (macroexp-inhibit-compiler-macros): Add
variable.
(macroexp--compiler-macro): Inspect that new variable and, if it is
non-nil, return the input form unchanged.
* lisp/progmodes/elisp-mode.el (elisp--local-variables): Silence
messages.  Avoid compiler macros.  (Bug#58148)
---
 lisp/emacs-lisp/macroexp.el  | 20 ++++++++++++++------
 lisp/progmodes/elisp-mode.el |  6 +++++-
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/lisp/emacs-lisp/macroexp.el b/lisp/emacs-lisp/macroexp.el
index 3ef924a5c73..6eb670d6dc1 100644
--- a/lisp/emacs-lisp/macroexp.el
+++ b/lisp/emacs-lisp/macroexp.el
@@ -105,13 +105,21 @@ macroexp--all-clauses
        (macroexp--all-forms clause skip)
       clause)))
 
+(defvar macroexp-inhibit-compiler-macros nil
+  "Inhibit application of compiler macros if non-nil.")
+
 (defun macroexp--compiler-macro (handler form)
-  (condition-case-unless-debug err
-      (apply handler form (cdr form))
-    (error
-     (message "Warning: Optimization failure for %S: Handler: %S\n%S"
-              (car form) handler err)
-     form)))
+  "Apply compiler macro HANDLER to FORM and return the result.
+Unless `macroexp-inhibit-compiler-macros' is non-nil, in which
+case return FORM unchanged."
+  (if macroexp-inhibit-compiler-macros
+      form
+    (condition-case-unless-debug err
+        (apply handler form (cdr form))
+      (error
+       (message "Warning: Optimization failure for %S: Handler: %S\n%S"
+                (car form) handler err)
+       form))))
 
 (defun macroexp--funcall-if-compiled (_form)
   "Pseudo function used internally by macroexp to delay warnings.
diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index 664299df288..ff90a744ea3 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -460,7 +460,11 @@ elisp--local-variables
                    (message "Ignoring macroexpansion error: %S" err) form))))
              (sexp
               (unwind-protect
-                  (let ((warning-minimum-log-level :emergency))
+                  ;; Silence any macro expansion errors when
+                  ;; attempting completion at point (bug#58148).
+                  (let ((inhibit-message t)
+                        (macroexp-inhibit-compiler-macros t)
+                        (warning-minimum-log-level :emergency))
                     (advice-add 'macroexpand-1 :around macroexpand-advice)
                     (macroexpand-all sexp elisp--local-macroenv))
                 (advice-remove 'macroexpand-1 macroexpand-advice)))
-- 
2.30.2


reply via email to

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