all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Adding missing C-x 5 C-j and C-x t C-j commands
@ 2022-05-22 19:53 Sean Whitton
  2022-05-23  2:24 ` Eli Zaretskii
  0 siblings, 1 reply; 22+ messages in thread
From: Sean Whitton @ 2022-05-22 19:53 UTC (permalink / raw)
  To: emacs-devel

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

We have C-x d, C-x 4 d, C-x 5 d and C-x t d, but only C-x C-j
and C-x 4 C-j.  My fingers try to use C-x 5 C-j, and find it isn't
there, at least biweekly.  Here is a draft patch to fill the gap.

C-x t C-j temporarily doesn't work due to #55582.

-- 
Sean Whitton

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-dired-jump-other-frame-and-dired-jump-other-tab.patch --]
[-- Type: text/x-diff, Size: 7690 bytes --]

From 2b5ced057a959ab51387ac5d45d2a7b10a414591 Mon Sep 17 00:00:00 2001
From: Sean Whitton <spwhitton@spwhitton.name>
Date: Sun, 22 May 2022 12:08:54 -0700
Subject: [PATCH] Add dired-jump-other-frame and dired-jump-other-tab

* lisp/bindings.el: Drop binding C-x C-j and C-x 4 C-j.
* lisp/dired.el: Bind C-x C-j, C-x 4 C-j, C-x 5 C-j and C-x t C-j
using autoload cookies.  (This parallels the way in which C-x d,
C-x 4 d, C-x 5 d and C-x t d are bound.)
(dired-up-directory): When optional argument is a function, switch to
the buffer using that function.
(dired-jump): Refactor to call dired-jump--internal.
(dired-jump-other-window): Refactor to call dired-jump--internal and
add "... in other window" to read-file-name prompt.
(dired-jump-other-frame, dired-jump-other-tab): New commands.
(dired-jump--internal): New function factored out of dired-jump.
* etc/NEWS:
* doc/emacs/dired.texi (Entering Dired): Document the change.
---
 doc/emacs/dired.texi |  9 +++++-
 etc/NEWS             |  4 +++
 lisp/bindings.el     |  3 --
 lisp/dired.el        | 66 ++++++++++++++++++++++++++++++++------------
 4 files changed, 60 insertions(+), 22 deletions(-)

diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi
index ed4ff5213f..5a95d6e8e1 100644
--- a/doc/emacs/dired.texi
+++ b/doc/emacs/dired.texi
@@ -111,8 +111,12 @@ Dired Enter
 
 @findex dired-jump
 @findex dired-jump-other-window
+@findex dired-jump-other-frame
+@findex dired-jump-other-tab
 @kindex C-x C-j
 @kindex C-x 4 C-j
+@kindex C-x 5 C-j
+@kindex C-x t C-j
   You can ask Emacs to invoke Dired on the default-directory
 (@pxref{File Names, default-directory}) of any buffer, by typing
 @kbd{C-x C-j} (@code{dired-jump}).  If the buffer visits a file, this
@@ -123,7 +127,10 @@ Dired Enter
 and places point on the line that corresponds to the directory where
 you invoked @code{dired-jump}.  Typing @kbd{C-x 4 C-j}
 (@code{dired-jump-other-window}) has the same effect, but displays the
-Dired buffer in a new window.
+Dired buffer in a new window; similarly @kbd{C-x 5 C-j}
+(@code{dired-jump-other-frame}) to display the Dired buffer in a new
+frame and @kbd{C-x t C-j} (@code{dired-jump-other-tab}) to display the
+Dired buffer in a new tab.
 
   The variable @code{dired-listing-switches} specifies the options to
 give to @command{ls} for listing the directory; this string
diff --git a/etc/NEWS b/etc/NEWS
index 190620619f..31105bfbec 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1493,6 +1493,10 @@ If non-nil (which is the default), hitting 'RET' or 'mouse-1' on
 the directory components at the directory displayed at the start of
 the buffer will take you to that directory.
 
++++
+*** New commands 'dired-jump-other-frame' and 'dired-jump-other-tab'.
+These are bound to 'C-x 5 C-j' and 'C-x t C-j' respectively.
+
 ** Exif
 
 ---
diff --git a/lisp/bindings.el b/lisp/bindings.el
index ed1325e326..4ed197f1d4 100644
--- a/lisp/bindings.el
+++ b/lisp/bindings.el
@@ -1501,9 +1501,6 @@ esc-map
 (define-key ctl-x-map "'" 'expand-abbrev)
 (define-key ctl-x-map "\C-b" 'list-buffers)
 
-(define-key ctl-x-map "\C-j" 'dired-jump)
-(define-key ctl-x-4-map "\C-j" 'dired-jump-other-window)
-
 (define-key ctl-x-map "z" 'repeat)
 
 (defvar ctl-x-x-map
diff --git a/lisp/dired.el b/lisp/dired.el
index 89fbd52aa6..d8fa726c6f 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -2583,8 +2583,13 @@ dired-up-directory
   "Run Dired on parent directory of current directory.
 Find the parent directory either in this buffer or another buffer.
 Creates a buffer if necessary.
-If OTHER-WINDOW (the optional prefix arg), display the parent
-directory in another window."
+
+When called interactively with a prefix argument, display the
+parent directory in another window.
+
+When called from Lisp, if OTHER-WINDOW is a function, switch to
+the buffer by calling that function.  When OTHER-WINDOW is
+otherwise non-nil, use `switch-to-buffer-other-window'."
   (interactive "P")
   (let* ((dir (dired-current-directory))
 	 (up (file-name-directory (directory-file-name dir))))
@@ -2592,11 +2597,12 @@ dired-up-directory
 	;; Only try dired-goto-subdir if buffer has more than one dir.
 	(and (cdr dired-subdir-alist)
 	     (dired-goto-subdir up))
-	(progn
-	  (if other-window
-	      (dired-other-window up)
-	    (dired--find-possibly-alternative-file up))
-	  (dired-goto-file dir)))))
+        (progn (pcase other-window
+                 ('nil (dired--find-possibly-alternative-file up))
+                 ((or (pred functionp) (pred symbolp))
+                  (funcall other-window (dired-noselect up)))
+                 (_ (dired-other-window up)))
+               (dired-goto-file dir)))))
 
 (defun dired-get-file-for-visit ()
   "Get the current line's file name, with an error if file does not exist."
@@ -4704,6 +4710,7 @@ archive-superior-buffer
 (defvar tar-superior-buffer)
 (declare-function dired-omit-mode "dired-x" (&optional arg))
 
+;;;###autoload (define-key ctl-x-map "\C-j" #'dired-jump)
 ;;;###autoload
 (defun dired-jump (&optional other-window file-name)
   "Jump to Dired buffer corresponding to current buffer.
@@ -4723,6 +4730,39 @@ dired-jump
   (interactive
    (list nil (and current-prefix-arg
                   (read-file-name "Jump to Dired file: "))))
+  (dired-jump--internal (if other-window
+                            #'switch-to-buffer-other-window
+                          #'pop-to-buffer-same-window)
+                        file-name))
+
+;;;###autoload (define-key ctl-x-4-map "\C-j" #'dired-jump-other-window)
+;;;###autoload
+(defun dired-jump-other-window (&optional file-name)
+  "Like \\[dired-jump] (`dired-jump') but in other window."
+  (interactive
+   (list (and current-prefix-arg
+              (read-file-name "Jump to Dired file in other window: "))))
+  (dired-jump--internal #'switch-to-buffer-other-window file-name))
+
+;;;###autoload (define-key ctl-x-5-map "\C-j" #'dired-jump-other-frame)
+;;;###autoload
+(defun dired-jump-other-frame (&optional file-name)
+  "Like \\[dired-jump] (`dired-jump') but in other frame."
+  (interactive
+   (list (and current-prefix-arg
+              (read-file-name "Jump to Dired file in other frame: "))))
+  (dired-jump--internal #'switch-to-buffer-other-frame file-name))
+
+;;;###autoload (define-key tab-prefix-map "\C-j" #'dired-jump-other-tab)
+;;;###autoload
+(defun dired-jump-other-tab (&optional file-name)
+  "Like \\[dired-jump] (`dired-jump') but make new tab."
+  (interactive
+   (list (and current-prefix-arg
+              (read-file-name "Jump to Dired file in other tab: "))))
+  (dired-jump--internal #'switch-to-buffer-other-tab file-name))
+
+(defun dired-jump--internal (other-window file-name)
   (cond
    ((and (bound-and-true-p archive-subfile-mode)
          (buffer-live-p archive-superior-buffer))
@@ -4746,9 +4786,7 @@ dired-jump
               ;; refresh and try again
               (dired-insert-subdir (file-name-directory dir))
               (dired-goto-file dir)))
-        (if other-window
-            (dired-other-window dir)
-          (dired dir))
+        (funcall other-window (dired-noselect dir))
         (if file
             (or (dired-goto-file file)
                 ;; refresh and try again
@@ -4760,14 +4798,6 @@ dired-jump
                   (dired-omit-mode)
                   (dired-goto-file file)))))))))
 
-;;;###autoload
-(defun dired-jump-other-window (&optional file-name)
-  "Like \\[dired-jump] (`dired-jump') but in other window."
-  (interactive
-   (list (and current-prefix-arg
-	      (read-file-name "Jump to Dired file: "))))
-  (dired-jump t file-name))
-
 (provide 'dired)
 
 (run-hooks 'dired-load-hook)		; for your customizations
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2022-06-09  6:44 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-22 19:53 Adding missing C-x 5 C-j and C-x t C-j commands Sean Whitton
2022-05-23  2:24 ` Eli Zaretskii
2022-05-23  4:57   ` Sean Whitton
2022-05-23  4:59     ` Sean Whitton
2022-05-23  7:56       ` Juri Linkov
2022-05-23  9:16         ` Eli Zaretskii
2022-05-23 13:54           ` Sean Whitton
2022-05-23 14:07             ` Eli Zaretskii
2022-05-23 20:52               ` Sean Whitton
2022-05-23 13:35         ` Sean Whitton
2022-05-23 12:26     ` Stefan Monnier
2022-05-23 16:52       ` Juri Linkov
2022-06-07 20:17         ` Howard Melman
2022-06-08  2:29           ` Eli Zaretskii
2022-06-08  6:40           ` Juri Linkov
2022-06-08 12:27             ` Howard Melman
2022-06-08 16:08               ` Juri Linkov
2022-06-08 19:17                 ` Howard Melman
2022-06-09  2:41                   ` Howard Melman
2022-06-09  6:44                     ` Juri Linkov
2022-06-09  5:02                   ` Eli Zaretskii
2022-06-09  6:42                     ` Juri Linkov

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.