Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
From: Tassilo Horn <tsdh@gnu.org>
To: info-gnus-english@gnu.org
Subject: Re: font-locked Gnus browse server
Date: Fri, 15 May 2015 11:06:33 +0200	[thread overview]
Message-ID: <87r3qitdk6.fsf@gnu.org> (raw)
In-Reply-To: <874mngfabn.fsf@debian.uxu>

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	other threads:[~2015-05-15  9:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-10 23:03 Emanuel Berg
2015-05-13 13:17 ` Tassilo Horn
     [not found] ` <mailman.2946.1431523050.904.info-gnus-english@gnu.org>
2015-05-13 21:15   ` Emanuel Berg
2015-05-15  9:06     ` Tassilo Horn [this message]
     [not found]     ` <mailman.3058.1431680808.904.info-gnus-english@gnu.org>
2015-05-15 14:07       ` Emanuel Berg
2015-05-16  7:33         ` Tassilo Horn
     [not found]         ` <mailman.3122.1431761615.904.info-gnus-english@gnu.org>
2015-05-16 21:25           ` Emanuel Berg
2015-05-18 11:35             ` Tassilo Horn
2015-05-18 19:58               ` Emanuel Berg

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=87r3qitdk6.fsf@gnu.org \
    --to=tsdh@gnu.org \
    --cc=info-gnus-english@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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).