diff options
| -rw-r--r-- | lisp/ChangeLog | 15 | ||||
| -rw-r--r-- | lisp/autorevert.el | 82 |
2 files changed, 77 insertions, 20 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 502cc2ff8c0..7eef2c80382 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,18 @@ | |||
| 1 | 2013-01-11 Michael Albinus <michael.albinus@gmx.de> | ||
| 2 | |||
| 3 | * autorevert.el (top): Require 'cl in order to pacify byte compiler. | ||
| 4 | (auto-revert-notify-rm-watch): Ignore errors. | ||
| 5 | (auto-revert-notify-add-watch): Ignore errors. Use '(modify) for | ||
| 6 | inotify, and '(size last-write-time) for w32notify. Set | ||
| 7 | buffer-local `auto-revert-use-notify' to nil when adding a file | ||
| 8 | watch fails - this is a fallback to the file modification check. | ||
| 9 | (auto-revert-notify-event-p, auto-revert-notify-event-descriptor) | ||
| 10 | (auto-revert-notify-event-action) | ||
| 11 | (auto-revert-notify-event-file-name): New defuns. | ||
| 12 | (auto-revert-notify-handler): Use them. Implement first | ||
| 13 | plausibility checks. | ||
| 14 | (auto-revert-handler): Handle also `auto-revert-tail-mode'. | ||
| 15 | |||
| 1 | 2013-01-11 Julien Danjou <julien@danjou.info> | 16 | 2013-01-11 Julien Danjou <julien@danjou.info> |
| 2 | 17 | ||
| 3 | * color.el (color-rgb-to-hsv): Fix conversion computing in case min and | 18 | * color.el (color-rgb-to-hsv): Fix conversion computing in case min and |
diff --git a/lisp/autorevert.el b/lisp/autorevert.el index ea7e6ca3a36..78c4aaaa143 100644 --- a/lisp/autorevert.el +++ b/lisp/autorevert.el | |||
| @@ -97,6 +97,7 @@ | |||
| 97 | 97 | ||
| 98 | ;; Dependencies: | 98 | ;; Dependencies: |
| 99 | 99 | ||
| 100 | (eval-when-compile (require 'cl)) | ||
| 100 | (require 'timer) | 101 | (require 'timer) |
| 101 | 102 | ||
| 102 | ;; Custom Group: | 103 | ;; Custom Group: |
| @@ -466,9 +467,10 @@ will use an up-to-date value of `auto-revert-interval'" | |||
| 466 | (defun auto-revert-notify-rm-watch () | 467 | (defun auto-revert-notify-rm-watch () |
| 467 | "Disable file watch for current buffer's associated file." | 468 | "Disable file watch for current buffer's associated file." |
| 468 | (when auto-revert-notify-watch-descriptor | 469 | (when auto-revert-notify-watch-descriptor |
| 469 | (funcall (if (fboundp 'inotify-rm-watch) | 470 | (ignore-errors |
| 470 | 'inotify-rm-watch 'w32notify-rm-watch) | 471 | (funcall (if (fboundp 'inotify-rm-watch) |
| 471 | auto-revert-notify-watch-descriptor) | 472 | 'inotify-rm-watch 'w32notify-rm-watch) |
| 473 | auto-revert-notify-watch-descriptor)) | ||
| 472 | (remhash auto-revert-notify-watch-descriptor | 474 | (remhash auto-revert-notify-watch-descriptor |
| 473 | auto-revert-notify-watch-descriptor-hash-list)) | 475 | auto-revert-notify-watch-descriptor-hash-list)) |
| 474 | (setq auto-revert-notify-watch-descriptor nil | 476 | (setq auto-revert-notify-watch-descriptor nil |
| @@ -481,21 +483,62 @@ will use an up-to-date value of `auto-revert-interval'" | |||
| 481 | (let ((func (if (fboundp 'inotify-add-watch) | 483 | (let ((func (if (fboundp 'inotify-add-watch) |
| 482 | 'inotify-add-watch 'w32notify-add-watch)) | 484 | 'inotify-add-watch 'w32notify-add-watch)) |
| 483 | (aspect (if (fboundp 'inotify-add-watch) | 485 | (aspect (if (fboundp 'inotify-add-watch) |
| 484 | '(close-write) '(last-write-time)))) | 486 | '(modify) '(size last-write-time)))) |
| 485 | (setq auto-revert-notify-watch-descriptor | 487 | (setq auto-revert-notify-watch-descriptor |
| 486 | (funcall func buffer-file-name aspect 'auto-revert-notify-handler)) | 488 | (ignore-errors |
| 487 | (puthash auto-revert-notify-watch-descriptor | 489 | (funcall |
| 488 | (current-buffer) | 490 | func buffer-file-name aspect 'auto-revert-notify-handler))) |
| 489 | auto-revert-notify-watch-descriptor-hash-list)))) | 491 | (if auto-revert-notify-watch-descriptor |
| 492 | (puthash auto-revert-notify-watch-descriptor | ||
| 493 | (current-buffer) | ||
| 494 | auto-revert-notify-watch-descriptor-hash-list) | ||
| 495 | ;; Fallback to file checks. | ||
| 496 | (set (make-local-variable 'auto-revert-use-notify) nil))))) | ||
| 497 | |||
| 498 | (defun auto-revert-notify-event-p (event) | ||
| 499 | "Check that event is a file watch event." | ||
| 500 | (cond ((featurep 'inotify) | ||
| 501 | (and (listp event) (= (length event) 4))) | ||
| 502 | ((featurep 'w32notify) | ||
| 503 | (and (listp event) (= (length event) 3) (stringp (nth 2 event)))))) | ||
| 504 | |||
| 505 | (defun auto-revert-notify-event-descriptor (event) | ||
| 506 | "Return watch descriptor of notification event, or nil." | ||
| 507 | (and (auto-revert-notify-event-p event) (car event))) | ||
| 508 | |||
| 509 | (defun auto-revert-notify-event-action (event) | ||
| 510 | "Return action of notification event, or nil." | ||
| 511 | (and (auto-revert-notify-event-p event) (nth 1 event))) | ||
| 512 | |||
| 513 | (defun auto-revert-notify-event-file-name (event) | ||
| 514 | "Return file name of notification event, or nil." | ||
| 515 | (and (auto-revert-notify-event-p event) | ||
| 516 | (cond ((featurep 'inotify) (nth 3 event)) | ||
| 517 | ((featurep 'w32notify) (nth 2 event))))) | ||
| 490 | 518 | ||
| 491 | (defun auto-revert-notify-handler (event) | 519 | (defun auto-revert-notify-handler (event) |
| 492 | "Handle an event returned from file watch." | 520 | "Handle an event returned from file watch." |
| 493 | (when (listp event) | 521 | (when (auto-revert-notify-event-p event) |
| 494 | (let ((buffer | 522 | (let* ((descriptor (auto-revert-notify-event-descriptor event)) |
| 495 | (gethash (car event) auto-revert-notify-watch-descriptor-hash-list))) | 523 | (action (auto-revert-notify-event-action event)) |
| 496 | (when (bufferp buffer) | 524 | (file (auto-revert-notify-event-file-name event)) |
| 497 | (with-current-buffer buffer | 525 | (buffer (gethash descriptor |
| 498 | (setq auto-revert-notify-modified-p t)))))) | 526 | auto-revert-notify-watch-descriptor-hash-list))) |
| 527 | ;; Check, that event is meant for us. | ||
| 528 | ;; TODO: Filter events which stop watching, like `move' or `removed'. | ||
| 529 | (ignore-errors | ||
| 530 | (assert descriptor) | ||
| 531 | (when (featurep 'inotify) (assert (memq 'modify descriptor))) | ||
| 532 | (when (featurep 'w32notify) (assert (eq 'modified descriptor))) | ||
| 533 | (assert (bufferp buffer)) | ||
| 534 | (when (stringp file) | ||
| 535 | (assert (string-equal | ||
| 536 | (directory-file-name file) | ||
| 537 | (directory-file-name (buffer-file-name buffer)))))) | ||
| 538 | |||
| 539 | ;; Mark buffer modified. | ||
| 540 | (with-current-buffer buffer | ||
| 541 | (setq auto-revert-notify-modified-p t))))) | ||
| 499 | 542 | ||
| 500 | (defun auto-revert-active-p () | 543 | (defun auto-revert-active-p () |
| 501 | "Check if auto-revert is active (in current buffer or globally)." | 544 | "Check if auto-revert is active (in current buffer or globally)." |
| @@ -514,6 +557,8 @@ This is an internal function used by Auto-Revert Mode." | |||
| 514 | (let* ((buffer (current-buffer)) size | 557 | (let* ((buffer (current-buffer)) size |
| 515 | (revert | 558 | (revert |
| 516 | (or (and buffer-file-name | 559 | (or (and buffer-file-name |
| 560 | (or (not auto-revert-use-notify) | ||
| 561 | auto-revert-notify-modified-p) | ||
| 517 | (if auto-revert-tail-mode | 562 | (if auto-revert-tail-mode |
| 518 | ;; Tramp caches the file attributes. Setting | 563 | ;; Tramp caches the file attributes. Setting |
| 519 | ;; `remote-file-name-inhibit-cache' forces Tramp | 564 | ;; `remote-file-name-inhibit-cache' forces Tramp |
| @@ -524,12 +569,9 @@ This is an internal function used by Auto-Revert Mode." | |||
| 524 | (setq size | 569 | (setq size |
| 525 | (nth 7 (file-attributes | 570 | (nth 7 (file-attributes |
| 526 | buffer-file-name)))))) | 571 | buffer-file-name)))))) |
| 527 | (if auto-revert-use-notify | 572 | (and (not (file-remote-p buffer-file-name)) |
| 528 | ;; There are file watches. | 573 | (file-readable-p buffer-file-name) |
| 529 | auto-revert-notify-modified-p | 574 | (not (verify-visited-file-modtime buffer))))) |
| 530 | (and (not (file-remote-p buffer-file-name)) | ||
| 531 | (file-readable-p buffer-file-name) | ||
| 532 | (not (verify-visited-file-modtime buffer)))))) | ||
| 533 | (and (or auto-revert-mode | 575 | (and (or auto-revert-mode |
| 534 | global-auto-revert-non-file-buffers) | 576 | global-auto-revert-non-file-buffers) |
| 535 | revert-buffer-function | 577 | revert-buffer-function |