What does this "local file variable" mean?

I read about the kill-emacs-hook variable in the emacs manual. It says:

kill-emacs-hook is a variable defined in "C source code".
Its value
(org-babel-remove-temporary-directory migemo-pattern-alist-save)

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

Documentation:
A hook that starts when kill-emacs called.
... abbreviated ...

I do not understand this sentence: "local file variable". What does this "local file variable" mean?

+4
source share
2 answers

Emacs has a tool for specifying buffer variables in the contents of a file. http://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html#Specifying-File-Variables

This is often used to indicate file mode -*- python -*- or, for example. preferred indentation style or tab width; but it could potentially give the file author full control over your Emacs if you allow it. However, for variables that are considered unsafe, the default behavior is to ask the user to confirm before allowing entry into force. See the manual for further discussion.

+4
source

By default, when you set a variable with setq , the value is global. This means that all buffers will see the new value.

However, some variables, called local buffer variables, work differently. When the local buffer variable is set, its value changes only for the buffer where setq occurred. Other buffers do not see the change.

These buffer local variables can take their value from the contents of the file that is currently visiting the buffer. If the file contains a correctly formatted string (see @tripleee answer), then the local buffer variable will be initialized with the value when the file is open.

As a side note, there are also local directory variables that set a local buffer variable for each buffer by visiting a file in the directory.

+2
source

All Articles