From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Making a key undefined again Date: Tue, 26 Oct 2021 15:33:13 -0400 Message-ID: References: <20211004081724.6281.11798@vcs0.savannah.gnu.org> <87sfx10xs6.fsf@gnus.org> <87h7dfpjn3.fsf@gnus.org> <31b2f1e94178d73e5f05@heytings.org> <87czo3pgs1.fsf@gnus.org> <31b2f1e9412d60db82df@heytings.org> <87o87moopl.fsf@gnus.org> <19fca5d18b63e6eff5de@heytings.org> <87wnmaiida.fsf@gnus.org> <87zgr6gw9s.fsf@gnus.org> <87r1chhhkh.fsf@gnus.org> <871r4hf83m.fsf@gnus.org> <878ryhjia1.fsf@bernoul.li> <87sfwon2ip.fsf@bernoul.li> <87mtmvn4ty.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="18139"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Lars Ingebrigtsen , Gregory Heytings , Stefan Kangas , Emacs developers To: Jonas Bernoulli Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Oct 26 21:36:00 2021 Return-path: Envelope-to: ged-emacs-devel@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 1mfSEq-0004Sj-1w for ged-emacs-devel@m.gmane-mx.org; Tue, 26 Oct 2021 21:36:00 +0200 Original-Received: from localhost ([::1]:37996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfSEo-0001fJ-Vx for ged-emacs-devel@m.gmane-mx.org; Tue, 26 Oct 2021 15:35:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43212) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfSDS-0000Kg-HX for emacs-devel@gnu.org; Tue, 26 Oct 2021 15:34:35 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:40443) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfSDP-0005HS-Cy for emacs-devel@gnu.org; Tue, 26 Oct 2021 15:34:33 -0400 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id D61914413B8; Tue, 26 Oct 2021 15:34:28 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 55E194413B0; Tue, 26 Oct 2021 15:34:27 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1635276867; bh=+rn3/kYe98zZBrVtxMKWop0w5WXH7Ir50UUyWrIj5iQ=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=Qf3rzbxyeyh4QgN/c/Yh245SRTGaLfdDaoNc6ODiC3DjJ2T+AVuP4KvDl07WCE8Fy muyBi2sLcESdusugUG5bGnlwzVeU02RB5c/kcH75Op5RM7SAXDedkKmdnC3i6Y8qWB RF6zoYvvMiNr1ylZGRuLAaUfigv9PoWHtPefbuT4V27uMY74iwC4yew+xGXpSPB3E2 +/miWosqQ3ZOU9qe+5/WKhJRngWpNUlVqC9o4Og5seY7KTmY5MKNXUAoosx6igP7lh UdvjRiEbR1+97AMsF5o+G3qzSdnE4w/IMnVpuHYGO4Ri3EJG/FYw/Q4UmLuQo/1AVK beyOjNnF1rL6g== Original-Received: from alfajor (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 42AE2120414; Tue, 26 Oct 2021 15:34:27 -0400 (EDT) In-Reply-To: <87mtmvn4ty.fsf@bernoul.li> (Jonas Bernoulli's message of "Tue, 26 Oct 2021 18:11:53 +0200") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:277926 Archived-At: Jonas Bernoulli [2021-10-26 18:11:53] wrote: > Stefan Monnier writes: >>> There always is a (EVENT) entry in the keymap itself because of this line >>> further up: >>> >>> (define-key keymap key nil) >>> >>> (At which point KEY still has the form [EVENT], not (EVENT).) >> >> Actually, it's not guaranteed. Try it with: >> >> (let ((parent (make-sparse-keymap)) >> (child (make-keymap))) >> (set-keymap-parent child parent) >> (define-key parent [?a] nil) >> (define-key child [?a] 'bar) >> child) >> >> :-( > > That can be fixed too. Of course. I think what I'm getting at is that the best fix is to implement it inside `define-key` such that (define-key map :remove-nonparent-binding) does that you want. It's probably easy to implement there. [ Where `:remove-nonparent-binding` is a candidate for a better name, of course. ] >>> but that breaks when `foo-next-thing' is renamed to `foo-forward'. >>> And even if that never happens, it still complicates `foobar-mode-map', >>> which now has a binding for `foo-next-thing', which isn't actually >>> necessary because an identical binding exists in the parent keymap >>> `foo-mode-map'. >> How common is this case? > When implementing an alternative set of key bindings across all of Emacs > that diverge from the "standard Emacs key bindings" a lot (up to the > scale of Vim but possibly not quite *that* drastically different), then > it might be needed for essentially every keymap. Interesting. Maybe such scenarios would also benefit from a more general "rewrite-keymap" operation, maybe by combining `map-keymap` and a new `keymap-clear` operation that just empties a keymap completely. >> So your notion of "no binding at all" can also be described as something >> like "use the binding of the parent". > Yes. (Or the default binding, or ...) > remove(add(MAP KEY) KEY) == MAP Do we need to distinguish (let ((map (make-sparse-keymap))) (define-key map [?a ?b] 'foo) (define-key map [?a ?b] :remove-nonparent-binding) map) from (let ((map (make-sparse-keymap))) (define-key map [?a] (make-sparse-keymap)) (define-key map [?a ?b] 'foo) (define-key map [?a ?b] :remove-nonparent-binding) map) ? Stefan