aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2015-05-22 00:03:12 -0400
committerStefan Monnier2015-05-22 00:03:12 -0400
commit9e41e0bc6a6fdb7a01841db62d8de42d67be534a (patch)
tree13383ba728a0d12bc47f408d1408a862dc6d36fd
parentea92591983a05bd85d52a6a07dd3b7149feb46d2 (diff)
downloademacs-9e41e0bc6a6fdb7a01841db62d8de42d67be534a.tar.gz
emacs-9e41e0bc6a6fdb7a01841db62d8de42d67be534a.zip
* lisp/autorevert.el: Use lexical-binding. Fix hook usage.
(global-auto-revert-ignore-buffer, auto-revert-notify-modified-p) (auto-revert-notify-watch-descriptor): Use defvar-local. (find-file-hook, auto-revert-tail-mode, ) (auto-revert-notify-add-watch): Use setq-local. (auto-revert-notify-add-watch): Don't call make-local-variable on kill-buffer-hook (bug#20601).
-rw-r--r--lisp/autorevert.el37
1 files changed, 17 insertions, 20 deletions
diff --git a/lisp/autorevert.el b/lisp/autorevert.el
index 357916c6b4d..2ff7c0115f3 100644
--- a/lisp/autorevert.el
+++ b/lisp/autorevert.el
@@ -1,4 +1,4 @@
1;;; autorevert.el --- revert buffers when files on disk change 1;;; autorevert.el --- revert buffers when files on disk change -*- lexical-binding:t -*-
2 2
3;; Copyright (C) 1997-1999, 2001-2015 Free Software Foundation, Inc. 3;; Copyright (C) 1997-1999, 2001-2015 Free Software Foundation, Inc.
4 4
@@ -95,7 +95,7 @@
95;; mode. For example, the following line will activate Auto-Revert 95;; mode. For example, the following line will activate Auto-Revert
96;; Mode in all C mode buffers: 96;; Mode in all C mode buffers:
97;; 97;;
98;; (add-hook 'c-mode-hook 'turn-on-auto-revert-mode) 98;; (add-hook 'c-mode-hook #'turn-on-auto-revert-mode)
99 99
100;;; Code: 100;;; Code:
101 101
@@ -260,10 +260,9 @@ buffers. CPU usage depends on the version control system."
260 :type 'boolean 260 :type 'boolean
261 :version "22.1") 261 :version "22.1")
262 262
263(defvar global-auto-revert-ignore-buffer nil 263(defvar-local global-auto-revert-ignore-buffer nil
264 "When non-nil, Global Auto-Revert Mode will not revert this buffer. 264 "When non-nil, Global Auto-Revert Mode will not revert this buffer.
265This variable becomes buffer local when set in any fashion.") 265This variable becomes buffer local when set in any fashion.")
266(make-variable-buffer-local 'global-auto-revert-ignore-buffer)
267 266
268(defcustom auto-revert-remote-files nil 267(defcustom auto-revert-remote-files nil
269 "If non-nil remote files are also reverted." 268 "If non-nil remote files are also reverted."
@@ -315,9 +314,9 @@ the list of old buffers.")
315 "Position of last known end of file.") 314 "Position of last known end of file.")
316 315
317(add-hook 'find-file-hook 316(add-hook 'find-file-hook
318 (lambda () 317 (lambda ()
319 (set (make-local-variable 'auto-revert-tail-pos) 318 (setq-local auto-revert-tail-pos
320 (nth 7 (file-attributes buffer-file-name))))) 319 (nth 7 (file-attributes buffer-file-name)))))
321 320
322(defvar auto-revert-notify-watch-descriptor-hash-list 321(defvar auto-revert-notify-watch-descriptor-hash-list
323 (make-hash-table :test 'equal) 322 (make-hash-table :test 'equal)
@@ -326,15 +325,13 @@ Hash key is a watch descriptor, hash value is a list of buffers
326which are related to files being watched and carrying the same 325which are related to files being watched and carrying the same
327default directory.") 326default directory.")
328 327
329(defvar auto-revert-notify-watch-descriptor nil 328(defvar-local auto-revert-notify-watch-descriptor nil
330 "The file watch descriptor active for the current buffer.") 329 "The file watch descriptor active for the current buffer.")
331(make-variable-buffer-local 'auto-revert-notify-watch-descriptor)
332(put 'auto-revert-notify-watch-descriptor 'permanent-local t) 330(put 'auto-revert-notify-watch-descriptor 'permanent-local t)
333 331
334(defvar auto-revert-notify-modified-p nil 332(defvar-local auto-revert-notify-modified-p nil
335 "Non-nil when file has been modified on the file system. 333 "Non-nil when file has been modified on the file system.
336This has been reported by a file notification event.") 334This has been reported by a file notification event.")
337(make-variable-buffer-local 'auto-revert-notify-modified-p)
338 335
339;; Functions: 336;; Functions:
340 337
@@ -370,7 +367,7 @@ without being changed in the part that is already in the buffer."
370 "Turn on Auto-Revert Mode. 367 "Turn on Auto-Revert Mode.
371 368
372This function is designed to be added to hooks, for example: 369This function is designed to be added to hooks, for example:
373 (add-hook 'c-mode-hook 'turn-on-auto-revert-mode)" 370 (add-hook 'c-mode-hook #'turn-on-auto-revert-mode)"
374 (auto-revert-mode 1)) 371 (auto-revert-mode 1))
375 372
376 373
@@ -420,8 +417,8 @@ Perform a full revert? ")
420 ;; else we might reappend our own end when we save 417 ;; else we might reappend our own end when we save
421 (add-hook 'before-save-hook (lambda () (auto-revert-tail-mode 0)) nil t) 418 (add-hook 'before-save-hook (lambda () (auto-revert-tail-mode 0)) nil t)
422 (or (local-variable-p 'auto-revert-tail-pos) ; don't lose prior position 419 (or (local-variable-p 'auto-revert-tail-pos) ; don't lose prior position
423 (set (make-local-variable 'auto-revert-tail-pos) 420 (setq-local auto-revert-tail-pos
424 (nth 7 (file-attributes buffer-file-name)))) 421 (nth 7 (file-attributes buffer-file-name))))
425 ;; let auto-revert-mode set up the mechanism for us if it isn't already 422 ;; let auto-revert-mode set up the mechanism for us if it isn't already
426 (or auto-revert-mode 423 (or auto-revert-mode
427 (let ((auto-revert-tail-mode t)) 424 (let ((auto-revert-tail-mode t))
@@ -434,7 +431,7 @@ Perform a full revert? ")
434 "Turn on Auto-Revert Tail mode. 431 "Turn on Auto-Revert Tail mode.
435 432
436This function is designed to be added to hooks, for example: 433This function is designed to be added to hooks, for example:
437 (add-hook 'my-logfile-mode-hook 'turn-on-auto-revert-tail-mode)" 434 (add-hook 'my-logfile-mode-hook #'turn-on-auto-revert-tail-mode)"
438 (auto-revert-tail-mode 1)) 435 (auto-revert-tail-mode 1))
439 436
440 437
@@ -495,7 +492,7 @@ will use an up-to-date value of `auto-revert-interval'"
495 (ignore-errors 492 (ignore-errors
496 (file-notify-rm-watch auto-revert-notify-watch-descriptor))))) 493 (file-notify-rm-watch auto-revert-notify-watch-descriptor)))))
497 auto-revert-notify-watch-descriptor-hash-list) 494 auto-revert-notify-watch-descriptor-hash-list)
498 (remove-hook 'kill-buffer-hook 'auto-revert-notify-rm-watch)) 495 (remove-hook 'kill-buffer-hook #'auto-revert-notify-rm-watch))
499 (setq auto-revert-notify-watch-descriptor nil 496 (setq auto-revert-notify-watch-descriptor nil
500 auto-revert-notify-modified-p nil)) 497 auto-revert-notify-modified-p nil))
501 498
@@ -508,7 +505,7 @@ will use an up-to-date value of `auto-revert-interval'"
508 (file-symlink-p (or buffer-file-name default-directory))) 505 (file-symlink-p (or buffer-file-name default-directory)))
509 506
510 ;; Fallback to file checks. 507 ;; Fallback to file checks.
511 (set (make-local-variable 'auto-revert-use-notify) nil) 508 (setq-local auto-revert-use-notify nil)
512 509
513 (when (not auto-revert-notify-watch-descriptor) 510 (when (not auto-revert-notify-watch-descriptor)
514 (setq auto-revert-notify-watch-descriptor 511 (setq auto-revert-notify-watch-descriptor
@@ -530,10 +527,10 @@ will use an up-to-date value of `auto-revert-interval'"
530 (gethash auto-revert-notify-watch-descriptor 527 (gethash auto-revert-notify-watch-descriptor
531 auto-revert-notify-watch-descriptor-hash-list)) 528 auto-revert-notify-watch-descriptor-hash-list))
532 auto-revert-notify-watch-descriptor-hash-list) 529 auto-revert-notify-watch-descriptor-hash-list)
533 (add-hook (make-local-variable 'kill-buffer-hook) 530 (add-hook 'kill-buffer-hook
534 'auto-revert-notify-rm-watch)) 531 #'auto-revert-notify-rm-watch nil t))
535 ;; Fallback to file checks. 532 ;; Fallback to file checks.
536 (set (make-local-variable 'auto-revert-use-notify) nil))))) 533 (setq-local auto-revert-use-notify nil)))))
537 534
538;; If we have file notifications, we want to update the auto-revert buffers 535;; If we have file notifications, we want to update the auto-revert buffers
539;; immediately when a notification occurs. Since file updates can happen very 536;; immediately when a notification occurs. Since file updates can happen very