Commit bea584fa authored by Glenn Morris's avatar Glenn Morris

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 @@
2011-02-19 Glenn Morris <rgm@gnu.org>
* dired-x.texi (Technical Details): No longer redefines dired-add-entry,
dired-initial-position, dired-clean-up-after-deletion, or
dired-read-shell-command.
dired-initial-position, dired-clean-up-after-deletion,
dired-read-shell-command, or dired-find-buffer-nocreate.
2011-02-18 Glenn Morris <rgm@gnu.org>
......
......@@ -174,19 +174,19 @@ Point}).
@node Technical Details, , Features, Introduction
@section Technical Details
@cindex Redefined functions
@cindex Modified functions
@cindex @file{dired-aux.el}
When loaded this code @emph{redefines} the standard @file{dired.el}
function @code{dired-find-buffer-nocreate}. In addition, once
@file{dired-x.el} is loaded, the following Dired functions offer
additional features. @code{dired-add-entry} obeys Dired Omit mode
(@pxref{Omitting Files in Dired}), if it is active.
@code{dired-initial-position} obeys @code{dired-find-subdir}
(@pxref{Miscellaneous Commands}). @code{dired-clean-up-after-deletion}
respects the value of @code{dired-clean-up-buffers-too}.
@code{dired-read-shell-command} uses @code{dired-guess-shell-command}
(@pxref{Shell Command Guessing}) to offer a smarter default command.
When @file{dired-x.el} is loaded, some standard Dired functions from
@file{dired.el} and @file{dired-aux.el} offer additional features.
@code{dired-add-entry} obeys Dired Omit mode (@pxref{Omitting Files in
Dired}), if it is active. @code{dired-find-buffer-nocreate} and
@code{dired-initial-position} respect the value of
@code{dired-find-subdir} (@pxref{Miscellaneous Commands}).
@code{dired-clean-up-after-deletion} respects the value of
@code{dired-clean-up-buffers-too}. @code{dired-read-shell-command} uses
@code{dired-guess-shell-command} (@pxref{Shell Command Guessing}) to
offer a smarter default command.
@node Installation, Omitting Files in Dired, Introduction, Top
@chapter Installation
......
......@@ -22,6 +22,9 @@
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-aux.el (dired-read-shell-command): Merge dired-x's version.
......
......@@ -42,13 +42,12 @@
;; ;; (dired-omit-mode 1)
;; ))
;;
;; At load time dired-x.el will install itself, redefine some functions, and
;; bind some dired keys.
;; At load time dired-x.el will install itself and 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.
;; When loaded this code redefines dired.el's dired-find-buffer-nocreate.
;; *Please* see the `dired-x' info pages for more details.
......@@ -1306,31 +1305,6 @@ Otherwise obeys the value of `dired-vm-read-only-folders'."
;;; 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
(defun dired-buffer-more-recently-used-p (buffer1 buffer2)
"Return t if BUFFER1 is more recently used than BUFFER2.
......
......@@ -847,28 +847,47 @@ periodically reverts at specified time intervals."
;; killed buffer, it is removed from this list.
"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)
;; This differs from dired-buffers-for-dir in that it does not consider
;; subdirs of default-directory and searches for the first match only.
;; Also, the major mode must be MODE.
(setq dirname (expand-file-name dirname))
(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))
(if (and (featurep 'dired-x)
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))
(or (car (sort buffers #'dired-buffer-more-recently-used-p))
;; ---unless it's the only possibility:
(and cur-buf-matches cur-buf)))
;; No dired-x, or dired-find-subdir nil.
(setq dirname (expand-file-name dirname))
(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
......
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