Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
* font-locked Gnus browse server
@ 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>
  0 siblings, 2 replies; 9+ messages in thread
From: Emanuel Berg @ 2015-05-10 23:03 UTC (permalink / raw)
  To: info-gnus-english

Here is a dump [1] of how it could look, and the Elisp
[2] that makes it look that way easily enough.

Doesn't it look nice and, uhm, colorful?

It seems even tho `font-lock-mode' is on, you still
have to call `font-lock-fontify-buffer' to get the
action. I put it in `gnus-browse-mode-hook' but
I don't think you should have to (?). Anyway, enjoy :)

[1] http://user.it.uu.se/~embe8573/dumps/gnus-server-color.png
[2] http://user.it.uu.se/~embe8573/conf/emacs-init/gnus/browse.el

-- 
underground experts united
http://user.it.uu.se/~embe8573

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: font-locked Gnus browse server
  2015-05-10 23:03 font-locked Gnus browse server Emanuel Berg
@ 2015-05-13 13:17 ` Tassilo Horn
       [not found] ` <mailman.2946.1431523050.904.info-gnus-english@gnu.org>
  1 sibling, 0 replies; 9+ messages in thread
From: Tassilo Horn @ 2015-05-13 13:17 UTC (permalink / raw)
  To: info-gnus-english

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

> Here is a dump [1] of how it could look, and the Elisp
> [2] that makes it look that way easily enough.
>
> Doesn't it look nice and, uhm, colorful?
>
> It seems even tho `font-lock-mode' is on, you still
> have to call `font-lock-fontify-buffer' to get the
> action.

I think it would be there immediately if you call
`font-lock-add-keywords' with nil in place of 'gnus-browse-mode.

> I put it in `gnus-browse-mode-hook' but I don't think you should have
> to (?). Anyway, enjoy :)

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.

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: font-locked Gnus browse server
       [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
       [not found]     ` <mailman.3058.1431680808.904.info-gnus-english@gnu.org>
  0 siblings, 2 replies; 9+ messages in thread
From: Emanuel Berg @ 2015-05-13 21:15 UTC (permalink / raw)
  To: info-gnus-english

Tassilo Horn <tsdh@gnu.org> writes:

>> Here is a dump [1] of how it could look, and the
>> Elisp [2] that makes it look that way easily
>> enough. Doesn't it look nice and, uhm, colorful?
>> It seems even tho `font-lock-mode' is on, you still
>> have to call `font-lock-fontify-buffer' to get
>> the action.
>
> I think it would be there immediately if you call
> `font-lock-add-keywords' with nil in place of
> 'gnus-browse-mode.

From (describe-function 'font-lock-add-keywords)

    MODE should be a symbol, the major mode command
    name, such as `c-mode' or nil. If nil,
    highlighting keywords are added for the
    current buffer.

>> I put it in `gnus-browse-mode-hook' but
>> I don't think you should have to (?).
>
> 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.

-- 
underground experts united
http://user.it.uu.se/~embe8573

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: font-locked Gnus browse server
  2015-05-13 21:15   ` Emanuel Berg
@ 2015-05-15  9:06     ` Tassilo Horn
       [not found]     ` <mailman.3058.1431680808.904.info-gnus-english@gnu.org>
  1 sibling, 0 replies; 9+ messages in thread
