unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#47620: [PATCH] Allow complex key bindings in project-switch-project
@ 2021-04-06 14:57 Dario Gjorgjevski
  2021-04-07  0:28 ` Dmitry Gutov
  0 siblings, 1 reply; 2+ messages in thread
From: Dario Gjorgjevski @ 2021-04-06 14:57 UTC (permalink / raw)
  To: 47620

[-- Attachment #1: Type: text/plain, Size: 737 bytes --]

Hi,

project-switch-project currently only allows for single-char bindings to
be used for its commands.  Starting with emacs -Q, evaluate

    (require 'project)
    (define-key project-prefix-map (kbd "M-s g") 'rgrep)
    (add-to-list 'project-switch-commands '(rgrep "grep"))

and then run project-switch-project (by default bound to C-x p p) and
choose a project (hopefully you already have one available).  You will
see "[M-s g] grep" shown in the prompt, but you will not be able to
choose it by typing M-s g.

The patch attached bellow allows for any kind of key binding to be used.
Admittedly, there may be a better way to do it since I did not spend
much time looking into it.

Please, share your thoughts.

Best regards,
Dario


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Allow complex key bindings in project-switch-project --]
[-- Type: text/x-diff, Size: 2570 bytes --]

From dbd256fced765e55bbe8a589874490a121546ae1 Mon Sep 17 00:00:00 2001
From: Dario Gjorgjevski <dario.gjorgjevski+git@gmail.com>
Date: Tue, 6 Apr 2021 16:51:28 +0200
Subject: [PATCH] Allow complex key bindings in project-switch-project

* lisp/progmodes/project.el (project-switch-project): Replace
read-event with an overriding local map and read-key-sequence to allow
for complex key bindings to be read.
---
 lisp/progmodes/project.el | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 910f70db03..84d02e25d9 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -1338,23 +1338,27 @@ made from `project-switch-commands'.
 When called in a program, it will use the project corresponding
 to directory DIR."
   (interactive (list (project-prompt-project-dir)))
-  (let ((commands-menu
-         (mapcar
-          (lambda (row)
-            (if (characterp (car row))
-                ;; Deprecated format.
-                ;; XXX: Add a warning about it?
-                (reverse row)
-              row))
-          project-switch-commands))
-        command)
+  (let* ((commands-menu
+          (mapcar
+           (lambda (row)
+             (if (characterp (car row))
+                 ;; Deprecated format.
+                 ;; XXX: Add a warning about it?
+                 (reverse row)
+               row))
+           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)))
+                (define-key temp-map (vector keychar) cmd)))))
+         command)
     (while (not command)
-      (let ((choice (read-event (project--keymap-prompt))))
-        (when (setq command
-                    (or (car
-                         (seq-find (lambda (row) (equal choice (nth 2 row)))
-                                   commands-menu))
-                        (lookup-key project-prefix-map (vector choice))))
+      (let ((overriding-local-map commands-map)
+            (choice (read-key-sequence (project--keymap-prompt))))
+        (when (setq command (lookup-key commands-map choice))
           (unless (or project-switch-use-entire-map
                       (assq command commands-menu))
             ;; TODO: Add some hint to the prompt, like "key not
-- 
2.31.GIT


[-- Attachment #3: Type: text/plain, Size: 127 bytes --]

-- 
$ keyserver=hkps://hkps.pool.sks-keyservers.net
$ keyid=744A4F0B4F1C9371
$ gpg --keyserver $keyserver --search-keys $keyid

^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#47620: [PATCH] Allow complex key bindings in project-switch-project
  2021-04-06 14:57 bug#47620: [PATCH] Allow complex key bindings in project-switch-project Dario Gjorgjevski
@ 2021-04-07  0:28 ` Dmitry Gutov
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Gutov @ 2021-04-07  0:28 UTC (permalink / raw)
  To: Dario Gjorgjevski, 47620-done

Hi Dario,

On 06.04.2021 17:57, Dario Gjorgjevski wrote:

> project-switch-project currently only allows for single-char bindings to
> be used for its commands.  Starting with emacs -Q, evaluate
> 
>      (require 'project)
>      (define-key project-prefix-map (kbd "M-s g") 'rgrep)
>      (add-to-list 'project-switch-commands '(rgrep "grep"))
> 
> and then run project-switch-project (by default bound to C-x p p) and
> choose a project (hopefully you already have one available).  You will
> see "[M-s g] grep" shown in the prompt, but you will not be able to
> choose it by typing M-s g.
> 
> The patch attached bellow allows for any kind of key binding to be used.
> Admittedly, there may be a better way to do it since I did not spend
> much time looking into it.
> 
> Please, share your thoughts.

Thanks for the patch, it's a nice addition.

Note that it broke the ability to 'C-g' out of the second prompt, see 
the follow-up commit 1ff7cde102.

Likewise, any proposals with a better way to do this are welcome.

(Meantime, closing.)





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-04-07  0:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-06 14:57 bug#47620: [PATCH] Allow complex key bindings in project-switch-project Dario Gjorgjevski
2021-04-07  0:28 ` Dmitry Gutov

unofficial mirror of bug-gnu-emacs@gnu.org 

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/emacs-bugs/0 emacs-bugs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 emacs-bugs emacs-bugs/ https://yhetil.org/emacs-bugs \
		bug-gnu-emacs@gnu.org
	public-inbox-index emacs-bugs

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.bugs
	nntp://news.gmane.io/gmane.emacs.bugs


code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs.git

AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git