Reputation: 11
I'm trying to extend Dired in emacs 26 windows to show junctions similarly to symlinks. I've got everything done except I can't get the junction file name part to be fontified.
Here's what I've done so far:
(defface dired-junction
'((t (:inherit font-lock-keyword-face)))
"Face used for junctions."
:group 'dired-faces
:version "22.1")
(defvar dired-junction-face 'dired-junction
"Face name used for junctions.")
(defvar dired-re-jun (concat dired-re-maybe-mark dired-re-inode-size "J[^:]"))
; ;; Symbolic links. pb: this needs to be part of dired-font-lock-keywords
; (list dired-re-sym
; '(".+" (dired-move-to-filename) nil (0 dired-symlink-face)))
;; Junctions.
(push (list dired-re-jun
'(".+" (dired-move-to-filename) nil (0 dired-junction-face)))
dired-font-lock-keywords)
I don't know where Dired uses the dired-font-lock-keywords
for fontification, so either I've left something out, or else I don't understand how to add to the dired-font-lock-keywords
variable properly.
Note the J
for junction is what I am using to replace the l
for symlink or d
for directory.
Upvotes: 0
Views: 111
Reputation: 11
It turns out that the way I was trying to do it actually does work. My problem was that it needs to eval'ed before dired is first loaded. That is no doubt also related to the elisp doc saying that font-lock-add-keywords
should only be called in the init file, and therefore before all the structures are set up apparently.
No doubt the other approaches suggested would also work, but I gave up debugging them once I figured out the source of my initial problem.
Thanks for the suggestions; without them I would never have figured it out. Emacs code is truly byzantine. In fact, I had to refactor a lot of ls-lisp-insert-directory
just to figure out what it was doing.
Upvotes: 0
Reputation: 30701
Maybe this will get you started...
You don't need a variable whose value is a face. Just use the face directly. Not important, but just FYI.
Use font-lock-add-keywords
. See (elisp) Customizing Keywords. And see (elisp) Search-based Fontification, which tells you not to set variable font-lock-keywords
directly:
The value of this variable is a list of the keywords to highlight. Lisp programs should not set this variable directly. Normally, the value is automatically set by Font Lock mode, using the
KEYWORDS
element infont-lock-defaults
. The value can also be altered using the functionsfont-lock-add-keywords
andfont-lock-remove-keywords
(See Customizing Keywords).
Upvotes: 0