unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Zehao Hu <huzehao1998@gmail.com>
To: 60081@debbugs.gnu.org
Subject: bug#60081: 29.0.60; compiler-macros in keymap.el accept wrong number of arguments
Date: Thu, 15 Dec 2022 16:54:26 +0800	[thread overview]
Message-ID: <CAB41456uip=m5h=hapPC9hvhc-eE4-tjQ9WXkaU1ZkZUcpt_QA@mail.gmail.com> (raw)
In-Reply-To: <CAB41454xBLVEEHh2TOGPMUbwTzCD1NsAz0ofz7=Pdub8dZdnkw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2383 bytes --]

Hi all,

I'm sure that this is the same bug as bug #50043, #58148, #58396

In bug #58356,
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>Lars Ingebrigtsen [2022-10-11 20:27:42] wrote:
>> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>>> Because that's the sort of error you can get if you try to macro-expand
>>> code that's syntactically invalid.  E.g. try to compile a file with
>>>
>>>     (add-to-list x)
>>>
>>> and you should see a similar error.  For `elisp--local-variables`,
>>> syntactically invalid code is the normal case (more or less) both
>>> because it's used when we're in the middle of writing the code, and also
>>> because of how it works (it takes the code from beginning-of-defun up
>>> to point and throws away whatever follows, just adding enough closing
>>> parens that the resutling string is `read`able).
>>
>> I see.
>>
>> Shouldn't this function then be suppressing all errors while it's doing
>> this exploratory macro-expansion stuff?
>
>Yes (plus silence the messages plus avoid compiler macros).

Here is a simple workaround:

(require 'loadhist)

(defun cmacro-ignore-elisp-witness (oldfn form &rest args)
  "Add this advicing function around compiler macros to ignore
`elisp--witness--lisp'"
  (unless (eq 'elisp--witness--lisp (car args))
    (apply oldfn form args)))

(defun cmacro-add-advice (file-or-entry)
  "Add `cmacro-ignore-elisp-witness' to compiler macros in FILE or in ENTRY
from `load-history'"
  (let ((entry (if (stringp file-or-entry)
                   (file-loadhist-lookup file-or-entry)
                 file-or-entry)))
    (dolist (cell (cdr entry))
      (when-let*
          (((consp cell))
           ((eq 'defun (car cell)))
           (symbol
            (cdr cell))
           ((symbolp symbol))
           (cmacro
            (get symbol 'compiler-macro))
           ((not (advice-member-p #'cmacro-ignore-elisp-witness symbol))))
        (advice-add cmacro :around #'cmacro-ignore-elisp-witness)))))

;; Advicing existing compiler macros
(dolist (entry load-history)
  (cmacro-add-advice entry))

;; And the ones in the future
(add-hook 'after-load-functions #'cmacro-add-advice)
(dolist (entry load-history)
  (cmacro-add-advice entry))

(add-hook 'after-load-functions #'cmacro-add-advice)

Or maybe edit `byte-run--set-compiler-macro', to change the `*--anon-cmacro'
and to advice the `compiler-function'.

[-- Attachment #2: Type: text/html, Size: 3096 bytes --]

      reply	other threads:[~2022-12-15  8:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-14 15:23 bug#60081: 29.0.60; compiler-macros in keymap.el accept wrong number of arguments Zehao Hu
2022-12-15  3:45 ` Zehao Hu
2022-12-15  8:54   ` Zehao Hu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAB41456uip=m5h=hapPC9hvhc-eE4-tjQ9WXkaU1ZkZUcpt_QA@mail.gmail.com' \
    --to=huzehao1998@gmail.com \
    --cc=60081@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).