From: Sean Whitton <spwhitton@spwhitton.name>
To: emacs-devel@gnu.org
Subject: Adding missing C-x 5 C-j and C-x t C-j commands
Date: Sun, 22 May 2022 12:53:25 -0700 [thread overview]
Message-ID: <87a6b9xs22.fsf@athena.silentflame.com> (raw)
[-- 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
next reply other threads:[~2022-05-22 19:53 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-22 19:53 Sean Whitton [this message]
2022-05-23 2:24 ` Adding missing C-x 5 C-j and C-x t C-j commands 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
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=87a6b9xs22.fsf@athena.silentflame.com \
--to=spwhitton@spwhitton.name \
--cc=emacs-devel@gnu.org \
/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).