From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#63648: 29.0.90; project.el: with switch-use-entire-map, switch-project errors on non-project commands Date: Fri, 20 Oct 2023 22:25:06 +0300 Message-ID: <8562bdad-e487-886a-af49-7f67d8d14b7a@gutov.dev> References: <86wmxb2qvh.fsf@mail.linkov.net> <8634zyjt0k.fsf@mail.linkov.net> <8d1fb7ac-5c82-0ec2-8ae2-d09c131ec165@gutov.dev> <86edj6hyem.fsf@mail.linkov.net> <8634zitwoy.fsf@mail.linkov.net> <50d46d30-a796-b855-0d4c-690d6cb3d15b@gutov.dev> <86il88x9cy.fsf@mail.linkov.net> <4367c45c-95b3-6a29-4ba3-068a3c748452@gutov.dev> <2e34e515-a921-a969-0915-bea94c745f8b@gutov.dev> <868r9258oi.fsf@mail.linkov.net> <86edishisp.fsf@mail.linkov.net> <6fc81cbf-a21f-c5b4-aa56-e8518b8570d7@gutov.dev> <86msxgatuy.fsf@mail.linkov.net> <86y1gynr2u.fsf@mail.linkov.net> <7c72fd8c-c3f6-a974-8a4b-a081f7a9fe1a@gutov.dev> <86ttqmv7c6.fsf@mail.linkov.net> <56e7d865-0456-db7d-3a5d-1235e62508bf@gutov.dev> <865y31onju.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35184"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Cc: Spencer Baugh , 63648@debbugs.gnu.org, sbaugh@catern.com To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Oct 20 21:26:05 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 1qtv8E-0008rA-Co for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 20 Oct 2023 21:26:03 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtv7p-0006cD-2r; Fri, 20 Oct 2023 15:25:37 -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 1qtv7n-0006br-Ix for bug-gnu-emacs@gnu.org; Fri, 20 Oct 2023 15:25:35 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qtv7n-0004Yu-AZ for bug-gnu-emacs@gnu.org; Fri, 20 Oct 2023 15:25:35 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qtv8E-0002d4-BR for bug-gnu-emacs@gnu.org; Fri, 20 Oct 2023 15:26:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 20 Oct 2023 19:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63648 X-GNU-PR-Package: emacs Original-Received: via spool by 63648-submit@debbugs.gnu.org id=B63648.169782995010089 (code B ref 63648); Fri, 20 Oct 2023 19:26:02 +0000 Original-Received: (at 63648) by debbugs.gnu.org; 20 Oct 2023 19:25:50 +0000 Original-Received: from localhost ([127.0.0.1]:41469 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qtv81-0002ce-Gu for submit@debbugs.gnu.org; Fri, 20 Oct 2023 15:25:49 -0400 Original-Received: from wout3-smtp.messagingengine.com ([64.147.123.19]:39681) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qtv7w-0002cF-Hn for 63648@debbugs.gnu.org; Fri, 20 Oct 2023 15:25:48 -0400 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 3D9BE3200A1E; Fri, 20 Oct 2023 15:25:10 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 20 Oct 2023 15:25:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm1; t= 1697829909; x=1697916309; bh=84MIfI/7XJdI8q7m7z0DoFmocx7BmtOhHV3 qyns5Q3Y=; b=nesOCGsjq5Rghps1xNtkPL6ga9kqYAqjdVuZJMCrv4UHh8fg4lL tpjQn4THJBuSDm6c87sMMHAYz1zBGc4Z25RgfVFonrCkX9mjfyejtwCDGuWgCWRw tm5NdKga5M8n0MD9tBjMv11t1XUQ0vNigUIxLV2HxymL5PLWqJ0Tg6tEd6J+PjT0 HktrriOPxJ88sG/CG53cXWwxdXmC51Gh8nvk6ee+ZXZucI6m+Oeyjej+7LrfMnuy PCLiK/6KTnXRMjZo2AcWldyxrxlq3Ac1lRyCuFXlm3imdHuuhZXms0Z7VDZBOLwe MBEakEj6UNb4A/4AzmhqtllmuTGIj4coDKw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1697829909; x=1697916309; bh=84MIfI/7XJdI8q7m7z0DoFmocx7BmtOhHV3 qyns5Q3Y=; b=vRfFRIXG46M6y3G39wf6nDrpO/i7bG1Qx/Hew+RF0xiN+Hwp9+8 X5F0pRU84D8b7dTieO7EcSVH/dXWPxj20Pe3I3X4mcTKh50bjM/9ouze+0cT4CpQ F4pneXe9r06S3e9PxfdvarI55gcy7iW36YOmA0IaDnCOEL9d5uRijevNvdGid9f6 PwZOJQavJp1/N8rsZuyGpdgLt9XSgfi8mSDnsZu5Zl9IU98HOKVRqPPAQraKoudV dqGmqqAois2dUvlYtHS9zQUMufPr7725TTQzwZCvmWX1zADoFfDVUpVgdwtWHLoz GO4AV2QvErTRUtn5kXnAUfD4eV6tzw3wj0Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrjeekgddufeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtfeejnecuhfhrohhmpeffmhhi thhrhicuifhuthhovhcuoegumhhithhrhiesghhuthhovhdruggvvheqnecuggftrfgrth htvghrnhepiefgteevheevveffheeltdeukeeiieekueefgedugfefgefhudelgfefveel vdevnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepug hmihhtrhihsehguhhtohhvrdguvghv X-ME-Proxy: Feedback-ID: i0e71465a:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 20 Oct 2023 15:25:07 -0400 (EDT) Content-Language: en-US In-Reply-To: <865y31onju.fsf@mail.linkov.net> 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:272809 Archived-At: On 20/10/2023 09:44, Juri Linkov wrote: >> 'C-x d' will result in a warning echo, though, instead of just using >> 'd'. If you really prefer that, try experimenting with the below addition, >> but I'm wary of edge cases, since we want to keep supporting sub-maps like >> in bug#47620. It also might feel a little too "magical" now that there are >> more details printed (it also doesn't handle extremes like 'C-c C-x C-c' >> still). >> >> @@ -2003,7 +2003,9 @@ project--switch-project-command >> (help-key-description choice >> nil))))) >> (setq choice (read-key-sequence (concat "Choose: " prompt))) >> (when (setq command (lookup-key commands-map choice)) >> - (when (numberp command) (setq command nil)) >> + (when (numberp command) >> + (setq command >> + (lookup-key commands-map (substring choice command)))) > Wow, it works nicely for 'C-x p p C-x d'. > But strange it fails for 'C-x p p C-x v d' > with the same error: > > (wrong-type-argument commandp 1) That's because (lookup-key ... "vd") also returns 1. I haven't been able to find a solution that works like we would expect. The most trivial would be to loop cutting off invalid prefixes, but then we end up with 'd', not 'v'. That's probably not what you want. Ideally, 'read-key-sequence' would stop at the user pressing 'v' and return "^Xv", then the rest would work out okay. But I haven't managed to have it do that, even when using overriding-terminal-local-map and temporarily altering the global map. My experimental patch is below, you can try tweaking it. And overall I'm not sure it's a constructive approach because you might have been going for 'C-x v d' (where the 'v' translation is correct), but you might have been going for 'C-x v D' or 'C-x v v' instead, very different commands. It might be better to report unknown key sequence and let the user make an explicit choice, like it works now. Depends on whether you notice the key sequence echoing while doing that input. diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index fda1081eb62..09d7e1025ca 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -1983,7 +1983,6 @@ project--switch-project-command project-switch-commands)) (commands-map (let ((temp-map (make-sparse-keymap))) - (set-keymap-parent temp-map project-prefix-map) (dolist (row commands-menu temp-map) (when-let ((cmd (nth 0 row)) (keychar (nth 2 row))) @@ -1991,7 +1990,15 @@ project--switch-project-command command choice) (while (not command) - (let* ((overriding-local-map commands-map) + (let* ((map + (let ((map (make-sparse-keymap))) + (set-keymap-parent map (if project-switch-use-entire-map + project-prefix-map + commands-map)) + (define-key map "\e\e\e" 'keyboard-escape-quit) + (define-key map "\C-g" 'keyboard-quit) + map)) + (overriding-terminal-local-map map) (prompt (if project-switch-use-entire-map (project--keymap-prompt) (project--menu-prompt)))) @@ -2001,16 +2008,20 @@ project--switch-project-command (propertize "Unrecognized input" 'face 'warning) (help-key-description choice nil))))) - (setq choice (read-key-sequence (concat "Choose: " prompt))) - (when (setq command (lookup-key commands-map choice)) - (when (numberp command) (setq command nil)) + (unwind-protect + (progn + (use-global-map map) + (setq choice (read-key-sequence (concat "Choose: " prompt) nil t nil t))) + (use-global-map global-map)) + (when (setq command (lookup-key map choice)) + (while (numberp command) + (setq choice (substring choice command)) + (setq command (lookup-key map choice))) + (when (memq command '(keyboard-quit keyboard-escape-quit)) + (call-interactively command)) (unless (or project-switch-use-entire-map (assq command commands-menu)) - (setq command nil))) - (let ((global-command (lookup-key (current-global-map) choice))) - (when (memq global-command - '(keyboard-quit keyboard-escape-quit)) - (call-interactively global-command))))) + (setq command nil))))) (message nil) command))