]> git.eshelyaron.com Git - emacs.git/commitdiff
project.el: Simplify -other-foo commands
authorEshel Yaron <me@eshelyaron.com>
Tue, 18 Feb 2025 08:36:30 +0000 (09:36 +0100)
committerEshel Yaron <me@eshelyaron.com>
Tue, 18 Feb 2025 08:36:30 +0000 (09:36 +0100)
lisp/progmodes/project.el

index 3d437671d8c6eae50460191b0428916f6e08045c..1e85336bf6a150ff831bc0d6dfe442cf0cba2f61 100644 (file)
@@ -907,43 +907,23 @@ DIRS must contain directory names."
 
 ;;;###autoload (define-key ctl-x-map "p" project-prefix-map)
 
-;; We can't have these place-specific maps inherit from
-;; project-prefix-map because project--other-place-command needs to
-;; know which map the key binding came from, as if it came from one of
-;; these maps, we don't want to set display-buffer-overriding-action
+(defvar-keymap project-other-window-map
+  :doc "Keymap for project commands that display buffers in other windows."
+  :parent project-prefix-map
+  "C-o" #'project-display-buffer)
 
-(defvar project-other-window-map
-  (let ((map (make-sparse-keymap)))
-    (define-key map "\C-o" #'project-display-buffer)
-    map)
-  "Keymap for project commands that display buffers in other windows.")
+(defvar-keymap project-other-frame-map
+  :doc "Keymap for project commands that display buffers in other frames."
+  :parent project-prefix-map
+  "C-o" #'project-display-buffer-other-frame)
 
-(defvar project-other-frame-map
-  (let ((map (make-sparse-keymap)))
-    (define-key map "\C-o" #'project-display-buffer-other-frame)
-    map)
-  "Keymap for project commands that display buffers in other frames.")
-
-(defun project--other-place-command (action &optional map)
-  (let* ((key (read-key-sequence-vector nil t))
-         (place-cmd (lookup-key map key))
-         (generic-cmd (lookup-key project-prefix-map key))
-         (switch-to-buffer-obey-display-actions t)
-         (display-buffer-overriding-action (unless place-cmd action)))
-    (if-let ((cmd (or place-cmd generic-cmd)))
-        (call-interactively cmd)
-      (user-error "%s is undefined" (key-description key)))))
-
-(defun project--other-place-prefix (place &optional extra-keymap)
+(defun project--other-place-prefix (place &optional keymap)
   (cl-assert (member place '(window frame tab)))
   (prefix-command-preserve-state)
   (let ((inhibit-message t)) (funcall (intern (format "other-%s-prefix" place))))
   (message "Display next project command buffer in a new %s..." place)
   ;; Should return exitfun from set-transient-map
-  (set-transient-map (if extra-keymap
-                         (make-composed-keymap project-prefix-map
-                                               extra-keymap)
-                       project-prefix-map)))
+  (set-transient-map (or keymap project-prefix-map)))
 
 ;;;###autoload
 (defun project-other-window-command ()
@@ -951,14 +931,9 @@ DIRS must contain directory names."
 
 The following commands are available:
 
-\\{project-prefix-map}
 \\{project-other-window-map}"
   (interactive)
-  (if (< emacs-major-version 30)
-      (project--other-place-command '((display-buffer-pop-up-window)
-                                      (inhibit-same-window . t))
-                                    project-other-window-map)
-    (project--other-place-prefix 'window project-other-window-map)))
+  (project--other-place-prefix 'window project-other-window-map))
 
 ;;;###autoload (define-key ctl-x-4-map "p" #'project-other-window-command)
 
@@ -968,13 +943,9 @@ The following commands are available:
 
 The following commands are available:
 
-\\{project-prefix-map}
 \\{project-other-frame-map}"
   (interactive)
-  (if (< emacs-major-version 30)
-      (project--other-place-command '((display-buffer-pop-up-frame))
-                                    project-other-frame-map)
-    (project--other-place-prefix 'frame project-other-frame-map)))
+  (project--other-place-prefix 'frame project-other-frame-map))
 
 ;;;###autoload (define-key ctl-x-5-map "p" #'project-other-frame-command)
 
@@ -986,9 +957,7 @@ The following commands are available:
 
 \\{project-prefix-map}"
   (interactive)
-  (if (< emacs-major-version 30)
-      (project--other-place-command '((display-buffer-in-new-tab)))
-    (project--other-place-prefix 'tab)))
+  (project--other-place-prefix 'tab))
 
 ;;;###autoload
 (when (bound-and-true-p tab-prefix-map)