Subject: Re: bug#65558: 30.0.50; project-other-{window,frame,tab}-command a bit too obtrusive

From: Dmitry Gutov <[email-masked]>
Date: Thu, 19 Oct 2023 15:40:35 +0300

Hi Juri,

On 30/08/2023 19:50, Juri Linkov wrote:
>> Thanks for the pointer! That is a long thread so I only skimmed it. I
>> think you meant this snippet in [0]:
>>
>>> (defun project-other-window-command ()
>>>    (interactive)
>>>    (other-window-prefix)
>>>    (set-transient-map (make-composed-keymap project-prefix-map
>>>                                             project-other-window-map)))
> Exactly.  And the same for the frame command in the most recent patch
> I posted to bug#63648, and I confirm that your bug report is fixed with it.
> 
>> That indeed fixes the issue. My only concern is that
>> `other-window-prefix' is a new function introduced in Emacs 28.
> Indeed, it would take more efforts to provide backward-compatibility
> for older Emacs versions.

I think we can install this (tweaked) part of your changes from that 
other bug to close this report.

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index b9ecb770e60..508ade2e0c7 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -880,6 +880,17 @@ project--other-place-command
         (call-interactively cmd)
       (user-error "%s is undefined" (key-description key)))))
 
+(defun project--other-place-prefix (place &optional extra-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)))
+
 ;;;###autoload
 (defun project-other-window-command ()
   "Run project command, displaying resultant buffer in another window.
@@ -889,10 +900,13 @@ project-other-window-command
 \\{project-prefix-map}
 \\{project-other-window-map}"
   (interactive)
-  (project--other-place-command '((display-buffer-pop-up-window)
-                                  (inhibit-same-window . t))
-                                project-other-window-map))
+  (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)))
 
+;; TODO: maybe rename to project-other-window-prefix
 ;;;###autoload (define-key ctl-x-4-map "p" #'project-other-window-command)
 
 ;;;###autoload
@@ -904,8 +918,10 @@ project-other-frame-command
 \\{project-prefix-map}
 \\{project-other-frame-map}"
   (interactive)
-  (project--other-place-command '((display-buffer-pop-up-frame))
-                                project-other-frame-map))
+  (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)))
 
 ;;;###autoload (define-key ctl-x-5-map "p" #'project-other-frame-command)
 
@@ -917,7 +933,9 @@ project-other-tab-command
 
 \\{project-prefix-map}"
   (interactive)
-  (project--other-place-command '((display-buffer-in-new-tab))))
+  (if (< emacs-major-version 30)
+      (project--other-place-command '((display-buffer-in-new-tab)))
+    (project--other-place-prefix 'tab)))
 
 ;;;###autoload
 (when (bound-and-true-p tab-prefix-map)