diff options
| -rw-r--r-- | lisp/autorevert.el | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/lisp/autorevert.el b/lisp/autorevert.el index 4fb865e8adb..1dc2f0eafdf 100644 --- a/lisp/autorevert.el +++ b/lisp/autorevert.el | |||
| @@ -287,7 +287,7 @@ You should set this variable through Custom." | |||
| 287 | (dolist (buf (buffer-list)) | 287 | (dolist (buf (buffer-list)) |
| 288 | (with-current-buffer buf | 288 | (with-current-buffer buf |
| 289 | (when (symbol-value 'auto-revert-notify-watch-descriptor) | 289 | (when (symbol-value 'auto-revert-notify-watch-descriptor) |
| 290 | (auto-revert-notify-rm-watch)))))) | 290 | (auto-revert-notify-rm-watch t)))))) |
| 291 | :initialize 'custom-initialize-default | 291 | :initialize 'custom-initialize-default |
| 292 | :version "24.4") | 292 | :version "24.4") |
| 293 | 293 | ||
| @@ -371,7 +371,7 @@ without being changed in the part that is already in the buffer." | |||
| 371 | 'kill-buffer-hook | 371 | 'kill-buffer-hook |
| 372 | #'auto-revert-remove-current-buffer | 372 | #'auto-revert-remove-current-buffer |
| 373 | nil t)) | 373 | nil t)) |
| 374 | (when auto-revert-notify-watch-descriptor (auto-revert-notify-rm-watch)) | 374 | (when auto-revert-notify-watch-descriptor (auto-revert-notify-rm-watch t)) |
| 375 | (auto-revert-remove-current-buffer)) | 375 | (auto-revert-remove-current-buffer)) |
| 376 | (auto-revert-set-timer) | 376 | (auto-revert-set-timer) |
| 377 | (when auto-revert-mode | 377 | (when auto-revert-mode |
| @@ -480,7 +480,7 @@ specifies in the mode line." | |||
| 480 | (dolist (buf (buffer-list)) | 480 | (dolist (buf (buffer-list)) |
| 481 | (with-current-buffer buf | 481 | (with-current-buffer buf |
| 482 | (when auto-revert-notify-watch-descriptor | 482 | (when auto-revert-notify-watch-descriptor |
| 483 | (auto-revert-notify-rm-watch)))))) | 483 | (auto-revert-notify-rm-watch t)))))) |
| 484 | 484 | ||
| 485 | (defun auto-revert-set-timer () | 485 | (defun auto-revert-set-timer () |
| 486 | "Restart or cancel the timer used by Auto-Revert Mode. | 486 | "Restart or cancel the timer used by Auto-Revert Mode. |
| @@ -497,8 +497,10 @@ will use an up-to-date value of `auto-revert-interval'" | |||
| 497 | auto-revert-interval | 497 | auto-revert-interval |
| 498 | 'auto-revert-buffers)))) | 498 | 'auto-revert-buffers)))) |
| 499 | 499 | ||
| 500 | (defun auto-revert-notify-rm-watch () | 500 | (defun auto-revert-notify-rm-watch (remove-descriptor) |
| 501 | "Disable file notification for current buffer's associated file." | 501 | "Disable file notification for current buffer's associated file. |
| 502 | If REMOVE-DESCRIPTOR is non-nil, remove the corresponding notification | ||
| 503 | descriptor; otherwise assume that it has already been removed." | ||
| 502 | (when auto-revert-notify-watch-descriptor | 504 | (when auto-revert-notify-watch-descriptor |
| 503 | (maphash | 505 | (maphash |
| 504 | (lambda (key value) | 506 | (lambda (key value) |
| @@ -507,13 +509,19 @@ will use an up-to-date value of `auto-revert-interval'" | |||
| 507 | (if value | 509 | (if value |
| 508 | (puthash key value auto-revert-notify-watch-descriptor-hash-list) | 510 | (puthash key value auto-revert-notify-watch-descriptor-hash-list) |
| 509 | (remhash key auto-revert-notify-watch-descriptor-hash-list) | 511 | (remhash key auto-revert-notify-watch-descriptor-hash-list) |
| 510 | (ignore-errors | 512 | (when remove-descriptor |
| 511 | (file-notify-rm-watch auto-revert-notify-watch-descriptor))))) | 513 | (ignore-errors |
| 514 | (file-notify-rm-watch auto-revert-notify-watch-descriptor)))))) | ||
| 512 | auto-revert-notify-watch-descriptor-hash-list) | 515 | auto-revert-notify-watch-descriptor-hash-list) |
| 513 | (remove-hook 'kill-buffer-hook #'auto-revert-notify-rm-watch t)) | 516 | (remove-hook 'kill-buffer-hook #'auto-revert-notify-rm-watch-callback t)) |
| 514 | (setq auto-revert-notify-watch-descriptor nil | 517 | (setq auto-revert-notify-watch-descriptor nil |
| 515 | auto-revert-notify-modified-p nil)) | 518 | auto-revert-notify-modified-p nil)) |
| 516 | 519 | ||
| 520 | (defun auto-revert-notify-rm-watch-callback () | ||
| 521 | "Disable file notification for current buffer's associated file, | ||
| 522 | and remove the notification descriptor." | ||
| 523 | (auto-revert-notify-rm-watch t)) | ||
| 524 | |||
| 517 | (defun auto-revert-notify-add-watch () | 525 | (defun auto-revert-notify-add-watch () |
| 518 | "Enable file notification for current buffer's associated file." | 526 | "Enable file notification for current buffer's associated file." |
| 519 | ;; We can assume that `auto-revert-notify-watch-descriptor' is nil. | 527 | ;; We can assume that `auto-revert-notify-watch-descriptor' is nil. |
| @@ -553,7 +561,8 @@ will use an up-to-date value of `auto-revert-interval'" | |||
| 553 | (gethash auto-revert-notify-watch-descriptor | 561 | (gethash auto-revert-notify-watch-descriptor |
| 554 | auto-revert-notify-watch-descriptor-hash-list)) | 562 | auto-revert-notify-watch-descriptor-hash-list)) |
| 555 | auto-revert-notify-watch-descriptor-hash-list) | 563 | auto-revert-notify-watch-descriptor-hash-list) |
| 556 | (add-hook 'kill-buffer-hook #'auto-revert-notify-rm-watch nil t))))) | 564 | (add-hook 'kill-buffer-hook #'auto-revert-notify-rm-watch-callback |
| 565 | nil t))))) | ||
| 557 | 566 | ||
| 558 | ;; If we have file notifications, we want to update the auto-revert buffers | 567 | ;; If we have file notifications, we want to update the auto-revert buffers |
| 559 | ;; immediately when a notification occurs. Since file updates can happen very | 568 | ;; immediately when a notification occurs. Since file updates can happen very |
| @@ -609,7 +618,9 @@ no more reverts are possible until the next call of | |||
| 609 | (file-name-nondirectory buffer-file-name))) | 618 | (file-name-nondirectory buffer-file-name))) |
| 610 | ;; A buffer w/o a file, like dired. | 619 | ;; A buffer w/o a file, like dired. |
| 611 | (null buffer-file-name))) | 620 | (null buffer-file-name))) |
| 612 | (auto-revert-notify-rm-watch)))) | 621 | ;; Since we got a `stopped' event, the notification descriptor |
| 622 | ;; is already gone; don't try to remove it. | ||
| 623 | (auto-revert-notify-rm-watch nil)))) | ||
| 613 | 624 | ||
| 614 | ;; Loop over all buffers, in order to find the intended one. | 625 | ;; Loop over all buffers, in order to find the intended one. |
| 615 | (cl-dolist (buffer buffers) | 626 | (cl-dolist (buffer buffers) |