Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically refreshing (not just tailing) a file in Emacs

Tags:

emacs

I have a process that outputs text to a file output.log . Sometimes this process deletes the file and starts over.

I would like to keep track of the contents of this file within Emacs automatically. I have used auto-revert-tail-mode before, but this appends new output to the buffer, displaying content that may not be in the file anymore (e.g. because the processes deleted the previous file and created a new one).

The only command that seems to do the job is C-x C-v RET (which calls find-alternate-file on the original filename), but I have to type this manually.

Does Emacs provide any built-in mechanism to keep track of the contents of a file? Or perhaps there is a way to have auto-revert-tail-mode add some marker to indicate when the file was deleted and re-created from scratch?

like image 984
Amelio Vazquez-Reina Avatar asked Jan 15 '23 01:01

Amelio Vazquez-Reina


2 Answers

M-x auto-revert-mode should do what you are looking for. It updates the content of the file.

Also when you feel that you have to do manually, you can use emacs macro (M-x kmacro-start-macro) and bind it to a key.

like image 99
aartist Avatar answered Jan 19 '23 10:01

aartist


There is also M-x global-auto-revert-mode that applies auto-revert-mode to all new buffers, in case you forget it. You can set it in .emacs with (global-auto-revert-mode 1)

like image 31
Emre Sahin Avatar answered Jan 19 '23 12:01

Emre Sahin