emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: New feature in project.el: Remembering the previously used projects


From: Philip K.
Subject: Re: New feature in project.el: Remembering the previously used projects
Date: Fri, 29 May 2020 09:31:34 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Dmitry Gutov <dgutov@yandex.ru> writes:

> On 29.05.2020 02:05, Basil L. Contovounesios wrote:

>> Could project-switch-project reuse read-multiple-choice or similar?
>
> I'm attaching a patch that makes it use read-multiple-choice, check it
> out. But I'm not sure the result looks better than what we have now.
>
> Suggestions on "similar" welcome.

I tried to same thing last night, but didn't get around to submitting it
in time. It's mosty the same, I just dropped project--keymap-prompt and
changed the type of project-switch-commands, because it seemed easier
that way.

I think it can be improved by adding a "case-insenstive" option to
read-multiple-choice, because for example currently it seems to
highlight the second "f" in "Find file"
                                  ^
        this one here ____________|

I have tried something out, and will submit a patch right after this one.

-- 
        Philip K.

>From 8b320e00fbd89a3b8e9097b04cf307d3230e6ed6 Mon Sep 17 00:00:00 2001
From: Philip K <philip@warpmail.net>
Date: Fri, 29 May 2020 09:23:15 +0200
Subject: [PATCH] Reworked project-switch-project to use read-multiple-choice

---
 lisp/progmodes/project.el | 44 ++++++++++++++-------------------------
 1 file changed, 16 insertions(+), 28 deletions(-)

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 92293d0e2d..cdc27d11f5 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -792,28 +792,21 @@ project-prompt-project-dir
 ;;; Project switching
 
 ;;;###autoload
-(defvar project-switch-commands
-  '(("f" "Find file" project-find-file)
-    ("s" "Find regexp" project-find-regexp)
-    ("d" "Dired" project-dired)
-    ("e" "Eshell" project-eshell))
+(defcustom project-switch-commands
+  '((?f "Find file" project-find-file)
+    (?s "Find regexp" project-find-regexp)
+    (?d "Dired" project-dired)
+    (?e "Eshell" project-eshell))
   "Alist mapping keys to project switching menu entries.
 Used by `project-switch-project' to construct a dispatch menu of
 commands available upon \"switching\" to another project.
 
 Each element looks like (KEY LABEL COMMAND), where COMMAND is the
 command to run when KEY is pressed.  LABEL is used to distinguish
-the choice in the dispatch menu.")
-
-(defun project--keymap-prompt ()
-  "Return a prompt for the project swithing dispatch menu."
-  (mapconcat
-   (pcase-lambda (`(,key ,label))
-     (format "[%s] %s"
-             (propertize (key-description `(,key)) 'face 'bold)
-             label))
-   project-switch-commands
-   "  "))
+the choice in the dispatch menu."
+  :type '(repeat (list (character :tag "Invocation Key")
+                       (string :tag "Label")
+                       (function :tag "Command"))))
 
 ;;;###autoload
 (defun project-switch-project ()
@@ -821,18 +814,13 @@ project-switch-project
 The available commands are picked from `project-switch-commands'
 and presented in a dispatch menu."
   (interactive)
-  (let ((dir (project-prompt-project-dir))
-        (choice nil))
-    (while (not (and choice
-                     (or (equal choice (kbd "C-g"))
-                         (assoc choice project-switch-commands))))
-      (setq choice (read-key-sequence (project--keymap-prompt))))
-    (if (equal choice (kbd "C-g"))
-        (message "Quit")
-      (let ((default-directory dir)
-            (project-current-inhibit-prompt t))
-        (call-interactively
-         (nth 2 (assoc choice project-switch-commands)))))))
+  (let* ((default-directory (project-prompt-project-dir))
+         (choice (read-multiple-choice
+                  "Open project via"
+                  (mapcar #'butlast project-switch-commands)))
+         (project-current-inhibit-prompt t))
+    (call-interactively
+     (nth 2 (assq (car choice) project-switch-commands)))))
 
 (provide 'project)
 ;;; project.el ends here
-- 
2.20.1


reply via email to

[Prev in Thread] Current Thread [Next in Thread]