help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Levels of font lock – Dired, Dired+ and Diredful


From: Yuri Khan
Subject: Levels of font lock – Dired, Dired+ and Diredful
Date: Mon, 22 May 2017 16:48:52 +0700

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?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]