diff options
| author | Michael Albinus | 2018-11-04 12:51:39 +0100 |
|---|---|---|
| committer | Michael Albinus | 2018-11-04 12:51:39 +0100 |
| commit | d10036d73759234d67cb587e1876fbfbf7483e83 (patch) | |
| tree | 428cd6f634fd37557a652596b3aa95989f5ad263 | |
| parent | b4eb908f858284a7962851fd99c94598f76afa6f (diff) | |
| download | emacs-d10036d73759234d67cb587e1876fbfbf7483e83.tar.gz emacs-d10036d73759234d67cb587e1876fbfbf7483e83.zip | |
Fix Bug#33194
* lisp/autorevert.el (auto-revert-notify-add-watch):
Handle buffers with same descriptor properly.
(auto-revert-notify-handler): Handle all buffers with same
descriptor. (Bug#33194)
* lisp/filenotify.el (file-notify-callback): Simplify.
| -rw-r--r-- | lisp/autorevert.el | 58 | ||||
| -rw-r--r-- | lisp/filenotify.el | 13 |
2 files changed, 39 insertions, 32 deletions
diff --git a/lisp/autorevert.el b/lisp/autorevert.el index fc3469e03df..2cf5b427ea3 100644 --- a/lisp/autorevert.el +++ b/lisp/autorevert.el | |||
| @@ -515,32 +515,43 @@ will use an up-to-date value of `auto-revert-interval'" | |||
| 515 | 515 | ||
| 516 | (defun auto-revert-notify-add-watch () | 516 | (defun auto-revert-notify-add-watch () |
| 517 | "Enable file notification for current buffer's associated file." | 517 | "Enable file notification for current buffer's associated file." |
| 518 | ;; We can assume that `buffer-file-name' and | 518 | ;; We can assume that `auto-revert-notify-watch-descriptor' is nil. |
| 519 | ;; `auto-revert-notify-watch-descriptor' are non-nil. | ||
| 520 | (unless (or auto-revert-notify-watch-descriptor | 519 | (unless (or auto-revert-notify-watch-descriptor |
| 521 | (string-match auto-revert-notify-exclude-dir-regexp | 520 | (string-match auto-revert-notify-exclude-dir-regexp |
| 522 | (expand-file-name default-directory)) | 521 | (expand-file-name default-directory)) |
| 523 | (file-symlink-p (or buffer-file-name default-directory))) | 522 | (file-symlink-p (or buffer-file-name default-directory))) |
| 524 | (setq auto-revert-notify-watch-descriptor | 523 | ;; Check, whether this has been activated already. |
| 525 | (ignore-errors | 524 | (let ((file (if buffer-file-name |
| 526 | (if buffer-file-name | 525 | (expand-file-name buffer-file-name default-directory) |
| 527 | (file-notify-add-watch | 526 | (expand-file-name default-directory)))) |
| 528 | (expand-file-name buffer-file-name default-directory) | 527 | (maphash |
| 529 | '(change attribute-change) | 528 | (lambda (key _value) |
| 530 | 'auto-revert-notify-handler) | 529 | (when (and |
| 531 | (file-notify-add-watch | 530 | (equal (file-notify--watch-absolute-filename |
| 532 | (expand-file-name default-directory) | 531 | (gethash key file-notify-descriptors)) |
| 533 | '(change) | 532 | (directory-file-name file)) |
| 534 | 'auto-revert-notify-handler)))) | 533 | (equal (file-notify--watch-callback |
| 535 | (when auto-revert-notify-watch-descriptor | 534 | (gethash key file-notify-descriptors)) |
| 536 | (setq auto-revert-notify-modified-p t) | 535 | 'auto-revert-notify-handler)) |
| 537 | (puthash | 536 | (setq auto-revert-notify-watch-descriptor key))) |
| 538 | auto-revert-notify-watch-descriptor | ||
| 539 | (cons (current-buffer) | ||
| 540 | (gethash auto-revert-notify-watch-descriptor | ||
| 541 | auto-revert-notify-watch-descriptor-hash-list)) | ||
| 542 | auto-revert-notify-watch-descriptor-hash-list) | 537 | auto-revert-notify-watch-descriptor-hash-list) |
| 543 | (add-hook 'kill-buffer-hook #'auto-revert-notify-rm-watch nil t)))) | 538 | ;; Create a new watch if needed. |
| 539 | (unless auto-revert-notify-watch-descriptor | ||
| 540 | (setq auto-revert-notify-watch-descriptor | ||
| 541 | (ignore-errors | ||
| 542 | (file-notify-add-watch | ||
| 543 | file | ||
| 544 | (if buffer-file-name '(change attribute-change) '(change)) | ||
| 545 | 'auto-revert-notify-handler)))) | ||
| 546 | (when auto-revert-notify-watch-descriptor | ||
| 547 | (setq auto-revert-notify-modified-p t) | ||
| 548 | (puthash | ||
| 549 | auto-revert-notify-watch-descriptor | ||
| 550 | (cons (current-buffer) | ||
| 551 | (gethash auto-revert-notify-watch-descriptor | ||
| 552 | auto-revert-notify-watch-descriptor-hash-list)) | ||
| 553 | auto-revert-notify-watch-descriptor-hash-list) | ||
| 554 | (add-hook 'kill-buffer-hook #'auto-revert-notify-rm-watch nil t))))) | ||
| 544 | 555 | ||
| 545 | ;; If we have file notifications, we want to update the auto-revert buffers | 556 | ;; If we have file notifications, we want to update the auto-revert buffers |
| 546 | ;; immediately when a notification occurs. Since file updates can happen very | 557 | ;; immediately when a notification occurs. Since file updates can happen very |
| @@ -626,10 +637,7 @@ no more reverts are possible until the next call of | |||
| 626 | auto-revert-buffers-counter) | 637 | auto-revert-buffers-counter) |
| 627 | (auto-revert-handler) | 638 | (auto-revert-handler) |
| 628 | (setq auto-revert-buffers-counter-lockedout | 639 | (setq auto-revert-buffers-counter-lockedout |
| 629 | auto-revert-buffers-counter)) | 640 | auto-revert-buffers-counter)))))))))) |
| 630 | |||
| 631 | ;; No need to check other buffers. | ||
| 632 | (cl-return))))))))) | ||
| 633 | 641 | ||
| 634 | (defun auto-revert-active-p () | 642 | (defun auto-revert-active-p () |
| 635 | "Check if auto-revert is active (in current buffer or globally)." | 643 | "Check if auto-revert is active (in current buffer or globally)." |
diff --git a/lisp/filenotify.el b/lisp/filenotify.el index 59a8c0e88aa..a133f9ea7ec 100644 --- a/lisp/filenotify.el +++ b/lisp/filenotify.el | |||
| @@ -45,11 +45,11 @@ could use another implementation.") | |||
| 45 | (:constructor nil) | 45 | (:constructor nil) |
| 46 | (:constructor | 46 | (:constructor |
| 47 | file-notify--watch-make (directory filename callback))) | 47 | file-notify--watch-make (directory filename callback))) |
| 48 | ;; Watched directory | 48 | ;; Watched directory. |
| 49 | directory | 49 | directory |
| 50 | ;; Watched relative filename, nil if watching the directory. | 50 | ;; Watched relative filename, nil if watching the directory. |
| 51 | filename | 51 | filename |
| 52 | ;; Function to propagate events to | 52 | ;; Function to propagate events to. |
| 53 | callback) | 53 | callback) |
| 54 | 54 | ||
| 55 | (defun file-notify--watch-absolute-filename (watch) | 55 | (defun file-notify--watch-absolute-filename (watch) |
| @@ -242,11 +242,10 @@ EVENT is the cadr of the event in `file-notify-handle-event' | |||
| 242 | ;;(message | 242 | ;;(message |
| 243 | ;;"file-notify-callback %S %S %S %S %S" | 243 | ;;"file-notify-callback %S %S %S %S %S" |
| 244 | ;;desc action file file1 watch) | 244 | ;;desc action file file1 watch) |
| 245 | (if file1 | 245 | (funcall (file-notify--watch-callback watch) |
| 246 | (funcall (file-notify--watch-callback watch) | 246 | (if file1 |
| 247 | `(,desc ,action ,file ,file1)) | 247 | `(,desc ,action ,file ,file1) |
| 248 | (funcall (file-notify--watch-callback watch) | 248 | `(,desc ,action ,file)))) |
| 249 | `(,desc ,action ,file)))) | ||
| 250 | 249 | ||
| 251 | ;; Send `stopped' event. | 250 | ;; Send `stopped' event. |
| 252 | (when (or stopped | 251 | (when (or stopped |