* Dired - highlight the name of the directory in directory headers
@ 2020-11-18 16:56 Sebastian Tennant
2020-11-18 18:42 ` Michael Heerdegen
2020-11-18 23:08 ` Drew Adams
0 siblings, 2 replies; 4+ messages in thread
From: Sebastian Tennant @ 2020-11-18 16:56 UTC (permalink / raw)
To: help-gnu-emacs
Hello all,
I thought it would be easy to highlight the name of the directory in
directory headers in Dired buffers. For example:
/home/bob/Notes:
^^^^^
My first approach was to use font-lock-add-keywords:
(font-lock-add-keywords 'dired-mode '("\\([^/]+\\):\n" . (1 'bold)))
but try as I might I could not get this to work.
I then thought I would add a function to dired-mode-hook:
(defun highlight-directory-name-in-headers ()
(hi-lock-face-buffer "\\([^/]+\\):\n" 'bold 1))
(add-hook 'dired-mode-hook 'highlight-directory-name-in-headers t)
but that didn't work either.
In the end, I got the mode hook to 'work' by delaying the call to
hi-lock-face-buffer:
(defun highlight-directory-name-in-headers ()
(run-at-time
0.1 nil 'hi-lock-face-buffer "\\([^/]+\\):\n" 'bold 1))
but this is an ugly kludge if ever I saw one.
How should it be done?
sebyte
--
Dorothy Annan Trevor Tennant database - DATTdb
http://dattdb.info
^ permalink raw reply [flat|nested] 4+ messages in thread
* Dired - highlight the name of the directory in directory headers
@ 2020-11-18 17:45 Sebastian Tennant
0 siblings, 0 replies; 4+ messages in thread
From: Sebastian Tennant @ 2020-11-18 17:45 UTC (permalink / raw)
To: help-gnu-emacs
Hello all,
I reached for a timer because I've been working with them recently
but, of course, using advice is aprroximately one hundred times
better:
(advice-add
'dired-mode :after
(lambda (&rest args)
(hi-lock-face-buffer "\\([^/]+\\):\n" 'bold 1))
'((name . highlight-directory-name-in-headers)))
I'd still love to know why adding an 'ordinary' function to
dired-mode-hook doesn't work.
sebyte
--
Dorothy Annan Trevor Tennant database - DATTdb
http://dattdb.info
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Dired - highlight the name of the directory in directory headers
2020-11-18 16:56 Dired - highlight the name of the directory in directory headers Sebastian Tennant
@ 2020-11-18 18:42 ` Michael Heerdegen
2020-11-18 23:08 ` Drew Adams
1 sibling, 0 replies; 4+ messages in thread
From: Michael Heerdegen @ 2020-11-18 18:42 UTC (permalink / raw)
To: help-gnu-emacs
Sebastian Tennant <sdt@sebyte.me> writes:
> Hello all,
>
> I thought it would be easy to highlight the name of the directory in
> directory headers in Dired buffers. For example:
>
> /home/bob/Notes:
> ^^^^^
> My first approach was to use font-lock-add-keywords:
>
> (font-lock-add-keywords 'dired-mode '("\\([^/]+\\):\n" . (1 'bold)))
>
> but try as I might I could not get this to work.
One problem with your code is that `font-lock-add-keywords' expects a
_list_ of keywords.
I think it's also better to match the end of the line instead of the
newline char.
Dired uses this:
(list dired-subdir-regexp '(1 dired-header-face))
I think it's best to start with that. It has the advantage that it
doesn't accidentally match file names including a colon.
Michael.
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: Dired - highlight the name of the directory in directory headers
2020-11-18 16:56 Dired - highlight the name of the directory in directory headers Sebastian Tennant
2020-11-18 18:42 ` Michael Heerdegen
@ 2020-11-18 23:08 ` Drew Adams
1 sibling, 0 replies; 4+ messages in thread
From: Drew Adams @ 2020-11-18 23:08 UTC (permalink / raw)
To: Sebastian Tennant, help-gnu-emacs
> I thought it would be easy to highlight the name of the directory in
> directory headers in Dired buffers. For example:
>
> /home/bob/Notes:
> ^^^^^
> My first approach was to use font-lock-add-keywords:
>
> (font-lock-add-keywords 'dired-mode '("\\([^/]+\\):\n" . (1 'bold)))
>
> but try as I might I could not get this to work.
FWIW, Dired+ highlights this line (with face
`diredp-dir-heading') using this font-lock entry:
'("^ \\(.+:\\)$" 1 diredp-dir-heading) ; Directory headers
https://www.emacswiki.org/emacs/download/dired%2b.el
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-11-18 23:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-18 16:56 Dired - highlight the name of the directory in directory headers Sebastian Tennant
2020-11-18 18:42 ` Michael Heerdegen
2020-11-18 23:08 ` Drew Adams
-- strict thread matches above, loose matches on Subject: below --
2020-11-18 17:45 Sebastian Tennant
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.