aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2015-02-21 13:11:55 +0100
committerMichael Albinus2015-02-21 13:11:55 +0100
commit629ed7714a0387cfb9fa5d928159a52f1b088def (patch)
treeb0ac27261a93467bcb386c6c85317a48443199de
parent6982acc4e1561e681ea18a91ee87c32cd3b47f57 (diff)
downloademacs-629ed7714a0387cfb9fa5d928159a52f1b088def.tar.gz
emacs-629ed7714a0387cfb9fa5d928159a52f1b088def.zip
Support file notifications for dired auto-revert
* autorevert.el (auto-revert-notify-add-watch) (auto-revert-notify-handler, auto-revert-buffers): Handle also buffers without an associated file, like dired buffers.
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/autorevert.el84
2 files changed, 51 insertions, 39 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 7f5fb7ddf0d..0211458daab 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12015-02-21 Michael Albinus <michael.albinus@gmx.de>
2
3 * autorevert.el (auto-revert-notify-add-watch)
4 (auto-revert-notify-handler, auto-revert-buffers): Handle also
5 buffers without an associated file, like dired buffers.
6
12015-02-21 Dima Kogan <dima@secretsauce.net> 72015-02-21 Dima Kogan <dima@secretsauce.net>
2 8
3 * autorevert.el (auto-revert-mode, auto-revert-tail-mode) 9 * autorevert.el (auto-revert-mode, auto-revert-tail-mode)
diff --git a/lisp/autorevert.el b/lisp/autorevert.el
index 4dd021e4c76..6489a3e04c2 100644
--- a/lisp/autorevert.el
+++ b/lisp/autorevert.el
@@ -505,16 +505,22 @@ will use an up-to-date value of `auto-revert-interval'"
505 ;; `auto-revert-use-notify' are non-nil. 505 ;; `auto-revert-use-notify' are non-nil.
506 (when (or (string-match auto-revert-notify-exclude-dir-regexp 506 (when (or (string-match auto-revert-notify-exclude-dir-regexp
507 (expand-file-name default-directory)) 507 (expand-file-name default-directory))
508 (file-symlink-p buffer-file-name)) 508 (file-symlink-p (or buffer-file-name default-directory)))
509 ;; Fallback to file checks. 509 ;; Fallback to file checks.
510 (set (make-local-variable 'auto-revert-use-notify) nil)) 510 (set (make-local-variable 'auto-revert-use-notify) nil))
511 511
512 (when (not auto-revert-notify-watch-descriptor) 512 (when (not auto-revert-notify-watch-descriptor)
513 (setq auto-revert-notify-watch-descriptor 513 (setq auto-revert-notify-watch-descriptor
514 (ignore-errors 514 (ignore-errors
515 (file-notify-add-watch 515 (if buffer-file-name
516 (expand-file-name buffer-file-name default-directory) 516 (file-notify-add-watch
517 '(change attribute-change) 'auto-revert-notify-handler))) 517 (expand-file-name buffer-file-name default-directory)
518 '(change attribute-change)
519 'auto-revert-notify-handler)
520 (file-notify-add-watch
521 (expand-file-name default-directory)
522 '(change)
523 'auto-revert-notify-handler))))
518 (if auto-revert-notify-watch-descriptor 524 (if auto-revert-notify-watch-descriptor
519 (progn 525 (progn
520 (puthash 526 (puthash
@@ -563,40 +569,40 @@ no more reverts are possible until the next call of
563 auto-revert-notify-watch-descriptor-hash-list))) 569 auto-revert-notify-watch-descriptor-hash-list)))
564 ;; Check, that event is meant for us. 570 ;; Check, that event is meant for us.
565 (cl-assert descriptor) 571 (cl-assert descriptor)
566 ;; We do not handle `deleted', because nothing has to be refreshed. 572 ;; Since we watch a directory, a file name must be returned.
567 (unless (eq action 'deleted) 573 (cl-assert (stringp file))
568 (cl-assert (memq action '(attribute-changed changed created renamed)) 574 (when (eq action 'renamed) (cl-assert (stringp file1)))
569 t) 575 ;; Loop over all buffers, in order to find the intended one.
570 ;; Since we watch a directory, a file name must be returned. 576 (cl-dolist (buffer buffers)
571 (cl-assert (stringp file)) 577 (when (buffer-live-p buffer)
572 (when (eq action 'renamed) (cl-assert (stringp file1))) 578 (with-current-buffer buffer
573 ;; Loop over all buffers, in order to find the intended one. 579 (when (or
574 (cl-dolist (buffer buffers) 580 ;; A buffer associated with a file.
575 (when (buffer-live-p buffer) 581 (and (stringp buffer-file-name)
576 (with-current-buffer buffer 582 (or
577 (when (and (stringp buffer-file-name) 583 (and (memq action '(attribute-changed changed created))
578 (or 584 (string-equal
579 (and (memq action '(attribute-changed changed 585 (file-name-nondirectory file)
580 created)) 586 (file-name-nondirectory buffer-file-name)))
581 (string-equal 587 (and (eq action 'renamed)
582 (file-name-nondirectory file) 588 (string-equal
583 (file-name-nondirectory buffer-file-name))) 589 (file-name-nondirectory file1)
584 (and (eq action 'renamed) 590 (file-name-nondirectory buffer-file-name)))))
585 (string-equal 591 ;; A buffer w/o a file, like dired.
586 (file-name-nondirectory file1) 592 (and (null buffer-file-name)
587 (file-name-nondirectory buffer-file-name))))) 593 (memq action '(created renamed deleted))))
588 ;; Mark buffer modified. 594 ;; Mark buffer modified.
589 (setq auto-revert-notify-modified-p t) 595 (setq auto-revert-notify-modified-p t)
590 596
591 ;; Revert the buffer now if we're not locked out 597 ;; Revert the buffer now if we're not locked out.
592 (when (/= auto-revert-buffers-counter-lockedout 598 (when (/= auto-revert-buffers-counter-lockedout
593 auto-revert-buffers-counter) 599 auto-revert-buffers-counter)
594 (auto-revert-handler) 600 (auto-revert-handler)
595 (setq auto-revert-buffers-counter-lockedout 601 (setq auto-revert-buffers-counter-lockedout
596 auto-revert-buffers-counter)) 602 auto-revert-buffers-counter))
597 603
598 ;; No need to check other buffers. 604 ;; No need to check other buffers.
599 (cl-return))))))))) 605 (cl-return))))))))
600 606
601(defun auto-revert-active-p () 607(defun auto-revert-active-p ()
602 "Check if auto-revert is active (in current buffer or globally)." 608 "Check if auto-revert is active (in current buffer or globally)."
@@ -750,7 +756,7 @@ the timer when no buffers need to be checked."
750 (delq buf auto-revert-buffer-list))) 756 (delq buf auto-revert-buffer-list)))
751 (when (auto-revert-active-p) 757 (when (auto-revert-active-p)
752 ;; Enable file notification. 758 ;; Enable file notification.
753 (when (and auto-revert-use-notify buffer-file-name 759 (when (and auto-revert-use-notify
754 (not auto-revert-notify-watch-descriptor)) 760 (not auto-revert-notify-watch-descriptor))
755 (auto-revert-notify-add-watch)) 761 (auto-revert-notify-add-watch))
756 (auto-revert-handler))) 762 (auto-revert-handler)))