1 ;;; wl-highlight.el -- Hilight modules for Wanderlust.
3 ;; Copyright (C) 1998,1999,2000 Yuuichi Teranishi <teranisi@gohome.org>
5 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Keywords: mail, net news
8 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
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)
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.
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.
32 (if (and (featurep 'xemacs)
36 (provide 'wl-highlight) ; circular dependency
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)))
54 (put 'wl-defface 'lisp-indent-function 'defun)
56 (defgroup wl-faces nil
58 :prefix "wl-highlight-"
62 (defgroup wl-summary-faces nil
63 "Wanderlust, Faces of summary buffer."
64 :prefix "wl-highlight-"
68 (defgroup wl-folder-faces nil
69 "Wanderlust, Faces of folder buffer."
70 :prefix "wl-highlight-"
74 (defgroup wl-message-faces nil
75 "Wanderlust, Faces of message buffer."
76 :prefix "wl-highlight-"
79 ;; for message header and signature
81 (wl-defface wl-highlight-message-headers
88 (:foreground "gray" :bold t))
91 (:foreground "gray50" :bold t)))
92 "Face used for displaying header names."
93 :group 'wl-message-faces
96 (wl-defface wl-highlight-message-header-contents
100 (:foreground "green"))
103 (:foreground "LightSkyBlue" :bold t))
106 (:foreground "purple" :bold t)))
107 "Face used for displaying header content."
108 :group 'wl-message-faces
111 (wl-defface wl-highlight-message-important-header-contents
115 (:foreground "yellow"))
118 (:foreground "yellow" :bold t))
121 (:foreground "brown" :bold t)))
122 "Face used for displaying contents of special headers."
123 :group 'wl-message-faces
126 (wl-defface wl-highlight-message-important-header-contents2
133 (:foreground "orange" :bold t))
136 (:foreground "DarkSlateBlue" :bold t)))
137 "Face used for displaying contents of special headers."
138 :group 'wl-message-faces
141 (wl-defface wl-highlight-message-citation-header
145 (:foreground "cyan"))
148 (:foreground "SkyBlue"))
151 (:foreground "DarkGreen")))
152 "Face used for displaying header of quoted texts."
153 :group 'wl-message-faces
156 (wl-defface wl-highlight-message-unimportant-header-contents
160 (:foreground "green"))
163 (:foreground "GreenYellow" :bold t))
166 (:foreground "DarkGreen" :bold t)))
167 "Face used for displaying contents of unimportant headers."
168 :group 'wl-message-faces
171 (wl-defface wl-highlight-message-signature
174 (:foreground "khaki"))
177 (:foreground "DarkSlateBlue")))
178 "Face used for displaying signature."
179 :group 'wl-message-faces
184 (wl-defface wl-highlight-header-separator-face
188 (:foreground "black" :background "yellow"))
190 (:foreground "Black" :background "DarkKhaki")))
191 "Face used for displaying header separator."
195 ;; important messages
197 (wl-defface wl-highlight-summary-important-face
201 (:foreground "magenta"))
204 (:foreground "orange"))
207 (:foreground "purple")))
208 "Face used for displaying important messages."
209 :group 'wl-summary-faces
212 (wl-defface wl-highlight-summary-new-face
219 (:foreground "tomato"))
222 (:foreground "tomato")))
223 "Face used for displaying new messages."
224 :group 'wl-summary-faces
227 (wl-defface wl-highlight-summary-displaying-face
229 (:underline t :bold t)))
230 "Face used for displaying message."
231 :group 'wl-summary-faces
234 (wl-defface wl-highlight-thread-indent-face
236 (:foreground "gray40")))
237 "Face used for displaying indented thread."
238 :group 'wl-summary-faces
241 ;; unimportant messages
243 (wl-defface wl-highlight-summary-unread-face
247 (:foreground "cyan"))
250 (:foreground "LightSkyBlue"))
253 (:foreground "RoyalBlue")))
254 "Face used for displaying unread messages."
255 :group 'wl-summary-faces
258 (wl-defface wl-highlight-summary-deleted-face
262 (:foreground "blue"))
265 (:foreground "gray"))
268 (:foreground "DarkKhaki")))
269 "Face used for displaying messages mark as deleted."
270 :group 'wl-summary-faces
273 (wl-defface wl-highlight-summary-refiled-face
277 (:foreground "blue"))
280 (:foreground "blue"))
283 (:foreground "firebrick")))
284 "Face used for displaying messages mark as refiled."
285 :group 'wl-summary-faces
288 (wl-defface wl-highlight-summary-copied-face
292 (:foreground "blue"))
295 (:foreground "cyan"))
298 (:foreground "blue")))
299 "Face used for displaying messages mark as copied."
300 :group 'wl-summary-faces
304 (wl-defface wl-highlight-summary-temp-face
308 (:foreground "gold"))
310 (:foreground "HotPink1")))
311 "Face used for displaying messages mark as temp."
312 :group 'wl-summary-faces
315 (wl-defface wl-highlight-summary-target-face
319 (:foreground "gold"))
321 (:foreground "HotPink1")))
322 "Face used for displaying messages mark as target."
323 :group 'wl-summary-faces
326 (wl-defface wl-highlight-summary-low-read-face
330 (:foreground "yellow" :italic t))
333 (:foreground "PaleGreen" :italic t))
336 (:foreground "Green3" :italic t)))
337 "Face used for displaying low interest read messages."
338 :group 'wl-summary-faces
341 (wl-defface wl-highlight-summary-high-read-face
347 (:foreground "PaleGreen" :bold t))
350 (:foreground "SeaGreen" :bold t)))
351 "Face used for displaying high interest read messages."
352 :group 'wl-summary-faces
355 (wl-defface wl-highlight-summary-low-unread-face
359 (:foreground "cyan" :italic t))
362 (:foreground "LightSkyBlue" :italic t))
365 (:foreground "RoyalBlue" :italic t)))
366 "Face used for displaying low interest unread messages."
367 :group 'wl-summary-faces
370 (wl-defface wl-highlight-summary-high-unread-face
373 (:foreground "red" :bold t))
376 (:foreground "tomato" :bold t))
379 (:foreground "tomato" :bold t)))
380 "Face used for displaying high interest unread messages."
381 :group 'wl-summary-faces
386 (wl-defface wl-highlight-summary-thread-top-face
390 (:foreground "green"))
393 (:foreground "GreenYellow"))
396 (:foreground "green4")))
397 "Face used for displaying top thread message."
398 :group 'wl-summary-faces
401 (wl-defface wl-highlight-summary-normal-face
405 (:foreground "yellow"))
408 (:foreground "PaleGreen"))
411 (:foreground "SeaGreen")))
412 "Face used for displaying normal message."
413 :group 'wl-summary-faces
418 (wl-defface wl-highlight-folder-unknown-face
422 (:foreground "cyan"))
425 (:foreground "pink"))
428 (:foreground "RoyalBlue")))
429 "Face used for displaying unread folder."
430 :group 'wl-folder-faces
433 (wl-defface wl-highlight-folder-killed-face
437 (:foreground "gray"))
439 (:foreground "gray50")))
440 "Face used for displaying killed folder."
441 :group 'wl-folder-faces
444 (wl-defface wl-highlight-folder-zero-face
448 (:foreground "green"))
451 (:foreground "SkyBlue"))
454 (:foreground "BlueViolet")))
455 "Face used for displaying folder needs no sync."
456 :group 'wl-folder-faces
459 (wl-defface wl-highlight-folder-few-face
463 (:foreground "yellow"))
466 (:foreground "orange"))
469 (:foreground "OrangeRed3")))
470 "Face used for displaying folder contains few unsync messages."
471 :group 'wl-folder-faces
474 (wl-defface wl-highlight-folder-many-face
481 (:foreground "HotPink1"))
484 (:foreground "tomato")))
485 "Face used for displaying folder contains many unsync messages."
486 :group 'wl-folder-faces
489 (wl-defface wl-highlight-folder-unread-face
493 (:foreground "magenta"))
496 (:foreground "gold"))
499 (:foreground "MediumVioletRed")))
500 "Face used for displaying unread folder."
501 :group 'wl-folder-faces
504 (wl-defface wl-highlight-folder-opened-face
508 (:foreground "blue"))
511 (:foreground "PaleGreen"))
514 (:foreground "ForestGreen")))
515 "Face used for displaying opened group folder."
516 :group 'wl-folder-faces
519 (wl-defface wl-highlight-folder-closed-face
523 (:foreground "cyan"))
526 (:foreground "GreenYellow"))
529 (:foreground "DarkOliveGreen4")))
530 "Face used for displaying closed group folder."
531 :group 'wl-folder-faces
534 (wl-defface wl-highlight-folder-path-face
536 (:bold t :underline t)))
537 "Face used for displaying path."
538 :group 'wl-folder-faces
541 (wl-defface wl-highlight-demo-face
545 (:foreground "green"))
548 (:foreground "GreenYellow"))
551 (:foreground "blue2")))
552 "Face used for displaying demo."
555 (wl-defface wl-highlight-logo-face
559 (:foreground "cyan"))
562 (:foreground "SkyBlue"))
565 (:foreground "SteelBlue")))
566 "Face used for displaying demo."
569 (wl-defface wl-highlight-refile-destination-face
572 (:foreground "pink"))
575 (:foreground "red")))
576 "Face used for displaying refile destination."
577 :group 'wl-summary-faces
582 (wl-defface wl-highlight-message-cited-text-1
586 (:foreground "magenta"))
589 (:foreground "HotPink1"))
592 (:foreground "ForestGreen")))
593 "Face used for displaying quoted text from other messages."
594 :group 'wl-message-faces
597 (wl-defface wl-highlight-message-cited-text-2
601 (:foreground "blue"))
603 (:foreground "violet")))
604 "Face used for displaying quoted text from other messages."
605 :group 'wl-message-faces
608 (wl-defface wl-highlight-message-cited-text-3
612 (:foreground "cyan"))
614 (:foreground "orchid3")))
615 "Face used for displaying quoted text from other messages."
616 :group 'wl-message-faces
619 (wl-defface wl-highlight-message-cited-text-4
623 (:foreground "green"))
625 (:foreground "purple1")))
626 "Face used for displaying quoted text from other messages."
627 :group 'wl-message-faces
630 (wl-defface wl-highlight-message-cited-text-5
634 (:foreground "yellow"))
636 (:foreground "MediumPurple1")))
637 "Face used for displaying quoted text from other messages."
638 :group 'wl-message-faces
641 (wl-defface wl-highlight-message-cited-text-6
647 (:foreground "PaleVioletRed")))
648 "Face used for displaying quoted text from other messages."
649 :group 'wl-message-faces
652 (wl-defface wl-highlight-message-cited-text-7
656 (:foreground "magenta"))
658 (:foreground "LightPink")))
659 "Face used for displaying quoted text from other messages."
660 :group 'wl-message-faces
663 (wl-defface wl-highlight-message-cited-text-8
667 (:foreground "blue"))
669 (:foreground "salmon")))
670 "Face used for displaying quoted text from other messages."
671 :group 'wl-message-faces
674 (wl-defface wl-highlight-message-cited-text-9
678 (:foreground "cyan"))
680 (:foreground "SandyBrown")))
681 "Face used for displaying quoted text from other messages."
682 :group 'wl-message-faces
685 (wl-defface wl-highlight-message-cited-text-10
689 (:foreground "green"))
691 (:foreground "wheat")))
692 "Face used for displaying quoted text from other messages."
693 :group 'wl-message-faces
696 (defvar wl-highlight-folder-opened-regexp " *\\(\\[\\-\\]\\)")
697 (defvar wl-highlight-folder-closed-regexp " *\\(\\[\\+\\]\\)")
698 (defvar wl-highlight-folder-leaf-regexp "[ ]*\\([-%\\+]\\)\\(.*\\):.*$")
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]../..\(.*\)..:.. \\[")
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))
721 (defmacro wl-delete-all-overlays ()
722 "Delete all momentary overlays."
723 '(let ((overlays (overlays-in (point-min) (point-max)))
725 (while (setq overlay (car overlays))
726 (if (overlay-get overlay 'wl-momentary-overlay)
727 (delete-overlay overlay))
728 (setq overlays (cdr overlays)))))
730 (defun wl-highlight-summary-displaying ()
732 (wl-delete-all-overlays)
739 (setq ov (make-overlay bol eol))
740 (overlay-put ov 'face 'wl-highlight-summary-displaying-face)
741 (overlay-put ov 'evaporate t)
742 (overlay-put ov 'wl-momentary-overlay t))))
744 (defun wl-highlight-folder-group-line (numbers)
750 (let ((text-face (cond ((looking-at wl-highlight-folder-opened-regexp)
751 'wl-highlight-folder-opened-face)
752 ((looking-at wl-highlight-folder-closed-regexp)
753 'wl-highlight-folder-closed-face))))
754 (if (and wl-highlight-folder-by-numbers
755 (re-search-forward "[0-9-]+/[0-9-]+/[0-9-]+" eol t))
756 (let* ((unsync (nth 0 numbers))
757 (unread (nth 1 numbers))
758 (face (cond ((and unsync (zerop unsync))
759 (if (and unread (> unread 0))
760 'wl-highlight-folder-unread-face
761 'wl-highlight-folder-zero-face))
763 (>= unsync wl-folder-many-unsync-threshold))
764 'wl-highlight-folder-many-face)
766 'wl-highlight-folder-few-face))))
767 (if (numberp wl-highlight-folder-by-numbers)
769 (put-text-property bol (match-beginning 0) 'face text-face)
770 (put-text-property (match-beginning 0) (match-end 0)
772 ;; Remove previous face.
773 (put-text-property bol (match-end 0) 'face nil)
774 (put-text-property bol (match-end 0) 'face face)))
775 (put-text-property bol eol 'face text-face)))))
777 (defun wl-highlight-summary-line-string (line mark temp-mark indent)
779 (cond ((and (string= temp-mark "+")
780 (member mark (list wl-summary-unread-cached-mark
781 wl-summary-unread-uncached-mark
782 wl-summary-new-mark)))
783 (setq fsymbol 'wl-highlight-summary-high-unread-face))
784 ((and (string= temp-mark "-")
785 (member mark (list wl-summary-unread-cached-mark
786 wl-summary-unread-uncached-mark
787 wl-summary-new-mark)))
788 (setq fsymbol 'wl-highlight-summary-low-unread-face))
789 ((string= temp-mark "o")
790 (setq fsymbol 'wl-highlight-summary-refiled-face))
791 ((string= temp-mark "O")
792 (setq fsymbol 'wl-highlight-summary-copied-face))
793 ((string= temp-mark "D")
794 (setq fsymbol 'wl-highlight-summary-deleted-face))
795 ((string= temp-mark "*")
796 (setq fsymbol 'wl-highlight-summary-temp-face))
797 ((string= mark wl-summary-new-mark)
798 (setq fsymbol 'wl-highlight-summary-new-face))
799 ((member mark (list wl-summary-unread-cached-mark
800 wl-summary-unread-uncached-mark))
801 (setq fsymbol 'wl-highlight-summary-unread-face))
802 ((or (string= mark wl-summary-important-mark))
803 (setq fsymbol 'wl-highlight-summary-important-face))
804 ((string= temp-mark "-")
805 (setq fsymbol 'wl-highlight-summary-low-read-face))
806 ((string= temp-mark "+")
807 (setq fsymbol 'wl-highlight-summary-high-read-face))
808 (t (if (zerop (length indent))
809 (setq fsymbol 'wl-highlight-summary-thread-top-face)
810 (setq fsymbol 'wl-highlight-summary-normal-face))))
811 (put-text-property 0 (length line) 'face fsymbol line))
812 (if wl-use-highlight-mouse-line
813 (put-text-property 0 (length line) 'mouse-face 'highlight line)))
815 (defun wl-highlight-summary-current-line (&optional smark regexp temp-too)
818 (let ((inhibit-read-only t)
819 (case-fold-search nil) temp-mark status-mark
820 (deactivate-mark nil)
823 wl-summary-buffer-number-regexp
824 "\\(.\\)\\(.\\)../..\(.*\)..:.. \\("
825 wl-highlight-thread-indent-string-regexp
827 fregexp fsymbol bol eol matched thread-top looked-at)
833 (setq status-mark smark)
834 (setq looked-at (looking-at sregexp))
836 (setq status-mark (buffer-substring (match-beginning 2)
840 (setq looked-at (looking-at sregexp)))
842 (setq temp-mark (buffer-substring (match-beginning 1)
845 ((string= temp-mark "*")
846 (setq fsymbol 'wl-highlight-summary-temp-face))
847 ((string= temp-mark "D")
848 (setq fsymbol 'wl-highlight-summary-deleted-face))
849 ((string= temp-mark "O")
850 (setq fsymbol 'wl-highlight-summary-copied-face))
851 ((string= temp-mark "o")
852 (setq fsymbol 'wl-highlight-summary-refiled-face)))))
855 ((and (string= temp-mark "+")
856 (member status-mark (list wl-summary-unread-cached-mark
857 wl-summary-unread-uncached-mark
858 wl-summary-new-mark)))
859 (setq fsymbol 'wl-highlight-summary-high-unread-face))
860 ((and (string= temp-mark "-")
861 (member status-mark (list wl-summary-unread-cached-mark
862 wl-summary-unread-uncached-mark
863 wl-summary-new-mark)))
864 (setq fsymbol 'wl-highlight-summary-low-unread-face))
865 ((string= status-mark wl-summary-new-mark)
866 (setq fsymbol 'wl-highlight-summary-new-face))
867 ((member status-mark (list wl-summary-unread-cached-mark
868 wl-summary-unread-uncached-mark))
869 (setq fsymbol 'wl-highlight-summary-unread-face))
870 ((string= status-mark wl-summary-important-mark)
871 (setq fsymbol 'wl-highlight-summary-important-face))
873 ((string= temp-mark "-")
874 (setq fsymbol 'wl-highlight-summary-low-read-face))
875 ((string= temp-mark "+")
876 (setq fsymbol 'wl-highlight-summary-high-read-face))
878 (t (if (and looked-at
879 (string= (buffer-substring
882 (setq fsymbol 'wl-highlight-summary-thread-top-face)
883 (setq fsymbol 'wl-highlight-summary-normal-face)))))
884 (put-text-property bol eol 'face fsymbol)
885 (if wl-use-highlight-mouse-line
886 (put-text-property bol
887 ;;; Use bol instead of (1- (match-end 0))
888 ;;; (1- (match-end 0))
889 eol 'mouse-face 'highlight))
890 ;;; (put-text-property (match-beginning 3) (match-end 3)
891 ;;; 'face 'wl-highlight-thread-indent-face)
894 (wl-dnd-set-drag-starter bol eol)))))
896 (defun wl-highlight-folder (start end)
897 "Highlight folder between start and end.
899 wl-highlight-folder-unknown-face unread messages
900 wl-highlight-folder-zero-face folder needs no sync
901 wl-highlight-folder-few-face folder contains few unsync messages
902 wl-highlight-folder-many-face folder contains many unsync messages
903 wl-highlight-folder-opened-face opened group folder
904 wl-highlight-folder-closed-face closed group folder
907 wl-highlight-folder-opened-regexp matches opened group folder
908 wl-highlight-folder-closed-regexp matches closed group folder
912 (let ((s start)) (setq start end end s)))
913 (let* ((lines (count-lines start end))
919 (narrow-to-region start end)
923 (wl-highlight-folder-current-line)
924 (forward-line 1)))))))
926 (defun wl-highlight-folder-path (folder-path)
927 "Highlight current folder path...overlay"
929 (wl-delete-all-overlays)
930 (let ((fp folder-path) ov)
931 (goto-char (point-min))
935 (or (looking-at "^[ ]*\\[[\\+-]\\]\\(.+\\):.*\n")
936 (looking-at "^[ ]*\\([^ \\[].+\\):.*\n"))
938 (get-text-property (point) 'wl-folder-entity-id)
941 (setq ov (make-overlay
944 (setq wl-folder-buffer-cur-point (point))
945 (overlay-put ov 'face 'wl-highlight-folder-path-face)
946 (overlay-put ov 'evaporate t)
947 (overlay-put ov 'wl-momentary-overlay t))
950 (defun wl-highlight-refile-destination-string (string)
951 (put-text-property 0 (length string) 'face
952 'wl-highlight-refile-destination-face
955 (defun wl-highlight-summary-all ()
958 (wl-highlight-summary (point-min)(point-max)))
960 (defun wl-highlight-summary (start end)
961 "Highlight summary between start and end.
963 wl-highlight-summary-unread-face unread messages
964 wl-highlight-summary-important-face important messages
965 wl-highlight-summary-deleted-face messages mark as deleted
966 wl-highlight-summary-refiled-face messages mark as refiled
967 wl-highlight-summary-copied-face messages mark as copied
968 wl-highlight-summary-new-face new messages
971 wl-highlight-summary-unread-regexp matches unread messages
972 wl-highlight-summary-important-regexp matches important messages
973 wl-highlight-summary-deleted-regexp matches messages mark as deleted
974 wl-highlight-summary-refiled-regexp matches messages mark as refiled
975 wl-highlight-summary-copied-regexp matches messages mark as copied
976 wl-highlight-summary-new-regexp matches new messages
979 (let ((s start)) (setq start end end s)))
980 (let (lines too-big gc-message e p hend i percent)
982 (unless wl-summary-lazy-highlight
983 (setq lines (count-lines start end)
984 too-big (and wl-highlight-max-summary-lines
985 (> lines wl-highlight-max-summary-lines))))
988 (while (and (not (eobp))
990 (wl-highlight-summary-current-line nil nil
991 (or wl-summary-lazy-highlight
993 (when (and (not wl-summary-lazy-highlight)
994 (> lines elmo-display-progress-threshold))
996 (setq percent (/ (* i 100) lines))
997 (if (or (zerop (% percent 5)) (= i lines))
998 (elmo-display-progress
999 'wl-highlight-summary "Highlighting..."
1002 (unless wl-summary-lazy-highlight
1003 (message "Highlighting...done")))))
1005 (defun wl-highlight-summary-window (&optional win beg)
1006 "Highlight summary window.
1007 This function is defined for `window-scroll-functions'"
1008 (if wl-summary-highlight
1009 (with-current-buffer (window-buffer win)
1010 (wl-highlight-summary (window-start win)
1012 (goto-char (window-start win))
1013 (forward-line (frame-height))
1015 (set-buffer-modified-p nil))))
1017 (defun wl-highlight-headers (&optional for-draft)
1018 (let ((beg (point-min))
1019 (end (or (save-excursion (re-search-forward "^$" nil t)
1022 (wl-highlight-message beg end nil)
1024 (wl-highlight-message-add-buttons-to-header beg end)
1025 (when wl-highlight-x-face-function
1026 (funcall wl-highlight-x-face-function beg end)))
1027 (run-hooks 'wl-highlight-headers-hook)))
1029 (defun wl-highlight-message-add-buttons-to-header (start end)
1032 (narrow-to-region start end)
1033 (let ((case-fold-search t)
1034 (alist wl-highlight-message-header-button-alist)
1037 (setq entry (car alist)
1039 (goto-char (point-min))
1040 (while (re-search-forward (car entry) nil t)
1041 (setq start (match-beginning 0)
1042 end (if (re-search-forward "^[^ \t]" nil t)
1046 (while (re-search-forward (nth 1 entry) end t)
1047 (goto-char (match-end 0))
1048 (wl-message-add-button
1049 (match-beginning (nth 2 entry))
1050 (match-end (nth 2 entry))
1051 (nth 3 entry) (match-string (nth 4 entry))))
1052 (goto-char end)))))))
1054 (defun wl-highlight-body-all ()
1055 (wl-highlight-message (point-min) (point-max) t t))
1057 (defun wl-highlight-body ()
1058 (let ((beg (or (save-excursion (goto-char (point-min))
1059 (re-search-forward "^$" nil t))
1062 (wl-highlight-message beg end t)))
1064 (defun wl-highlight-body-region (beg end)
1065 (wl-highlight-message beg end t t))
1067 (defun wl-highlight-signature-search-simple (beg end)
1068 "Search signature area in the body message between BEG and END.
1069 Returns start point of signature."
1072 (if (re-search-backward "\n--+ *\n" beg t)
1073 (if (eq (char-after (point)) ?\n)
1078 (defun wl-highlight-signature-search (beg end)
1079 "Search signature area in the body message between BEG and END.
1080 Returns start point of signature."
1084 ;; look for legal signature separator (check at first for fasten)
1085 (re-search-backward "\n-- \n" beg t)
1087 ;; look for dual separator
1090 (re-search-backward "^[^A-Za-z0-9> \t\n]+ *$" beg t)
1091 (> (- (match-end 0) (match-beginning 0)) 10);; "10" is a magic number.
1094 (regexp-quote (buffer-substring (match-beginning 0) (match-end 0)))
1097 ;; look for user specified signature-separator
1098 (if (stringp wl-highlight-signature-separator)
1099 (re-search-backward wl-highlight-signature-separator nil t);; case one string
1100 (let ((sep wl-highlight-signature-separator)) ;; case list
1102 (not (re-search-backward (car sep) beg t)))
1103 (setq sep (cdr sep)))
1104 (point))) ;; if no separator found, returns end.
1107 (defun wl-highlight-message (start end hack-sig &optional body-only)
1108 "Highlight message headers between start and end.
1110 wl-highlight-message-headers the part before the colon
1111 wl-highlight-message-header-contents the part after the colon
1112 wl-highlight-message-important-header-contents contents of \"special\"
1114 wl-highlight-message-important-header-contents2 contents of \"special\"
1116 wl-highlight-message-unimportant-header-contents contents of unimportant
1118 wl-highlight-message-cited-text quoted text from other
1120 wl-highlight-message-citation-header header of quoted texts
1121 wl-highlight-message-signature signature
1124 wl-highlight-important-header-regexp what makes a \"special\" header
1125 wl-highlight-important-header2-regexp what makes a \"special\" header
1126 wl-highlight-unimportant-header-regexp what makes a \"special\" header
1127 wl-highlight-citation-prefix-regexp matches lines of quoted text
1128 wl-highlight-citation-header-regexp matches headers for quoted text
1130 If HACK-SIG is true,then we search backward from END for something that
1131 looks like the beginning of a signature block, and don't consider that a
1132 part of the message (this is because signatures are often incorrectly
1133 interpreted as cited text.)"
1135 (let ((s start)) (setq start end end s)))
1136 (let ((too-big (and wl-highlight-max-message-size
1138 wl-highlight-max-message-size)))
1147 ;; take off signature
1148 (if (and hack-sig (not too-big))
1149 (setq end (funcall wl-highlight-signature-search-function
1150 (- end wl-max-signature-size) end)))
1152 (not (eq end real-end)))
1153 (put-text-property end (point-max)
1154 'face 'wl-highlight-message-signature))
1155 (narrow-to-region start end)
1157 ;; narrow down to just the headers...
1159 ;; If this search fails then the narrowing performed above
1161 (if (re-search-forward (format
1163 (regexp-quote mail-header-separator))
1165 (narrow-to-region (point-min) (match-beginning 0)))
1166 ;; highlight only when header is not too-big.
1167 (when (or (null wl-highlight-max-header-size)
1168 (< (point) wl-highlight-max-header-size))
1170 (while (and (not body-only)
1173 ((looking-at "^[^ \t\n:]+[ \t]*:")
1174 (put-text-property (match-beginning 0) (match-end 0)
1175 'face 'wl-highlight-message-headers)
1176 (setq p (match-end 0))
1177 (setq hend (save-excursion (std11-field-end end)))
1180 (let ((regexp-alist wl-highlight-message-header-alist))
1182 (when (save-match-data
1183 (looking-at (caar regexp-alist)))
1184 (put-text-property p hend 'face
1185 (cdar regexp-alist))
1187 (setq regexp-alist (cdr regexp-alist)))
1188 (throw 'match nil))))
1191 p hend 'face 'wl-highlight-message-header-contents)))
1193 ;; ignore non-header field name lines
1194 (t (forward-line 1))))))
1195 (let (prefix prefix-face-alist pair end)
1198 ((looking-at mail-header-separator)
1199 (put-text-property (match-beginning 0) (match-end 0)
1200 'face 'wl-highlight-header-separator-face)
1201 (goto-char (match-end 0)))
1202 ((null wl-highlight-force-citation-header-regexp)
1204 ((looking-at wl-highlight-force-citation-header-regexp)
1205 (setq current 'wl-highlight-message-citation-header)
1206 (setq end (match-end 0)))
1207 ((null wl-highlight-citation-prefix-regexp)
1209 ((looking-at wl-highlight-citation-prefix-regexp)
1210 (setq prefix (buffer-substring (point)
1212 (setq pair (assoc prefix prefix-face-alist))
1214 (setq prefix-face-alist
1215 (append prefix-face-alist
1221 (% (length prefix-face-alist)
1223 wl-highlight-citation-face-list))
1224 wl-highlight-citation-face-list)))))))
1225 (unless wl-highlight-highlight-citation-too
1226 (goto-char (match-end 0)))
1227 (setq current (cdr pair)))
1228 ((null wl-highlight-citation-header-regexp)
1230 ((looking-at wl-highlight-citation-header-regexp)
1231 (setq current 'wl-highlight-message-citation-header)
1232 (setq end (match-end 0)))
1233 (t (setq current nil)))
1236 (forward-line 1) ; this is to put the \n in the face too
1238 ;;; ((inhibit-read-only t))
1239 (put-text-property p (or end (point))
1244 (run-hooks 'wl-highlight-message-hook))))))
1246 ;; highlight-mouse-line for folder mode
1248 (defun wl-highlight-folder-mouse-line ()
1250 (let* ((end (save-excursion (end-of-line) (point)))
1252 (re-search-forward "[^ ]" end t)
1254 (inhibit-read-only t))
1255 (put-text-property beg end 'mouse-face 'highlight)))
1258 (product-provide (provide 'wl-highlight) (require 'wl-version))
1260 ;;; wl-highlight.el ends here