>From bc52db3611612fc595793fd5f2aebd4a7d9bdb59 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 4 Jul 2020 22:40:36 -0700 Subject: [PATCH] Add define-other-window-command and project-other-window-prefix-map * lisp/progmodes/project.el: Add project-other-window-prefix-map, bind to C-x 4 p, and use define-other-window-command to define the map's commands. * lisp/window.el: Add define-other-window-command. --- lisp/progmodes/project.el | 28 ++++++++++++++++++++++++++++ lisp/window.el | 17 +++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 0a15939d24..3a0034b24a 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -512,6 +512,19 @@ project-prefix-map ;;;###autoload (define-key ctl-x-map "p" project-prefix-map) +;;;###autoload +(defvar project-other-window-prefix-map + (let ((map (make-sparse-keymap))) + (define-key map "f" 'project-find-file-other-window) + (define-key map "b" 'project-switch-to-buffer-other-window) + (define-key map "d" 'project-dired-other-window) + (define-key map "e" 'project-eshell-other-window) + (define-key map "p" 'project-switch-project-other-window) + map) + "Keymap for -other-window project commands.") + +;;;###autoload (define-key ctl-x-4-map "p" project-other-window-prefix-map) + (defun project--value-in-dir (var dir) (with-temp-buffer (setq default-directory dir) @@ -864,6 +877,21 @@ project-kill-buffers (length bufs) (project-root pr))) (mapc #'kill-buffer bufs)))) +;;;###autoload +(define-other-window-command project-find-file) + +;;;###autoload +(define-other-window-command project-switch-to-buffer) + +;;;###autoload +(define-other-window-command project-dired) + +;;;###autoload +(define-other-window-command project-eshell) + +;;;###autoload +(define-other-window-command project-switch-project) + ;;; Project list diff --git a/lisp/window.el b/lisp/window.el index 675aff041b..519e15ac79 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -4042,6 +4042,23 @@ same-window-prefix 'reuse))) (message "Display next command buffer in the same window...")) +(defmacro define-other-window-command (function) + "Define a version of FUNCTION which displays its buffer in another window. + +The new function will be named 'FUNCTION-other-window'." + (let ((other-window-function + (intern (concat (symbol-name function) "-other-window")))) + `(defun ,other-window-function (&rest args) + ,(concat "Like `" (symbol-name function) + "' but prefer to display resultant buffer in another window.") + ,@(if (commandp function) '((interactive)) '()) + (let ((display-buffer-overriding-action + '((display-buffer-pop-up-window) + (inhibit-same-window . t)))) + (if (called-interactively-p) + (call-interactively ',function) + (apply ',function args)))))) + ;; This should probably return non-nil when the selected window is part ;; of an atomic window whose root is the frame's root window. (defun one-window-p (&optional nomini all-frames) -- 2.26.2