>From 37bc752289bd101ceb725446b425944630971f61 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 18 Jul 2020 08:59:19 -0700 Subject: [PATCH 2/2] WIP: Add project-other-place-commands and functions which use it --- lisp/progmodes/project.el | 51 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 4f0233c8b7..f67698ac96 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -985,6 +985,36 @@ project-switch-commands Used by `project-switch-project' to construct a dispatch menu of commands available upon \"switching\" to another project. +Each element looks like (COMMAND LABEL), where COMMAND should be +bound in `project-prefix-map'. LABEL is used to distinguish the +choice in the dispatch menu." + :type '(alist :key-type function + :value-type string) + :options (mapcan (lambda (ent) + (and (commandp (cdr ent)) + (list (cdr ent)))) + (cdr project-prefix-map)) + :version "28.1") + +;; "other-place" because non-prototype patch will also add an entry +;; in ctl-x-5-map and under C-x t p +(defcustom project-other-place-commands + '((project-find-file . "Find file") + (project-switch-to-buffer . "Switch to buffer") + (project-dired . "Dired") + ;; Eshell uses the current window by default, but Shell defaults + ;; to using the other window. If a user has added an entry to + ;; `display-buffer-alist' for Shell, they probably want to add an + ;; entry here, too + (project-eshell . "Eshell") + (project-switch-project . "Switch project")) + "Alist mapping commands to descriptions. +Used by `project-other-window-command' to construct a dispatch menu of +commands available to be displayed in another window. + +Commands in this list should be ones which normally display their +buffer in the current window. + Each element looks like (COMMAND LABEL), where COMMAND should be bound in `project-prefix-map'. LABEL is used to distinguish the choice in the dispatch menu." @@ -1006,7 +1036,7 @@ project-switch-use-entire-map :type 'bool :version "28.1") -(defun project--keymap-prompt () +(defun project--keymap-prompt (cmds) "Return a prompt for the project swithing dispatch menu." (mapconcat (pcase-lambda (`(,cmd . ,label)) @@ -1014,7 +1044,7 @@ project--keymap-prompt (format "[%s] %s" (propertize (key-description key) 'face 'bold) label))) - project-switch-commands + cmds " ")) ;;;###autoload @@ -1025,12 +1055,27 @@ project-switch-project (interactive) (let* ((default-directory (project-prompt-project-dir)) (project-current-inhibit-prompt t) - (key (read-key-sequence-vector (project--keymap-prompt))) + (key (read-key-sequence-vector + (project--keymap-prompt project-switch-commands))) (cmd (lookup-key project-prefix-map key))) (if (and cmd (or project-switch-use-entire-map (assq cmd project-switch-commands))) (call-interactively cmd) (user-error "%s is undefined" (key-description key))))) +(defun project-other-window-command () + (interactive) + (let* ((key (read-key-sequence-vector + (project--keymap-prompt project-other-place-commands))) + (cmd (lookup-key project-prefix-map key))) + (if (and cmd (assq cmd project-other-place-commands)) + (let ((display-buffer-overriding-action + '((display-buffer-pop-up-window) + (inhibit-same-window . t)))) + (call-interactively cmd)) + (user-error "%s is undefined" (key-description key))))) + +;;;###autoload (define-key ctl-x-4-map "p" 'project-other-window-command) + (provide 'project) ;;; project.el ends here -- 2.27.0