0

I use GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.23) of 2020-11-09 (bundled with Ubuntu 21.10) with this init file:

% cat ~/.emacs.d/init-1.el
(add-hook 'before-save-hook 'time-stamp)

I have this file:

% cat good
modification : (2022-01-21 17:08:15 WET)
<!-- Local Variables: -->
<!-- time-stamp-pattern: "-10/modification :[ \t]+\\\\?[\"(]+%:y-%02m-%02d %02H:%02M:%02S %Z\\\\?[\")]" -->
<!-- End: -->

(ended by an empty line, not visible here).

If you wish to reproduce my experiment, you may save time by creating ~/.emacs.d/init-1.el and good in your system and protecting good.

Then run this in Terminal:

cp good good1
chmod u+w good1
emacs -Q --load ~/.emacs.d/init-1.el good1&

In Emacs, delete or remove the trailing new line or run M-x time-stamp, check that the timestamp updates. So far so good.

Capitalize the m in both instances of modification in the file good1.

time-stamp is now broken: editing and saving or M-x time-stamp won't ever update the timestamp again, unless you restore the initial ms or kill the buffer and reload the file.

Can you confirm my experiment?

Is it Emacs bug?

1 Answer 1

1

Local variables are only read when the file is opened or when the major mode of the buffer is set. See the "Local Variables in Files" section of the Emacs manual: (info "(emacs) File Variables").

If you change it in the buffer and save, that does not change the value of the time-stamp-pattern variable. You need to kill the buffer and do find-file again; or revert the buffer from the file with M-x revert-buffer; or simpler, call normal-mode.

Thanks to @db48x and @phils for correcting and enhancing the answer.

3
  • 1
    Simpler to just call normal-mode.
    – db48x
    Jan 21 at 21:45
  • 1
    Since (IIRC) Emacs 26, local variables are processed when changing the major mode of an existing buffer, rather than only when initially visiting the file.
    – phils
    Jan 22 at 10:39
  • You are right: I'll expand the answer to include that.
    – NickD
    Jan 22 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.