unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Levels of font lock – Dired, Dired+ and Diredful
@ 2017-05-22  9:48 Yuri Khan
  2017-05-23  3:22 ` Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: Yuri Khan @ 2017-05-22  9:48 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org

Hello list,

I just spent an hour investigating an interaction of multiple packages
tinkering with font lock. I’m pretty sure I ought to file a bug report
but not so sure against what.

There is a concept of levels of font lock. A major mode sets up three
lists of keywords in a buffer-local ‘font-lock-defaults’ variable.
Then, depending on the user’s ‘font-lock-maximum-decoration’, more or
fewer keywords get applied.

The base Dired mode defines only one level:

  (setq-local font-lock-defaults
              '(dired-font-lock-keywords t nil nil beginning-of-line))

Dired+ by Drew Adams, in its dired-mode-hook handler, replaces that
with a three-element list with two different sets of keywords:

            (set (make-local-variable 'font-lock-defaults)
                 ;; Two levels.  Use 3-element list, since it is
standard to have one more
                 ;; than the number of levels.  This is necessary for
it to work with
                 ;; `font(-lock)-menus.el'.
                 '((dired-font-lock-keywords
                    dired-font-lock-keywords
                    diredp-font-lock-keywords-1)
                   t nil nil beginning-of-line))

Diredful by Thamer Mahmoud keeps a list of rules for highlighting
files by extension, file name regexp, or full Dired line regexp, and
provides a convenient UI for editing these rules. Behind the scene, it
adds keywords to ‘dired-font-lock-keywords’:

      (add-to-list 'dired-font-lock-keywords
                   (list regexp face-list))


Now the problem is when I use both of these together. I play on the
Insane level (font-lock-maximum-decoration set to t). It appears that
I “only” get the last level of font lock —
‘diredp-font-lock-keywords-1’ from Dired+. I do not get the additions
by Diredful.

I can work around the issue by changing Diredful to add to both lists
(dired-font-lock-keywords and diredp-font-lock-keywords-1). But this
feels wrong; Diredful should not have to know about Dired+.

On the other hand, I can work around the issue by changing Dired+ so
that instead of ‘diredp-font-lock-keywords-1’ it uses a new variable
which is set in the same dired-mode-hook handler to the result of
(append dired-font-lock-keywords diredp-font-lock-keywords-1). This
feels cleaner but now it’s highly probable that some of Dired+’s
keywords duplicate and/or override those of base Dired.

What do you think?



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Levels of font lock – Dired, Dired+ and Diredful
  2017-05-22  9:48 Levels of font lock – Dired, Dired+ and Diredful Yuri Khan
@ 2017-05-23  3:22 ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2017-05-23  3:22 UTC (permalink / raw)
  To: help-gnu-emacs

> There is a concept of levels of font lock. A major mode sets up three
> lists of keywords in a buffer-local ‘font-lock-defaults’ variable.

Yes, but it's poorly supported, as you've seen.

Personally I find it to be misguided, anyway: it'd be better for the
"font-lock-keywords" to depend on config vars so you can affect the
various parts independently.  But this requires a redesign of
font-lock-keywords and noone's been very interested in going down
that route.  Such a redesign could be very useful, tho, e.g. allowing
better debugging (or even edebug-ing).


        Stefan




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-05-23  3:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-22  9:48 Levels of font lock – Dired, Dired+ and Diredful Yuri Khan
2017-05-23  3:22 ` Stefan Monnier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).