aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/project.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/progmodes/project.el')
-rw-r--r--lisp/progmodes/project.el24
1 files changed, 13 insertions, 11 deletions
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index b5e7414c2b2..4410b406230 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -711,10 +711,10 @@ It's also possible to enter an arbitrary directory."
711 711
712;;; Project switching 712;;; Project switching
713 713
714(defvar project-switch-keymap (make-sparse-keymap) 714(defvar project--switch-alist nil
715 "Keymap of commands for \"switching\" to a project. 715 "Association list mapping characters to commands.
716Used by `project-switch-project' to construct a dispatch menu of 716Used by `project-switch-project' to construct a dispatch menu of
717commands available for \"switching\" to another project.") 717commands available upon \"switching\" to another project.")
718 718
719;;;###autoload 719;;;###autoload
720(defun project-dired () 720(defun project-dired ()
@@ -737,7 +737,8 @@ commands available for \"switching\" to another project.")
737SYMBOL should stand for a function to be invoked by the key KEY. 737SYMBOL should stand for a function to be invoked by the key KEY.
738LABEL is used to distinguish the function in the dispatch menu." 738LABEL is used to distinguish the function in the dispatch menu."
739 (function-put symbol 'dispatch-label label) 739 (function-put symbol 'dispatch-label label)
740 (define-key project-switch-keymap key symbol)) 740 ;; XXX: It could host the label as well now.
741 (add-to-list 'project--switch-alist `(,key . ,symbol)))
741 742
742(project-add-switch-command 743(project-add-switch-command
743 'project-find-file "f" "Find file") 744 'project-find-file "f" "Find file")
@@ -751,12 +752,13 @@ LABEL is used to distinguish the function in the dispatch menu."
751(defun project--keymap-prompt () 752(defun project--keymap-prompt ()
752 "Return a prompt for the project swithing dispatch menu." 753 "Return a prompt for the project swithing dispatch menu."
753 (let ((prompt "")) 754 (let ((prompt ""))
754 (map-keymap 755 (mapc
755 (lambda (event value) 756 (lambda (entry)
756 (let ((key (propertize (key-description `(,event)) 'face 'bold)) 757 (pcase-let* ((`(,char . ,symbol) entry)
757 (desc (function-get value 'dispatch-label))) 758 (key (propertize (key-description `(,char)) 'face 'bold))
759 (desc (function-get symbol 'dispatch-label)))
758 (setq prompt (concat (format "[%s] %s " key desc) prompt)))) 760 (setq prompt (concat (format "[%s] %s " key desc) prompt))))
759 project-switch-keymap) 761 project--switch-alist)
760 prompt)) 762 prompt))
761 763
762;;;###autoload 764;;;###autoload
@@ -769,12 +771,12 @@ and presented in a dispatch menu."
769 (choice nil)) 771 (choice nil))
770 (while (not (and choice 772 (while (not (and choice
771 (or (equal choice (kbd "C-g")) 773 (or (equal choice (kbd "C-g"))
772 (lookup-key project-switch-keymap choice)))) 774 (assoc choice project--switch-alist))))
773 (setq choice (read-key-sequence (project--keymap-prompt)))) 775 (setq choice (read-key-sequence (project--keymap-prompt))))
774 (if (equal choice (kbd "C-g")) 776 (if (equal choice (kbd "C-g"))
775 (message "Quit") 777 (message "Quit")
776 (let ((default-directory dir)) 778 (let ((default-directory dir))
777 (funcall (lookup-key project-switch-keymap choice)))))) 779 (funcall (assoc-default choice project--switch-alist))))))
778 780
779(provide 'project) 781(provide 'project)
780;;; project.el ends here 782;;; project.el ends here