Commit bea584fa authored by Glenn Morris's avatar Glenn Morris
Browse files

Merge dired-x's dired-find-buffer-nocreate into dired.el.

* lisp/dired-x.el (dired-find-buffer-nocreate): Merge into dired.el.

* lisp/dired.el (dired-find-buffer-nocreate): Merge dired-x version.

* doc/misc/dired-x.texi (Technical Details):
No longer redefines dired-find-buffer-nocreate.
parent 615d868e
...@@ -51,8 +51,8 @@ ...@@ -51,8 +51,8 @@
2011-02-19 Glenn Morris <rgm@gnu.org> 2011-02-19 Glenn Morris <rgm@gnu.org>
* dired-x.texi (Technical Details): No longer redefines dired-add-entry, * dired-x.texi (Technical Details): No longer redefines dired-add-entry,
dired-initial-position, dired-clean-up-after-deletion, or dired-initial-position, dired-clean-up-after-deletion,
dired-read-shell-command. dired-read-shell-command, or dired-find-buffer-nocreate.
2011-02-18 Glenn Morris <rgm@gnu.org> 2011-02-18 Glenn Morris <rgm@gnu.org>
......
...@@ -174,19 +174,19 @@ Point}). ...@@ -174,19 +174,19 @@ Point}).
@node Technical Details, , Features, Introduction @node Technical Details, , Features, Introduction
@section Technical Details @section Technical Details
@cindex Redefined functions @cindex Modified functions
@cindex @file{dired-aux.el} @cindex @file{dired-aux.el}
When loaded this code @emph{redefines} the standard @file{dired.el} When @file{dired-x.el} is loaded, some standard Dired functions from
function @code{dired-find-buffer-nocreate}. In addition, once @file{dired.el} and @file{dired-aux.el} offer additional features.
@file{dired-x.el} is loaded, the following Dired functions offer @code{dired-add-entry} obeys Dired Omit mode (@pxref{Omitting Files in
additional features. @code{dired-add-entry} obeys Dired Omit mode Dired}), if it is active. @code{dired-find-buffer-nocreate} and
(@pxref{Omitting Files in Dired}), if it is active. @code{dired-initial-position} respect the value of
@code{dired-initial-position} obeys @code{dired-find-subdir} @code{dired-find-subdir} (@pxref{Miscellaneous Commands}).
(@pxref{Miscellaneous Commands}). @code{dired-clean-up-after-deletion} @code{dired-clean-up-after-deletion} respects the value of
respects the value of @code{dired-clean-up-buffers-too}. @code{dired-clean-up-buffers-too}. @code{dired-read-shell-command} uses
@code{dired-read-shell-command} uses @code{dired-guess-shell-command} @code{dired-guess-shell-command} (@pxref{Shell Command Guessing}) to
(@pxref{Shell Command Guessing}) to offer a smarter default command. offer a smarter default command.
@node Installation, Omitting Files in Dired, Introduction, Top @node Installation, Omitting Files in Dired, Introduction, Top
@chapter Installation @chapter Installation
......
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
2011-02-19 Glenn Morris <rgm@gnu.org> 2011-02-19 Glenn Morris <rgm@gnu.org>
* dired-x.el (dired-find-buffer-nocreate): Merge into dired.el.
* dired.el (dired-find-buffer-nocreate): Merge dired-x version.
* dired-x.el (dired-read-shell-command): Merge into dired-aux's version. * dired-x.el (dired-read-shell-command): Merge into dired-aux's version.
* dired-aux.el (dired-read-shell-command): Merge dired-x's version. * dired-aux.el (dired-read-shell-command): Merge dired-x's version.
......
...@@ -42,13 +42,12 @@ ...@@ -42,13 +42,12 @@
;; ;; (dired-omit-mode 1) ;; ;; (dired-omit-mode 1)
;; )) ;; ))
;; ;;
;; At load time dired-x.el will install itself, redefine some functions, and ;; At load time dired-x.el will install itself and bind some dired keys.
;; bind some dired keys. ;; Some dired.el and dired-aux.el functions have extra features if
;; dired-x is loaded.
;; User customization: M-x customize-group RET dired-x RET. ;; User customization: M-x customize-group RET dired-x RET.
;; When loaded this code redefines dired.el's dired-find-buffer-nocreate.
;; *Please* see the `dired-x' info pages for more details. ;; *Please* see the `dired-x' info pages for more details.
...@@ -1306,31 +1305,6 @@ Otherwise obeys the value of `dired-vm-read-only-folders'." ...@@ -1306,31 +1305,6 @@ Otherwise obeys the value of `dired-vm-read-only-folders'."
;;; MISCELLANEOUS INTERNAL FUNCTIONS. ;;; MISCELLANEOUS INTERNAL FUNCTIONS.
(declare-function dired-old-find-buffer-nocreate "dired-x")
(or (fboundp 'dired-old-find-buffer-nocreate)
(fset 'dired-old-find-buffer-nocreate
(symbol-function 'dired-find-buffer-nocreate)))
;; REDEFINE.
;; Redefines dired.el's version of `dired-find-buffer-nocreate'
(defun dired-find-buffer-nocreate (dirname &optional mode)
(if (and dired-find-subdir
;; don't try to find a wildcard as a subdirectory
(string-equal dirname (file-name-directory dirname)))
(let* ((cur-buf (current-buffer))
(buffers (nreverse
(dired-buffers-for-dir (expand-file-name dirname))))
(cur-buf-matches (and (memq cur-buf buffers)
;; wildcards must match, too:
(equal dired-directory dirname))))
;; We don't want to switch to the same buffer---
(setq buffers (delq cur-buf buffers));;need setq with delq
(or (car (sort buffers #'dired-buffer-more-recently-used-p))
;; ---unless it's the only possibility:
(and cur-buf-matches cur-buf)))
(dired-old-find-buffer-nocreate dirname mode)))
;; This should be a builtin ;; This should be a builtin
(defun dired-buffer-more-recently-used-p (buffer1 buffer2) (defun dired-buffer-more-recently-used-p (buffer1 buffer2)
"Return t if BUFFER1 is more recently used than BUFFER2. "Return t if BUFFER1 is more recently used than BUFFER2.
......
...@@ -847,28 +847,47 @@ periodically reverts at specified time intervals." ...@@ -847,28 +847,47 @@ periodically reverts at specified time intervals."
;; killed buffer, it is removed from this list. ;; killed buffer, it is removed from this list.
"Alist of expanded directories and their associated dired buffers.") "Alist of expanded directories and their associated dired buffers.")
(defvar dired-find-subdir)
;; FIXME add a doc-string, and document dired-x extensions.
(defun dired-find-buffer-nocreate (dirname &optional mode) (defun dired-find-buffer-nocreate (dirname &optional mode)
;; This differs from dired-buffers-for-dir in that it does not consider ;; This differs from dired-buffers-for-dir in that it does not consider
;; subdirs of default-directory and searches for the first match only. ;; subdirs of default-directory and searches for the first match only.
;; Also, the major mode must be MODE. ;; Also, the major mode must be MODE.
(setq dirname (expand-file-name dirname)) (if (and (featurep 'dired-x)
(let (found (blist dired-buffers)) ; was (buffer-list) dired-find-subdir
(or mode (setq mode 'dired-mode)) ;; Don't try to find a wildcard as a subdirectory.
(while blist (string-equal dirname (file-name-directory dirname)))
(if (null (buffer-name (cdr (car blist)))) (let* ((cur-buf (current-buffer))
(setq blist (cdr blist)) (buffers (nreverse
(with-current-buffer (cdr (car blist)) (dired-buffers-for-dir (expand-file-name dirname))))
(if (and (eq major-mode mode) (cur-buf-matches (and (memq cur-buf buffers)
dired-directory ;; nil during find-alternate-file ;; Wildcards must match, too:
(equal dirname (equal dired-directory dirname))))
(expand-file-name ;; We don't want to switch to the same buffer---
(if (consp dired-directory) (setq buffers (delq cur-buf buffers))
(car dired-directory) (or (car (sort buffers #'dired-buffer-more-recently-used-p))
dired-directory)))) ;; ---unless it's the only possibility:
(setq found (cdr (car blist)) (and cur-buf-matches cur-buf)))
blist nil) ;; No dired-x, or dired-find-subdir nil.
(setq blist (cdr blist)))))) (setq dirname (expand-file-name dirname))
found)) (let (found (blist dired-buffers)) ; was (buffer-list)
(or mode (setq mode 'dired-mode))
(while blist
(if (null (buffer-name (cdr (car blist))))
(setq blist (cdr blist))
(with-current-buffer (cdr (car blist))
(if (and (eq major-mode mode)
dired-directory ;; nil during find-alternate-file
(equal dirname
(expand-file-name
(if (consp dired-directory)
(car dired-directory)
dired-directory))))
(setq found (cdr (car blist))
blist nil)
(setq blist (cdr blist))))))
found)))
;; Read in a new dired buffer ;; Read in a new dired buffer
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment