Function: so-long--hack-one-local-variable
so-long--hack-one-local-variable is a byte-compiled function defined
in so-long.el.gz.
Signature
(so-long--hack-one-local-variable ORIG-FUN VAR VAL)
Documentation
Prevent the original major mode being restored after so-long-mode.
This advice is needed and enabled only for Emacs versions < 26.1.
If the local mode pseudo-variable is used, set-auto-mode-0 will call it
firstly, and subsequently hack-one-local-variable may call it again.
Usually hack-one-local-variable tries to avoid processing that second call,
by testing the value against major-mode; but as we may have changed the
major mode to so-long-mode by this point, that protection is insufficient
and so we need to perform our own test.
We likewise need to support an equivalent of the no-mode behavior in 26.1+
to ensure that so-long-mode-revert will not restore a file-local mode again
after it has already reverted to the original mode.
The changes to normal-mode in Emacs 26.1 modified the execution order, and
makes this advice unnecessary. The relevant NEWS entry is:
** File local and directory local variables are now initialized each
time the major mode is set, not just when the file is first visited.
These local variables will thus not vanish on setting a major mode.
Source Code
;; Defined in /usr/src/emacs/lisp/so-long.el.gz
(defun so-long--hack-one-local-variable (orig-fun var val)
;; Advice, enabled with:
;; (advice-add 'hack-one-local-variable :around
;; #'so-long--hack-one-local-variable)
"Prevent the original major mode being restored after `so-long-mode'.
This advice is needed and enabled only for Emacs versions < 26.1.
If the local `mode' pseudo-variable is used, `set-auto-mode-0' will call it
firstly, and subsequently `hack-one-local-variable' may call it again.
Usually `hack-one-local-variable' tries to avoid processing that second call,
by testing the value against `major-mode'; but as we may have changed the
major mode to `so-long-mode' by this point, that protection is insufficient
and so we need to perform our own test.
We likewise need to support an equivalent of the `no-mode' behavior in 26.1+
to ensure that `so-long-mode-revert' will not restore a file-local mode again
after it has already reverted to the original mode.
The changes to `normal-mode' in Emacs 26.1 modified the execution order, and
makes this advice unnecessary. The relevant NEWS entry is:
** File local and directory local variables are now initialized each
time the major mode is set, not just when the file is first visited.
These local variables will thus not vanish on setting a major mode."
(if (eq var 'mode)
;; Adapted directly from `hack-one-local-variable'
(let ((mode (intern (concat (downcase (symbol-name val))
"-mode"))))
(unless (or so-long--hack-local-variables-no-mode
(let ((origmode (so-long-original 'major-mode)))
;; We bind origmode because (indirect-function nil) is an
;; error in Emacs versions < 25.1, and so we need to test
;; it first.
(and origmode
(eq (indirect-function mode)
(indirect-function origmode)))))
(funcall orig-fun var val)))
;; VAR is not the 'mode' pseudo-variable.
(funcall orig-fun var val)))