emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 1e96b97 2/2: Merge branch 'master' of git.sv.gnu.org:/srv/git/ema


From: Michael Albinus
Subject: master 1e96b97 2/2: Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs
Date: Tue, 13 Jul 2021 13:50:46 -0400 (EDT)

branch: master
commit 1e96b97e3c4aa9cf119a7158ae77cf8c2d6c116d
Merge: cce8482 5afe276
Author: Michael Albinus <michael.albinus@gmx.de>
Commit: Michael Albinus <michael.albinus@gmx.de>

    Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs
---
 doc/emacs/dired.texi |  9 +++++++++
 etc/NEWS             |  5 +++++
 lisp/dired.el        | 18 ++++++++++++++++--
 3 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi
index 3625703..3fbaf8b 100644
--- a/doc/emacs/dired.texi
+++ b/doc/emacs/dired.texi
@@ -457,6 +457,15 @@ Visit the parent directory of the current directory
 for @file{..} and typing @kbd{f} there.
 @end table
 
+@defopt dired-kill-when-opening-new-dired-buffer
+  When visiting a new sub-directory in Dired, Emacs will (by default)
+open a new buffer to display this new directory, and leave the old
+Dired buffer as is.  If this user option is non-@code{nil}, the old
+Dired buffer will be killed after selecting the new directory.  This
+means that if you're traversing a directory structure in Dired, you
+won't end up with more than a single Dired buffer.
+@end defopt
+
 @node Marks vs Flags
 @section Dired Marks vs.@: Flags
 
diff --git a/etc/NEWS b/etc/NEWS
index fd661a1..a3f1283 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -778,6 +778,11 @@ time zones will use a form like "+0100" instead of "CET".
 
 ** Dired
 
++++
+*** New user option 'dired-kill-when-opening-new-dired-buffer'.
+If non-nil, Dired will kill the current buffer when selecting a new
+directory to display.
+
 ---
 *** Behavior change on 'dired-clean-confirm-killing-deleted-buffers'.
 Previously, if 'dired-clean-up-buffers-too' was non-nil, and
diff --git a/lisp/dired.el b/lisp/dired.el
index fb353a9..da803fe 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -356,6 +356,11 @@ is anywhere on its Dired line, except the beginning of the 
line."
   :group 'dired
   :version "28.1")
 
+(defcustom dired-kill-when-opening-new-dired-buffer nil
+  "If non-nil, kill the current buffer when selecting a new directory."
+  :type 'boolean
+  :version "28.1")
+
 
 ;;; Internal variables
 
@@ -2379,7 +2384,7 @@ directory in another window."
        (progn
          (if other-window
              (dired-other-window up)
-           (dired up))
+           (dired--find-possibly-alternative-file up))
          (dired-goto-file dir)))))
 
 (defun dired-get-file-for-visit ()
@@ -2403,7 +2408,16 @@ directory in another window."
 (defun dired-find-file ()
   "In Dired, visit the file or directory named on this line."
   (interactive)
-  (dired--find-file #'find-file (dired-get-file-for-visit)))
+  (dired--find-possibly-alternative-file (dired-get-file-for-visit)))
+
+(defun dired--find-possibly-alternative-file (file)
+  "Find FILE, but respect `dired-kill-when-opening-new-dired-buffer'."
+  (if (and dired-kill-when-opening-new-dired-buffer
+           (file-directory-p file))
+      (progn
+        (set-buffer-modified-p nil)
+        (dired--find-file #'find-alternate-file file))
+    (dired--find-file #'find-file file)))
 
 (defun dired--find-file (find-file-function file)
   "Call FIND-FILE-FUNCTION on FILE, but bind some relevant variables."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]