aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2020-05-12 04:13:48 +0300
committerSimen Heggestøyl2020-05-26 17:41:24 +0200
commitc8cca68751ac3ebd702ab809bc2bb2cc352a190e (patch)
tree3029cb32fed90b5d3e5ca86040dbc1e8bc7de8bf
parent9422fb5e686a66898c2de76226f8a404ab253136 (diff)
downloademacs-c8cca68751ac3ebd702ab809bc2bb2cc352a190e.tar.gz
emacs-c8cca68751ac3ebd702ab809bc2bb2cc352a190e.zip
Use an alist instead of a keymap
* lisp/progmodes/project.el: (project--switch-alist): New variable to use instead of project-switch-keymap, which remove. Update all references.
-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 3e943ca0533..7209246c228 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -776,10 +776,10 @@ It's also possible to enter an arbitrary directory."
776 776
777;;; Project switching 777;;; Project switching
778 778
779(defvar project-switch-keymap (make-sparse-keymap) 779(defvar project--switch-alist nil
780 "Keymap of commands for \"switching\" to a project. 780 "Association list mapping characters to commands.
781Used by `project-switch-project' to construct a dispatch menu of 781Used by `project-switch-project' to construct a dispatch menu of
782commands available for \"switching\" to another project.") 782commands available upon \"switching\" to another project.")
783 783
784;;;###autoload 784;;;###autoload
785(defun project-dired () 785(defun project-dired ()
@@ -802,7 +802,8 @@ commands available for \"switching\" to another project.")
802SYMBOL should stand for a function to be invoked by the key KEY. 802SYMBOL should stand for a function to be invoked by the key KEY.
803LABEL is used to distinguish the function in the dispatch menu." 803LABEL is used to distinguish the function in the dispatch menu."
804 (function-put symbol 'dispatch-label label) 804 (function-put symbol 'dispatch-label label)
805 (define-key project-switch-keymap key symbol)) 805 ;; XXX: It could host the label as well now.
806 (add-to-list 'project--switch-alist `(,key . ,symbol)))
806 807
807(project-add-switch-command 808(project-add-switch-command
808 'project-find-file "f" "Find file") 809 'project-find-file "f" "Find file")
@@ -816,12 +817,13 @@ LABEL is used to distinguish the function in the dispatch menu."
816(defun project--keymap-prompt () 817(defun project--keymap-prompt ()
817 "Return a prompt for the project swithing dispatch menu." 818 "Return a prompt for the project swithing dispatch menu."
818 (let ((prompt "")) 819 (let ((prompt ""))
819 (map-keymap 820 (mapc
820 (lambda (event value) 821 (lambda (entry)
821 (let ((key (propertize (key-description `(,event)) 'face 'bold)) 822 (pcase-let* ((`(,char . ,symbol) entry)
822 (desc (function-get value 'dispatch-label))) 823 (key (propertize (key-description `(,char)) 'face 'bold))
824 (desc (function-get symbol 'dispatch-label)))
823 (setq prompt (concat (format "[%s] %s " key desc) prompt)))) 825 (setq prompt (concat (format "[%s] %s " key desc) prompt))))
824 project-switch-keymap) 826 project--switch-alist)
825 prompt)) 827 prompt))
826 828
827;;;###autoload 829;;;###autoload
@@ -834,12 +836,12 @@ and presented in a dispatch menu."
834 (choice nil)) 836 (choice nil))
835 (while (not (and choice 837 (while (not (and choice
836 (or (equal choice (kbd "C-g")) 838 (or (equal choice (kbd "C-g"))
837 (lookup-key project-switch-keymap choice)))) 839 (assoc choice project--switch-alist))))
838 (setq choice (read-key-sequence (project--keymap-prompt)))) 840 (setq choice (read-key-sequence (project--keymap-prompt))))
839 (if (equal choice (kbd "C-g")) 841 (if (equal choice (kbd "C-g"))
840 (message "Quit") 842 (message "Quit")
841 (let ((default-directory dir)) 843 (let ((default-directory dir))
842 (funcall (lookup-key project-switch-keymap choice)))))) 844 (funcall (assoc-default choice project--switch-alist))))))
843 845
844(provide 'project) 846(provide 'project)
845;;; project.el ends here 847;;; project.el ends here