aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Teirlinck2004-03-23 05:20:11 +0000
committerLuc Teirlinck2004-03-23 05:20:11 +0000
commit573e4d2ddd5c6f06f818fb238a907633ed2be1f2 (patch)
treed72228c73d11b63380d07d9287557e69d4db2304
parentd6af0bff2d4cec7cd3f4f0738dcdeda7dd2ddbd7 (diff)
downloademacs-573e4d2ddd5c6f06f818fb238a907633ed2be1f2.tar.gz
emacs-573e4d2ddd5c6f06f818fb238a907633ed2be1f2.zip
(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.
-rw-r--r--lisp/dired.el42
1 files changed, 30 insertions, 12 deletions
diff --git a/lisp/dired.el b/lisp/dired.el
index c3511baea47..7b4b6974845 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -513,12 +513,34 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh."
513 (setq dir-or-list dirname)) 513 (setq dir-or-list dirname))
514 (dired-internal-noselect dir-or-list switches))) 514 (dired-internal-noselect dir-or-list switches)))
515 515
516;; The following is an internal dired function. It returns non-nil if
517;; the directory visited by the current dired buffer has changed on
518;; disk. DIRNAME should be the directory name of that directory.
519(defun dired-directory-changed-p (dirname)
520 (not (let ((attributes (file-attributes dirname))
521 (modtime (visited-file-modtime)))
522 (or (eq modtime 0)
523 (not (eq (car attributes) t))
524 (and (= (car (nth 5 attributes)) (car modtime))
525 (= (nth 1 (nth 5 attributes)) (cdr modtime)))))))
526
527(defun dired-buffer-stale-p (&optional noconfirm)
528 "Return non-nil if current dired buffer needs updating.
529If NOCONFIRM is non-nil, then this function always returns nil
530for a remote directory. This feature is used by Auto Revert Mode."
531 (let ((dirname
532 (if (consp dired-directory) (car dired-directory) dired-directory)))
533 (and (stringp dirname)
534 (not (when noconfirm (file-remote-p dirname)))
535 (file-readable-p dirname)
536 (dired-directory-changed-p dirname))))
537
516;; Separate function from dired-noselect for the sake of dired-vms.el. 538;; Separate function from dired-noselect for the sake of dired-vms.el.
517(defun dired-internal-noselect (dir-or-list &optional switches mode) 539(defun dired-internal-noselect (dir-or-list &optional switches mode)
518 ;; If there is an existing dired buffer for DIRNAME, just leave 540 ;; If there is an existing dired buffer for DIRNAME, just leave
519 ;; buffer as it is (don't even call dired-revert). 541 ;; buffer as it is (don't even call dired-revert).
520 ;; This saves time especially for deep trees or with ange-ftp. 542 ;; This saves time especially for deep trees or with ange-ftp.
521 ;; The user can type `g'easily, and it is more consistent with find-file. 543 ;; The user can type `g' easily, and it is more consistent with find-file.
522 ;; But if SWITCHES are given they are probably different from the 544 ;; But if SWITCHES are given they are probably different from the
523 ;; buffer's old value, so call dired-sort-other, which does 545 ;; buffer's old value, so call dired-sort-other, which does
524 ;; revert the buffer. 546 ;; revert the buffer.
@@ -544,20 +566,14 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh."
544 ;; kill-all-local-variables any longer. 566 ;; kill-all-local-variables any longer.
545 (setq buffer (create-file-buffer (directory-file-name dirname))))) 567 (setq buffer (create-file-buffer (directory-file-name dirname)))))
546 (set-buffer buffer) 568 (set-buffer buffer)
547 (if (not new-buffer-p) ; existing buffer ... 569 (if (not new-buffer-p) ; existing buffer ...
548 (cond (switches ; ... but new switches 570 (cond (switches ; ... but new switches
549 ;; file list may have changed 571 ;; file list may have changed
550 (setq dired-directory dir-or-list) 572 (setq dired-directory dir-or-list)
551 ;; this calls dired-revert 573 ;; this calls dired-revert
552 (dired-sort-other switches)) 574 (dired-sort-other switches))
553 ;; If directory has changed on disk, offer to revert. 575 ;; If directory has changed on disk, offer to revert.
554 ((if (let ((attributes (file-attributes dirname)) 576 ((when (dired-directory-changed-p dirname)
555 (modtime (visited-file-modtime)))
556 (or (eq modtime 0)
557 (not (eq (car attributes) t))
558 (and (= (car (nth 5 attributes)) (car modtime))
559 (= (nth 1 (nth 5 attributes)) (cdr modtime)))))
560 nil
561 (message "%s" 577 (message "%s"
562 (substitute-command-keys 578 (substitute-command-keys
563 "Directory has changed on disk; type \\[revert-buffer] to update Dired"))))) 579 "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 ;; based on dired-directory, e.g. with ange-ftp to a SysV host 650 ;; based on dired-directory, e.g. with ange-ftp to a SysV host
635 ;; where ls won't understand -Al switches. 651 ;; where ls won't understand -Al switches.
636 (run-hooks 'dired-before-readin-hook) 652 (run-hooks 'dired-before-readin-hook)
637 (message "Reading directory %s..." dirname)
638 (if (consp buffer-undo-list) 653 (if (consp buffer-undo-list)
639 (setq buffer-undo-list nil)) 654 (setq buffer-undo-list nil))
640 (let (buffer-read-only 655 (let (buffer-read-only
@@ -643,7 +658,6 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh."
643 (widen) 658 (widen)
644 (erase-buffer) 659 (erase-buffer)
645 (dired-readin-insert)) 660 (dired-readin-insert))
646 (message "Reading directory %s...done" dirname)
647 (goto-char (point-min)) 661 (goto-char (point-min))
648 ;; Must first make alist buffer local and set it to nil because 662 ;; Must first make alist buffer local and set it to nil because
649 ;; dired-build-subdir-alist will call dired-clear-alist first 663 ;; 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;; Dired mode is suitable only for specially formatted data. 1215;; Dired mode is suitable only for specially formatted data.
1202(put 'dired-mode 'mode-class 'special) 1216(put 'dired-mode 'mode-class 'special)
1203 1217
1218(defvar buffer-stale-function)
1219
1204(defun dired-mode (&optional dirname switches) 1220(defun dired-mode (&optional dirname switches)
1205 "\ 1221 "\
1206Mode for \"editing\" directory listings. 1222Mode for \"editing\" directory listings.
@@ -1279,6 +1295,8 @@ Keybindings:
1279 (propertized-buffer-identification "%17b")) 1295 (propertized-buffer-identification "%17b"))
1280 (set (make-local-variable 'revert-buffer-function) 1296 (set (make-local-variable 'revert-buffer-function)
1281 (function dired-revert)) 1297 (function dired-revert))
1298 (set (make-local-variable 'buffer-stale-function)
1299 (function dired-buffer-stale-p))
1282 (set (make-local-variable 'page-delimiter) 1300 (set (make-local-variable 'page-delimiter)
1283 "\n\n") 1301 "\n\n")
1284 (set (make-local-variable 'dired-directory) 1302 (set (make-local-variable 'dired-directory)