Subject: 25.0.90; Saving a buffer under auto-revert turns off file notifications

From: Eli Zaretskii <[email-masked]>
Date: Thu, 04 Feb 2016 20:34:10 +0200

emacs -Q
  C-x C-f SOME-FILE RET
  M-x auto-revert-mode RET
  M-: auto-revert-use-notify RET => t

Modify the buffer and save it with "C-x C-s".  Then:

  M-: auto-revert-use-notify RET => nil

This is on MS-Windows; the same recipe on GNU/Linux with inotify
doesn't have this problem.

Looking under the hood reveals that filenotify.el sends a 'stopped'
notification when Emacs renames SOME-FILE to SOME-FILE~, to back it
up.  In response, auto-revert-mode turns off file notifications and
falls back to polling.

It looks like the reason is this condition in filenotify.el:

        ;; Check for stopped.
        (setq
         stopped
         (or
          stopped
          (and
           (memq action '(deleted renamed))
           (= (length (cdr registered)) 1)
           (or
            (string-equal
             (file-name-nondirectory file)
	     (file-name-nondirectory (car registered)))
            (string-equal
             (file-name-nondirectory file)
             (car (cadr registered)))))))

The second call to string-equal is the culprit: the file names match,
so 'stopped' gets a non-nil value.

I don't understand the logic of this: at least with w32notify, when a
file is in auto-revert-mode, we watch the entire parent directory of
that file, so there's no need to send the 'stopped' event when the
file is renamed or deleted, only when the parent directory is deleted.

This second call to string-equal was added as part of kqueue
back-port, but it affects all the backends, and there's no comment or
anything in the log message that explains the rationale for this part
of the change, only a laconic "Add kqueue support."

What is the reason for this test, and should it perhaps be limited to
kqueue?

In GNU Emacs 25.0.90.2 (i686-pc-mingw32)
 of 2016-01-31 built on HOME-C4E4A596F7
Windowing system distributor 'Microsoft Corp.', version 5.1.2600
Configured using:
 'configure --prefix=/d/usr --enable-checking=yes,glyphs
 --with-wide-int --with-modules 'CFLAGS=-Og -gdwarf-4 -g3''

Configured features:
XPM JPEG TIFF GIF PNG RSVG SOUND NOTIFY ACL GNUTLS LIBXML2 ZLIB
TOOLKIT_SCROLL_BARS MODULES

Important settings:
  value of $LANG: ENU
  locale-coding-system: cp1255

Major mode: Mail

Minor modes in effect:
  shell-dirtrack-mode: t
  flyspell-mode: t
  diff-auto-refine-mode: t
  desktop-save-mode: t
  save-place-mode: t
  show-paren-mode: t
  display-time-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  temp-buffer-resize-mode: t
  line-number-mode: t
  auto-fill-function: mail-mode-auto-fill
  abbrev-mode: t

Recent messages:
Mark saved where search started [2 times]
Mark set
Mark saved where search started
Mark set
Saving file d:/gnu/git/emacs/branch/lisp/filenotify.el...
Wrote d:/gnu/git/emacs/branch/lisp/filenotify.el
Mark set
Undo!
Saving file d:/gnu/git/emacs/branch/lisp/filenotify.el...
Wrote d:/gnu/git/emacs/branch/lisp/filenotify.el

Load-path shadows:
d:/usr/share/emacs/site-lisp/soap-inspect hides d:/usr/share/emacs/25.0.90/lisp/net/soap-inspect
d:/usr/share/emacs/site-lisp/soap-client hides d:/usr/share/emacs/25.0.90/lisp/net/soap-client

Features:
(descr-text iso-transl ebuff-menu pp shadow emacsbug ruby-mode smie
shell character-fold misearch multi-isearch rmailout url-util
url-parse url-vars rfc2104 network-stream nsm starttls tls gnutls
mail-extr smtpmail auth-source eieio eieio-core cl-macs password-cache
dabbrev mailalias sendmail shr-color color shr dom subr-x browse-url
cl-seq conf-mode arc-mode archive-mode vc-bzr org-element org-rmail
org-mhe org-irc org-info org-gnus org-docview doc-view image-mode
org-bibtex bibtex org-bbdb org-w3m org advice org-macro org-footnote
org-pcomplete pcomplete org-list org-faces org-entities org-version
ob-emacs-lisp ob ob-tangle ob-ref ob-lob ob-table ob-exp org-src
ob-keys ob-comint comint ansi-color ring ob-core ob-eval org-compat
org-macs org-loaddefs find-func cal-menu calendar cal-loaddefs
bat-mode make-mode parse-time vc-cvs generic vc-svn texinfo jka-compr
noutline outline bug-reference flyspell add-log info vc vc-dispatcher
vc-git diff-mode easy-mmode map seq byte-opt gv bytecomp byte-compile
cconv cl-extra qp rmailsum rmailmm message dired-x dired format-spec
rfc822 mml mml-sec epg epg-config gnus-util mm-decode mm-bodies
mm-encode mailabbrev gmm-utils mailheader mail-parse rfc2231 rmail
rfc2047 rfc2045 ietf-drums mm-util help-fns help-mode mail-prsvr
mail-utils desktop frameset server filecache mairix cus-edit cus-start
cus-load wid-edit saveplace midnight ispell generic-x cc-mode cc-fonts
easymenu cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine
cc-vars cc-defs cl-loaddefs pcase cl-lib paren battery time time-date
mule-util tooltip eldoc electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel dos-w32 ls-lisp disp-table w32-win w32-vars
term/common-win tool-bar dnd fontset image regexp-opt fringe
tabulated-list newcomment elisp-mode lisp-mode prog-mode register page
menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core frame cl-generic cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese
eucjp-ms cp51932 hebrew greek romanian slovak czech european ethiopic
indian cyrillic chinese charscript case-table epa-hook jka-cmpr-hook
help simple abbrev minibuffer cl-preloaded nadvice loaddefs button
faces cus-face macroexp files text-properties overlay sha1 md5 base64
format env code-pages mule custom widget hashtable-print-readable
backquote w32notify w32 multi-tty make-network-process emacs)

Memory information:
((conses 16 1766138 246501)
 (symbols 56 51658 10)
 (miscs 48 3618 4548)
 (strings 16 128344 31235)
 (string-bytes 1 3335828)
 (vectors 16 42573)
 (vector-slots 8 1729654 252618)
 (floats 8 498 992)
 (intervals 40 338547 2583)
 (buffers 856 223))