Subject: Re: bug#39597: 27.0.60: M-x occur adds fontification to fundamental-mode

From: Juri Linkov <[email-masked]>
Date: Sun, 23 Feb 2020 02:24:15 +0200

> Idle musing: I wonder if something could be done inside
> fundamental-mode.  It's not the only fontification issue I've noticed
> there[1].
>
> [1] E.g. (I was about to report this as a distinct issue… someday…)
>
>     C-x b foo
>     foo RET bar RET baz RET
>     M-s h r a RET RET
>     aaaa
>
>     ⇒ In all modes *but* fundamental-mode, hi-lock-mode dynamically
>     highlights new matches (e.g. the added "aaaa" string here).
>
>     This bug is not strictly related to the current one, since the
>     former has been with us since at least 26.3, but that does make me
>     wonder whether both issues could be solved by turning some font-lock
>     knob in fundamental-mode…

Searching for "font-lock-specified-p" in hi-lock.el
shows these fragments of code.  This first condition decides
whether to use font-lock for highlighting matches
that returns nil in fundamental-mode:

      (if (and font-lock-mode (font-lock-specified-p major-mode))

      ;; FIXME: Calling `font-lock-remove-keywords' causes
      ;; `font-lock-specified-p' to go from nil to non-nil (because it
      ;; calls font-lock-set-defaults).  This is yet-another bug in
      ;; font-lock-add/remove-keywords, which we circumvent here by
      ;; testing `font-lock-fontified' (bug#19796).