From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Robert Pluim 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 18:36:01 +0100 Message-ID: <871qlpvrwe.fsf@gmail.com> References: <875yb2gfqp.fsf@bernoul.li> <87v8j2hsa8.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="31585"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 62207@debbugs.gnu.org To: Jonas Bernoulli Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Mar 15 18:37:17 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 1pcV3s-0007yO-HG for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 15 Mar 2023 18:37:16 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pcV3f-0008Ej-W8; Wed, 15 Mar 2023 13:37:04 -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 1pcV3f-0008Eb-8V for bug-gnu-emacs@gnu.org; Wed, 15 Mar 2023 13:37:03 -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 1pcV3f-0007k4-0O for bug-gnu-emacs@gnu.org; Wed, 15 Mar 2023 13:37:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pcV3e-0004Kq-Hd for bug-gnu-emacs@gnu.org; Wed, 15 Mar 2023 13:37:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Robert Pluim Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 15 Mar 2023 17:37:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62207 X-GNU-PR-Package: emacs Original-Received: via spool by 62207-submit@debbugs.gnu.org id=B62207.167890177216605 (code B ref 62207); Wed, 15 Mar 2023 17:37:02 +0000 Original-Received: (at 62207) by debbugs.gnu.org; 15 Mar 2023 17:36:12 +0000 Original-Received: from localhost ([127.0.0.1]:40497 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pcV2p-0004Jl-Pr for submit@debbugs.gnu.org; Wed, 15 Mar 2023 13:36:12 -0400 Original-Received: from mail-wm1-f46.google.com ([209.85.128.46]:46612) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pcV2n-0004JW-8k for 62207@debbugs.gnu.org; Wed, 15 Mar 2023 13:36:10 -0400 Original-Received: by mail-wm1-f46.google.com with SMTP id l7-20020a05600c1d0700b003eb5e6d906bso1794086wms.5 for <62207@debbugs.gnu.org>; Wed, 15 Mar 2023 10:36:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678901763; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=Q7++Me/lV1CkIzjfXSLUvNRS2p2lRyOK3/fgpizjx7k=; b=pjSnFV99wWpWVM70Sx3Z+UymkievJgrptFUanpFQFTyBIBlDWtzBuNczTOrwlh2/yh 4HKZS5hJZqp78kdCzrTlDXZqfS/OP7t4w9W8onrLDWl/4w1HSRGH2ISreZU7tvUeSC9/ RTIvDJTjQRZQ2PP2katbHTGuy82yPO777EAblEm8rlr17TB87nwsUQS7R5fH+CAFs2ul fs6F7oGbxmc4slZ/pa7beNliMRnC0n3F6WAuRmfmVA0DYlA5bmlnW3ZkAA1YpQgowYkL oPzejm6eNT2HoVWorDFMaxZbHP/ExTvdl6Zb9++zH91tE8bU48OdQczKFgh3AWI9X2uE cwbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678901763; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Q7++Me/lV1CkIzjfXSLUvNRS2p2lRyOK3/fgpizjx7k=; b=KygJw4nW9ggfirhRj4sInhlr3surdHDk6tJWAe79Pi1LqAtIifyt3fhKdruULDhQKy cvSAyqwFcdxdT0Ct8KD1LSZhlkQwgWM3P2bTikXKxV32gK/Hi0Riy831Y46xfRhmmZzG /GmVX0nsV5JkEGpyxqXYsrLROdplsqNXySYLNQQtUBJuQE8SkpU3KjSfSgH5lIRajEqt iwPO+1tv2enqq1hqjmhfmPEzF4BkvRFZL2RtsU0wRkGDIZEwBJEvjQk0L+wquzekGkNx Jp41f+u1MYjhmpOPCOk78V2srTPfZk2io14aIlXpAcn+bLC3qt5+ku7zogSeueEdreYY UEog== X-Gm-Message-State: AO0yUKVsx5qfoVKaIizUbTSjVk2fT9fAirkNR0/pB+t+Yr/tCbums+m6 puG3y7phyunHoylLNmxfDGmAh028d1o= X-Google-Smtp-Source: AK7set8xZVwgrY3mb4xBqTpbksJHObrCVZdHEPHo4DgZZKU1YgQZEyFuMAXwEqGffbniR6VxPbjg3A== X-Received: by 2002:a05:600c:190a:b0:3e0:6c4:6a38 with SMTP id j10-20020a05600c190a00b003e006c46a38mr18248177wmq.33.1678901762668; Wed, 15 Mar 2023 10:36:02 -0700 (PDT) Original-Received: from rltb ([82.66.8.55]) by smtp.gmail.com with ESMTPSA id p15-20020a7bcdef000000b003dc4480df80sm2413884wmj.34.2023.03.15.10.36.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 10:36:02 -0700 (PDT) In-Reply-To: <87v8j2hsa8.fsf@bernoul.li> (Jonas Bernoulli's message of "Wed, 15 Mar 2023 17:51:27 +0100") 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:257968 Archived-At: >>>>> On Wed, 15 Mar 2023 17:51:27 +0100, Jonas Bernoulli said: Jonas> As a side-note, it would be nice if it were possible to lookup a Jonas> key in a keymap only, while ignoring bindings in its parent keymap. A feature request and a bug report? Tsk ;-) Luckily the infrastructure is actually there already. The following passes my admittedly quick testing for both. diff --git c/lisp/keymap.el i/lisp/keymap.el index 4f02639ffe2..706da70d360 100644 --- c/lisp/keymap.el +++ i/lisp/keymap.el @@ -370,7 +370,7 @@ key-translate (make-char-table 'keyboard-translate-table nil))) (aset keyboard-translate-table (key-parse from) (key-parse to))) -(defun keymap-lookup (keymap key &optional accept-default no-remap position) +(defun keymap-lookup (keymap key &optional accept-default no-remap position noparent) "Return the binding for command KEY in KEYMAP. KEY is a string that satisfies `key-valid-p'. @@ -406,8 +406,10 @@ keymap-lookup (keymap--check key) (when (and keymap position) (error "Can't pass in both keymap and position")) + (when (and (not keymap) noparent) + (error "Must specify keymap when noparent is t")) (if keymap - (let ((value (lookup-key keymap (key-parse key) accept-default))) + (let ((value (lookup-key keymap (key-parse key) accept-default noparent))) (if (and (not no-remap) (symbolp value)) (or (command-remapping value) value) diff --git c/src/keymap.c i/src/keymap.c index 23453eaa9a6..a660a687994 100644 --- c/src/keymap.c +++ i/src/keymap.c @@ -887,22 +887,23 @@ store_in_keymap (Lisp_Object keymap, register Lisp_Object idx, keymap_end: /* We have scanned the entire keymap, and not found a binding for IDX. Let's add one. */ - { - Lisp_Object elt; + if (!remove) + { + Lisp_Object elt; - if (CONSP (idx) && CHARACTERP (XCAR (idx))) - { - /* IDX specifies a range of characters, and not all of them - were handled yet, which means this keymap doesn't have a - char-table. So, we insert a char-table now. */ - elt = Fmake_char_table (Qkeymap, Qnil); - Fset_char_table_range (elt, idx, NILP (def) ? Qt : def); - } - else - elt = Fcons (idx, def); - CHECK_IMPURE (insertion_point, XCONS (insertion_point)); - XSETCDR (insertion_point, Fcons (elt, XCDR (insertion_point))); - } + if (CONSP (idx) && CHARACTERP (XCAR (idx))) + { + /* IDX specifies a range of characters, and not all of them + were handled yet, which means this keymap doesn't have a + char-table. So, we insert a char-table now. */ + elt = Fmake_char_table (Qkeymap, Qnil); + Fset_char_table_range (elt, idx, NILP (def) ? Qt : def); + } + else + elt = Fcons (idx, def); + CHECK_IMPURE (insertion_point, XCONS (insertion_point)); + XSETCDR (insertion_point, Fcons (elt, XCDR (insertion_point))); + } } return def; @@ -1240,14 +1241,15 @@ DEFUN ("command-remapping", Fcommand_remapping, Scommand_remapping, 1, 3, 0, if (NILP (keymaps)) command = Fkey_binding (command_remapping_vector, Qnil, Qt, position); else - command = Flookup_key (keymaps, command_remapping_vector, Qnil); + command = Flookup_key (keymaps, command_remapping_vector, Qnil, Qnil); return FIXNUMP (command) ? Qnil : command; } static Lisp_Object -lookup_key_1 (Lisp_Object keymap, Lisp_Object key, Lisp_Object accept_default) +lookup_key_1 (Lisp_Object keymap, Lisp_Object key, Lisp_Object accept_default, Lisp_Object noparent) { bool t_ok = !NILP (accept_default); + bool noinherit = !NILP (noparent); if (!CONSP (keymap) && !NILP (keymap)) keymap = get_keymap (keymap, true, true); @@ -1275,7 +1277,7 @@ lookup_key_1 (Lisp_Object keymap, Lisp_Object key, Lisp_Object accept_default) if (!FIXNUMP (c) && !SYMBOLP (c) && !CONSP (c) && !STRINGP (c)) message_with_string ("Key sequence contains invalid event %s", c, 1); - Lisp_Object cmd = access_keymap (keymap, c, t_ok, 0, 1); + Lisp_Object cmd = access_keymap (keymap, c, t_ok, noinherit, 1); if (idx == length) return cmd; @@ -1290,7 +1292,7 @@ lookup_key_1 (Lisp_Object keymap, Lisp_Object key, Lisp_Object accept_default) /* Value is number if KEY is too long; nil if valid but has no definition. */ /* GC is possible in this function. */ -DEFUN ("lookup-key", Flookup_key, Slookup_key, 2, 3, 0, +DEFUN ("lookup-key", Flookup_key, Slookup_key, 2, 4, 0, doc: /* Look up key sequence KEY in KEYMAP. Return the definition. This is a legacy function; see `keymap-lookup' for the recommended function to use instead. @@ -1310,9 +1312,9 @@ DEFUN ("lookup-key", Flookup_key, Slookup_key, 2, 3, 0, usable as a general function for probing keymaps. However, if the third optional argument ACCEPT-DEFAULT is non-nil, `lookup-key' will recognize the default bindings, just as `read-key-sequence' does. */) - (Lisp_Object keymap, Lisp_Object key, Lisp_Object accept_default) + (Lisp_Object keymap, Lisp_Object key, Lisp_Object accept_default, Lisp_Object noparent) { - Lisp_Object found = lookup_key_1 (keymap, key, accept_default); + Lisp_Object found = lookup_key_1 (keymap, key, accept_default, noparent); if (!NILP (found) && !NUMBERP (found)) return found; @@ -1390,7 +1392,7 @@ DEFUN ("lookup-key", Flookup_key, Slookup_key, 2, 3, 0, } /* Check for match. */ - found = lookup_key_1 (keymap, new_key, accept_default); + found = lookup_key_1 (keymap, new_key, accept_default, noparent); if (!NILP (found) && !NUMBERP (found)) break; @@ -1432,7 +1434,7 @@ DEFUN ("lookup-key", Flookup_key, Slookup_key, 2, 3, 0, } /* Check for match. */ - found = lookup_key_1 (keymap, new_key, accept_default); + found = lookup_key_1 (keymap, new_key, accept_default, noparent); if (!NILP (found) && !NUMBERP (found)) break; } @@ -1823,7 +1825,7 @@ DEFUN ("key-binding", Fkey_binding, Skey_binding, 1, 4, 0, } Lisp_Object value = Flookup_key (Fcurrent_active_maps (Qt, position), - key, accept_default); + key, accept_default, Qnil); if (NILP (value) || FIXNUMP (value)) return Qnil; @@ -1864,7 +1866,7 @@ DEFUN ("minor-mode-key-binding", Fminor_mode_key_binding, Sminor_mode_key_bindin int j; for (int i = j = 0; i < nmaps; i++) if (!NILP (maps[i]) - && !NILP (binding = Flookup_key (maps[i], key, accept_default)) + && !NILP (binding = Flookup_key (maps[i], key, accept_default, Qnil)) && !FIXNUMP (binding)) { if (KEYMAPP (binding)) @@ -2013,7 +2015,7 @@ DEFUN ("accessible-keymaps", Faccessible_keymaps, Saccessible_keymaps, { /* If a prefix was specified, start with the keymap (if any) for that prefix, so we don't waste time considering other prefixes. */ - Lisp_Object tem = Flookup_key (keymap, prefix, Qt); + Lisp_Object tem = Flookup_key (keymap, prefix, Qt, Qnil); /* Flookup_key may give us nil, or a number, if the prefix is not defined in this particular map. It might even give us a list that isn't a keymap. */ @@ -2453,7 +2455,7 @@ preferred_sequence_p (Lisp_Object seq) shadow_lookup (Lisp_Object keymap, Lisp_Object key, Lisp_Object accept_default, bool remap) { - Lisp_Object value = Flookup_key (keymap, key, accept_default); + Lisp_Object value = Flookup_key (keymap, key, accept_default, Qnil); if (FIXNATP (value)) /* `key' is too long! */ return Qnil; @@ -3237,7 +3239,7 @@ describe_vector (Lisp_Object vector, Lisp_Object prefix, Lisp_Object args, one in the same keymap. */ if (!NILP (entire_map)) { - Lisp_Object tem = Flookup_key (entire_map, kludge, Qt); + Lisp_Object tem = Flookup_key (entire_map, kludge, Qt, Qnil); if (!EQ (tem, definition)) continue;