diff --git a/lisp/frame.el b/lisp/frame.el index d2376f1e339..1e18d41ac31 100644 --- a/lisp/frame.el +++ b/lisp/frame.el @@ -1108,6 +1108,8 @@ other-frame-prefix nil "[other-frame]") (message "Display next command buffer in a new frame...")) +(put 'other-frame-prefix 'prefix-command t) + (defun iconify-or-deiconify-frame () "Iconify the selected frame, or deiconify if it's currently an icon." (interactive) diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index a95d1267dd2..7298ffe19c8 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -934,6 +934,8 @@ project-other-window-command project-other-window-map) (project--other-place-prefix 'window project-other-window-map))) +(put 'project-other-window-command 'prefix-command t) + ;;;###autoload (define-key ctl-x-4-map "p" #'project-other-window-command) ;;;###autoload @@ -950,6 +952,8 @@ project-other-frame-command project-other-frame-map) (project--other-place-prefix 'frame project-other-frame-map))) +(put 'project-other-frame-command 'prefix-command t) + ;;;###autoload (define-key ctl-x-5-map "p" #'project-other-frame-command) ;;;###autoload @@ -964,10 +968,54 @@ project-other-tab-command (project--other-place-command '((display-buffer-in-new-tab))) (project--other-place-prefix 'tab))) +(put 'project-other-tab-command 'prefix-command t) + ;;;###autoload (when (bound-and-true-p tab-prefix-map) (define-key tab-prefix-map "p" #'project-other-tab-command)) +;;;###autoload +(defun other-project-prefix () + "\"Switch\" to another project before running an Emacs command. +The next command you invoke will prompt for the project in which to run +the command." + (interactive) + (prefix-command-preserve-state) + (letrec ((depth (minibuffer-depth)) + (echofun (lambda () "[switch-project]")) + (around-fun + (lambda (command &rest _args) + (interactive) + (advice-remove this-command around-fun) + (if (or (eq this-command 'other-project-prefix) + (eq last-command-event help-char)) + (call-interactively command) + (let* ((this-command-saved this-command) + (root (funcall project-prompter))) + (if (or (string-prefix-p "project-" + (symbol-name this-command-saved)) + (get this-command-saved 'project-aware)) + (let ((project-current-directory-override root)) + (call-interactively command)) + (let ((default-directory root)) + (call-interactively command))))))) + (prefun + (lambda () + (unless (or (> (minibuffer-depth) depth) + (get this-command 'prefix-command)) + (remove-hook 'pre-command-hook prefun) + (remove-hook 'prefix-command-echo-keystrokes-functions echofun) + (when (and this-command (symbolp this-command)) + (advice-add this-command :around around-fun)))))) + (add-hook 'pre-command-hook prefun) + (add-hook 'prefix-command-echo-keystrokes-functions echofun) + (set-transient-map project-prefix-map) + (message (concat "Type " (project--keymap-prompt) " or any global key")))) + +(put 'other-project-prefix 'prefix-command t) + +;; (define-key project-prefix-map (kbd "P") #'other-project-prefix) + (declare-function grep-read-files "grep") (declare-function xref--find-ignores-arguments "xref") diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index dac57ce2070..9a16d20be73 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el @@ -2855,6 +2855,8 @@ other-tab-prefix nil "[other-tab]") (message "Display next command buffer in a new tab...")) +(put 'other-tab-prefix 'prefix-command t) + ;;; Short aliases and keybindings diff --git a/lisp/window.el b/lisp/window.el index 8feeba0d83e..7d2c7f9977d 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -4044,6 +4044,8 @@ other-window-prefix nil "[other-window]") (message "Display next command buffer in a new window...")) +(put 'other-window-prefix 'prefix-command t) + (defun same-window-prefix () "Display the buffer of the next command in the same window. The next buffer is the buffer displayed by the next command invoked @@ -9269,7 +9271,8 @@ display-buffer-override-next-command (> (minibuffer-depth) minibuffer-depth) ;; But don't remove immediately after ;; adding the hook by the same command below. - (eq this-command command)) + (eq this-command command) + (get this-command 'prefix-command)) (funcall exitfun)))) ;; Call post-function after the next command finishes (bug#49057). (add-hook 'post-command-hook postfun)