From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/79437 Path: news.gmane.org!not-for-mail From: Michael Piotrowski Newsgroups: gmane.emacs.gnus.general Subject: Re: setting face in gnus-user-format-function-x Date: Mon, 11 Jul 2011 18:57:31 +0200 Organization: dynalabs Network Research Unit Message-ID: References: <87sjs5thro.fsf@micropit.couberia.bzh> <87hb8b8i2u.fsf@micropit.couberia.bzh> <87hb7hdjdj.fsf@micropit.couberia.bzh> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1310404067 20504 80.91.229.12 (11 Jul 2011 17:07:47 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 11 Jul 2011 17:07:47 +0000 (UTC) To: ding@gnus.org Original-X-From: ding-owner+M27733@lists.math.uh.edu Mon Jul 11 19:07:43 2011 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QgJxG-0006iZ-TL for ding-account@gmane.org; Mon, 11 Jul 2011 19:07:35 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1QgJwI-0005Gx-3n; Mon, 11 Jul 2011 12:06:34 -0500 Original-Received: from mx2.math.uh.edu ([129.7.128.33]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1QgJwG-0005Gj-HM for ding@lists.math.uh.edu; Mon, 11 Jul 2011 12:06:32 -0500 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx2.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1QgJwE-00076L-Hf for ding@lists.math.uh.edu; Mon, 11 Jul 2011 12:06:32 -0500 Original-Received: from lo.gmane.org ([80.91.229.12]) by quimby.gnus.org with esmtp (Exim 4.72) (envelope-from ) id 1QgJwB-0004iU-LI for ding@gnus.org; Mon, 11 Jul 2011 19:06:27 +0200 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1QgJwB-0005lt-2G for ding@gnus.org; Mon, 11 Jul 2011 19:06:27 +0200 Original-Received: from hpblade4.ifi.uzh.ch ([130.60.156.149]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 11 Jul 2011 19:06:27 +0200 Original-Received: from mxp by hpblade4.ifi.uzh.ch with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 11 Jul 2011 19:06:27 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 97 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: hpblade4.ifi.uzh.ch User-Agent: Gnus/5.110018 (No Gnus v0.18) Emacs/23.2 (berkeley-unix) X-Face: %OvAx]kKl`N,i?yQ+$^p9w2oy)Yg|O}a_~6wtRQ@UTZ*(jSPubbonT]m++M>YBtJqkZZa!W"y5`aI.FoKO%$JHz=ws|i?y^o2bds(+pcp>gcX]H}?-tCzL^ABzJUWYzS{"!_hFg:JD)`kxRKLsNp X-Operating-System: NetBSD Cancel-Lock: sha1:D34R+/D+PfdiytgsTO/xYFYFg70= X-Spam-Score: -4.9 (----) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:79437 Archived-At: 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. Public key at (ID 0x1614A044)