info-gnus-english
[Top][All Lists]
Advanced

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

Re: font-locked Gnus browse server


From: Tassilo Horn
Subject: Re: font-locked Gnus browse server
Date: Fri, 15 May 2015 11:06:33 +0200
User-agent: Gnus/5.130014 (Ma Gnus v0.14) Emacs/25.0.50 (gnu/linux)

Emanuel Berg <embe8573@student.uu.se> writes:

>> Or you can put your current `font-lock-add-keywords'
>> call into your ~/.gnus. Then it would be evaluated
>> before gnus-browse-mode was activated.
>
> It is in an init file and it is evaluated before the
> mode is set.  For some reason it doesn't kick in
> without the explicit call to
> `font-lock-fontify-buffer'. That has never been needed
> elsewhere in my experience.

Ah, yeah, now I see it.  I've thought you'd call
`font-lock-add-keywords' in the hook but you actually only call
`font-lock-fontify-buffer' there.

I think the reason why you need to trigger font-locking explicitly using
`font-lock-fontify-buffer' (or `font-lock-ensure') is that
`gnus-browse-mode' doesn't set `font-lock-defaults' which would be used
to initialize `font-lock-keywords'.  And that says:

,----[ C-h v nil RET ]
| font-lock-keywords is a variable defined in `font-lock.el'.
| [...] 
| A user-level keywords list is what a major mode or the user would
| set up.  Normally the list would come from `font-lock-defaults'.
| through selection of a fontification level and evaluation of any
| contained expressions.  You can also alter it by calling
| `font-lock-add-keywords' or `font-lock-remove-keywords' with MODE = nil.
| [...]
`----

So calling `font-lock-add-keywords' with MODE = nil will also trigger
font-lock, and indeed

--8<---------------cut here---------------start------------->8---
(defun th/gnus-browse-mode-init ()
  (font-lock-add-keywords
   nil
   '(("^\\(.\\)[[:space:]]+\\([[:digit:]]+\\):[[:space:]]\\(.*\\)"
      (1 font-lock-keyword-face)
      (2 font-lock-variable-name-face)
      (3 font-lock-function-name-face)))))

(add-hook 'gnus-browse-mode-hook #'th/gnus-browse-mode-init)
--8<---------------cut here---------------end--------------->8---

does work for me.

Bye,
Tassilo




reply via email to

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