diff options
| author | Eli Zaretskii | 2004-02-16 13:12:21 +0000 |
|---|---|---|
| committer | Eli Zaretskii | 2004-02-16 13:12:21 +0000 |
| commit | ed35db71b41bc7189196455fb9b827d8b20001a6 (patch) | |
| tree | b54722fae7aabe4daf8c74a08f2c2b321bf20521 | |
| parent | ebb8cb682a16160f5b2db373f5e7276dd74f1892 (diff) | |
| download | emacs-ed35db71b41bc7189196455fb9b827d8b20001a6.tar.gz emacs-ed35db71b41bc7189196455fb9b827d8b20001a6.zip | |
Added support to detect changed dired buffers.
(auto-revert-active-p): New.
(auto-revert-list-diff): New.
(auto-revert-dired-file-list): New.
(auto-revert-dired-changed-p): New.
(auto-revert-handler): New.
(auto-revert-active-p): New.
(auto-revert-buffers): Moved logic to
`auto-revert-handler' and `auto-revert-active-p'
| -rw-r--r-- | lisp/autorevert.el | 97 |
1 files changed, 79 insertions, 18 deletions
diff --git a/lisp/autorevert.el b/lisp/autorevert.el index fac91332a5e..9005a7c4063 100644 --- a/lisp/autorevert.el +++ b/lisp/autorevert.el | |||
| @@ -244,6 +244,82 @@ Use `auto-revert-mode' to revert a particular buffer." | |||
| 244 | 'auto-revert-buffers) | 244 | 'auto-revert-buffers) |
| 245 | nil))) | 245 | nil))) |
| 246 | 246 | ||
| 247 | (defun auto-revert-active-p () | ||
| 248 | "Check if auto-revert is active (in current buffer or globally)." | ||
| 249 | (or auto-revert-mode | ||
| 250 | (and | ||
| 251 | global-auto-revert-mode | ||
| 252 | (not global-auto-revert-ignore-buffer) | ||
| 253 | (not (memq major-mode | ||
| 254 | global-auto-revert-ignore-modes))))) | ||
| 255 | |||
| 256 | (defun auto-revert-list-diff (a b) | ||
| 257 | "Check if strings in list A differ from list B." | ||
| 258 | (when (and a b) | ||
| 259 | (setq a (sort a 'string-lessp)) | ||
| 260 | (setq b (sort b 'string-lessp)) | ||
| 261 | (let (elt1 elt2) | ||
| 262 | (catch 'break | ||
| 263 | (while (and (setq elt1 (and a (pop a))) | ||
| 264 | (setq elt2 (and b (pop b)))) | ||
| 265 | (if (not (string= elt1 elt2)) | ||
| 266 | (throw 'break t))))))) | ||
| 267 | |||
| 268 | (defun auto-revert-dired-file-list () | ||
| 269 | "Return list of dired files." | ||
| 270 | (let (list) | ||
| 271 | (save-excursion | ||
| 272 | (goto-char (point-min)) | ||
| 273 | (while (not (eobp)) | ||
| 274 | (if (setq file (dired-get-filename t t)) | ||
| 275 | (push file list)) | ||
| 276 | (forward-line 1))) | ||
| 277 | list)) | ||
| 278 | |||
| 279 | (defun auto-revert-dired-changed-p () | ||
| 280 | "Check if dired buffer has changed." | ||
| 281 | (when (and (stringp dired-directory) | ||
| 282 | ;; Exclude remote buffers, would be too slow for user | ||
| 283 | ;; modem, timeouts, network lag ... all is possible | ||
| 284 | (not (string-match "@" dired-directory)) | ||
| 285 | (file-directory-p dired-directory)) | ||
| 286 | (let ((files (directory-files dired-directory)) | ||
| 287 | (dired (auto-revert-dired-file-list))) | ||
| 288 | (or (not (eq (length files) (length dired))) | ||
| 289 | (auto-revert-list-diff files dired))))) | ||
| 290 | |||
| 291 | (defun auto-revert-buffer-p () | ||
| 292 | "Check if current buffer should be reverted." | ||
| 293 | ;; Always include dired buffers to list. It would be too expensive | ||
| 294 | ;; to test the "revert" status here each time timer launches. | ||
| 295 | (or (eq major-mode 'dired-mode) | ||
| 296 | (and (not (buffer-modified-p)) | ||
| 297 | (if (buffer-file-name) | ||
| 298 | (and (file-readable-p (buffer-file-name)) | ||
| 299 | (not (verify-visited-file-modtime buf))) | ||
| 300 | (and revert-buffer-function | ||
| 301 | (or (and global-auto-revert-mode | ||
| 302 | global-auto-revert-non-file-buffers) | ||
| 303 | auto-revert-mode)))))) | ||
| 304 | |||
| 305 | (defun auto-revert-handler () | ||
| 306 | "Revert current buffer." | ||
| 307 | (let (done) | ||
| 308 | (cond | ||
| 309 | ((eq major-mode 'dired-mode) | ||
| 310 | ;; Dired includes revert-buffer-function | ||
| 311 | (when (and revert-buffer-function | ||
| 312 | (auto-revert-dired-changed-p)) | ||
| 313 | (setq done t) | ||
| 314 | (revert-buffer t t t))) | ||
| 315 | ((or (buffer-file-name) | ||
| 316 | revert-buffer-function) | ||
| 317 | (setq done t) | ||
| 318 | (revert-buffer 'ignore-auto 'dont-ask 'preserve-modes))) | ||
| 319 | (if (and done | ||
| 320 | auto-revert-verbose) | ||
| 321 | (message "Reverting buffer `%s'." (buffer-name))))) | ||
| 322 | |||
| 247 | (defun auto-revert-buffers () | 323 | (defun auto-revert-buffers () |
| 248 | "Revert buffers as specified by Auto-Revert and Global Auto-Revert Mode. | 324 | "Revert buffers as specified by Auto-Revert and Global Auto-Revert Mode. |
| 249 | 325 | ||
| @@ -294,24 +370,9 @@ the timer when no buffers need to be checked." | |||
| 294 | (memq buf auto-revert-buffer-list)) | 370 | (memq buf auto-revert-buffer-list)) |
| 295 | (setq auto-revert-buffer-list | 371 | (setq auto-revert-buffer-list |
| 296 | (delq buf auto-revert-buffer-list))) | 372 | (delq buf auto-revert-buffer-list))) |
| 297 | (when (and | 373 | (when (and (auto-revert-active-p) |
| 298 | (or auto-revert-mode | 374 | (auto-revert-buffer-p)) |
| 299 | (and | 375 | (auto-revert-handler) |
| 300 | global-auto-revert-mode | ||
| 301 | (not global-auto-revert-ignore-buffer) | ||
| 302 | (not (memq major-mode | ||
| 303 | global-auto-revert-ignore-modes)))) | ||
| 304 | (not (buffer-modified-p)) | ||
| 305 | (if (buffer-file-name) | ||
| 306 | (and (file-readable-p (buffer-file-name)) | ||
| 307 | (not (verify-visited-file-modtime buf))) | ||
| 308 | (and revert-buffer-function | ||
| 309 | (or (and global-auto-revert-mode | ||
| 310 | global-auto-revert-non-file-buffers) | ||
| 311 | auto-revert-mode)))) | ||
| 312 | (if auto-revert-verbose | ||
| 313 | (message "Reverting buffer `%s'." buf)) | ||
| 314 | (revert-buffer 'ignore-auto 'dont-ask 'preserve-modes) | ||
| 315 | ;; `preserve-modes' avoids changing the (minor) modes. But we | 376 | ;; `preserve-modes' avoids changing the (minor) modes. But we |
| 316 | ;; do want to reset the mode for VC, so we do it explicitly. | 377 | ;; do want to reset the mode for VC, so we do it explicitly. |
| 317 | (vc-find-file-hook))) | 378 | (vc-find-file-hook))) |