all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Kangas <stefankangas@gmail.com>
To: Lars Ingebrigtsen <larsi@gnus.org>, yyoncho <yyoncho@gmail.com>
Cc: 39149@debbugs.gnu.org
Subject: bug#39149: 27.0.50; describe-buffer-bindings is calling :filter function in wrong buffer
Date: Sat, 14 Nov 2020 16:24:07 -0800	[thread overview]
Message-ID: <CADwFkmmrKwmm90gWU+bC5=KbjajiCYGbXrtBV3cgfK4N0-y=7Q@mail.gmail.com> (raw)
In-Reply-To: <87361vhjxu.fsf@gnus.org>

Lars Ingebrigtsen <larsi@gnus.org> writes:

> yyoncho <yyoncho@gmail.com> writes:
>
>> To reproduce (eval in scratch buffer)
>> (define-key global-map (kbd "C-c C-l r")
>>   `(menu-item "2" switch-to-buffer
>>               :filter ,(lambda (cmd)
>>                          (print (format "Called in %s" (current-buffer)))
>>                          cmd)))
>> (with-temp-buffer
>>   (with-output-to-string
>>     (describe-buffer-bindings (get-buffer "*scratch*") [3 12] t)))
>>
>> This outputs:
>>
>> \"Called in  *temp*\"
>
> I tried this recipe, but I'm not getting the :filter function called at
> all.  Do you have a recipe, starting from "emacs -Q", that reproduces
> this bug?

I have pushed a fix to master (f08e6538dc) ensuring that we correctly
run the :filter function.

The bug can now be reproduced (on master and 26.3) using:

(progn
  (require 'ert)
  (let (was-in-buffer)
    (unwind-protect
        (progn
          (define-key global-map (kbd "C-c C-l r")
            `(menu-item "2" identity
                        :filter ,(lambda (cmd)
                                   (setq was-in-buffer
                                         (current-buffer))
                                   cmd)))
          (with-temp-buffer
            (let ((buf (get-buffer "*scratch*")))
              (describe-buffer-bindings buf nil t)
              (should was-in-buffer)
              (should (eq was-in-buffer buf)))))
      (define-key global-map (kbd "C-c C-l r") nil)
      (define-key global-map (kbd "C-c C-l") nil))))

As Andreas Schwab has pointed out, the problem is that describe-map (and
describe_map before it) has no idea about the buffer argument to
describe-bindings.  So if the above is to be made to work, we have to
make sure that it does.

I see two ways of doing that:

a) Add a new argument to describe-map with the original buffer.  Ensure
   that the :filter function is run there.

b) Change describe-map to return its output as a string.

The problem with a) is that describe-map already has a pretty long
argument list.  It also seems to me that the resulting code would not be
very easy to follow.

My preference would therefore be looking into option b) first.
If we can make it work, we could then just change the buffer in
describe-buffer-bindings before calling describe-map.

(It is true that the old C function "describe_map" has always inserted
its output in the current buffer.  It also true that it has always been
an internal function, and never exposed to Lisp directly.  So we should
be free to change its behavior, and we should probably better do it
before Emacs 28.1.)

Thoughts?

---

Also, a tangent:

IMHO, using `menu-item' in this way works as it stands, but it is a bit
strange conceptually.  We are binding a key to a `menu-item' that is
never intended to be used for a menu.  Yet IIUC this is the recommended
way of using :filter.

It would perhaps be better to have a specific format that allows for
these extended features, without needing to provide a `menu-item'.

(See `(elisp) Format of Keymaps' for more.)





  parent reply	other threads:[~2020-11-15  0:24 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-16  6:59 bug#39149: 27.0.50; describe-buffer-bindings is calling :filter function in wrong buffer yyoncho
2020-10-30 14:23 ` Lars Ingebrigtsen
2020-10-30 16:08   ` yyoncho
2020-10-30 16:16   ` Stefan Kangas
2020-10-30 18:03     ` Basil L. Contovounesios
2020-11-01 14:56       ` Stefan Kangas
2020-11-01 17:01         ` Basil L. Contovounesios
2020-11-01  4:31     ` Stefan Kangas
2020-11-15  0:24   ` Stefan Kangas [this message]
2020-11-15 15:15     ` Eli Zaretskii
2020-11-15 16:08       ` Stefan Kangas
2020-11-15 16:28         ` Eli Zaretskii
2022-04-17 15:37     ` Lars Ingebrigtsen
2022-04-17 16:02       ` Eli Zaretskii
2022-04-17 16:06         ` Lars Ingebrigtsen
2020-10-30 15:16 ` Andreas Schwab
2020-10-30 16:23   ` Stefan Kangas
2020-10-30 16:32     ` yyoncho
2020-10-30 16:46     ` Andreas Schwab

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

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

  git send-email \
    --in-reply-to='CADwFkmmrKwmm90gWU+bC5=KbjajiCYGbXrtBV3cgfK4N0-y=7Q@mail.gmail.com' \
    --to=stefankangas@gmail.com \
    --cc=39149@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=yyoncho@gmail.com \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.