Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
* howto define dynamic color with gnus-summary-line-format
@ 2008-02-19  3:14 haomiao
  2008-02-19  3:53 ` Bastien
       [not found] ` <mailman.7612.1203393193.18990.info-gnus-english@gnu.org>
  0 siblings, 2 replies; 9+ messages in thread
From: haomiao @ 2008-02-19  3:14 UTC (permalink / raw)
  To: info-gnus-english

Hi
      I want gnus can display different color according to some
dynamic condition in my summary buffer,
  for example
         if  date of mail is today, then  the date color is red
         else the date color is blue
      How can I get that effect, by setting gnus-summary-line-format
or something else?

      My current gnus-summary-line-format is
             (setq gnus-summary-line-format "%U%R%z %3{%uc%}: %1{%B
%-23,23n%} %s\n")

      I am using GNU Emacs 22.1.1 (i386-mingw-nt5.1.2600) and my gnus
is 5.10.8.

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

* Re: howto define dynamic color with gnus-summary-line-format
  2008-02-19  3:14 howto define dynamic color with gnus-summary-line-format haomiao
@ 2008-02-19  3:53 ` Bastien
       [not found] ` <mailman.7612.1203393193.18990.info-gnus-english@gnu.org>
  1 sibling, 0 replies; 9+ messages in thread
From: Bastien @ 2008-02-19  3:53 UTC (permalink / raw)
  To: haomiao; +Cc: info-gnus-english

haomiao <miaohaoz@ustc.edu> writes:

>       I want gnus can display different color according to some
> dynamic condition in my summary buffer,
>   for example
>          if  date of mail is today, then  the date color is red
>          else the date color is blue
>       How can I get that effect, by setting gnus-summary-line-format
> or something else?

Yes.

(info "(gnus)Group Line Specification")

,----
| `u'
|      User defined specifier.  The next character in the format string
|      should be a letter.  Gnus will call the function
|      `gnus-user-format-function-'`X', where `X' is the letter following
|      `%u'.  The function will be passed a single dummy parameter as
|      argument.  The function should return a string, which will be
|      inserted into the buffer just like information from any other
|      specifier.
`----

I guess you will have to write your own specifier so that it changes the
face for the date in the summary line.

-- 
Bastien

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

* Re: howto define dynamic color with gnus-summary-line-format
       [not found] ` <mailman.7612.1203393193.18990.info-gnus-english@gnu.org>
