+;;;###autoload
+(define-minor-mode auto-revert-tail-mode
+ "Toggle reverting tail of buffer when file on disk grows.
+With arg, turn Tail mode on iff arg is positive.
+
+When Tail mode is enabled, the tail of the file is constantly
+followed, as with the shell command `tail -f'. This means that
+whenever the file grows on disk (presumably because some
+background process is appending to it from time to time), this is
+reflected in the current buffer.
+
+You can edit the buffer and turn this mode off and on again as
+you please. But make sure the background process has stopped
+writing before you save the file!
+
+Use `auto-revert-mode' for changes other than appends!"
+ :group 'find-file :lighter auto-revert-tail-mode-text
+ (when auto-revert-tail-mode
+ (unless buffer-file-name
+ (auto-revert-tail-mode 0)
+ (error "This buffer is not visiting a file"))
+ (if (and (buffer-modified-p)
+ (not auto-revert-tail-pos) ; library was loaded only after finding file
+ (not (y-or-n-p "Buffer is modified, so tail offset may be wrong. Proceed? ")))
+ (auto-revert-tail-mode 0)
+ ;; else we might reappend our own end when we save
+ (add-hook 'before-save-hook (lambda () (auto-revert-tail-mode 0)) nil t)
+ (or (local-variable-p 'auto-revert-tail-pos) ; don't lose prior position
+ (set (make-local-variable 'auto-revert-tail-pos)
+ (save-restriction (widen) (1- (point-max)))))
+ ;; let auto-revert-mode set up the mechanism for us if it isn't already
+ (or auto-revert-mode
+ (let ((auto-revert-tail-mode t))
+ (auto-revert-mode 1)))
+ (setq auto-revert-mode nil))))
+
+
+;;;###autoload
+(defun turn-on-auto-revert-tail-mode ()
+ "Turn on Auto-Revert Tail Mode.
+
+This function is designed to be added to hooks, for example:
+ (add-hook 'my-logfile-mode-hook 'turn-on-auto-revert-tail-mode)"
+ (auto-revert-tail-mode 1))
+
+