From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.bugs Subject: bug#24237: 24.5; (elisp)`Extended Menu Items', :filter warning Date: Sun, 13 Dec 2020 11:52:53 -0800 (PST) Message-ID: <846fcdf8-9b51-4246-8200-b067e7006e24@default> References: <<<6c4f5089-43fa-4ca1-a656-1ec1684df960@default>>> <<<87v9d67ox6.fsf@gnus.org>>> <<<70cc884d-4f32-4a2e-b3f5-181709f2ca29@default>>> <<<83blexeod5.fsf@gnu.org>>> <> <<83v9d5d1yd.fsf@gnu.org>> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3701"; mail-complaints-to="usenet@ciao.gmane.io" Cc: larsi@gnus.org, 24237@debbugs.gnu.org, Stefan Monnier To: Eli Zaretskii , Drew Adams Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 13 20:56:11 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1koXTW-0000ry-Qc for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 13 Dec 2020 20:56:10 +0100 Original-Received: from localhost ([::1]:54290 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1koXTV-0001XF-T1 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 13 Dec 2020 14:56:09 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34704) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1koXTO-0001X3-HO for bug-gnu-emacs@gnu.org; Sun, 13 Dec 2020 14:56:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:38796) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1koXTO-0004ua-AA for bug-gnu-emacs@gnu.org; Sun, 13 Dec 2020 14:56:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1koXTO-0001IA-9L for bug-gnu-emacs@gnu.org; Sun, 13 Dec 2020 14:56:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Drew Adams Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 13 Dec 2020 19:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24237 X-GNU-PR-Package: emacs Original-Received: via spool by 24237-submit@debbugs.gnu.org id=B24237.16078893154741 (code B ref 24237); Sun, 13 Dec 2020 19:56:02 +0000 Original-Received: (at 24237) by debbugs.gnu.org; 13 Dec 2020 19:55:15 +0000 Original-Received: from localhost ([127.0.0.1]:50341 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1koXSc-0001EK-Jx for submit@debbugs.gnu.org; Sun, 13 Dec 2020 14:55:14 -0500 Original-Received: from aserp2130.oracle.com ([141.146.126.79]:34164) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1koXQW-00013j-I6 for 24237@debbugs.gnu.org; Sun, 13 Dec 2020 14:53:05 -0500 Original-Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BDJoSVM084160; Sun, 13 Dec 2020 19:52:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : sender : to : cc : subject : references : in-reply-to : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=SPhffe7EwEqjyZiv20un7/QIF42SmUJhw6jJId+8vcQ=; b=WJiJ5cyxinPqq7Cf6pFkXN8omzKcITz36B5m2+a/6XgW+YY11+nl+BEGk7Ya2VZxyKe4 VSLCEm8V2ai+tlwpqg5xjRIAXuyg5Q2zSOtuwiGDTudXkspc835Oshe+4hrhIGqgtyWM dRVdudlDlhmNvS2MYgg/VGKfTJg25Mo1j6HF6qifqoEq3KfM3yVZKU1HtLgJDOC0HUii mxqCiqZYk10qK8iqbXpEZVESpWR2QQLq4uasOuPrtqc1W4KY+4RzNN5P++EXQh38MTa0 kXZW6QpSXR1LcmMeGl/uZvzfZ9teFmYoK4G2/1wjR/hnr6lVLYpiDwR9f/WkufwLcmOD Xg== Original-Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2130.oracle.com with ESMTP id 35ckcb2v7p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sun, 13 Dec 2020 19:52:57 +0000 Original-Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BDJovAl174824; Sun, 13 Dec 2020 19:52:57 GMT Original-Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 35d7mp4wr6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 13 Dec 2020 19:52:56 +0000 Original-Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0BDJqsBB014526; Sun, 13 Dec 2020 19:52:55 GMT In-Reply-To: <<83v9d5d1yd.fsf@gnu.org>> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.5071.0 (x86)] X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9834 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012130156 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9834 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxlogscore=999 priorityscore=1501 mlxscore=0 suspectscore=0 adultscore=0 phishscore=0 malwarescore=0 impostorscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012130156 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:196002 Archived-At: > > "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." >=20 > That doesn't explain anything to me, sorry. Sorry. Does an example help? (global-set-key "\C-o"=20 '`(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 "<>" `(menu-item "" minor-mode-command :filter ,(lambda (cmd) (if (eq major-mode 'xyz-mode) cmd)))) (define-key minor-mode-map "<>" `(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" :filter (lambda (binding) (if binding)))) =20 The filter function will receive 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 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? >=20 > 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. >=20 > 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?