unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Eli Zaretskii <eliz@gnu.org>, Drew Adams <drew.adams@oracle.com>
Cc: larsi@gnus.org, 24237@debbugs.gnu.org,
	Stefan Monnier <monnier@iro.umontreal.ca>
Subject: bug#24237: 24.5; (elisp)`Extended Menu Items', :filter warning
Date: Sun, 13 Dec 2020 11:52:53 -0800 (PST)	[thread overview]
Message-ID: <846fcdf8-9b51-4246-8200-b067e7006e24@default> (raw)
In-Reply-To: <<83v9d5d1yd.fsf@gnu.org>>

> >  "use of a `menu-item' construct with a :filter
> >   to create a conditional _keyboard_ key binding.
> >   In such a case, the `menu-item' construct is not
> >   a real menu item - it is not placed on any menu."
> 
> That doesn't explain anything to me, sorry.

Sorry.  Does an example help?

(global-set-key
 "\C-o" 
 '`(menu-item
   "" forward-char
   :filter (lambda (cmd)
             (if (integerp prefix-arg) nil cmd))))

Stefan (cc'd), in particular, mentions this case
from time to time.  Here are some examples from him:

In emacs-devel thread "Proposed patch for lookup-key"
(2017-12-14):

  "bindings which are made dynamically conditional
   using a :filter function"

In help-gnu-emacs thread "How to define minor-mode
keybindings conditional on buffer's major-mode?"
(2013-10-04):

 (define-key minor-mode-map
   "<<key-binding1>>"
   `(menu-item
     "" minor-mode-command
     :filter ,(lambda (cmd)
                (if (eq major-mode 'xyz-mode) cmd))))
 (define-key minor-mode-map
   "<<key-binding2>>"
   `(menu-item
     "" minor-mode-command
     :filter ,(lambda (cmd)
                (if (not (eq major-mode 'xyz-mode)) cmd))))

In help-gnu-emacs thread "Commands with more than
one keybinding in menus" (2013-08-14):

 You can use dynamic key-bindings, i.e. instead of
 binding your key to
 (lambda () (interactive) (if foo (CMD))),
 bind it to
 (menu-item "" CMD :filter (lambda (cmd) (if foo cmd))).

In help-gnu-emacs thread "Shor-circuiting keybindings"
(2010-12-09):

 You can create conditional key bindings:
  (define-key map
    [?\C-b]
    '(menu-item "dummy" <command>
      :filter (lambda (binding)
                (if <condition> binding))))
                                      
 The filter function will receive <command> as
 argument (this is so that the same filter function
 can be used for several bindings) and can opt to
 return it or not or to return anything else (so
 you can create dynamic bindings, which is
 typically used to construct dynamic menus, such as
 the Buffers menu).
 The <command> you put as the "static binding" that
 gets passed to the filter is only used in cases
 such as where-is.

In help-gnu-emacs thread "HELP: One Bindkey for Two
Different Commands" (2007-11-30):

 How 'bout some neat hack like:
  (global-set-key "\M-o"
    '(menu-item "Foo" bar
      :filter (lambda (x)
                (if (cdr (window-list))
                    'other-window
                  'switch-to-buffer))))

> > Define "menu function", please.

?  (I don't think you answered that.  If you still
want to make a point about it, maybe let me know
what you mean by it.)

> > the case being discussed: an extended menu
> > item that's bound only to a keyboard key, i.e.,
> > that's not used in any menu?
> 
> I still don't understand what that means in practice.

Do the examples above help?  It's about using the
:filter mechanism designed for menu items with a
keyboard key instead, to create a key binding
that's "dynamic", i.e., conditional at the time
you use the key.

> > > could be called whenever the display engine needs to
> > > recalculate the contents and the dimensions of the menu, and that
> > > could basically be every redisplay cycle, depending on circumstances.
> >
> > See above.  There's no menu involved in the case
> > being discussed (at least none that's visible to
> > users, AFAIK).  So there should be no need or
> > possibility of recalculating menu contents and
> > dimensions.
> 
> Then you already know the answer and don't need any help, it seems.
> But if you do, please explain more about the specific use case you
> worry about.

Please reread what I said.  I'm not _aware_ of any
actual menu being involved in the keyboard-key case.
IF none is used, then I'm GUESSING that recalculating
menu contents (what menu?) doesn't happen.

But my point is only about having the doc address
this specific use case - use of :filter when only a
keyboard binding is used.  IF that in fact doesn't
involve any menus then shouldn't that paragraph be
clarified to exclude that case in its caveat?





       reply	other threads:[~2020-12-13 19:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <<<6c4f5089-43fa-4ca1-a656-1ec1684df960@default>
     [not found] ` <<<87v9d67ox6.fsf@gnus.org>
     [not found]   ` <<<70cc884d-4f32-4a2e-b3f5-181709f2ca29@default>
     [not found]     ` <<<83blexeod5.fsf@gnu.org>
     [not found]       ` <<e70746fb-1e56-4115-9fb8-1896c4e8b8d3@default>
     [not found]         ` <<83v9d5d1yd.fsf@gnu.org>
2020-12-13 19:52           ` Drew Adams [this message]
2020-12-19 10:47             ` bug#24237: 24.5; (elisp)`Extended Menu Items', :filter warning Eli Zaretskii
     [not found] <<<<<6c4f5089-43fa-4ca1-a656-1ec1684df960@default>
     [not found] ` <<<<<87v9d67ox6.fsf@gnus.org>
     [not found]   ` <<<<<70cc884d-4f32-4a2e-b3f5-181709f2ca29@default>
     [not found]     ` <<<<<83blexeod5.fsf@gnu.org>
     [not found]       ` <<<<e70746fb-1e56-4115-9fb8-1896c4e8b8d3@default>
     [not found]         ` <<<<83v9d5d1yd.fsf@gnu.org>
     [not found]           ` <<<846fcdf8-9b51-4246-8200-b067e7006e24@default>
     [not found]             ` <<<83y2hut6m7.fsf@gnu.org>
     [not found]               ` <<d15a8746-eb78-44b5-a4d6-af2285969b76@default>
     [not found]                 ` <<838s9ttxkk.fsf@gnu.org>
2020-12-19 19:35                   ` Drew Adams
2020-12-20  0:05                     ` Stefan Kangas
2020-12-20  1:23                       ` Drew Adams
     [not found] <<<<6c4f5089-43fa-4ca1-a656-1ec1684df960@default>
     [not found] ` <<<<87v9d67ox6.fsf@gnus.org>
     [not found]   ` <<<<70cc884d-4f32-4a2e-b3f5-181709f2ca29@default>
     [not found]     ` <<<<83blexeod5.fsf@gnu.org>
     [not found]       ` <<<e70746fb-1e56-4115-9fb8-1896c4e8b8d3@default>
     [not found]         ` <<<83v9d5d1yd.fsf@gnu.org>
     [not found]           ` <<846fcdf8-9b51-4246-8200-b067e7006e24@default>
     [not found]             ` <<83y2hut6m7.fsf@gnu.org>
2020-12-19 18:54               ` Drew Adams
2020-12-19 19:17                 ` Eli Zaretskii
     [not found] <<6c4f5089-43fa-4ca1-a656-1ec1684df960@default>
     [not found] ` <<87v9d67ox6.fsf@gnus.org>
     [not found]   ` <<70cc884d-4f32-4a2e-b3f5-181709f2ca29@default>
     [not found]     ` <<83blexeod5.fsf@gnu.org>
2020-12-13 17:24       ` Drew Adams
2020-12-13 17:56         ` Eli Zaretskii
2016-08-15 18:06 Drew Adams
2020-12-12 20:24 ` Lars Ingebrigtsen
2020-12-12 20:45   ` Drew Adams
2020-12-13 15:07     ` Eli Zaretskii

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=846fcdf8-9b51-4246-8200-b067e7006e24@default \
    --to=drew.adams@oracle.com \
    --cc=24237@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=larsi@gnus.org \
    --cc=monnier@iro.umontreal.ca \
    /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).