* Re: new tail-mode
[not found] ` <E1Bja5e-0006aS-5L@fencepost.gnu.org>
@ 2004-07-13 22:22 ` Daniel Pfeiffer
2004-07-14 18:27 ` Richard Stallman
2004-07-16 0:30 ` Luc Teirlinck
0 siblings, 2 replies; 5+ messages in thread
From: Daniel Pfeiffer @ 2004-07-13 22:22 UTC (permalink / raw)
[-- Attachment #1: Type: text/plain, Size: 915 bytes --]
Hi,
Richard Stallman <rms@gnu.org> skribis:
> Also if the file stops growing for a
> long time.
>
> Why even bother to check for that condition?
Polling is an inefficient mechanism! However some files like log files may
pause for days before growing again, so I have removed this.
> While the two concept have a general notion in common, tail-mode
> definitely does not revert in the Emacs sence.
>
> It does a kind of optimized revert which works for certain cases only.
> I think it is legitimate and clear to describe that as a kind of "revert".
Ok, I've translated it to be auto-revert-tail-mode. If it's ok, I'd also add
it to the mode line menu, just under Auto Revert.
coralament / best Grötens / liebe Grüße / best regards / elkorajn salutojn
Daniel Pfeiffer
--
lerne / learn / apprends / lär dig / ucz się Esperanto:
http://lernu.net/
[-- Attachment #2: autorevert.diff --]
[-- Type: application/octet-stream, Size: 9147 bytes --]
--- /home/pfeiffer/.emacs.d/cvs/lisp/autorevert.el.~1.34.~ 2004-06-23 23:02:21.000000000 +0200
+++ autorevert.el (buffer) 2004-07-14 00:13:02.244318000 +0200
@@ -62,8 +62,9 @@
;; Usage:
;;
-;; Go to the appropriate buffer and press:
+;; Go to the appropriate buffer and press either of:
;; M-x auto-revert-mode RET
+;; M-x auto-revert-tail-mode RET
;;
;; To activate Global Auto-Revert Mode, press:
;; M-x global-auto-revert-mode RET
@@ -105,13 +106,18 @@
;; Variables:
-;; Autoload for the benefit of `make-mode-line-mouse-sensitive'.
-;;;###autoload
+;;; What's this?: ;; Autoload for the benefit of `make-mode-line-mouse-sensitive'.
+;;; What's this?: ;;;###autoload
(defvar auto-revert-mode nil
"*Non-nil when Auto-Revert Mode is active.
Never set this variable directly, use the command `auto-revert-mode' instead.")
(put 'auto-revert-mode 'permanent-local t)
+(defvar auto-revert-tail-mode nil
+ "*Non-nil when Auto-Revert Tail Mode is active.
+Never set this variable directly, use the command `auto-revert-mode' instead.")
+(put 'auto-revert-tail-mode 'permanent-local t)
+
(defvar auto-revert-timer nil
"Timer used by Auto-Revert Mode.")
@@ -153,6 +159,13 @@
:group 'auto-revert
:type 'string)
+(defcustom auto-revert-tail-mode-text " Tail"
+ "String to display in the mode line when Auto-Revert Tail Mode is active.
+
+\(When the string is not empty, make sure that it has a leading space.)"
+ :group 'auto-revert
+ :type 'string)
+
(defcustom auto-revert-mode-hook nil
"Functions to run when Auto-Revert Mode is activated."
:tag "Auto Revert Mode Hook" ; To separate it from `global-...'
@@ -190,7 +203,7 @@
:type 'boolean
:link '(info-link "(emacs-xtra)Autorevert"))
-(defcustom global-auto-revert-ignore-modes '()
+(defcustom global-auto-revert-ignore-modes ()
"List of major modes Global Auto-Revert Mode should not check."
:group 'auto-revert
:type '(repeat sexp))
@@ -230,7 +243,7 @@
;; Internal variables:
-(defvar auto-revert-buffer-list '()
+(defvar auto-revert-buffer-list ()
"List of buffers in Auto-Revert Mode.
Note that only Auto-Revert Mode, never Global Auto-Revert Mode, adds
@@ -239,9 +252,16 @@
The timer function `auto-revert-buffers' is responsible for purging
the list of old buffers.")
-(defvar auto-revert-remaining-buffers '()
+(defvar auto-revert-remaining-buffers ()
"Buffers not checked when user input stopped execution.")
+(defvar auto-revert-tail-pos 0
+ "Position of last known end of file.")
+
+(add-hook 'find-file-hook
+ (lambda ()
+ (set (make-local-variable 'auto-revert-tail-pos)
+ (save-restriction (widen) (1- (point-max))))))
;; Functions:
@@ -251,7 +271,9 @@
With arg, turn Auto Revert mode on if and only if arg is positive.
This is a minor mode that affects only the current buffer.
-Use `global-auto-revert-mode' to automatically revert all buffers."
+Use `global-auto-revert-mode' to automatically revert all buffers.
+Use `auto-revert-tail-mode' if you know that the file will only grow
+without being changed in the part that is already in the buffer."
nil auto-revert-mode-text nil
(if auto-revert-mode
(if (not (memq (current-buffer) auto-revert-buffer-list))
@@ -260,7 +282,8 @@
(delq (current-buffer) auto-revert-buffer-list)))
(auto-revert-set-timer)
(when auto-revert-mode
- (auto-revert-buffers)))
+ (auto-revert-buffers)
+ (setq auto-revert-tail-mode nil)))
;;;###autoload
@@ -273,6 +296,51 @@
;;;###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-variable-buffer-local 'auto-revert-tail-pos)
+ (save-restriction (widen) (1- (point-max)))))
+ ;; let auto-revert-mode set up the mechanism for us
+ (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))
+
+
+;;;###autoload
(define-minor-mode global-auto-revert-mode
"Revert any buffer when file on disk changes.
@@ -298,12 +366,12 @@
(if (or global-auto-revert-mode auto-revert-buffer-list)
(run-with-timer auto-revert-interval
auto-revert-interval
- 'auto-revert-buffers)
- nil)))
+ 'auto-revert-buffers))))
(defun auto-revert-active-p ()
"Check if auto-revert is active (in current buffer or globally)."
(or auto-revert-mode
+ auto-revert-tail-mode
(and
global-auto-revert-mode
(not global-auto-revert-ignore-buffer)
@@ -313,18 +381,20 @@
(defun auto-revert-handler ()
"Revert current buffer, if appropriate.
This is an internal function used by Auto-Revert Mode."
- (unless (buffer-modified-p)
- (let ((buffer (current-buffer)) revert eob eoblist)
- (or (and buffer-file-name
- (not (file-remote-p buffer-file-name))
- (file-readable-p buffer-file-name)
- (not (verify-visited-file-modtime buffer))
- (setq revert t))
- (and (or auto-revert-mode global-auto-revert-non-file-buffers)
- revert-buffer-function
- (boundp 'buffer-stale-function)
- (functionp buffer-stale-function)
- (setq revert (funcall buffer-stale-function t))))
+ (when (or auto-revert-tail-mode (not (buffer-modified-p)))
+ (let* ((buffer (current-buffer))
+ (revert
+ (or (and buffer-file-name
+ (not (file-remote-p buffer-file-name))
+ (file-readable-p buffer-file-name)
+ (not (verify-visited-file-modtime buffer)))
+ (and (or auto-revert-mode auto-revert-tail-mode
+ global-auto-revert-non-file-buffers)
+ revert-buffer-function
+ (boundp 'buffer-stale-function)
+ (functionp buffer-stale-function)
+ (funcall buffer-stale-function t))))
+ eob eoblist)
(when revert
(when (and auto-revert-verbose
(not (eq revert 'fast)))
@@ -340,7 +410,9 @@
(= (window-point window) (point-max))
(push window eoblist)))
'no-mini t))
- (revert-buffer 'ignore-auto 'dont-ask 'preserve-modes)
+ (if auto-revert-tail-mode
+ (auto-revert-tail-handler)
+ (revert-buffer 'ignore-auto 'dont-ask 'preserve-modes))
(when buffer-file-name
(when eob (goto-char (point-max)))
(dolist (window eoblist)
@@ -350,6 +422,22 @@
(when (or revert auto-revert-check-vc-info)
(vc-find-file-hook)))))
+(defun auto-revert-tail-handler ()
+ (let ((size (nth 7 (file-attributes buffer-file-name)))
+ (modified (buffer-modified-p))
+ buffer-read-only ; ignore
+ (file buffer-file-name)
+ buffer-file-name) ; ignore that file has changed
+ (when (> size auto-revert-tail-pos)
+ (save-restriction
+ (widen)
+ (save-excursion
+ (goto-char (point-max))
+ (insert-file-contents file nil auto-revert-tail-pos size)))
+ (setq auto-revert-tail-pos size)
+ (set-buffer-modified-p modified)))
+ (set-visited-file-modtime))
+
(defun auto-revert-buffers ()
"Revert buffers as specified by Auto-Revert and Global Auto-Revert Mode.
@@ -376,8 +464,8 @@
(let ((bufs (if global-auto-revert-mode
(buffer-list)
auto-revert-buffer-list))
- (remaining '())
- (new '()))
+ (remaining ())
+ (new ()))
;; Partition `bufs' into two halves depending on whether or not
;; the buffers are in `auto-revert-remaining-buffers'. The two
;; halves are then re-joined with the "remaining" buffers at the
@@ -398,6 +486,7 @@
;; Test if someone has turned off Auto-Revert Mode in a
;; non-standard way, for example by changing major mode.
(if (and (not auto-revert-mode)
+ (not auto-revert-tail-mode)
(memq buf auto-revert-buffer-list))
(setq auto-revert-buffer-list
(delq buf auto-revert-buffer-list)))
[-- Attachment #3: Type: text/plain, Size: 142 bytes --]
_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: new tail-mode
2004-07-16 0:30 ` Luc Teirlinck
@ 2004-07-14 15:25 ` Daniel Pfeiffer
2004-07-18 3:11 ` Luc Teirlinck
0 siblings, 1 reply; 5+ messages in thread
From: Daniel Pfeiffer @ 2004-07-14 15:25 UTC (permalink / raw)
Cc: rms, emacs-devel
Saluton,
Sorry for the late reply! (Please use diff -u in the future, it's easier to
read.)
Luc Teirlinck <teirllm@dms.auburn.edu> skribis:
> without any prior mention of `auto-revert-tail-mode'. This is
> confusing.
Yes it's better to explain it like you do. I'd change "to tail a file, this
file" to "to tail a file, this library" because you're talking of two
different files.
> In as far as the proposed code change is concerned, I do not
> understand what the `auto-revert-tail-mode' which the patch removes is
> doing at that place. At this stage we know that the buffer is not
> visiting a file, so `auto-revert-tail-mode' should be nil.
You're right, I overdid checking the two variables.
Thanks for bothering to check my change, and feel free to apply your patch.
coralament / best Grötens / liebe Grüße / best regards / elkorajn salutojn
Daniel Pfeiffer
--
lerne / learn / apprends / lär dig / ucz się Esperanto:
http://lernu.net/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: new tail-mode
2004-07-13 22:22 ` new tail-mode Daniel Pfeiffer
@ 2004-07-14 18:27 ` Richard Stallman
2004-07-16 0:30 ` Luc Teirlinck
1 sibling, 0 replies; 5+ messages in thread
From: Richard Stallman @ 2004-07-14 18:27 UTC (permalink / raw)
Cc: emacs-devel
Ok, I've translated it to be auto-revert-tail-mode. If it's ok, I'd also add
it to the mode line menu, just under Auto Revert.
Ok.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: new tail-mode
2004-07-13 22:22 ` new tail-mode Daniel Pfeiffer
2004-07-14 18:27 ` Richard Stallman
@ 2004-07-16 0:30 ` Luc Teirlinck
2004-07-14 15:25 ` Daniel Pfeiffer
1 sibling, 1 reply; 5+ messages in thread
From: Luc Teirlinck @ 2004-07-16 0:30 UTC (permalink / raw)
Cc: rms, emacs-devel
The Commentary of autorevert.el now contains:
;; Go to the appropriate buffer and press either of:
;; M-x auto-revert-mode RET
;; M-x auto-revert-tail-mode RET
without any prior mention of `auto-revert-tail-mode'. This is
confusing. What about the patch below? I can install it if it looks
OK.
In as far as the proposed code change is concerned, I do not
understand what the `auto-revert-tail-mode' which the patch removes is
doing at that place. At this stage we know that the buffer is not
visiting a file, so `auto-revert-tail-mode' should be nil. The only
situation in which it could be t is if the user first enables
`auto-revert-tail-mode' and then explicitly makes the buffer visit no
file, a strange thing to do. If this situation would be worth
worrying about at all, which is not obvious, then the thing to do
would seem to disable `auto-revert-tail-mode' and print a message to
that effect. The patch below does not do that.
===File ~/auto-revert-diff==================================
*** autorevert.el 14 Jul 2004 16:36:00 -0500 1.35
--- autorevert.el 15 Jul 2004 16:59:47 -0500
***************
*** 34,40 ****
;;
;; This package contains two minor modes: Global Auto-Revert Mode and
;; Auto-Revert Mode. Both modes automatically revert buffers
! ;; whenever the corresponding files have been changed on disk.
;;
;; Auto-Revert Mode can be activated for individual buffers. Global
;; Auto-Revert Mode applies to all file buffers. (If the user option
--- 34,41 ----
;;
;; This package contains two minor modes: Global Auto-Revert Mode and
;; Auto-Revert Mode. Both modes automatically revert buffers
! ;; whenever the corresponding files have been changed on disk and the
! ;; buffer contains no unsaved changes.
;;
;; Auto-Revert Mode can be activated for individual buffers. Global
;; Auto-Revert Mode applies to all file buffers. (If the user option
***************
*** 59,64 ****
--- 60,72 ----
;; Just put point at the end of the buffer and it will stay there.
;; These rules apply to file buffers. For non-file buffers, the
;; behavior may be mode dependent.
+ ;;
+ ;; While you can use Auto Revert Mode to tail a file, this file
+ ;; contains a third minor mode, Auto Revert Tail Mode, which does so
+ ;; more efficiently, as long as you are sure that the file will only
+ ;; change by growing at the end. It only appends the new output,
+ ;; instead of reverting the entire buffer. It does so even if the
+ ;; buffer contains unsaved changes. (Because they will not be lost.)
;; Usage:
;;
***************
*** 389,395 ****
(not (file-remote-p buffer-file-name))
(file-readable-p buffer-file-name)
(not (verify-visited-file-modtime buffer)))
! (and (or auto-revert-mode auto-revert-tail-mode
global-auto-revert-non-file-buffers)
revert-buffer-function
(boundp 'buffer-stale-function)
--- 397,403 ----
(not (file-remote-p buffer-file-name))
(file-readable-p buffer-file-name)
(not (verify-visited-file-modtime buffer)))
! (and (or auto-revert-mode
global-auto-revert-non-file-buffers)
revert-buffer-function
(boundp 'buffer-stale-function)
============================================================
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: new tail-mode
2004-07-14 15:25 ` Daniel Pfeiffer
@ 2004-07-18 3:11 ` Luc Teirlinck
0 siblings, 0 replies; 5+ messages in thread
From: Luc Teirlinck @ 2004-07-18 3:11 UTC (permalink / raw)
Cc: rms, emacs-devel
Daniel Pfeiffer wrote:
I'd change "to tail a file, this file" to "to tail a file, this
library" because you're talking of two different files.
You are right, this was confusing. Thanks for pointing this out. I
actually used "to tail a file, this package", because it seemed more
consistent with the rest of the Commentary.
Sincerely,
Luc.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-07-18 3:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20040610095025.13f91ac1.occitan@esperanto.org>
[not found] ` <40E1D618.4040408@onlinehome.de>
[not found] ` <20040703155128.7fa0da2a@pfdabpc.inhouse.start.de>
[not found] ` <E1BhAOe-00087q-M8@fencepost.gnu.org>
[not found] ` <20040704124113.43b41a42@pfdabpc.inhouse.start.de>
[not found] ` <E1BhWlB-0007LN-8S@fencepost.gnu.org>
[not found] ` <20040705213402.04eb3175@pfdabpc.inhouse.start.de>
[not found] ` <E1BhxyA-0006m3-2w@fencepost.gnu.org>
[not found] ` <20040707213739.7a6193ea@pfdabpc.inhouse.start.de>
[not found] ` <E1BiiA3-0001XI-5L@fencepost.gnu.org>
[not found] ` <20040710201400.01ee8495@pfdabpc.inhouse.start.de>
[not found] ` <E1Bja5e-0006aS-5L@fencepost.gnu.org>
2004-07-13 22:22 ` new tail-mode Daniel Pfeiffer
2004-07-14 18:27 ` Richard Stallman
2004-07-16 0:30 ` Luc Teirlinck
2004-07-14 15:25 ` Daniel Pfeiffer
2004-07-18 3:11 ` Luc Teirlinck
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.