all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Yuri Khan <yuri.v.khan@gmail.com>
To: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Levels of font lock – Dired, Dired+ and Diredful
Date: Mon, 22 May 2017 16:48:52 +0700	[thread overview]
Message-ID: <CAP_d_8UqsBbcZ8Xya0184c4ozRWpURpe25Zt2ooJpZDh6RTzrw@mail.gmail.com> (raw)

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	other threads:[~2017-05-22  9:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-22  9:48 Yuri Khan [this message]
2017-05-23  3:22 ` Levels of font lock – Dired, Dired+ and Diredful Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAP_d_8UqsBbcZ8Xya0184c4ozRWpURpe25Zt2ooJpZDh6RTzrw@mail.gmail.com \
    --to=yuri.v.khan@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.