comparison lisp/dired.el @ 54512:1042cb3d696b

(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.
author Luc Teirlinck <teirllm@auburn.edu>
date Tue, 23 Mar 2004 05:20:11 +0000
parents 7efe8089eadf
children 924fccad3acb
comparison
equal deleted inserted replaced
54511:fe79cc82ab84 54512:1042cb3d696b
511 (if (consp dir-or-list) 511 (if (consp dir-or-list)
512 (setq dir-or-list (cons dirname (cdr dir-or-list))) 512 (setq dir-or-list (cons dirname (cdr dir-or-list)))
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.
529 If NOCONFIRM is non-nil, then this function always returns nil
530 for 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.
525 ;; A pity we can't possibly do "Directory has changed - refresh? " 547 ;; A pity we can't possibly do "Directory has changed - refresh? "
526 ;; like find-file does. 548 ;; like find-file does.
542 ;; We don't want default-major-mode to run hooks and set auto-fill 564 ;; We don't want default-major-mode to run hooks and set auto-fill
543 ;; or whatever, now that dired-mode does not 565 ;; or whatever, now that dired-mode does not
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")))))
564 ;; Else a new buffer 580 ;; Else a new buffer
565 (setq default-directory 581 (setq default-directory
632 (save-excursion 648 (save-excursion
633 ;; This hook which may want to modify dired-actual-switches 649 ;; This hook which may want to modify dired-actual-switches
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
641 ;; Don't make undo entries for readin. 656 ;; Don't make undo entries for readin.
642 (buffer-undo-list t)) 657 (buffer-undo-list t))
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
650 (set (make-local-variable 'dired-subdir-alist) nil) 664 (set (make-local-variable 'dired-subdir-alist) nil)
651 (dired-build-subdir-alist) 665 (dired-build-subdir-alist)
1199 (setq dired-mode-map map))) 1213 (setq dired-mode-map map)))
1200 1214
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 "\
1206 Mode for \"editing\" directory listings. 1222 Mode for \"editing\" directory listings.
1207 In Dired, you are \"editing\" a list of the files in a directory and 1223 In Dired, you are \"editing\" a list of the files in a directory and
1208 \(optionally) its subdirectories, in the format of `ls -lR'. 1224 \(optionally) its subdirectories, in the format of `ls -lR'.
1277 selective-display t ; for subdirectory hiding 1293 selective-display t ; for subdirectory hiding
1278 mode-line-buffer-identification 1294 mode-line-buffer-identification
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)
1285 (or dirname default-directory)) 1303 (or dirname default-directory))
1286 ;; list-buffers uses this to display the dir being edited in this buffer. 1304 ;; list-buffers uses this to display the dir being edited in this buffer.