b9f4c206e31a892602a0b11e46a605935ae43fca
[elisp/wanderlust.git] / wl / wl-highlight.el
1 ;;; wl-highlight.el -- Hilight modules for Wanderlust.
2
3 ;; Copyright 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
4
5 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Keywords: mail, net news
7 ;; Time-stamp: <00/03/05 00:59:10 teranisi>
8
9 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
10
11 ;; This program is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15 ;;
16 ;; This program is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20 ;;
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25 ;;
26
27 ;;; Commentary:
28 ;; 
29
30 ;;; Code:
31 ;; 
32
33 (if (and (featurep 'xemacs)
34          (featurep 'dragdrop))
35     (require 'wl-dnd))
36 (require 'wl-vars)
37 (provide 'wl-highlight)
38
39 (eval-when-compile
40   (if wl-on-xemacs
41       (require 'wl-xmas)
42     (if wl-on-nemacs
43         (require 'wl-nemacs)
44       (require 'wl-mule)))
45   (defun-maybe extent-begin-glyph (a))
46   (defun-maybe delete-extent (a))
47   (defun-maybe make-extent (a b))
48   (defun-maybe set-extent-begin-glyph (a b))
49   (defun-maybe set-extent-end-glyph (a b))
50   (defun-maybe extent-at (a b c d e))
51   (defun-maybe wl-dnd-set-drop-target (a b))
52   (defun-maybe wl-dnd-set-drag-starter (a b)))
53
54 (put 'wl-defface 'lisp-indent-function 'defun)
55
56 (defgroup wl-faces nil
57   "Wanderlust, Faces."
58   :prefix "wl-highlight-"
59   :group 'wl-highlight
60   :group 'wl)
61
62 (defgroup wl-summary-faces nil
63   "Wanderlust, Faces of summary buffer."
64   :prefix "wl-highlight-"
65   :group 'wl-highlight
66   :group 'wl-summary)
67
68 (defgroup wl-folder-faces nil
69   "Wanderlust, Faces of folder buffer."
70   :prefix "wl-highlight-"
71   :group 'wl-highlight
72   :group 'wl-folder)
73
74 (defgroup wl-message-faces nil
75   "Wanderlust, Faces of message buffer."
76   :prefix "wl-highlight-"
77   :group 'wl-highlight)
78
79 ;; for message header and signature
80
81 (wl-defface wl-highlight-message-headers
82   '(
83     (((type tty)
84       (background dark))
85      (:foreground "cyan"))
86     (((class color)
87       (background dark))
88      (:foreground "gray" :bold t))
89     (((class color)
90       (background light))
91      (:foreground "gray50" :bold t)))
92   "Face used for displaying header names."
93   :group 'wl-message-faces
94   :group 'wl-faces)
95
96 (wl-defface wl-highlight-message-header-contents
97   '(
98     (((type tty)
99       (background dark))
100      (:foreground "green"))
101     (((class color)
102       (background dark))
103      (:foreground "LightSkyBlue" :bold t))
104     (((class color)
105       (background light))
106      (:foreground "purple" :bold t)))
107   "Face used for displaying header content."
108   :group 'wl-message-faces
109   :group 'wl-faces)
110
111 (wl-defface wl-highlight-message-important-header-contents
112   '(
113     (((type tty)
114       (background dark))
115      (:foreground "yellow"))
116     (((class color)
117       (background dark))
118      (:foreground "yellow" :bold t))
119     (((class color)
120       (background light))
121      (:foreground "brown" :bold t)))
122   "Face used for displaying contents of special headers."
123   :group 'wl-message-faces
124   :group 'wl-faces)
125
126 (wl-defface wl-highlight-message-important-header-contents2
127   '(
128     (((type tty)
129       (background dark))
130      (:foreground "red"))
131     (((class color)
132       (background dark))
133      (:foreground "orange" :bold t))
134     (((class color)
135       (background light))
136      (:foreground "DarkSlateBlue" :bold t)))
137   "Face used for displaying contents of special headers."
138   :group 'wl-message-faces
139   :group 'wl-faces)
140
141 (wl-defface wl-highlight-message-citation-header
142   '(
143     (((type tty)
144       (background dark))
145      (:foreground "cyan"))
146     (((class color)
147       (background dark))
148      (:foreground "SkyBlue"))
149     (((class color)
150       (background light))
151      (:foreground "DarkGreen")))
152   "Face used for displaying header of quoted texts."
153   :group 'wl-message-faces
154   :group 'wl-faces)
155
156 (wl-defface wl-highlight-message-unimportant-header-contents
157   '(
158     (((type tty)
159       (background dark))
160      (:foreground "green"))
161     (((class color)
162       (background dark))
163      (:foreground "GreenYellow" :bold t))
164     (((class color)
165       (background light))
166      (:foreground "DarkGreen" :bold t)))
167   "Face used for displaying contents of unimportant headers."
168   :group 'wl-message-faces
169   :group 'wl-faces)
170
171 (wl-defface wl-highlight-message-signature
172   '((((class color)
173       (background dark))
174      (:foreground "khaki"))
175     (((class color)
176       (background light))
177      (:foreground "DarkSlateBlue")))
178   "Face used for displaying signature."
179   :group 'wl-message-faces
180   :group 'wl-faces)
181
182 ;; for draft
183
184 (wl-defface wl-highlight-header-separator-face
185   '(
186     (((type tty)
187       (background dark))
188      (:foreground "black" :background "yellow"))
189     (((class color))
190      (:foreground "Black" :background "DarkKhaki")))
191   "Face used for displaying header separator."
192   :group 'wl-draft
193   :group 'wl-faces)
194
195 ;; important messages
196
197 (wl-defface wl-highlight-summary-important-face
198   '(
199     (((type tty)
200       (background dark))
201      (:foreground "magenta"))
202     (((class color)
203       (background dark))
204      (:foreground "orange"))
205     (((class color)
206       (background light))
207      (:foreground "purple")))
208   "Face used for displaying important messages."
209   :group 'wl-summary-faces
210   :group 'wl-faces)
211
212 (wl-defface wl-highlight-summary-new-face
213   '(
214     (((type tty)
215       (background dark))
216      (:foreground "red"))
217     (((class color)
218       (background dark))
219      (:foreground "tomato"))
220     (((class color)
221       (background light))
222      (:foreground "tomato")))
223   "Face used for displaying new messages."
224   :group 'wl-summary-faces
225   :group 'wl-faces)
226
227 (wl-defface wl-highlight-summary-displaying-face
228   '((t
229      (:underline t :bold t)))
230   "Face used for displaying message."
231   :group 'wl-summary-faces
232   :group 'wl-faces)
233
234 (wl-defface wl-highlight-thread-indent-face
235   '((t
236      (:foreground "gray40")))
237   "Face used for displaying indented thread."
238   :group 'wl-summary-faces
239   :group 'wl-faces)
240
241 ;; unimportant messages
242
243 (wl-defface wl-highlight-summary-unread-face
244   '(
245     (((type tty)
246       (background dark))
247      (:foreground "cyan"))
248     (((class color)
249       (background dark))
250      (:foreground "LightSkyBlue"))
251     (((class color)
252       (background light))
253      (:foreground "RoyalBlue")))
254   "Face used for displaying unread messages."
255   :group 'wl-summary-faces
256   :group 'wl-faces)
257
258 (wl-defface wl-highlight-summary-deleted-face
259   '(
260     (((type tty)
261       (background dark))
262      (:foreground "blue"))
263     (((class color)
264       (background dark))
265      (:foreground "gray"))
266     (((class color)
267       (background light))
268      (:foreground "DarkKhaki")))
269   "Face used for displaying messages mark as deleted."
270   :group 'wl-summary-faces
271   :group 'wl-faces)
272
273 (wl-defface wl-highlight-summary-refiled-face
274   '(
275     (((type tty)
276       (background dark))
277      (:foreground "blue"))
278     (((class color)
279       (background dark))
280      (:foreground "blue"))
281     (((class color)
282       (background light))
283      (:foreground "firebrick")))
284   "Face used for displaying messages mark as refiled."
285   :group 'wl-summary-faces
286   :group 'wl-faces)
287
288 (wl-defface wl-highlight-summary-copied-face
289   '(
290     (((type tty)
291       (background dark))
292      (:foreground "blue"))
293     (((class color)
294       (background dark))
295      (:foreground "cyan"))
296     (((class color)
297       (background light))
298      (:foreground "blue")))
299   "Face used for displaying messages mark as copied."
300   :group 'wl-summary-faces
301   :group 'wl-faces)
302
303 ;; obsolete.
304 (wl-defface wl-highlight-summary-temp-face
305   '(
306     (((type tty)
307       (background dark))
308      (:foreground "gold"))
309     (((class color))
310      (:foreground "HotPink1")))
311   "Face used for displaying messages mark as temp."
312   :group 'wl-summary-faces
313   :group 'wl-faces)
314
315 (wl-defface wl-highlight-summary-target-face
316   '(
317     (((type tty)
318       (background dark))
319      (:foreground "gold"))
320     (((class color))
321      (:foreground "HotPink1")))
322   "Face used for displaying messages mark as target."
323   :group 'wl-summary-faces
324   :group 'wl-faces)
325
326 (wl-defface wl-highlight-summary-low-read-face
327   '(
328     (((type tty)
329       (background dark))
330      (:foreground "yellow" :italic t))
331     (((class color)
332       (background dark))
333      (:foreground "PaleGreen" :italic t))
334     (((class color)
335       (background light))
336      (:foreground "Green3" :italic t)))
337   "Face used for displaying low interest read messages."
338   :group 'wl-summary-faces
339   :group 'wl-faces)
340
341 (wl-defface wl-highlight-summary-high-read-face
342   '(
343     (((type tty))
344      (:bold t))
345     (((class color)
346       (background dark))
347      (:foreground "PaleGreen" :bold t))
348     (((class color)
349       (background light))
350      (:foreground "SeaGreen" :bold t)))
351   "Face used for displaying high interest read messages."
352   :group 'wl-summary-faces
353   :group 'wl-faces)
354
355 (wl-defface wl-highlight-summary-low-unread-face
356   '(
357     (((type tty)
358       (background dark))
359      (:foreground "cyan" :italic t))
360     (((class color)
361       (background dark))
362      (:foreground "LightSkyBlue" :italic t))
363     (((class color)
364       (background light))
365      (:foreground "RoyalBlue" :italic t)))
366   "Face used for displaying low interest unread messages."
367   :group 'wl-summary-faces
368   :group 'wl-faces)
369
370 (wl-defface wl-highlight-summary-high-unread-face
371   '(
372     (((type tty))
373      (:foreground "red" :bold t))
374     (((class color)
375       (background dark))
376      (:foreground "tomato" :bold t))
377     (((class color)
378       (background light))
379      (:foreground "tomato" :bold t)))
380   "Face used for displaying high interest unread messages."
381   :group 'wl-summary-faces
382   :group 'wl-faces)
383
384 ;; ordinary messages
385
386 (wl-defface wl-highlight-summary-thread-top-face
387   '(
388     (((type tty)
389       (background dark))
390      (:foreground "green"))
391     (((class color)
392       (background dark))
393      (:foreground "GreenYellow"))
394     (((class color)
395       (background light))
396      (:foreground "green4")))
397   "Face used for displaying top thread message."
398   :group 'wl-summary-faces
399   :group 'wl-faces)
400
401 (wl-defface wl-highlight-summary-normal-face
402   '(
403     (((type tty)
404       (background dark))
405      (:foreground "yellow"))
406     (((class color)
407       (background dark))
408      (:foreground "PaleGreen"))
409     (((class color)
410       (background light))
411      (:foreground "SeaGreen")))
412   "Face used for displaying normal message."
413   :group 'wl-summary-faces
414   :group 'wl-faces)
415
416 ;; folder
417
418 (wl-defface wl-highlight-folder-unknown-face
419   '(
420     (((type tty)
421       (background dark))
422      (:foreground "cyan"))
423     (((class color)
424       (background dark))
425      (:foreground "pink"))
426     (((class color)
427       (background light))
428      (:foreground "RoyalBlue")))
429   "Face used for displaying unread folder."
430   :group 'wl-folder-faces
431   :group 'wl-faces)
432
433 (wl-defface wl-highlight-folder-killed-face
434   '(
435     (((type tty)
436       (background dark))
437      (:foreground "gray"))
438     (((class color))
439      (:foreground "gray50")))
440   "Face used for displaying killed folder."
441   :group 'wl-folder-faces
442   :group 'wl-faces)
443
444 (wl-defface wl-highlight-folder-zero-face
445   '(
446     (((type tty)
447       (background dark))
448      (:foreground "green"))
449     (((class color)
450       (background dark))
451      (:foreground "SkyBlue"))
452     (((class color)
453       (background light))
454      (:foreground "BlueViolet")))
455   "Face used for displaying folder needs no sync."
456   :group 'wl-folder-faces
457   :group 'wl-faces)
458
459 (wl-defface wl-highlight-folder-few-face
460   '(
461     (((type tty)
462       (background dark))
463      (:foreground "yellow"))
464     (((class color)
465       (background dark))
466      (:foreground "orange"))
467     (((class color)
468       (background light))
469      (:foreground "OrangeRed3")))
470   "Face used for displaying folder contains few unsync messages."
471   :group 'wl-folder-faces
472   :group 'wl-faces)
473
474 (wl-defface wl-highlight-folder-many-face
475   '(
476     (((type tty)
477       (background dark))
478      (:foreground "red"))
479     (((class color)
480       (background dark))
481      (:foreground "HotPink1"))
482     (((class color)
483       (background light))
484      (:foreground "tomato")))
485   "Face used for displaying folder contains many unsync messages."
486   :group 'wl-folder-faces
487   :group 'wl-faces)
488
489 (wl-defface wl-highlight-folder-unread-face
490   '(
491     (((type tty)
492       (background dark))
493      (:foreground "magenta"))
494     (((class color)
495       (background dark))
496      (:foreground "gold"))
497     (((class color)
498       (background light))
499      (:foreground "MediumVioletRed")))
500   "Face used for displaying unread folder."
501   :group 'wl-folder-faces
502   :group 'wl-faces)
503
504 (wl-defface wl-highlight-folder-opened-face
505   '(
506     (((type tty)
507       (background dark))
508      (:foreground "blue"))
509     (((class color)
510       (background dark))
511      (:foreground "PaleGreen"))
512     (((class color)
513       (background light))
514      (:foreground "ForestGreen")))
515   "Face used for displaying opened group folder."
516   :group 'wl-folder-faces
517   :group 'wl-faces)
518
519 (wl-defface wl-highlight-folder-closed-face
520   '(
521     (((type tty)
522       (background dark))
523      (:foreground "cyan"))
524     (((class color)
525       (background dark))
526      (:foreground "GreenYellow"))
527     (((class color)
528       (background light))
529      (:foreground "DarkOliveGreen4")))
530   "Face used for displaying closed group folder."
531   :group 'wl-folder-faces
532   :group 'wl-faces)
533
534 (wl-defface wl-highlight-folder-path-face
535   '((t
536      (:bold t :underline t)))
537   "Face used for displaying path."
538   :group 'wl-folder-faces
539   :group 'wl-faces)
540
541 (wl-defface wl-highlight-demo-face
542   '(
543     (((type tty)
544       (background dark))
545      (:foreground "green"))
546     (((class color)
547       (background dark))
548      (:foreground "GreenYellow"))
549     (((class color)
550       (background light))
551      (:foreground "blue2")))
552   "Face used for displaying demo."
553   :group 'wl-faces)
554
555 (wl-defface wl-highlight-logo-face
556   '(
557     (((type tty)
558       (background dark))
559      (:foreground "cyan"))
560     (((class color)
561       (background dark))
562      (:foreground "SkyBlue"))
563     (((class color)
564       (background light))
565      (:foreground "SteelBlue")))
566   "Face used for displaying demo."
567   :group 'wl-faces)
568
569 (wl-defface wl-highlight-refile-destination-face
570   '((((class color)
571       (background dark))
572      (:foreground "pink"))
573     (((class color)
574       (background light))
575      (:foreground "red")))
576   "Face used for displaying refile destination."
577   :group 'wl-summary-faces
578   :group 'wl-faces)
579
580 ;; cited face
581
582 (wl-defface wl-highlight-message-cited-text-1
583   '(
584     (((type tty)
585       (background dark))
586      (:foreground "magenta"))
587     (((class color)
588       (background dark))
589      (:foreground "HotPink1"))
590     (((class color)
591       (background light))
592      (:foreground "ForestGreen")))
593   "Face used for displaying quoted text from other messages."
594   :group 'wl-message-faces
595   :group 'wl-faces)
596
597 (wl-defface wl-highlight-message-cited-text-2
598   '(
599     (((type tty)
600       (background dark))
601      (:foreground "blue"))
602     (((class color))
603      (:foreground "violet")))
604   "Face used for displaying quoted text from other messages."
605   :group 'wl-message-faces
606   :group 'wl-faces)
607
608 (wl-defface wl-highlight-message-cited-text-3
609   '(
610     (((type tty)
611       (background dark))
612      (:foreground "cyan"))
613     (((class color))
614      (:foreground "orchid3")))
615   "Face used for displaying quoted text from other messages."
616   :group 'wl-message-faces
617   :group 'wl-faces)
618
619 (wl-defface wl-highlight-message-cited-text-4
620   '(
621     (((type tty)
622       (background dark))
623      (:foreground "green"))
624     (((class color))
625      (:foreground "purple1")))
626   "Face used for displaying quoted text from other messages."
627   :group 'wl-message-faces
628   :group 'wl-faces)
629
630 (wl-defface wl-highlight-message-cited-text-5
631   '(
632     (((type tty)
633       (background dark))
634      (:foreground "yellow"))
635     (((class color))
636      (:foreground "MediumPurple1")))
637   "Face used for displaying quoted text from other messages."
638   :group 'wl-message-faces
639   :group 'wl-faces)
640
641 (wl-defface wl-highlight-message-cited-text-6
642   '(
643     (((type tty)
644       (background dark))
645      (:foreground "red"))
646     (((class color))
647      (:foreground "PaleVioletRed")))
648   "Face used for displaying quoted text from other messages."
649   :group 'wl-message-faces
650   :group 'wl-faces)
651
652 (wl-defface wl-highlight-message-cited-text-7
653   '(
654     (((type tty)
655       (background dark))
656      (:foreground "magenta"))
657     (((class color))
658      (:foreground "LightPink")))
659   "Face used for displaying quoted text from other messages."
660   :group 'wl-message-faces
661   :group 'wl-faces)
662
663 (wl-defface wl-highlight-message-cited-text-8
664   '(
665     (((type tty)
666       (background dark))
667      (:foreground "blue"))
668     (((class color))
669      (:foreground "salmon")))
670   "Face used for displaying quoted text from other messages."
671   :group 'wl-message-faces
672   :group 'wl-faces)
673
674 (wl-defface wl-highlight-message-cited-text-9
675   '(
676     (((type tty)
677       (background dark))
678      (:foreground "cyan"))
679     (((class color))
680      (:foreground "SandyBrown")))
681   "Face used for displaying quoted text from other messages."
682   :group 'wl-message-faces
683   :group 'wl-faces)
684
685 (wl-defface wl-highlight-message-cited-text-10
686   '(
687     (((type tty)
688       (background dark))
689      (:foreground "green"))
690     (((class color))
691      (:foreground "wheat")))
692   "Face used for displaying quoted text from other messages."
693   :group 'wl-message-faces
694   :group 'wl-faces)
695
696 (defvar wl-highlight-folder-opened-regexp " *\\(\\[\\-\\]\\)")
697 (defvar wl-highlight-folder-closed-regexp " *\\(\\[\\+\\]\\)")
698 (defvar wl-highlight-folder-leaf-regexp "[ ]*\\([-%\\+]\\)\\(.*\\):.*$")
699
700 (defvar wl-highlight-summary-unread-regexp " *[0-9]+[^0-9]\\(!\\|U\\)")
701 (defvar wl-highlight-summary-important-regexp " *[0-9]+[^0-9]\\$")
702 (defvar wl-highlight-summary-new-regexp " *[0-9]+[^0-9]N")
703 (defvar wl-highlight-summary-deleted-regexp " *[0-9]+D")
704 (defvar wl-highlight-summary-refiled-regexp " *[0-9]+o")
705 (defvar wl-highlight-summary-copied-regexp " *[0-9]+O")
706 (defvar wl-highlight-summary-target-regexp " *[0-9]+\\*")
707 ;(defvar wl-highlight-summary-thread-top-regexp " *[0-9]+[^0-9][^0-9]../..\(.*\)..:.. \\[")
708
709 (defvar wl-highlight-citation-face-list
710   '(wl-highlight-message-cited-text-1
711     wl-highlight-message-cited-text-2
712     wl-highlight-message-cited-text-3
713     wl-highlight-message-cited-text-4
714     wl-highlight-message-cited-text-5
715     wl-highlight-message-cited-text-6
716     wl-highlight-message-cited-text-7
717     wl-highlight-message-cited-text-8
718     wl-highlight-message-cited-text-9
719     wl-highlight-message-cited-text-10))
720
721 (defmacro defun-hilit (name &rest everything-else)
722   "Define a function for highlight. Nemacs implementation is set as empty."
723   (if wl-on-nemacs
724       (` (defun (, name) nil nil))
725     (` (defun (, name) (,@ everything-else)))))
726
727 (defmacro defun-hilit2 (name &rest everything-else)
728   "Define a function for highlight w/o nemacs."
729   (if wl-on-nemacs
730       () ; noop
731     (` (defun (, name) (,@ everything-else)))))
732
733 (defun-hilit wl-highlight-summary-displaying ()
734   (interactive)
735   (wl-delete-all-overlays)
736   (let (bol eol ov)
737     (save-excursion
738       (beginning-of-line)
739       (setq bol (point))
740       (save-excursion (end-of-line) (setq eol (point)))
741       (setq ov (make-overlay bol eol))
742       (overlay-put ov 'face 'wl-highlight-summary-displaying-face))))
743
744 (defun-hilit2 wl-highlight-folder-group-line (numbers)
745   (if wl-highlight-group-folder-by-numbers
746       (let (fsymbol bol eol)
747         (beginning-of-line)
748         (setq bol (point))
749         (save-excursion (end-of-line) (setq eol (point)))
750         (setq fsymbol 
751               (let ((unsync (nth 0 numbers))
752                     (unread (nth 1 numbers)))
753                 (cond ((and unsync (eq unsync 0))
754                        (if (and unread (> unread 0))
755                            'wl-highlight-folder-unread-face
756                          'wl-highlight-folder-zero-face))
757                       ((and unsync 
758                             (>= unsync wl-folder-many-unsync-threshold))
759                        'wl-highlight-folder-many-face)
760                       (t
761                        'wl-highlight-folder-few-face))))
762         (put-text-property bol eol 'face fsymbol))
763     (let ((highlights (list "opened" "closed"))
764           fregexp fsymbol bol eol matched type extent num type)
765       (beginning-of-line)
766       (setq bol (point))
767       (save-excursion (end-of-line) (setq eol (point)))
768       (catch 'highlighted
769         (while highlights
770           (setq fregexp (symbol-value
771                          (intern (format "wl-highlight-folder-%s-regexp" 
772                                          (car highlights)))))
773           (setq fsymbol (intern (format "wl-highlight-folder-%s-face"
774                                         (car highlights))))
775           (when (looking-at fregexp)
776             (put-text-property bol eol 'face fsymbol)
777             (setq matched t)
778             (throw 'highlighted nil))
779           (setq highlights (cdr highlights)))))))
780
781 (defun-hilit2 wl-highlight-summary-line-string (line mark temp-mark indent)
782   (let (fsymbol)
783     (cond ((and (string= temp-mark "+")
784                 (member mark (list wl-summary-unread-cached-mark
785                                    wl-summary-unread-uncached-mark
786                                    wl-summary-new-mark)))
787            (setq fsymbol 'wl-highlight-summary-high-unread-face))
788           ((and (string= temp-mark "-")
789                 (member mark (list wl-summary-unread-cached-mark
790                                    wl-summary-unread-uncached-mark
791                                    wl-summary-new-mark)))
792            (setq fsymbol 'wl-highlight-summary-low-unread-face))
793           ((string= temp-mark "o")
794            (setq fsymbol 'wl-highlight-summary-refiled-face))
795           ((string= temp-mark "O")
796            (setq fsymbol 'wl-highlight-summary-copied-face))
797           ((string= temp-mark "D")
798            (setq fsymbol 'wl-highlight-summary-deleted-face))
799           ((string= temp-mark "*")
800            (setq fsymbol 'wl-highlight-summary-temp-face))        
801           ((string= mark wl-summary-new-mark)
802            (setq fsymbol 'wl-highlight-summary-new-face))
803           ((member mark (list wl-summary-unread-cached-mark
804                               wl-summary-unread-uncached-mark))
805            (setq fsymbol 'wl-highlight-summary-unread-face))
806           ((or (string= mark wl-summary-important-mark))
807            (setq fsymbol 'wl-highlight-summary-important-face))
808           ((string= temp-mark "-")
809            (setq fsymbol 'wl-highlight-summary-low-read-face))
810           ((string= temp-mark "+")
811            (setq fsymbol 'wl-highlight-summary-high-read-face))
812           (t (if (= 0 (length indent))
813                  (setq fsymbol 'wl-highlight-summary-thread-top-face)
814                (setq fsymbol 'wl-highlight-summary-normal-face))))
815     (put-text-property 0 (length line) 'face fsymbol line))
816   (if wl-use-highlight-mouse-line 
817       (put-text-property 0 (length line) 'mouse-face 'highlight line)))
818   
819 (defun-hilit2 wl-highlight-summary-current-line (&optional smark regexp temp-too)
820   (interactive)
821   (save-excursion
822     (let ((inhibit-read-only t)
823           (case-fold-search nil) temp-mark status-mark
824           (sregexp (concat 
825                     "^" 
826                     wl-summary-buffer-number-regexp 
827                     "\\(.\\)\\(.\\)../..\(.*\)..:.. \\("
828                     wl-highlight-thread-indent-string-regexp
829                     "\\)\\["))
830           fregexp fsymbol bol eol matched thread-top looked-at)
831       (beginning-of-line)
832       (setq bol (point))
833       (save-excursion (end-of-line) (setq eol (point)))
834       (if smark 
835           (setq status-mark smark)
836         (setq looked-at (looking-at sregexp))
837         (setq status-mark (buffer-substring (match-beginning 2)
838                                             (match-end 2))))
839       (when temp-too
840         (unless looked-at
841           (setq looked-at (looking-at sregexp)))
842         (when looked-at
843           (setq temp-mark (buffer-substring (match-beginning 1)
844                                             (match-end 1)))
845           (cond
846            ((string= temp-mark "*")
847             (setq fsymbol 'wl-highlight-summary-temp-face))
848            ((string= temp-mark "D")
849             (setq fsymbol 'wl-highlight-summary-deleted-face))
850            ((string= temp-mark "O")
851             (setq fsymbol 'wl-highlight-summary-copied-face))
852            ((string= temp-mark "o")
853             (setq fsymbol 'wl-highlight-summary-refiled-face)))))
854       (if (not fsymbol)
855           (cond 
856            ((and (string= temp-mark "+")
857                  (member status-mark (list wl-summary-unread-cached-mark
858                                            wl-summary-unread-uncached-mark
859                                            wl-summary-new-mark)))
860             (setq fsymbol 'wl-highlight-summary-high-unread-face))
861            ((and (string= temp-mark "-")
862                  (member status-mark (list wl-summary-unread-cached-mark
863                                            wl-summary-unread-uncached-mark
864                                            wl-summary-new-mark)))
865             (setq fsymbol 'wl-highlight-summary-low-unread-face))
866            ((string= status-mark wl-summary-new-mark)
867             (setq fsymbol 'wl-highlight-summary-new-face))
868            ((member status-mark (list wl-summary-unread-cached-mark
869                                       wl-summary-unread-uncached-mark))
870             (setq fsymbol 'wl-highlight-summary-unread-face))
871            ((string= status-mark wl-summary-important-mark)
872             (setq fsymbol 'wl-highlight-summary-important-face))
873            ;; score mark
874            ((string= temp-mark "-")
875             (setq fsymbol 'wl-highlight-summary-low-read-face))
876            ((string= temp-mark "+")
877             (setq fsymbol 'wl-highlight-summary-high-read-face))
878            ;;
879            (t (if (and looked-at
880                        (string= (buffer-substring
881                                  (match-beginning 3) 
882                                  (match-end 3)) ""))
883                   (setq fsymbol 'wl-highlight-summary-thread-top-face)
884                 (setq fsymbol 'wl-highlight-summary-normal-face)))))
885       (put-text-property bol eol 'face fsymbol)
886       (if wl-use-highlight-mouse-line 
887           (put-text-property bol;(1- (match-end 0))
888                              eol 'mouse-face 'highlight))
889 ;      (put-text-property (match-beginning 3) (match-end 3)
890 ;                        'face 'wl-highlight-thread-indent-face)
891       ;; Dnd stuff.
892       (if wl-use-dnd
893           (wl-dnd-set-drag-starter bol eol)))))
894
895 (defun-hilit2 wl-highlight-folder (start end)
896   "Highlight folder between start and end.
897 Faces used:
898   wl-highlight-folder-unknown-face      unread messages
899   wl-highlight-folder-zero-face         folder needs no sync
900   wl-highlight-folder-few-face          folder contains few unsync messages
901   wl-highlight-folder-many-face         folder contains many unsync messages
902   wl-highlight-folder-opened-face       opened group folder
903   wl-highlight-folder-closed-face       closed group folder
904
905 Variables used:
906   wl-highlight-folder-opened-regexp     matches opened group folder
907   wl-highlight-folder-closed-regexp     matches closed group folder
908 "
909   (interactive "r")
910   (if (< end start)
911       (let ((s start)) (setq start end end s)))
912   (let* ((lines (count-lines start end))
913          (real-end end)
914          gc-message)
915     (save-excursion
916       (save-restriction
917         (widen)
918         (narrow-to-region start end)
919         (save-restriction
920           (goto-char start)
921           (while (not (eobp))
922             (wl-highlight-folder-current-line)
923             (forward-line 1)))))))
924
925 (if (not wl-on-nemacs)
926     (defsubst wl-delete-all-overlays ()
927       (mapcar (lambda (x) 
928                 (delete-overlay x))
929               (overlays-in (point-min) (point-max)))))
930
931 (defun-hilit2 wl-highlight-folder-path (folder-path)
932   "Highlight current folder path...overlay"
933   (save-excursion
934     (wl-delete-all-overlays)
935     (let ((fp folder-path) ov)
936       (goto-char (point-min))
937       (while (and fp
938                   (not (eobp)))
939         (beginning-of-line)
940         (or (looking-at "^[ ]*\\[[\\+-]\\]\\(.+\\):.*\n")
941             (looking-at "^[ ]*\\([^ \\[].+\\):.*\n"))
942         (when (equal
943                (get-text-property (point) 'wl-folder-entity-id)
944                (car fp))
945           (setq fp (cdr fp))
946           (setq ov (make-overlay 
947                     (match-beginning 1)
948                     (match-end 1)))
949           (setq wl-folder-buffer-cur-point (point))
950           (overlay-put ov 'face 'wl-highlight-folder-path-face))
951         (forward-line 1)))))
952
953 (defun-hilit2 wl-highlight-refile-destination-string (string)
954   (put-text-property 0 (length string) 'face 
955                      'wl-highlight-refile-destination-face
956                      string))
957
958 (defun-hilit wl-highlight-summary-all ()
959   "For evaluation"
960   (interactive)
961   (wl-highlight-summary (point-min)(point-max)))
962   
963 (defun-hilit2 wl-highlight-summary (start end)
964   "Highlight summary between start and end.
965 Faces used:
966   wl-highlight-summary-unread-face      unread messages
967   wl-highlight-summary-important-face   important messages
968   wl-highlight-summary-deleted-face     messages mark as deleted 
969   wl-highlight-summary-refiled-face     messages mark as refiled
970   wl-highlight-summary-copied-face      messages mark as copied
971   wl-highlight-summary-new-face         new messages
972
973 Variables used:
974   wl-highlight-summary-unread-regexp    matches unread messages
975   wl-highlight-summary-important-regexp matches important messages
976   wl-highlight-summary-deleted-regexp   matches messages mark as deleted 
977   wl-highlight-summary-refiled-regexp   matches messages mark as refiled
978   wl-highlight-summary-copied-regexp    matches messages mark as copied
979   wl-highlight-summary-new-regexp       matches new messages
980
981 If HACK-SIG is true,then we search backward from END for something that
982 looks like the beginning of a signature block, and don't consider that a
983 part of the message (this is because signatures are often incorrectly
984 interpreted as cited text.)"
985   (if (< end start)
986       (let ((s start)) (setq start end end s)))
987   (let* ((lines (count-lines start end))
988          (too-big (and wl-highlight-max-summary-lines
989                        (> lines wl-highlight-max-summary-lines)))
990          (real-end end)
991          gc-message
992          e p hend i percent)
993     (save-excursion
994       (save-restriction
995         (widen)
996         (narrow-to-region start end)
997         (if (not too-big)
998             (save-restriction
999               (goto-char start)
1000               (setq i 0)
1001               (while (not (eobp))
1002                 (wl-highlight-summary-current-line nil nil wl-summary-scored)
1003                 (setq i (+ i 1))
1004                 (setq percent (/ (* i 100) lines))
1005                 (if (eq (% percent 5) 0)
1006                     (elmo-display-progress
1007                      'wl-highlight-summary "Highlighting..."
1008                      percent))
1009                 (forward-line 1))
1010               (message "Highlighting...done.")))))))
1011
1012 (defun wl-highlight-headers ()
1013   (let ((beg (point-min))
1014         (end (or (save-excursion (re-search-forward "^$" nil t))
1015                  (point-max))))
1016     (wl-highlight-message beg end nil)
1017     (and wl-highlight-x-face-func
1018          (funcall wl-highlight-x-face-func beg end))
1019     (run-hooks 'wl-highlight-headers-hook)))
1020
1021 (defun wl-highlight-body-all ()
1022   (wl-highlight-message (point-min) (point-max) t t))
1023
1024 (defun-hilit wl-highlight-body ()
1025   (let ((beg (or (save-excursion (goto-char (point-min))
1026                                  (re-search-forward "^$" nil t))
1027                  (point-min)))
1028         (end (point-max)))
1029     (wl-highlight-message beg end t)))
1030
1031 (defun-hilit2 wl-highlight-body-region (beg end)
1032   (wl-highlight-message beg end t t))
1033
1034 (defun wl-highlight-signature-search-simple (beg end)
1035   "Search signature area in the body message between beg and end.
1036 Returns start point of signature."
1037   (save-excursion
1038     (goto-char end)
1039     (if (re-search-backward "\n--+ *\n" beg t)
1040         (if (eq (char-after (point)) ?\n)
1041             (1+ (point))
1042           (point))
1043       end)))
1044
1045 (defun wl-highlight-signature-search (beg end)
1046   "Search signature area in the body message between beg and end.
1047 Returns start point of signature."
1048   (save-excursion
1049     (goto-char end)
1050     (or
1051      ;; look for legal signature separator (check at first for fasten)
1052      (re-search-backward "\n-- \n" beg t)
1053
1054      ;; look for dual separator
1055      (save-excursion
1056        (and
1057         (re-search-backward "^[^A-Za-z0-9> \t\n]+ *$" beg t)
1058         (> (- (match-end 0) (match-beginning 0)) 10);; "10" is a magic number.
1059         (re-search-backward 
1060          (concat "^" 
1061                  (regexp-quote (buffer-substring (match-beginning 0) (match-end 0))) 
1062                  "$") beg t)))
1063
1064      ;; look for user specified signature-separator
1065      (if (stringp wl-highlight-signature-separator)
1066          (re-search-backward wl-highlight-signature-separator nil t);; case one string
1067        (let ((sep wl-highlight-signature-separator))            ;; case list
1068          (while (and sep
1069                      (not (re-search-backward (car sep) beg t)))
1070            (setq sep (cdr sep)))
1071          (point)))      ;; if no separator found, returns end.
1072      )))
1073
1074 (defun-hilit2 wl-highlight-message (start end hack-sig &optional body-only)
1075   "Highlight message headers between start and end.
1076 Faces used:
1077   wl-highlight-message-headers                    the part before the colon
1078   wl-highlight-message-header-contents            the part after the colon
1079   wl-highlight-message-important-header-contents  contents of \"special\" 
1080                                                   headers
1081   wl-highlight-message-important-header-contents2 contents of \"special\" 
1082                                                   headers
1083   wl-highlight-message-unimportant-header-contents contents of unimportant 
1084                                                    headers
1085   wl-highlight-message-cited-text                  quoted text from other 
1086                                                    messages
1087   wl-highlight-message-citation-header             header of quoted texts
1088   wl-highlight-message-signature                   signature
1089
1090 Variables used:
1091   wl-highlight-important-header-regexp   what makes a \"special\" header
1092   wl-highlight-important-header2-regexp  what makes a \"special\" header
1093   wl-highlight-unimportant-header-regexp what makes a \"special\" header
1094   wl-highlight-citation-prefix-regexp    matches lines of quoted text
1095   wl-highlight-citation-header-regexp    matches headers for quoted text
1096
1097 If HACK-SIG is true,then we search backward from END for something that
1098 looks like the beginning of a signature block, and don't consider that a
1099 part of the message (this is because signatures are often incorrectly
1100 interpreted as cited text.)"
1101   (if (< end start)
1102       (let ((s start)) (setq start end end s)))
1103   (let* ((too-big (and wl-highlight-max-message-size
1104                        (> (- end start)
1105                           wl-highlight-max-message-size)))
1106          (real-end end)
1107          current  beg
1108          e p hend)
1109     (save-excursion
1110       (save-restriction
1111         (widen)
1112         ;; take off signature
1113         (if (and hack-sig (not too-big))
1114             (setq end (funcall wl-highlight-signature-search-func 
1115                                (- end wl-max-signature-size) end)))
1116         (if hack-sig
1117             (put-text-property end (point-max)
1118                                'face 'wl-highlight-message-signature))
1119         (narrow-to-region start end)
1120
1121         (save-restriction
1122           ;; narrow down to just the headers...
1123           (goto-char start)
1124           ;; If this search fails then the narrowing performed above
1125           ;; is sufficient
1126           (if (re-search-forward (format 
1127                                   "^$\\|%s" 
1128                                   (regexp-quote mail-header-separator)) nil t)
1129               (narrow-to-region (point-min) (point)))
1130           (goto-char start)
1131           (while (and (not body-only)
1132                       (not (eobp)))
1133             (cond
1134              ((looking-at "^\\([^ \t\n:]+[ \t]*:\\) *\\(.*\\(\n[ \t].*\\)*\n\\)")
1135               (setq hend (match-end 0))
1136               (put-text-property (match-beginning 1) (match-end 1)
1137                                  'face 'wl-highlight-message-headers)
1138               (setq p (match-end 1))
1139               (cond
1140                ((catch 'match
1141                   (let ((regexp-alist wl-highlight-message-header-alist))
1142                     (while regexp-alist
1143                       (when (save-match-data
1144                               (looking-at (caar regexp-alist)))
1145                         (put-text-property
1146                          (match-beginning 2) (match-end 2)
1147                          'face
1148                          (cdar regexp-alist))
1149                         (throw 'match t))
1150                       (setq regexp-alist (cdr regexp-alist)))
1151                     (throw 'match nil))))
1152                (t
1153                 (put-text-property
1154                  (match-beginning 2) (match-end 2)
1155                  'face 'wl-highlight-message-header-contents)))
1156               (goto-char hend))
1157              ((looking-at mail-header-separator)
1158               (put-text-property (match-beginning 0) (match-end 0)
1159                                  'face 'wl-highlight-header-separator-face)
1160               (goto-char (match-end 0)))
1161              ;; ignore non-header field name lines
1162              (t (forward-line 1)))))
1163         ;; now do the body, unless it's too big....
1164         (if too-big
1165             nil
1166           (let (prefix prefix-face-alist pair end)
1167           (while (not (eobp))
1168             (cond 
1169              ((null wl-highlight-force-citation-header-regexp)
1170               nil) 
1171              ((looking-at wl-highlight-force-citation-header-regexp)
1172               (setq current 'wl-highlight-message-citation-header)
1173               (setq end (match-end 0)))
1174              ((null wl-highlight-citation-prefix-regexp)
1175               nil)
1176              ((looking-at wl-highlight-citation-prefix-regexp)
1177               (setq prefix (buffer-substring (point)
1178                                              (match-end 0)))
1179               (setq pair (assoc prefix prefix-face-alist))
1180               (unless pair
1181                 (setq prefix-face-alist
1182                       (append prefix-face-alist
1183                               (list 
1184                                (setq pair 
1185                                      (cons 
1186                                       prefix
1187                                       (nth 
1188                                        (% (length prefix-face-alist)
1189                                           (length
1190                                            wl-highlight-citation-face-list))
1191                                        wl-highlight-citation-face-list)))))))
1192               (unless wl-highlight-highlight-citation-too
1193                 (goto-char (match-end 0)))
1194               (setq current (cdr pair)))
1195              ((null wl-highlight-citation-header-regexp)
1196               nil)
1197              ((looking-at wl-highlight-citation-header-regexp)
1198               (setq current 'wl-highlight-message-citation-header)
1199               (setq end (match-end 0)))
1200              (t (setq current nil)))
1201             (cond (current
1202                    (setq p (point))
1203                    (forward-line 1) ; this is to put the \n in the face too
1204                    (let ();(inhibit-read-only t))
1205                      (put-text-property p (or end (point))
1206                                         'face current)
1207                      (setq end nil))
1208                    (forward-char -1)))
1209             (forward-line 1)))
1210           (run-hooks 'wl-highlight-message-hook))))))
1211
1212
1213 ;; highlight-mouse-line for folder mode
1214
1215 (defun wl-highlight-folder-mouse-line ()
1216   (interactive)
1217   (let* ((end (save-excursion (end-of-line) (point)))
1218          (beg (progn
1219                 (re-search-forward "[^ ]" end t)
1220                 (1- (point))))
1221          (inhibit-read-only t))
1222     (put-text-property beg end 'mouse-face 'highlight)))
1223
1224 ;;; wl-highlight.el ends here