Remove unused wl-highlight-summary-*-regexp
[elisp/wanderlust.git] / wl / wl-highlight.el
1 ;;; wl-highlight.el --- Hilight modules for Wanderlust.
2
3 ;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
4
5 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Keywords: mail, net news
7
8 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
9
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14 ;;
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19 ;;
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24 ;;
25
26 ;;; Commentary:
27 ;;
28
29 ;;; Code:
30 ;;
31
32 (if (and (featurep 'xemacs)
33          (featurep 'dragdrop))
34     (require 'wl-dnd))
35 (require 'wl-vars)
36 (provide 'wl-highlight)                 ; circular dependency
37
38 (eval-when-compile
39   (cond (wl-on-xemacs
40          (require 'wl-xmas))
41         (wl-on-emacs21
42          (require 'wl-e21))
43         (t
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-citation-face-list
701   '(wl-highlight-message-cited-text-1
702     wl-highlight-message-cited-text-2
703     wl-highlight-message-cited-text-3
704     wl-highlight-message-cited-text-4
705     wl-highlight-message-cited-text-5
706     wl-highlight-message-cited-text-6
707     wl-highlight-message-cited-text-7
708     wl-highlight-message-cited-text-8
709     wl-highlight-message-cited-text-9
710     wl-highlight-message-cited-text-10))
711
712 (defmacro wl-delete-all-overlays ()
713   "Delete all momentary overlays."
714   '(let ((overlays (overlays-in (point-min) (point-max)))
715          overlay)
716      (while (setq overlay (car overlays))
717        (if (overlay-get overlay 'wl-momentary-overlay)
718            (delete-overlay overlay))
719        (setq overlays (cdr overlays)))))
720
721 (defun wl-highlight-summary-displaying ()
722   (interactive)
723   (wl-delete-all-overlays)
724   (let (bol eol ov)
725     (save-excursion
726       (end-of-line)
727       (setq eol (point))
728       (beginning-of-line)
729       (setq bol (point))
730       (setq ov (make-overlay bol eol))
731       (overlay-put ov 'face 'wl-highlight-summary-displaying-face)
732       (overlay-put ov 'evaporate t)
733       (overlay-put ov 'wl-momentary-overlay t))))
734
735 (defun wl-highlight-folder-group-line (numbers)
736   (end-of-line)
737   (let ((eol (point))
738         bol)
739     (beginning-of-line)
740     (setq bol (point))
741     (let ((text-face (cond ((looking-at wl-highlight-folder-opened-regexp)
742                             'wl-highlight-folder-opened-face)
743                            ((looking-at wl-highlight-folder-closed-regexp)
744                             'wl-highlight-folder-closed-face))))
745       (if (and wl-highlight-folder-by-numbers
746                (re-search-forward "[0-9-]+/[0-9-]+/[0-9-]+" eol t))
747           (let* ((unsync (nth 0 numbers))
748                  (unread (nth 1 numbers))
749                  (face (cond ((and unsync (zerop unsync))
750                               (if (and unread (> unread 0))
751                                   'wl-highlight-folder-unread-face
752                                 'wl-highlight-folder-zero-face))
753                              ((and unsync
754                                    (>= unsync wl-folder-many-unsync-threshold))
755                               'wl-highlight-folder-many-face)
756                              (t
757                               'wl-highlight-folder-few-face))))
758             (if (numberp wl-highlight-folder-by-numbers)
759                 (progn
760                   (put-text-property bol (match-beginning 0) 'face text-face)
761                   (put-text-property (match-beginning 0) (match-end 0)
762                                      'face face))
763               ;; Remove previous face.
764               (put-text-property bol (match-end 0) 'face nil)
765               (put-text-property bol (match-end 0) 'face face)))
766         (put-text-property bol eol 'face text-face)))))
767
768 (defun wl-highlight-summary-line-string (line mark temp-mark indent)
769   (let (fsymbol)
770     (cond ((and (string= temp-mark "+")
771                 (member mark (list wl-summary-unread-cached-mark
772                                    wl-summary-unread-uncached-mark
773                                    wl-summary-new-mark)))
774            (setq fsymbol 'wl-highlight-summary-high-unread-face))
775           ((and (string= temp-mark "-")
776                 (member mark (list wl-summary-unread-cached-mark
777                                    wl-summary-unread-uncached-mark
778                                    wl-summary-new-mark)))
779            (setq fsymbol 'wl-highlight-summary-low-unread-face))
780           ((string= temp-mark "o")
781            (setq fsymbol 'wl-highlight-summary-refiled-face))
782           ((string= temp-mark "O")
783            (setq fsymbol 'wl-highlight-summary-copied-face))
784           ((string= temp-mark "D")
785            (setq fsymbol 'wl-highlight-summary-deleted-face))
786           ((string= temp-mark "*")
787            (setq fsymbol 'wl-highlight-summary-temp-face))
788           ((string= mark wl-summary-new-mark)
789            (setq fsymbol 'wl-highlight-summary-new-face))
790           ((member mark (list wl-summary-unread-cached-mark
791                               wl-summary-unread-uncached-mark))
792            (setq fsymbol 'wl-highlight-summary-unread-face))
793           ((or (string= mark wl-summary-important-mark))
794            (setq fsymbol 'wl-highlight-summary-important-face))
795           ((string= temp-mark "-")
796            (setq fsymbol 'wl-highlight-summary-low-read-face))
797           ((string= temp-mark "+")
798            (setq fsymbol 'wl-highlight-summary-high-read-face))
799           (t (if (zerop (length indent))
800                  (setq fsymbol 'wl-highlight-summary-thread-top-face)
801                (setq fsymbol 'wl-highlight-summary-normal-face))))
802     (put-text-property 0 (length line) 'face fsymbol line))
803   (if wl-use-highlight-mouse-line
804       (put-text-property 0 (length line) 'mouse-face 'highlight line)))
805
806 (defun wl-highlight-summary-current-line (&optional smark regexp temp-too)
807   (interactive)
808   (save-excursion
809     (let ((inhibit-read-only t)
810           (case-fold-search nil) temp-mark status-mark
811           (deactivate-mark nil)
812           fregexp fsymbol bol eol matched thread-top looked-at dest ds)
813       (end-of-line)
814       (setq eol (point))
815       (beginning-of-line)
816       (setq bol (point))
817       (if smark
818           (setq status-mark smark)
819         (setq status-mark (wl-summary-persistent-mark)))
820       (when temp-too
821         (setq temp-mark (wl-summary-temp-mark))
822         (cond
823          ((string= temp-mark "*")
824           (setq fsymbol 'wl-highlight-summary-temp-face))
825          ((string= temp-mark "D")
826           (setq fsymbol 'wl-highlight-summary-deleted-face))
827          ((string= temp-mark "O")
828           (setq fsymbol 'wl-highlight-summary-copied-face
829                 dest t))
830          ((string= temp-mark "o")
831           (setq fsymbol 'wl-highlight-summary-refiled-face
832                 dest t))))
833       (if (not fsymbol)
834           (cond
835            ((and (string= temp-mark "+")
836                  (member status-mark (list wl-summary-unread-cached-mark
837                                            wl-summary-unread-uncached-mark
838                                            wl-summary-new-mark)))
839             (setq fsymbol 'wl-highlight-summary-high-unread-face))
840            ((and (string= temp-mark "-")
841                  (member status-mark (list wl-summary-unread-cached-mark
842                                            wl-summary-unread-uncached-mark
843                                            wl-summary-new-mark)))
844             (setq fsymbol 'wl-highlight-summary-low-unread-face))
845            ((string= status-mark wl-summary-new-mark)
846             (setq fsymbol 'wl-highlight-summary-new-face))
847            ((member status-mark (list wl-summary-unread-cached-mark
848                                       wl-summary-unread-uncached-mark))
849             (setq fsymbol 'wl-highlight-summary-unread-face))
850            ((string= status-mark wl-summary-important-mark)
851             (setq fsymbol 'wl-highlight-summary-important-face))
852            ;; score mark
853            ((string= temp-mark "-")
854             (setq fsymbol 'wl-highlight-summary-low-read-face))
855            ((string= temp-mark "+")
856             (setq fsymbol 'wl-highlight-summary-high-read-face))
857            ;;
858            (t (if (null
859                    (wl-thread-entity-get-parent-entity
860                     (wl-thread-get-entity (wl-summary-message-number))))
861                   (setq fsymbol 'wl-highlight-summary-thread-top-face)
862                 (setq fsymbol 'wl-highlight-summary-normal-face)))))
863       (put-text-property bol eol 'face fsymbol)
864       (when dest
865         (put-text-property (next-single-property-change
866                             (next-single-property-change
867                              bol 'wl-summary-destination
868                              nil eol)
869                             'wl-summary-destination nil eol)
870                            eol
871                            'face
872                            'wl-highlight-refile-destination-face))
873       (if wl-use-highlight-mouse-line
874           (put-text-property bol
875 ;;; Use bol instead of (1- (match-end 0))
876 ;;;                          (1- (match-end 0))
877                              eol 'mouse-face 'highlight))
878 ;;;   (put-text-property (match-beginning 3) (match-end 3)
879 ;;;                      'face 'wl-highlight-thread-indent-face)
880       ;; Dnd stuff.
881       (if wl-use-dnd
882           (wl-dnd-set-drag-starter bol eol)))))
883
884 (defun wl-highlight-folder (start end)
885   "Highlight folder between start and end.
886 Faces used:
887   wl-highlight-folder-unknown-face      unread messages
888   wl-highlight-folder-zero-face         folder needs no sync
889   wl-highlight-folder-few-face          folder contains few unsync messages
890   wl-highlight-folder-many-face         folder contains many unsync messages
891   wl-highlight-folder-opened-face       opened group folder
892   wl-highlight-folder-closed-face       closed group folder
893
894 Variables used:
895   wl-highlight-folder-opened-regexp     matches opened group folder
896   wl-highlight-folder-closed-regexp     matches closed group folder
897 "
898   (interactive "r")
899   (if (< end start)
900       (let ((s start)) (setq start end end s)))
901   (let* ((lines (count-lines start end))
902          (real-end end)
903          gc-message)
904     (save-excursion
905       (save-restriction
906         (widen)
907         (narrow-to-region start end)
908         (save-restriction
909           (goto-char start)
910           (while (not (eobp))
911             (wl-highlight-folder-current-line)
912             (forward-line 1)))))))
913
914 (defun wl-highlight-folder-path (folder-path)
915   "Highlight current folder path...overlay"
916   (save-excursion
917     (wl-delete-all-overlays)
918     (let ((fp folder-path) ov)
919       (goto-char (point-min))
920       (while (and fp
921                   (not (eobp)))
922         (beginning-of-line)
923         (or (looking-at "^[ ]*\\[[\\+-]\\]\\(.+\\):.*\n")
924             (looking-at "^[ ]*\\([^ \\[].+\\):.*\n"))
925         (when (equal
926                (get-text-property (point) 'wl-folder-entity-id)
927                (car fp))
928           (setq fp (cdr fp))
929           (setq ov (make-overlay
930                     (match-beginning 1)
931                     (match-end 1)))
932           (setq wl-folder-buffer-cur-point (point))
933           (overlay-put ov 'face 'wl-highlight-folder-path-face)
934           (overlay-put ov 'evaporate t)
935           (overlay-put ov 'wl-momentary-overlay t))
936         (forward-line 1)))))
937
938 (defun wl-highlight-refile-destination-string (string)
939   (put-text-property 0 (length string) 'face
940                      'wl-highlight-refile-destination-face
941                      string))
942
943 (defun wl-highlight-summary-all ()
944   "For evaluation"
945   (interactive)
946   (wl-highlight-summary (point-min)(point-max)))
947
948 (defun wl-highlight-summary (start end &optional lazy)
949   "Highlight summary between start and end.
950 Faces used:
951   wl-highlight-summary-unread-face      unread messages
952   wl-highlight-summary-important-face   important messages
953   wl-highlight-summary-deleted-face     messages mark as deleted
954   wl-highlight-summary-refiled-face     messages mark as refiled
955   wl-highlight-summary-copied-face      messages mark as copied
956   wl-highlight-summary-new-face         new messages"
957   (if (< end start)
958       (let ((s start)) (setq start end end s)))
959   (let (lines too-big gc-message e p hend i percent)
960     (save-excursion
961       (unless wl-summary-lazy-highlight
962         (setq lines (count-lines start end)
963               too-big (and wl-highlight-max-summary-lines
964                            (> lines wl-highlight-max-summary-lines))))
965       (goto-char start)
966       (setq i 0)
967       (while (and (not (eobp))
968                   (< (point) end))
969         (when (or (not lazy)
970                   (null (get-text-property (point) 'face)))
971           (wl-highlight-summary-current-line nil nil
972                                              (or wl-summary-lazy-highlight
973                                                  wl-summary-scored)))
974         (forward-line 1))
975       (unless wl-summary-lazy-highlight
976         (message "Highlighting...done")))))
977
978 (defun wl-highlight-summary-window (&optional win beg)
979   "Highlight summary window.
980 This function is defined for `window-scroll-functions'"
981   (if wl-summary-highlight
982       (with-current-buffer (window-buffer win)
983         (when (eq major-mode 'wl-summary-mode)
984           (wl-highlight-summary (window-start win)
985                                 (window-end win)
986                                 'lazy)
987           (set-buffer-modified-p nil)))))
988
989 (defun wl-highlight-headers (&optional for-draft)
990   (let ((beg (point-min))
991         (end (or (save-excursion (re-search-forward "^$" nil t)
992                                  (point))
993                  (point-max))))
994     (wl-highlight-message beg end nil)
995     (unless for-draft
996       (when wl-highlight-x-face-function
997         (funcall wl-highlight-x-face-function)))
998     (run-hooks 'wl-highlight-headers-hook)))
999
1000 (defun wl-highlight-body-all ()
1001   (wl-highlight-message (point-min) (point-max) t t))
1002
1003 (defun wl-highlight-body ()
1004   (let ((beg (or (save-excursion (goto-char (point-min))
1005                                  (re-search-forward "^$" nil t))
1006                  (point-min)))
1007         (end (point-max)))
1008     (wl-highlight-message beg end t)))
1009
1010 (defun wl-highlight-body-region (beg end)
1011   (wl-highlight-message beg end t t))
1012
1013 (defun wl-highlight-signature-search-simple (beg end)
1014   "Search signature area in the body message between BEG and END.
1015 Returns start point of signature."
1016   (save-excursion
1017     (goto-char end)
1018     (if (re-search-backward "\n--+ *\n" beg t)
1019         (if (eq (char-after (point)) ?\n)
1020             (1+ (point))
1021           (point))
1022       end)))
1023
1024 (defun wl-highlight-signature-search (beg end)
1025   "Search signature area in the body message between BEG and END.
1026 Returns start point of signature."
1027   (save-excursion
1028     (goto-char end)
1029     (or
1030      ;; look for legal signature separator (check at first for fasten)
1031      (re-search-backward "\n-- \n" beg t)
1032
1033      ;; look for dual separator
1034      (save-excursion
1035        (and
1036         (re-search-backward "^[^A-Za-z0-9> \t\n]+ *$" beg t)
1037         (> (- (match-end 0) (match-beginning 0)) 10);; "10" is a magic number.
1038         (re-search-backward
1039          (concat "^"
1040                  (regexp-quote (buffer-substring (match-beginning 0) (match-end 0)))
1041                  "$") beg t)))
1042
1043      ;; look for user specified signature-separator
1044      (if (stringp wl-highlight-signature-separator)
1045          (re-search-backward wl-highlight-signature-separator nil t);; case one string
1046        (let ((sep wl-highlight-signature-separator))            ;; case list
1047          (while (and sep
1048                      (not (re-search-backward (car sep) beg t)))
1049            (setq sep (cdr sep)))
1050          (point)))      ;; if no separator found, returns end.
1051      )))
1052
1053 (defun wl-highlight-message (start end hack-sig &optional body-only)
1054   "Highlight message headers between start and end.
1055 Faces used:
1056   wl-highlight-message-headers                    the part before the colon
1057   wl-highlight-message-header-contents            the part after the colon
1058   wl-highlight-message-important-header-contents  contents of \"special\"
1059                                                   headers
1060   wl-highlight-message-important-header-contents2 contents of \"special\"
1061                                                   headers
1062   wl-highlight-message-unimportant-header-contents contents of unimportant
1063                                                    headers
1064   wl-highlight-message-cited-text                  quoted text from other
1065                                                    messages
1066   wl-highlight-message-citation-header             header of quoted texts
1067   wl-highlight-message-signature                   signature
1068
1069 Variables used:
1070   wl-highlight-important-header-regexp   what makes a \"special\" header
1071   wl-highlight-important-header2-regexp  what makes a \"special\" header
1072   wl-highlight-unimportant-header-regexp what makes a \"special\" header
1073   wl-highlight-citation-prefix-regexp    matches lines of quoted text
1074   wl-highlight-citation-header-regexp    matches headers for quoted text
1075
1076 If HACK-SIG is true,then we search backward from END for something that
1077 looks like the beginning of a signature block, and don't consider that a
1078 part of the message (this is because signatures are often incorrectly
1079 interpreted as cited text.)"
1080   (if (< end start)
1081       (let ((s start)) (setq start end end s)))
1082   (let ((too-big (and wl-highlight-max-message-size
1083                       (> (- end start)
1084                          wl-highlight-max-message-size)))
1085         (real-end end)
1086         current  beg
1087         e p hend)
1088     (if too-big
1089         nil
1090       (save-excursion
1091         (save-restriction
1092           (widen)
1093           ;; take off signature
1094           (if (and hack-sig (not too-big))
1095               (setq end (funcall wl-highlight-signature-search-function
1096                                  (- end wl-max-signature-size) end)))
1097           (if (and hack-sig
1098                    (not (eq end real-end)))
1099               (put-text-property end (point-max)
1100                                  'face 'wl-highlight-message-signature))
1101           (narrow-to-region start end)
1102           (save-restriction
1103             ;; narrow down to just the headers...
1104             (goto-char start)
1105             ;; If this search fails then the narrowing performed above
1106             ;; is sufficient
1107             (if (re-search-forward (format
1108                                     "^$\\|%s"
1109                                     (regexp-quote mail-header-separator))
1110                                    nil t)
1111                 (narrow-to-region (point-min) (match-beginning 0)))
1112             ;; highlight only when header is not too-big.
1113             (when (or (null wl-highlight-max-header-size)
1114                       (< (point) wl-highlight-max-header-size))
1115               (goto-char start)
1116               (while (and (not body-only)
1117                           (not (eobp)))
1118                 (cond
1119                  ((looking-at "^[^ \t\n:]+[ \t]*:")
1120                   (put-text-property (match-beginning 0) (match-end 0)
1121                                      'face 'wl-highlight-message-headers)
1122                   (setq p (match-end 0))
1123                   (setq hend (save-excursion (std11-field-end end)))
1124                   (cond
1125                    ((catch 'match
1126                       (let ((regexp-alist wl-highlight-message-header-alist))
1127                         (while regexp-alist
1128                           (when (save-match-data
1129                                   (looking-at (caar regexp-alist)))
1130                             (put-text-property p hend 'face
1131                                                (cdar regexp-alist))
1132                             (throw 'match t))
1133                           (setq regexp-alist (cdr regexp-alist)))
1134                         (throw 'match nil))))
1135                    (t
1136                     (put-text-property
1137                      p hend 'face 'wl-highlight-message-header-contents)))
1138                   (goto-char hend))
1139                  ;; ignore non-header field name lines
1140                  (t (forward-line 1))))))
1141           (let (prefix prefix-face-alist pair end)
1142             (while (not (eobp))
1143               (cond
1144                ((looking-at mail-header-separator)
1145                 (put-text-property (match-beginning 0) (match-end 0)
1146                                    'face 'wl-highlight-header-separator-face)
1147                 (goto-char (match-end 0)))
1148                ((null wl-highlight-force-citation-header-regexp)
1149                 nil)
1150                ((looking-at wl-highlight-force-citation-header-regexp)
1151                 (setq current 'wl-highlight-message-citation-header)
1152                 (setq end (match-end 0)))
1153                ((null wl-highlight-citation-prefix-regexp)
1154                 nil)
1155                ((looking-at wl-highlight-citation-prefix-regexp)
1156                 (setq prefix (buffer-substring (point)
1157                                                (match-end 0)))
1158                 (setq pair (assoc prefix prefix-face-alist))
1159                 (unless pair
1160                   (setq prefix-face-alist
1161                         (append prefix-face-alist
1162                                 (list
1163                                  (setq pair
1164                                        (cons
1165                                         prefix
1166                                         (nth
1167                                          (% (length prefix-face-alist)
1168                                             (length
1169                                              wl-highlight-citation-face-list))
1170                                          wl-highlight-citation-face-list)))))))
1171                 (unless wl-highlight-highlight-citation-too
1172                   (goto-char (match-end 0)))
1173                 (setq current (cdr pair)))
1174                ((null wl-highlight-citation-header-regexp)
1175                 nil)
1176                ((looking-at wl-highlight-citation-header-regexp)
1177                 (setq current 'wl-highlight-message-citation-header)
1178                 (setq end (match-end 0)))
1179                (t (setq current nil)))
1180               (cond (current
1181                      (setq p (point))
1182                      (forward-line 1) ; this is to put the \n in the face too
1183                      (let ()
1184 ;;;                    ((inhibit-read-only t))
1185                        (put-text-property p (or end (point))
1186                                           'face current)
1187                        (setq end nil))
1188                      (forward-char -1)))
1189               (forward-line 1)))
1190           (run-hooks 'wl-highlight-message-hook))))))
1191
1192 ;; highlight-mouse-line for folder mode
1193
1194 (defun wl-highlight-folder-mouse-line ()
1195   (interactive)
1196   (let* ((end (save-excursion (end-of-line) (point)))
1197          (beg (progn
1198                 (re-search-forward "[^ ]" end t)
1199                 (1- (point))))
1200          (inhibit-read-only t))
1201     (put-text-property beg end 'mouse-face 'highlight)))
1202
1203 (require 'product)
1204 (product-provide (provide 'wl-highlight) (require 'wl-version))
1205
1206 ;;; wl-highlight.el ends here