From 8b320e00fbd89a3b8e9097b04cf307d3230e6ed6 Mon Sep 17 00:00:00 2001 From: Philip K 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