From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jonas Bernoulli Newsgroups: gmane.emacs.bugs Subject: bug#62207: 29.0.60; Trying to remove non-existent key binding instead adds a binding Date: Wed, 15 Mar 2023 17:51:27 +0100 Message-ID: <87v8j2hsa8.fsf@bernoul.li> References: <875yb2gfqp.fsf@bernoul.li> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21666"; mail-complaints-to="usenet@ciao.gmane.io" To: 62207@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Mar 15 17:52:35 2023 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 1pcUMd-0005Vz-7U for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 15 Mar 2023 17:52:35 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pcUM7-0004YF-Ha; Wed, 15 Mar 2023 12:52:03 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pcUM6-0004Xr-FS for bug-gnu-emacs@gnu.org; Wed, 15 Mar 2023 12:52:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pcUM6-0000mA-7N for bug-gnu-emacs@gnu.org; Wed, 15 Mar 2023 12:52:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pcUM5-0002zg-Lw for bug-gnu-emacs@gnu.org; Wed, 15 Mar 2023 12:52:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jonas Bernoulli Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 15 Mar 2023 16:52:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62207 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.167889909811469 (code B ref -1); Wed, 15 Mar 2023 16:52:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 15 Mar 2023 16:51:38 +0000 Original-Received: from localhost ([127.0.0.1]:40458 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pcULh-0002yu-JK for submit@debbugs.gnu.org; Wed, 15 Mar 2023 12:51:37 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:55118) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pcULg-0002yl-GS for submit@debbugs.gnu.org; Wed, 15 Mar 2023 12:51:36 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pcULg-0004V5-6t for bug-gnu-emacs@gnu.org; Wed, 15 Mar 2023 12:51:36 -0400 Original-Received: from mail.hostpark.net ([212.243.197.30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pcULe-0000hm-5M for bug-gnu-emacs@gnu.org; Wed, 15 Mar 2023 12:51:35 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by mail.hostpark.net (Postfix) with ESMTP id 03F1116408 for ; Wed, 15 Mar 2023 17:51:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=bernoul.li; h= content-type:content-type:mime-version:message-id:date:date :references:in-reply-to:subject:subject:from:from:received :received; s=sel2011a; t=1678899089; bh=F0v079KatpJWeQ3RgAcd1EUI r4cfLMKGunX6s0gJPSU=; b=cuROmPHAhOVL/dsi+BtNzz3QOF9ql1vKwoxJnqL9 B0E5rhbcMH10OuH2CWMf+JRnYSNYyBZzRBjP4TbQxeYhNzILpXJvraqD1EqMfq7g FizqveLyyZg+V8x2hOcjva2fIlsox+ahFGjkvEPmjKg/wyFm3hY6Vn1ln3ia78TS B88= X-Virus-Scanned: by Hostpark/NetZone Mailprotection at hostpark.net Original-Received: from mail.hostpark.net ([127.0.0.1]) by localhost (mail1.hostpark.net [127.0.0.1]) (amavisd-new, port 10224) with ESMTP id WFDOogFHS5zd for ; Wed, 15 Mar 2023 17:51:29 +0100 (CET) Original-Received: from customer (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.hostpark.net (Postfix) with ESMTPSA id A8408164A8 for ; Wed, 15 Mar 2023 17:51:29 +0100 (CET) In-Reply-To: <875yb2gfqp.fsf@bernoul.li> Received-SPF: none client-ip=212.243.197.30; envelope-from=jonas@bernoul.li; helo=mail.hostpark.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_NONE=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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:257966 Archived-At: As a side-note, it would be nice if it were possible to lookup a key in a keymap only, while ignoring bindings in its parent keymap. I was reminded of this because I had to resurrect some old code of mine to work around this bug. The workaround is: (defun my--keymap-unset (keymap key &optional remove) (if remove (when (kmu-lookup-local-key keymap key nil t) (keymap-unset keymap key t)) (keymap-unset keymap key))) And below is the code I had to resurrect in order to make that happen. If `lookup-key', and similar, took a NOPARENT argument, all of that could be avoided. (defun kmu-lookup-local-key ( keymap key &optional accept-default no-remap position) "In KEYMAP, look up key sequence KEY. Return the definition. Unlike `keymap-lookup' (which see) this doesn't consider bindings made in KEYMAP's parent keymap." (keymap-lookup (kmu--strip-keymap keymap) key accept-default no-remap position)) (defun kmu--strip-keymap (keymap) "Return a copy of KEYMAP with all parent keymaps removed. This not only removes the parent keymap of KEYMAP but also recursively the parent keymap of any keymap a key in KEYMAP is bound to." (cl-labels ((strip-keymap (keymap) (set-keymap-parent keymap nil) (cl-loop for _key being the key-code of keymap using (key-binding binding) do (and (keymapp binding) (not (kmu-prefix-command-p binding)) (strip-keymap binding))) keymap)) (strip-keymap (copy-keymap keymap)))) (defun kmu-prefix-command-p (object) "Return non-nil if OBJECT is a symbol whose function definition is a keymap. The value returned is the keymap stored as OBJECT's variable definition or else the variable which holds the keymap." (and (symbolp object) (fboundp object) (keymapp (symbol-function object)) (if (and (boundp object) (keymapp (symbol-value object))) (symbol-value object) (kmu-keymap-variable (symbol-function object))))) (defun kmu-keymap-variable-p (object) "Return t if OBJECT is a symbol whose variable definition is a keymap." (and (symbolp object) (boundp object) (keymapp (symbol-value object))))