unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Sean Whitton <spwhitton@spwhitton.name>
To: 42210@debbugs.gnu.org
Cc: dgutov@yandex.ru, juri@linkov.net
Subject: bug#42210: Add -other-window variants of project-prefix-map commands
Date: Sat, 04 Jul 2020 23:13:58 -0700	[thread overview]
Message-ID: <87tuymh4k9.fsf@iris.silentflame.com> (raw)
In-Reply-To: <87blkw5cd3.fsf@iris.silentflame.com>

[-- Attachment #1: Type: text/plain, Size: 898 bytes --]

Hello,

On Fri 03 Jul 2020 at 05:54PM -07, Sean Whitton wrote:

> It seems like it would be a good idea to have
>
> C-x 4 p f
> be like
> C-x 4 4 C-x p f
>
> C-x 5 p e
> be like
> C-x 5 5 C-x p e
>
> etc., since many of the commands in project-prefix-map involve switching
> to another buffer.  Certainly project-switch-project, project-find-file
> and project-switch-to-buffer would be wanted.

Here is a patch implementing commands under C-x 4 p.  If the approach is
thought sound I can also prepare patches for C-x 5 p and C-x t p.

I have tested the attached change except for the autoload cookies which
I am not sure will work with my new macro.  And I'm not sure I should be
doing this with a macro instead of a function which calls fset -- please
advise.

If you want me to do copyright assignment before investing time giving
me feedback on my patch, I would be happy to.

-- 
Sean Whitton

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-define-other-window-command-and-project-other-wi.patch --]
[-- Type: text/x-diff, Size: 3182 bytes --]

From bc52db3611612fc595793fd5f2aebd4a7d9bdb59 Mon Sep 17 00:00:00 2001
From: Sean Whitton <spwhitton@spwhitton.name>
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)
+
 \f
 ;;; 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


       reply	other threads:[~2020-07-05  6:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87blkw5cd3.fsf@iris.silentflame.com>
2020-07-05  6:13 ` Sean Whitton [this message]
2020-07-05 14:41   ` bug#42210: Add -other-window variants of project-prefix-map commands Eli Zaretskii
2020-07-05 18:35   ` Drew Adams
2020-07-05 20:25     ` Sean Whitton
2020-07-06  0:00       ` Drew Adams
2020-07-06  0:19   ` Juri Linkov
2020-07-06  1:58     ` Sean Whitton
2020-07-06 22:59       ` Juri Linkov
2020-07-08  6:27         ` Sean Whitton
2020-07-09  0:10           ` Juri Linkov
2020-07-11 17:09             ` Sean Whitton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tuymh4k9.fsf@iris.silentflame.com \
    --to=spwhitton@spwhitton.name \
    --cc=42210@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    --cc=juri@linkov.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).