From: Michael Piotrowski <mxp@dynalabs.de>
To: ding@gnus.org
Subject: Re: setting face in gnus-user-format-function-x
Date: Mon, 11 Jul 2011 18:57:31 +0200 [thread overview]
Message-ID: <x6ipr8oiv8.fsf@dynalabs.de> (raw)
In-Reply-To: <87hb7hdjdj.fsf@micropit.couberia.bzh>
On 2011-06-23, pmlists@free.fr (Peter Münster) wrote:
> On Tue, Jun 07 2011, Michael Piotrowski wrote:
>
>> I just tried it. Using `gnus-summary-update-hook' works. For my
>> application--a different face for the date, depending on the age of the
>> message--I used the following two-step approach:
>>
>> 1. I have a user format function that adds a non-face property, roughly
>> something like this:
>>
>> (cond
>> ((= message-day today)
>> (put-text-property 0 10 'mxp-date 'today message-date))
>> ((= message-day (1- today))
>> (put-text-property 0 10 'mxp-date 'yesterday message-date))
>> (t
>> (put-text-property 0 10 'mxp-date 'older message-date)))
>>
>> 2. I have a function that looks for this property (using
>> `gnus-find-text-property-region') and sets the desired face. This
>> function is called by `gnus-summary-update-hook'.
>>
>> Up to now, this approach seems to work nicely. Maybe you can adapt it
>> to your needs.
>
> Unfortunately no success... :(
>
> This is, what I have now:
>
> (defun gnus-user-format-function-x (header)
> (let ((my-string (format "%c" gnus-tmp-unread)))
> (put-text-property 0 0 'my-test 'my-test my-string)
> my-string))
>
> (defun my-summary-update ()
> (dolist (region (gnus-find-text-property-region (point-min)
> (point-max)
> 'my-test))
> (destructuring-bind (start end function) region
> (put-text-property start end 'face gnus-face-2)
> (put-text-property start end 'gnus-face t))))
>
> (add-hook 'gnus-summary-update-hook 'my-summary-update)
>
> But the face is not set.
I found I needed to set `inhibit-read-only' to t; in any case, here are
my functions in full:
--8<---------------cut here---------------start------------->8---
(defun gnus-user-format-function-y (header)
"Format the message date with different faces, depending on how old the
message is."
(let* ((message-time (gnus-date-get-time (mail-header-date header)))
(message-date
(format-time-string "%Y-%m-%d" message-time))
(message-day
(string-to-number (format-time-string "%y%j" message-time)))
(today
(string-to-number (format-time-string "%y%j" (current-time)))))
(cond
((= message-day today)
(put-text-property 0 10 'mxp-date 'today message-date))
((= message-day (1- today))
(put-text-property 0 10 'mxp-date 'yesterday message-date))
(t
(put-text-property 0 10 'mxp-date 'older message-date)))
message-date))
(defun mxp-gnus-fontify-summary-line ()
(save-excursion
(let* ((inhibit-read-only t)
(date-region (gnus-find-text-property-region
(point-at-bol)
(point-at-eol) 'mxp-date))
(start (caar date-region))
(end (cadar date-region)))
(when (and start end (gnus-visual-p 'summary-highlight 'highlight))
(cond
((eq (caddar date-region) 'today)
(gnus-put-text-property start end 'face 'mxp-gnus-summary-today-face))
((eq (caddar date-region) 'yesterday)
(gnus-put-text-property start end 'face
'mxp-gnus-summary-yesterday-face))
(t
(gnus-put-text-property start end 'face 'mxp-gnus-summary-older-face)))
))))
(add-hook 'gnus-summary-update-hook 'mxp-gnus-fontify-summary-line)
--8<---------------cut here---------------end--------------->8---
Hope this helps
--
Dr.-Ing. Michael Piotrowski, M.A. <mxp@dynalabs.de>
Public key at <http://www.dynalabs.de/mxp/pubkey.txt> (ID 0x1614A044)
next prev parent reply other threads:[~2011-07-11 16:57 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-23 18:04 Peter Münster
2011-05-24 6:18 ` Reiner Steib
2011-05-25 13:38 ` Peter Münster
2011-05-26 6:37 ` Reiner Steib
2011-05-27 8:26 ` Peter Münster
2011-05-27 9:44 ` Michael Piotrowski
2011-05-30 18:10 ` Lars Magne Ingebrigtsen
2011-05-31 7:06 ` Peter Münster
2011-06-07 16:24 ` Michael Piotrowski
2011-06-23 8:47 ` Peter Münster
2011-06-26 10:06 ` Lars Magne Ingebrigtsen
2011-06-27 12:46 ` Peter Münster
2011-06-30 2:23 ` Lars Magne Ingebrigtsen
2011-06-30 5:14 ` Peter Münster
2011-06-30 22:03 ` Lars Magne Ingebrigtsen
2011-07-13 9:15 ` setting face in gnus-user-format-function-x (solved) Peter Münster
2011-07-13 11:35 ` Peter Münster
2011-07-14 8:12 ` Peter Münster
2011-07-14 19:09 ` Reiner Steib
2011-07-11 16:57 ` Michael Piotrowski [this message]
2011-07-13 7:36 ` setting face in gnus-user-format-function-x Peter Münster
2011-07-18 21:09 ` special face for marks (was: setting face in gnus-user-format-function-x) Peter Münster
2011-07-19 10:09 ` special face for marks lee
2011-07-19 10:58 ` Peter Münster
2011-07-19 17:51 ` lee
2011-09-29 9:41 ` Ted Zlatanov
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=x6ipr8oiv8.fsf@dynalabs.de \
--to=mxp@dynalabs.de \
--cc=ding@gnus.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).