Al Haji-Ali <[email protected]> writes:

> When font-lock-set-defaults is called before org-set-font-lock-defaults, 
> font-lock-keywords is reset to global. As a result, font-lock-add-keywords 
> with MODE=nil modifies the global variable. This causes keyword highlighting 
> to leak across buffers.
>
> Details:
>
> * In font-lock:
>
> - font-lock-set-defaults makes font-lock-keywords buffer-local with 
> (setq-local font-lock-keywords ...).
> - font-lock-add-keywords with MODE=nil then affects the buffer-local variable.
> - font-lock-set-defaults is set to t, so subsequent calls assume this state.
>
> * In org-mode:
>
> - org-set-font-lock-defaults calls (kill-local-variable 'font-lock-keywords), 
> which makes font-lock-keywords global again.
> - font-lock-set-defaults is not reset, so later calls assume a local variable 
> exists when it does not.
>
> If font-lock-set-defaults runs before org-set-font-lock-defaults, 
> font-lock-keywords becomes global. A later (font-lock-add-keywords nil ...) 
> updates the global variable, affecting all buffers and overriding local 
> font-lock settings.

This indeed sounds wrong on Org side.
Reading through 24.7.1 Font Lock Basics

       There are several variables that control how Font Lock mode
    highlights text.  But major modes should not set any of these variables
    directly.  Instead, they should set ‘font-lock-defaults’ as a
    buffer-local variable.  The value assigned to this variable is used, if
    and when Font Lock mode is enabled, to set all the other variables.

In other words, Org mode should not touch font-lock-keywords.

I looked up the git history and mailing list archives. The only
potential thing I found is in
https://list.orgmode.org/orgmode/[email protected]/ where
Bastien referred to another bug and provided a (now dead) link
http://article.gmane.org/gmane.emacs.orgmode/73429 to some bug report.

In any case, even if there was a bug, we should not touch
font-lock-keywords regardless whether the bug is fixed that way.

Fixed, on main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=ce0f03fe6

-- 
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

Reply via email to