diff options
| author | Simen Heggestøyl | 2020-05-16 09:53:43 +0200 |
|---|---|---|
| committer | Simen Heggestøyl | 2020-05-26 17:41:24 +0200 |
| commit | c6f56bd279bf466450fe9174b3b09201c844eca1 (patch) | |
| tree | c23d728c598f608b9ed69e6e77dd882a151274d5 | |
| parent | 46bb2cbd00eb29eb6bb68f2bd8e47c94365d4e25 (diff) | |
| download | emacs-c6f56bd279bf466450fe9174b3b09201c844eca1.tar.gz emacs-c6f56bd279bf466450fe9174b3b09201c844eca1.zip | |
Turn project switch menu var into a public alist
* lisp/progmodes/project.el: Require seq.
(project--switch-alist): Remove in favor of the public
'project-switch-menu'.
(project-add-switch-command): Remove; not needed now that
'project-switch-menu' is a public alist.
(project-switch-menu): New variable mapping keys to project switching
menu entries.
(project--keymap-prompt, project-switch-project): Adjust to the new
'project-switch-menu' format.
| -rw-r--r-- | lisp/progmodes/project.el | 64 |
1 files changed, 26 insertions, 38 deletions
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index edf690cdf9c..a00bb703814 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el | |||
| @@ -93,6 +93,7 @@ | |||
| 93 | ;;; Code: | 93 | ;;; Code: |
| 94 | 94 | ||
| 95 | (require 'cl-generic) | 95 | (require 'cl-generic) |
| 96 | (require 'seq) | ||
| 96 | (eval-when-compile (require 'subr-x)) | 97 | (eval-when-compile (require 'subr-x)) |
| 97 | 98 | ||
| 98 | (defvar project-find-functions (list #'project-try-vc) | 99 | (defvar project-find-functions (list #'project-try-vc) |
| @@ -791,60 +792,47 @@ It's also possible to enter an arbitrary directory." | |||
| 791 | 792 | ||
| 792 | ;;; Project switching | 793 | ;;; Project switching |
| 793 | 794 | ||
| 794 | (defvar project--switch-alist nil | ||
| 795 | "Association list mapping characters to commands. | ||
| 796 | Used by `project-switch-project' to construct a dispatch menu of | ||
| 797 | commands available upon \"switching\" to another project.") | ||
| 798 | |||
| 799 | ;;;###autoload | 795 | ;;;###autoload |
| 800 | (defun project-add-switch-command (symbol key label) | 796 | (defvar project-switch-menu |
| 801 | "Add a function to the project switching dispatch menu. | 797 | '(("f" "Find file" project-find-file) |
| 802 | SYMBOL should stand for a function to be invoked by the key KEY. | 798 | ("s" "Find regexp" project-find-regexp) |
| 803 | LABEL is used to distinguish the function in the dispatch menu." | 799 | ("d" "Dired" project-dired) |
| 804 | (function-put symbol 'dispatch-label label) | 800 | ("e" "Eshell" project-eshell)) |
| 805 | ;; XXX: It could host the label as well now. | 801 | "Alist mapping keys to project switching menu entries. |
| 806 | (add-to-list 'project--switch-alist `(,key . ,symbol))) | 802 | Used by `project-switch-project' to construct a dispatch menu of |
| 807 | 803 | commands available upon \"switching\" to another project. | |
| 808 | (project-add-switch-command | ||
| 809 | 'project-find-file "f" "Find file") | ||
| 810 | |||
| 811 | (project-add-switch-command | ||
| 812 | 'project-find-regexp "s" "Find regexp") | ||
| 813 | |||
| 814 | (project-add-switch-command | ||
| 815 | 'project-dired "d" "Dired") | ||
| 816 | 804 | ||
| 817 | (project-add-switch-command | 805 | Each element looks like (KEY LABEL COMMAND), where COMMAND is the |
| 818 | 'project-eshell "e" "Eshell") | 806 | command to run when KEY is pressed. LABEL is used to distinguish |
| 807 | the choice in the dispatch menu.") | ||
| 819 | 808 | ||
| 820 | (defun project--keymap-prompt () | 809 | (defun project--keymap-prompt () |
| 821 | "Return a prompt for the project swithing dispatch menu." | 810 | "Return a prompt for the project swithing dispatch menu." |
| 822 | (let ((prompt "")) | 811 | (string-trim |
| 823 | (mapc | 812 | (seq-mapcat |
| 824 | (lambda (entry) | 813 | (pcase-lambda (`(,key ,label)) |
| 825 | (pcase-let* ((`(,char . ,symbol) entry) | 814 | (format "[%s] %s " |
| 826 | (key (propertize (key-description `(,char)) 'face 'bold)) | 815 | (propertize (key-description `(,key)) 'face 'bold) |
| 827 | (desc (function-get symbol 'dispatch-label))) | 816 | label)) |
| 828 | (setq prompt (concat (format "[%s] %s " key desc) prompt)))) | 817 | project-switch-menu 'string))) |
| 829 | project--switch-alist) | ||
| 830 | prompt)) | ||
| 831 | 818 | ||
| 832 | ;;;###autoload | 819 | ;;;###autoload |
| 833 | (defun project-switch-project () | 820 | (defun project-switch-project () |
| 834 | "\"Switch\" to another project by running a chosen command. | 821 | "\"Switch\" to another project by running a chosen command. |
| 835 | The available commands are picked from `project-switch-keymap' | 822 | The available commands are picked from `project-switch-menu' and |
| 836 | and presented in a dispatch menu." | 823 | presented in a dispatch menu." |
| 837 | (interactive) | 824 | (interactive) |
| 838 | (let* ((dir (project-prompt-project-dir)) | 825 | (let ((dir (project-prompt-project-dir)) |
| 839 | (choice nil)) | 826 | (choice nil)) |
| 840 | (while (not (and choice | 827 | (while (not (and choice |
| 841 | (or (equal choice (kbd "C-g")) | 828 | (or (equal choice (kbd "C-g")) |
| 842 | (assoc choice project--switch-alist)))) | 829 | (assoc choice project-switch-menu)))) |
| 843 | (setq choice (read-key-sequence (project--keymap-prompt)))) | 830 | (setq choice (read-key-sequence (project--keymap-prompt)))) |
| 844 | (if (equal choice (kbd "C-g")) | 831 | (if (equal choice (kbd "C-g")) |
| 845 | (message "Quit") | 832 | (message "Quit") |
| 846 | (let ((default-directory dir)) | 833 | (let ((default-directory dir)) |
| 847 | (call-interactively (assoc-default choice project--switch-alist)))))) | 834 | (call-interactively |
| 835 | (nth 2 (assoc choice project-switch-menu))))))) | ||
| 848 | 836 | ||
| 849 | (provide 'project) | 837 | (provide 'project) |
| 850 | ;;; project.el ends here | 838 | ;;; project.el ends here |