Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

why 4 inotfy events when saving a file?

10 views
Skip to first unread message

Gregor Zattler

unread,
Mar 10, 2013, 5:44:42 PM3/10/13
to help-gnu-emacs
Dear Emacs users and developers,

saving a file from Emacs gives 4 inotify events:

how to reproduce:

on first terminal do:
emacs-snapshot -nw -Q /tmp/inotify.test
modify file


on second terminal do
inotifywait -m -q --format '%e %w%f' /tmp/inotify.test


on first terminal do
^x^s (safe buffer)

result on second terminal is:
MODIFY /tmp/inotify.test
OPEN /tmp/inotify.test
MODIFY /tmp/inotify.test
CLOSE_WRITE,CLOSE /tmp/inotify.test


why are there so many events?



This is with
GNU Emacs 24.3.50.1 (i486-pc-linux-gnu, GTK+ Version 3.4.2) of
2013-03-04 on dex, modified by Debian



Thanx for your attention, Gregor
--
-... --- .-. . -.. ..--.. ...-.-

Eli Zaretskii

unread,
Mar 10, 2013, 6:09:44 PM3/10/13
to help-gn...@gnu.org
> Date: Sun, 10 Mar 2013 22:44:42 +0100
> From: Gregor Zattler <tele...@gmx.net>
>
> saving a file from Emacs gives 4 inotify events:
>
> how to reproduce:
>
> on first terminal do:
> emacs-snapshot -nw -Q /tmp/inotify.test
> modify file
>
>
> on second terminal do
> inotifywait -m -q --format '%e %w%f' /tmp/inotify.test
>
>
> on first terminal do
> ^x^s (safe buffer)
>
> result on second terminal is:
> MODIFY /tmp/inotify.test
> OPEN /tmp/inotify.test
> MODIFY /tmp/inotify.test
> CLOSE_WRITE,CLOSE /tmp/inotify.test
>
>
> why are there so many events?

Because that's what Emacs does when it saves the file, first to the
old version, then to the new. Take a look at the implementation of
write-region, which is the primitive used by save-buffer to write the
buffer to its file, you will see all those operations there.

Barry Margolin

unread,
Mar 10, 2013, 8:59:22 PM3/10/13
to
In article <mailman.21821.1362951...@gnu.org>,
Gregor Zattler <tele...@gmx.net> wrote:

> Dear Emacs users and developers,
>
> saving a file from Emacs gives 4 inotify events:
>
> how to reproduce:
>
> on first terminal do:
> emacs-snapshot -nw -Q /tmp/inotify.test
> modify file
>
>
> on second terminal do
> inotifywait -m -q --format '%e %w%f' /tmp/inotify.test
>
>
> on first terminal do
> ^x^s (safe buffer)
>
> result on second terminal is:
> MODIFY /tmp/inotify.test
> OPEN /tmp/inotify.test
> MODIFY /tmp/inotify.test
> CLOSE_WRITE,CLOSE /tmp/inotify.test
>
>
> why are there so many events?

To save the backup file. First it renames inotify.test to
inotify.test.~<version>~, then it writes the buffer to a new
inotify.test file.

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Gregor Zattler

unread,
Mar 11, 2013, 7:14:17 PM3/11/13
to help-gnu-emacs
Hi Eli, Emacs users and developers,
* Eli Zaretskii <el...@gnu.org> [11. Mar. 2013]:
>> Date: Sun, 10 Mar 2013 22:44:42 +0100
>> From: Gregor Zattler <tele...@gmx.net>
>>
>> saving a file from Emacs gives 4 inotify events:
[...]
>> why are there so many events?
>
> Because that's what Emacs does when it saves the file, first to the
> old version, then to the new. Take a look at the implementation of
> write-region, which is the primitive used by save-buffer to write the
> buffer to its file, you will see all those operations there.

Thanks (also to Barry Margolin) for the explanation. I now
search for a after-file-save-hook. But I didn't find it. Is
there some such thing?


Ciao, Gregor

B. T. Raven

unread,
Mar 11, 2013, 10:21:14 PM3/11/13
to
C-h v after TAB shows:

after-save-hook is a variable defined in `files.el'.
Its value is nil

This variable is potentially risky when used as a file local variable.

Documentation:
Normal hook that is run after a buffer is saved to its file.

You can customize this variable.

Ed

>
>
> Ciao, Gregor
>

William Gardella

unread,
Mar 11, 2013, 11:07:28 PM3/11/13
to help-gn...@gnu.org
Hi Gregor,

Gregor Zattler <tele...@gmx.net> writes:

> Thanks (also to Barry Margolin) for the explanation. I now
> search for a after-file-save-hook. But I didn't find it. Is
> there some such thing?
>
>
> Ciao, Gregor

There is, in, fact, an `after-save-hook'. :) Please see also (info
"(elisp) Saving Buffers").

--
Regards,
WGG


0 new messages