From bea584fae3e985332d15a05fd08b3c322a965c75 Mon Sep 17 00:00:00 2001 From: Glenn Morris Date: Sat, 19 Feb 2011 12:36:54 -0800 Subject: [PATCH] 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. --- doc/misc/ChangeLog | 4 ++-- doc/misc/dired-x.texi | 22 ++++++++--------- lisp/ChangeLog | 3 +++ lisp/dired-x.el | 32 +++---------------------- lisp/dired.el | 55 +++++++++++++++++++++++++++++-------------- 5 files changed, 56 insertions(+), 60 deletions(-) diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog index 164fdc4ed65..8906c53aeed 100644 --- a/doc/misc/ChangeLog +++ b/doc/misc/ChangeLog @@ -51,8 +51,8 @@ 2011-02-19 Glenn Morris * 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 diff --git a/doc/misc/dired-x.texi b/doc/misc/dired-x.texi index c4e474f0943..003046d5a7c 100644 --- a/doc/misc/dired-x.texi +++ b/doc/misc/dired-x.texi @@ -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 diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 840f96bfcf1..16f1c7dbe5e 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -22,6 +22,9 @@ 2011-02-19 Glenn Morris + * 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. diff --git a/lisp/dired-x.el b/lisp/dired-x.el index 042fbe0b085..ff051f65fe9 100644 --- a/lisp/dired-x.el +++ b/lisp/dired-x.el @@ -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. diff --git a/lisp/dired.el b/lisp/dired.el index c5174561faf..1834fe3eeb3 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -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 -- 2.39.5