Commit 573e4d2d authored by Luc Teirlinck's avatar Luc Teirlinck
Browse files

(dired-directory-changed-p, dired-buffer-stale-p): New functions.

(dired-internal-noselect): Use dired-directory-changed-p.
Eliminate revert messages.
(dired-mode): Set buffer-stale-function to dired-buffer-stale-p.
parent d6af0bff
...@@ -513,12 +513,34 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh." ...@@ -513,12 +513,34 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh."
(setq dir-or-list dirname)) (setq dir-or-list dirname))
(dired-internal-noselect dir-or-list switches))) (dired-internal-noselect dir-or-list switches)))
;; The following is an internal dired function. It returns non-nil if
;; the directory visited by the current dired buffer has changed on
;; disk. DIRNAME should be the directory name of that directory.
(defun dired-directory-changed-p (dirname)
(not (let ((attributes (file-attributes dirname))
(modtime (visited-file-modtime)))
(or (eq modtime 0)
(not (eq (car attributes) t))
(and (= (car (nth 5 attributes)) (car modtime))
(= (nth 1 (nth 5 attributes)) (cdr modtime)))))))
(defun dired-buffer-stale-p (&optional noconfirm)
"Return non-nil if current dired buffer needs updating.
If NOCONFIRM is non-nil, then this function always returns nil
for a remote directory. This feature is used by Auto Revert Mode."
(let ((dirname
(if (consp dired-directory) (car dired-directory) dired-directory)))
(and (stringp dirname)
(not (when noconfirm (file-remote-p dirname)))
(file-readable-p dirname)
(dired-directory-changed-p dirname))))
;; Separate function from dired-noselect for the sake of dired-vms.el. ;; Separate function from dired-noselect for the sake of dired-vms.el.
(defun dired-internal-noselect (dir-or-list &optional switches mode) (defun dired-internal-noselect (dir-or-list &optional switches mode)
;; If there is an existing dired buffer for DIRNAME, just leave ;; If there is an existing dired buffer for DIRNAME, just leave
;; buffer as it is (don't even call dired-revert). ;; buffer as it is (don't even call dired-revert).
;; This saves time especially for deep trees or with ange-ftp. ;; This saves time especially for deep trees or with ange-ftp.
;; The user can type `g'easily, and it is more consistent with find-file. ;; The user can type `g' easily, and it is more consistent with find-file.
;; But if SWITCHES are given they are probably different from the ;; But if SWITCHES are given they are probably different from the
;; buffer's old value, so call dired-sort-other, which does ;; buffer's old value, so call dired-sort-other, which does
;; revert the buffer. ;; revert the buffer.
...@@ -544,20 +566,14 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh." ...@@ -544,20 +566,14 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh."
;; kill-all-local-variables any longer. ;; kill-all-local-variables any longer.
(setq buffer (create-file-buffer (directory-file-name dirname))))) (setq buffer (create-file-buffer (directory-file-name dirname)))))
(set-buffer buffer) (set-buffer buffer)
(if (not new-buffer-p) ; existing buffer ... (if (not new-buffer-p) ; existing buffer ...
(cond (switches ; ... but new switches (cond (switches ; ... but new switches
;; file list may have changed ;; file list may have changed
(setq dired-directory dir-or-list) (setq dired-directory dir-or-list)
;; this calls dired-revert ;; this calls dired-revert
(dired-sort-other switches)) (dired-sort-other switches))
;; If directory has changed on disk, offer to revert. ;; If directory has changed on disk, offer to revert.
((if (let ((attributes (file-attributes dirname)) ((when (dired-directory-changed-p dirname)
(modtime (visited-file-modtime)))
(or (eq modtime 0)
(not (eq (car attributes) t))
(and (= (car (nth 5 attributes)) (car modtime))
(= (nth 1 (nth 5 attributes)) (cdr modtime)))))
nil
(message "%s" (message "%s"
(substitute-command-keys (substitute-command-keys
"Directory has changed on disk; type \\[revert-buffer] to update Dired"))))) "Directory has changed on disk; type \\[revert-buffer] to update Dired")))))
...@@ -634,7 +650,6 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh." ...@@ -634,7 +650,6 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh."
;; based on dired-directory, e.g. with ange-ftp to a SysV host ;; based on dired-directory, e.g. with ange-ftp to a SysV host
;; where ls won't understand -Al switches. ;; where ls won't understand -Al switches.
(run-hooks 'dired-before-readin-hook) (run-hooks 'dired-before-readin-hook)
(message "Reading directory %s..." dirname)
(if (consp buffer-undo-list) (if (consp buffer-undo-list)
(setq buffer-undo-list nil)) (setq buffer-undo-list nil))
(let (buffer-read-only (let (buffer-read-only
...@@ -643,7 +658,6 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh." ...@@ -643,7 +658,6 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh."
(widen) (widen)
(erase-buffer) (erase-buffer)
(dired-readin-insert)) (dired-readin-insert))
(message "Reading directory %s...done" dirname)
(goto-char (point-min)) (goto-char (point-min))
;; Must first make alist buffer local and set it to nil because ;; Must first make alist buffer local and set it to nil because
;; dired-build-subdir-alist will call dired-clear-alist first ;; dired-build-subdir-alist will call dired-clear-alist first
...@@ -1201,6 +1215,8 @@ If HDR is non-nil, insert a header line with the directory name." ...@@ -1201,6 +1215,8 @@ If HDR is non-nil, insert a header line with the directory name."
;; Dired mode is suitable only for specially formatted data. ;; Dired mode is suitable only for specially formatted data.
(put 'dired-mode 'mode-class 'special) (put 'dired-mode 'mode-class 'special)
(defvar buffer-stale-function)
(defun dired-mode (&optional dirname switches) (defun dired-mode (&optional dirname switches)
"\ "\
Mode for \"editing\" directory listings. Mode for \"editing\" directory listings.
...@@ -1279,6 +1295,8 @@ Keybindings: ...@@ -1279,6 +1295,8 @@ Keybindings:
(propertized-buffer-identification "%17b")) (propertized-buffer-identification "%17b"))
(set (make-local-variable 'revert-buffer-function) (set (make-local-variable 'revert-buffer-function)
(function dired-revert)) (function dired-revert))
(set (make-local-variable 'buffer-stale-function)
(function dired-buffer-stale-p))
(set (make-local-variable 'page-delimiter) (set (make-local-variable 'page-delimiter)
"\n\n") "\n\n")
(set (make-local-variable 'dired-directory) (set (make-local-variable 'dired-directory)
......
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