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.
source share