@ 2008-02-20  2:48   ` haomiao
  2008-02-20  7:16     ` Bastien
       [not found]     ` <mailman.7673.1203491830.18990.info-gnus-english@gnu.org>
  0 siblings, 2 replies; 9+ messages in thread
From: haomiao @ 2008-02-20  2:48 UTC (permalink / raw)
  To: info-gnus-english

Thank you.

> ,----
> | `u'
> |      User defined specifier.  The next character in the format string
> |      should be a letter.  Gnus will call the function
> |      `gnus-user-format-function-'`X', where `X' is the letter following
> |      `%u'.  The function will be passed a single dummy parameter as
> |      argument.  The function should return a string, which will be
> |      inserted into the buffer just like information from any other
> |      specifier.
> `----
>
> I guess you will have to write your own specifier so that it changes the
> face for the date in the summary line.
>
I tyied but failed, here is my .gnus.el:
----------------------------------
(copy-face 'default 'face-3)
(set-face-foreground 'face-3 "DeepSkyBlue1")
(setq gnus-face-3 'face-3)

(defun gnus-user-format-function-c (header)
   "Return a string like MM/DD from a Date header."
   (condition-case ()
      (format-time-string
         "%m/%d"
         (safe-date-to-time (mail-header-date header)))
      (error "  -   ")))

(defun gnus-user-format-function-z (header)
   "test dynamic color"
   (if  (string=
           (format-time-string "%m%d")
           (format-time-string
              "%m%d"
              (safe-date-to-time (mail-header-date header))))
      ;; then
      (set-face-foreground 'face-3 "red")
      ;; else
      (set-face-foreground 'face-3 "blue"))
   "")

(setq gnus-summary-line-format "%uz%U%R%z %3{%uc%}: %1{%B%-23,23n%} %s
\n")
-------------------------------------------------------------

It seemed that emacs only display the summary buffer after the last
call of gnus-user-format-function-z.
So the color is all the same.

Is there any advice?

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

* Re: howto define dynamic color with gnus-summary-line-format
  2008-02-20  2:48   ` haomiao
@ 2008-02-20  7:16     ` Bastien
       [not found]     ` <mailman.7673.1203491830.18990.info-gnus-english@gnu.org>
  1 sibling, 0 replies; 9+ messages in thread
From: Bastien @ 2008-02-20  7:16 UTC (permalink / raw)
  To: haomiao; +Cc: info-gnus-english

haomiao <miaohaoz@ustc.edu> writes:

> (defun gnus-user-format-function-z (header)
>    "test dynamic color"
>    (if  (string=
>            (format-time-string "%m%d")
>            (format-time-string
>               "%m%d"
>               (safe-date-to-time (mail-header-date header))))
>       ;; then
>       (set-face-foreground 'face-3 "red")
>       ;; else
>       (set-face-foreground 'face-3 "blue"))
>    "")

Don't use `set-face-foreground'. 

Try this instead:

(defun gnus-user-format-function-z (header)
  "Test dynamic color"
  (let ((date-time (safe-date-to-time (mail-header-date header))))
    (if (string= date-time (format-time-string "%m%d"))
	(propertize date-time 'face my-red-face) 
      (propertize date-time 'face my-blue-face))))

And define `my-red-face' and `my-blue-face'.

-- 
Bastien

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

* Re: howto define dynamic color with gnus-summary-line-format
       [not found]     ` <mailman.7673.1203491830.18990.info-gnus-english@gnu.org>
@ 2008-02-21  0:57       ` haomiao
  2008-02-25  7:39         ` Bastien
  2008-02-25 23:46         ` Johan Bockgård
  0 siblings, 2 replies; 9+ messages in thread
From: haomiao @ 2008-02-21  0:57 UTC (permalink / raw)
  To: info-gnus-english

On Feb 20, 3:16 pm, Bastien <b...@altern.org> wrote:
> Try this instead:
>
> (defun gnus-user-format-function-z (header)
>   "Test dynamic color"
>   (let ((date-time (safe-date-to-time (mail-header-date header))))
>     (if (string= date-time (format-time-string "%m%d"))
>         (propertize date-time 'face my-red-face)
>       (propertize date-time 'face my-blue-face))))
>
> And define `my-red-face' and `my-blue-face'.

Still not worked, my code is

--------------
(copy-face 'default 'my-red-face)
(set-face-foreground 'my-red-face "red")
(copy-face 'default 'my-blue-face)
(set-face-foreground 'my-blue-face "blue")

(defun gnus-user-format-function-a (header)
   "Test dynamic color"
   (let  ((date-time (format-time-string "%m/%d" (safe-date-to-time
(mail-header-date header)))))
      (if (string= date-time (format-time-string "%m/%d"))
         (propertize date-time 'face 'my-red-face 'mouse-face 'my-blue-
face)
         (propertize date-time 'face 'my-blue-face 'mouse-face 'my-red-
face))))

(setq gnus-summary-line-format "%U%R%z %ua: %1{%B%-23,23n%} %s\n")
-------------

It seems that gnus will modify the face property of the text
returned,  but not the mouse-face property.

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

* Re: howto define dynamic color with gnus-summary-line-format
  2008-02-21  0:57       ` haomiao
@ 2008-02-25  7:39         ` Bastien
  2008-02-25 23:46         ` Johan Bockgård
  1 sibling, 0 replies; 9+ messages in thread
From: Bastien @ 2008-02-25  7:39 UTC (permalink / raw)
  To: haomiao; +Cc: info-gnus-english

haomiao <miaohaoz@ustc.edu> writes:

> On Feb 20, 3:16 pm, Bastien <b...@altern.org> wrote:
>> Try this instead:
>>
>> (defun gnus-user-format-function-z (header)
>>   "Test dynamic color"
>>   (let ((date-time (safe-date-to-time (mail-header-date header))))
>>     (if (string= date-time (format-time-string "%m%d"))
>>         (propertize date-time 'face my-red-face)
>>       (propertize date-time 'face my-blue-face))))
>>
>> And define `my-red-face' and `my-blue-face'.
>
> Still not worked, my code is
>
> --------------
> (copy-face 'default 'my-red-face)
> (set-face-foreground 'my-red-face "red")
> (copy-face 'default 'my-blue-face)
> (set-face-foreground 'my-blue-face "blue")
>
> (defun gnus-user-format-function-a (header)
>    "Test dynamic color"
>    (let  ((date-time (format-time-string "%m/%d" (safe-date-to-time
> (mail-header-date header)))))
>       (if (string= date-time (format-time-string "%m/%d"))
>          (propertize date-time 'face 'my-red-face 'mouse-face 'my-blue-
> face)
>          (propertize date-time 'face 'my-blue-face 'mouse-face 'my-red-
> face))))
>
> (setq gnus-summary-line-format "%U%R%z %ua: %1{%B%-23,23n%} %s\n")
> -------------
>
> It seems that gnus will modify the face property of the text
> returned,  but not the mouse-face property.

I tested and you're right, the 'mouse-face property is okay, but not the
'face property.  There is something weird in there.

Does someone can investigate this problem?

-- 
Bastien

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

* Re: howto define dynamic color with gnus-summary-line-format
  2008-02-21  0:57       ` haomiao
  2008-02-25  7:39         ` Bastien
@ 2008-02-25 23:46         ` Johan Bockgård
  2008-02-26  0:51           ` Bastien
  2008-03-05  0:52           ` haomiao
  1 sibling, 2 replies; 9+ messages in thread
From: Johan Bockgård @ 2008-02-25 23:46 UTC (permalink / raw)
  To: info-gnus-english

haomiao <miaohaoz@ustc.edu> writes:

> (defun gnus-user-format-function-a (header)
>    "Test dynamic color"
>    (let  ((date-time (format-time-string "%m/%d" (safe-date-to-time
> (mail-header-date header)))))
>       (if (string= date-time (format-time-string "%m/%d"))
>          (propertize date-time 'face 'my-red-face 'mouse-face 'my-blue-
> face)
>          (propertize date-time 'face 'my-blue-face 'mouse-face 'my-red-
> face))))
>
> It seems that gnus will modify the face property of the text
> returned,  but not the mouse-face property.

Try

    [...]
    (propertize date-time 'face 'my-red-face 'mouse-face 'my-blue-face
                'gnus-face t)
    (propertize date-time 'face 'my-blue-face 'mouse-face 'my-red-face
                'gnus-face t)

-- 
Johan Bockgård

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

* Re: howto define dynamic color with gnus-summary-line-format
  2008-02-25 23:46         ` Johan Bockgård
@ 2008-02-26  0:51           ` Bastien
  2008-03-05  0:52           ` haomiao
  1 sibling, 0 replies; 9+ messages in thread
From: Bastien @ 2008-02-26  0:51 UTC (permalink / raw)
  To: info-gnus-english

bojohan+news@dd.chalmers.se (Johan Bockgård) writes:

> haomiao <miaohaoz@ustc.edu> writes:
>
>> (defun gnus-user-format-function-a (header)
>>    "Test dynamic color"
>>    (let  ((date-time (format-time-string "%m/%d" (safe-date-to-time
>> (mail-header-date header)))))
>>       (if (string= date-time (format-time-string "%m/%d"))
>>          (propertize date-time 'face 'my-red-face 'mouse-face 'my-blue-
>> face)
>>          (propertize date-time 'face 'my-blue-face 'mouse-face 'my-red-
>> face))))
>>
>> It seems that gnus will modify the face property of the text
>> returned,  but not the mouse-face property.
>
> Try
>
>     [...]
>     (propertize date-time 'face 'my-red-face 'mouse-face 'my-blue-face
>                 'gnus-face t)
>     (propertize date-time 'face 'my-blue-face 'mouse-face 'my-red-face
>                 'gnus-face t)

It works nice for me.  

Could you explain this a bit more?  Why is the 'gnus-face property
necessary so that the 'face property is taken into account?

BTW, I did notice that (global-font-lock-mode -1) doesn't prevent 
Gnus from being fontified.  Is it related to a specific handling of
faces in Gnus?

Thanks in advance for details,

-- 
Bastien

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

* Re: howto define dynamic color with gnus-summary-line-format
  2008-02-25 23:46         ` Johan Bockgård
  2008-02-26  0:51           ` Bastien
@ 2008-03-05  0:52           ` haomiao
  1 sibling, 0 replies; 9+ messages in thread
From: haomiao @ 2008-03-05  0:52 UTC (permalink / raw)
  To: info-gnus-english

> Try
>
>     [...]
>     (propertize date-time 'face 'my-red-face 'mouse-face 'my-blue-face
>                 'gnus-face t)
>     (propertize date-time 'face 'my-blue-face 'mouse-face 'my-red-face
>                 'gnus-face t)
>
It worked, thank you!

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

end of thread, other threads:[~2008-03-05  0:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-19  3:14 howto define dynamic color with gnus-summary-line-format haomiao
2008-02-19  3:53 ` Bastien
     [not found] ` <mailman.7612.1203393193.18990.info-gnus-english@gnu.org>
2008-02-20  2:48   ` haomiao
2008-02-20  7:16     ` Bastien
     [not found]     ` <mailman.7673.1203491830.18990.info-gnus-english@gnu.org>
2008-02-21  0:57       ` haomiao
2008-02-25  7:39         ` Bastien
2008-02-25 23:46         ` Johan Bockgård
2008-02-26  0:51           ` Bastien
2008-03-05  0:52           ` haomiao

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