From: Tassilo Horn @ 2015-05-15  9:06 UTC (permalink / raw)
  To: info-gnus-english

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



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: font-locked Gnus browse server
       [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>
  0 siblings, 2 replies; 9+ messages in thread
From: Emanuel Berg @ 2015-05-15 14:07 UTC (permalink / raw)
  To: info-gnus-english

Tassilo Horn <tsdh@gnu.org> writes:

> 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'.

You mean like this?

    (defvar gnus-browse-font-lock-keywords
      '(("^K"                       . font-lock-builtin-face)
        ("\\([[:digit:]].*\\):"    (1 font-lock-function-name-face))
        ("\\(gmane\\.\\)\\(.*\\)"  (1 font-lock-comment-face)
                                   (2 font-lock-variable-name-face) )
        ("\\(gwene\\.\\)\\(.*\\)"  (1 font-lock-constant-face)
                                   (2 font-lock-type-face)) ))

    (defun gnus-browse-mode-hook-f ()
      (set (make-local-variable 'font-lock-defaults)
           '(gnus-browse-font-lock-keywords t)) )
    (add-hook 'gnus-browse-mode-hook 'gnus-browse-mode-hook-f)

> So calling `font-lock-add-keywords' with MODE = nil
> will also trigger font-lock, and indeed ...
>
> th/gnus-browse-mode-init () (font-lock-add-keywords
> nil ... )
>
> (add-hook 'gnus-browse-mode-hook
> #'th/gnus-browse-mode-init)
>
> does work for me.

With MODE as nil the font lock is done one the basis
of the current buffer. It is not related to the mode
itself apart from the invocation being placed in the
mode entry hook. This means the keywords have to be
added every time the mode is entered.

-- 
underground experts united
http://user.it.uu.se/~embe8573

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: font-locked Gnus browse server
  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>
  1 sibling, 0 replies; 9+ messages in thread
From: Tassilo Horn @ 2015-05-16  7:33 UTC (permalink / raw)
  To: info-gnus-english

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

>> 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'.
>
> You mean like this?
>
>     (defvar gnus-browse-font-lock-keywords
>       '(("^K"                       . font-lock-builtin-face)
>         ("\\([[:digit:]].*\\):"    (1 font-lock-function-name-face))
>         ("\\(gmane\\.\\)\\(.*\\)"  (1 font-lock-comment-face)
>                                    (2 font-lock-variable-name-face) )
>         ("\\(gwene\\.\\)\\(.*\\)"  (1 font-lock-constant-face)
>                                    (2 font-lock-type-face)) ))
>
>     (defun gnus-browse-mode-hook-f ()
>       (set (make-local-variable 'font-lock-defaults)
>            '(gnus-browse-font-lock-keywords t)) )
>     (add-hook 'gnus-browse-mode-hook 'gnus-browse-mode-hook-f)

Yes, this could also work.  BTW, `font-lock-defaults' is automatically
buffer-local, no need to make it so.

>> So calling `font-lock-add-keywords' with MODE = nil
>> will also trigger font-lock, and indeed ...
>>
>> th/gnus-browse-mode-init () (font-lock-add-keywords
>> nil ... )
>>
>> (add-hook 'gnus-browse-mode-hook
>> #'th/gnus-browse-mode-init)
>>
>> does work for me.
>
> With MODE as nil the font lock is done one the basis
> of the current buffer. It is not related to the mode
> itself apart from the invocation being placed in the
> mode entry hook. This means the keywords have to be
> added every time the mode is entered.

Yes, but that doesn't make a difference, no?

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: font-locked Gnus browse server
       [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
  0 siblings, 1 reply; 9+ messages in thread
From: Emanuel Berg @ 2015-05-16 21:25 UTC (permalink / raw)
  To: info-gnus-english

Tassilo Horn <tsdh@gnu.org> writes:

> Yes, this could also work. BTW, `font-lock-defaults'
> is automatically buffer-local, no need to make
> it so.

Check out `gnus-server-mode' - gnus-srvr.el, which
I have as

    /usr/share/emacs/24.4/lisp/gnus/gnus-srvr.el

line 263:

    (set (make-local-variable 'font-lock-defaults) ; ...

>> With MODE as nil the font lock is done one the
>> basis of the current buffer. It is not related to
>> the mode itself apart from the invocation being
>> placed in the mode entry hook. This means the
>> keywords have to be added every time the mode
>> is entered.
>
> Yes, but that doesn't make a difference, no?

All three solutions are equally bad in that all rely
on the hook.

The best solution would be to change
`gnus-browse-mode' to do what gnus-server-mode does so
`font-lock-defaults' is set and one only has to bother
with the colors in an ordinary init file and can drop
the hook.

-- 
underground experts united
http://user.it.uu.se/~embe8573

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: font-locked Gnus browse server
  2015-05-16 21:25           ` Emanuel Berg
@ 2015-05-18 11:35             ` Tassilo Horn
  2015-05-18 19:58               ` Emanuel Berg
  0 siblings, 1 reply; 9+ messages in thread
From: Tassilo Horn @ 2015-05-18 11:35 UTC (permalink / raw)
  To: info-gnus-english

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

>> Yes, this could also work. BTW, `font-lock-defaults'
>> is automatically buffer-local, no need to make
>> it so.
>
> Check out `gnus-server-mode' - gnus-srvr.el, which
> I have as
>
>     /usr/share/emacs/24.4/lisp/gnus/gnus-srvr.el
>
> line 263:
>
>     (set (make-local-variable 'font-lock-defaults) ; ...

Maybe it hasn't been buffer-local by default in Emacs 18, and that's a
relict of that time.

>>> With MODE as nil the font lock is done one the
>>> basis of the current buffer. It is not related to
>>> the mode itself apart from the invocation being
>>> placed in the mode entry hook. This means the
>>> keywords have to be added every time the mode
>>> is entered.
>>
>> Yes, but that doesn't make a difference, no?
>
> All three solutions are equally bad in that all rely
> on the hook.
>
> The best solution would be to change
> `gnus-browse-mode' to do what gnus-server-mode does so
> `font-lock-defaults' is set and one only has to bother
> with the colors in an ordinary init file and can drop
> the hook.

Of course, that would be legit.

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: font-locked Gnus browse server
  2015-05-18 11:35             ` Tassilo Horn
@ 2015-05-18 19:58               ` Emanuel Berg
  0 siblings, 0 replies; 9+ messages in thread
From: Emanuel Berg @ 2015-05-18 19:58 UTC (permalink / raw)
  To: info-gnus-english

Tassilo Horn <tsdh@gnu.org> writes:

> Maybe it hasn't been buffer-local by default in
> Emacs 18, and that's a relict of that time.

OK:

    ;; (setq gnus-browse-mode-hook nil)

    (defun gnus-browse-mode-hook-f ()
      (setq font-lock-defaults
            '(gnus-browse-font-lock-keywords t)) )

    (add-hook 'gnus-browse-mode-hook 'gnus-browse-mode-hook-f)

-- 
underground experts united
http://user.it.uu.se/~embe8573



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-05-18 19:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-10 23:03 font-locked Gnus browse server 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
     [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

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).