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#45329: 26.3; Provide equivalent of :filter for non-menu key bindings Date: Sat, 19 Dec 2020 17:20:01 -0800 (PST) Message-ID: <5f36c96e-d41a-40eb-bb0c-30967ba29936@default> 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="39524"; mail-complaints-to="usenet@ciao.gmane.io" To: 45329@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 20 02:21:29 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 1kqnPc-000ACO-VX for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 20 Dec 2020 02:21:29 +0100 Original-Received: from localhost ([::1]:47440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqnPc-0003oO-1t for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 19 Dec 2020 20:21:28 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39466) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqnPC-0003o9-Qy for bug-gnu-emacs@gnu.org; Sat, 19 Dec 2020 20:21:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:60188) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kqnPC-0007g0-JF for bug-gnu-emacs@gnu.org; Sat, 19 Dec 2020 20:21:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kqnPC-0004wf-EL for bug-gnu-emacs@gnu.org; Sat, 19 Dec 2020 20:21: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, 20 Dec 2020 01:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 45329 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.160842721518918 (code B ref -1); Sun, 20 Dec 2020 01:21:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 20 Dec 2020 01:20:15 +0000 Original-Received: from localhost ([127.0.0.1]:43501 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kqnOR-0004v4-4h for submit@debbugs.gnu.org; Sat, 19 Dec 2020 20:20:15 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:41234) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kqnON-0004uu-Vl for submit@debbugs.gnu.org; Sat, 19 Dec 2020 20:20:14 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39174) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqnON-0003XB-7F for bug-gnu-emacs@gnu.org; Sat, 19 Dec 2020 20:20:11 -0500 Original-Received: from userp2130.oracle.com ([156.151.31.86]:42564) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqnOI-0007Dc-1w for bug-gnu-emacs@gnu.org; Sat, 19 Dec 2020 20:20:08 -0500 Original-Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BK1K3GK007805 for ; Sun, 20 Dec 2020 01:20:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : sender : to : subject : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=4h/30RqIkzA8mQVEQRi88Wqkw7V43AhwqmQ6rt4CXp0=; b=gz+IWzXRu2trjUjKuN2Nvx40BS/FuUiWQd817UqjNK+Gf9hLNQ2KDovqp9eYlnjT3544 EV0kzdDO2qy1AQzi7ICHQu6H+485HVzratDZLAqwYgZB371Ae+dIIklT/yQb4Migu/pL BxG4jUiSn1ZS1vyA06lk04ZmbvooD9W0wNWsqBRYt3FKN+Srn6xNQ9JXjIds5kgUg/Hx xeU9hnP3XukjITz0gM3/kprn1ZS5e5sjOALeaZreYolWAzrb/9U1HRlUbkwvetpl+Aog XPN82y/0v6qkbFT8Sq+7uekSlFcg79e7xwKJTsduYahaCG3dz88FWTBfEMYZmeXrfXY6 Aw== Original-Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 35h8xqsjb4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Sun, 20 Dec 2020 01:20:03 +0000 Original-Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BK1AUUF186580 for ; Sun, 20 Dec 2020 01:20:03 GMT Original-Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3030.oracle.com with ESMTP id 35huetsq26-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sun, 20 Dec 2020 01:20:03 +0000 Original-Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0BK1K2kb028763 for ; Sun, 20 Dec 2020 01:20:02 GMT X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.5095.0 (x86)] X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9840 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012200007 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9840 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 clxscore=1015 priorityscore=1501 mlxscore=0 lowpriorityscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 phishscore=0 impostorscore=0 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012200008 Received-SPF: pass client-ip=156.151.31.86; envelope-from=drew.adams@oracle.com; helo=userp2130.oracle.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:196447 Archived-At: See Emacs bug #24237. Using an extended menu item key binding you can create a key binding that is "dynamic", or "dynamically conditional", even for a keyboard key.=20 By "dynamic" is meant that whether or not the key is effectively bound (non-nil) and, if so, which command it is effectively bound to, can be conditional according to the context current at the time the key is used. For "whether", instead of binding a key to a command whose definition does something conditional ... (defvar toto nil "...") (defun foo () (interactive) (and toto (message "FOO"))) (global-set-key "\C-f" 'foo) ... you can move the condition to the key binding itself, that is, bind the key conditionally: (defun toto-filter (cmd) (and toto cmd)) (global-set-key "\C-b" '(menu-item "" foo :filter toto-filter)) (global-set-key "\C-f" '(menu-item "" bar :filter toto-filter)) (defun foo () (interactive) (message "FOO")) (defun bar () (interactive) (message "BAR")) When `toto' is nil, `C-b' and `C-f' are unbound. In this case, we made use of the same filter for two different key bindings. Both commands, `foo' and `bar', have bindings that are, in effect, conditional on the value of variable `toto'. Instead of a filter returning nil sometimes (which effectively means the key isn't bound then), it can return different commands. Several examples and some explanation are given in bug #24237. The feature request is to provide this same capability without using an extended menu item, because the KEY arg to `global-set-key' or `define-key' need not have anything to do with a menu. Let KEY be associated with a filter. How (e.g. syntax) to do that is up for grabs. I don't have a strong opinion about that. Apparently Emacs doesn't want to just document the above use case as is, i.e., advertise that you can use an extended menu item for this. Fair enough. One possibility for doing this is to just allow the filter function as an optional arg (similarly for `define-key'): (global-set-key KEY COMMAND &optional FILTER-FN)=20 On the other hand, the REAL-BINDING part of the extended menu item can also be somewhat useful: "it is only used in cases such as `where-is'", as the static or nominal binding. If we want to allow for that then this could be the signature: (global-set-key KEY COMMAND &optional FILTER-FN NOMINAL-COMMAND)=20 When this feature is documented in the Elisp manual it would make sense to point out that FILTER-FN here is exactly as in an extended menu item. (And if we include NOMINAL-COMMAND, mention that that corresponds to the REAL-BINDING of an extended menu item.) In GNU Emacs 26.3 (build 1, x86_64-w64-mingw32) of 2019-08-29 Repository revision: 96dd0196c28bc36779584e47fffcca433c9309cd Windowing system distributor `Microsoft Corp.', version 10.0.18362 Configured using: `configure --without-dbus --host=3Dx86_64-w64-mingw32 --without-compress-install 'CFLAGS=3D-O2 -static -g3''