1 ;;; mew-highlight.el --- Highlight for Mew
3 ;; Author: Kazu Yamamoto <Kazu@Mew.org>
4 ;; Created: Oct 18, 1997
5 ;; Revised: Aug 30, 1999
9 (defconst mew-highlight-version "mew-highlight.el version 0.04")
17 (defun mew-summary-highlight-setup ()
18 "A function to setup mouse line for Summary and Virtual mode."
19 (if (and mew-xemacs-p mew-use-highlight-mouse-line)
20 (setq mode-motion-hook mew-highlight-mouse-line-function)))
22 (defalias 'mew-virtual-highlight-setup 'mew-summary-highlight-setup)
24 (defun mew-highlight-cursor-line ()
25 "A function to highlight the cursor line in Summary and Virtual mode."
26 (if mew-use-highlight-cursor-line
28 (if (mew-overlay-p mew-overlay-cursor-line)
29 (mew-overlay-move mew-overlay-cursor-line
30 (save-excursion (beginning-of-line) (point))
31 (save-excursion (end-of-line) (point)))
32 (setq mew-overlay-cursor-line
34 (save-excursion (beginning-of-line) (point))
35 (save-excursion (end-of-line) (point))))
36 (mew-overlay-put mew-overlay-cursor-line 'face
37 mew-highlight-cursor-line-face))))
38 (if mew-use-cursor-mark
40 (if (mew-local-variable-p 'overlay-arrow-position)
42 (make-local-variable 'overlay-arrow-position)
43 (setq overlay-arrow-position (make-marker)))
44 (if (mew-local-variable-p 'overlay-arrow-string)
46 (make-local-variable 'overlay-arrow-string)
47 (setq overlay-arrow-string mew-cursor-mark))
48 (set-marker overlay-arrow-position
49 (save-excursion (beginning-of-line) (point))))))
51 (defun mew-highlight-url ()
52 "A function to highlight URL in Message mode."
53 (if mew-use-highlight-url
56 (let ((url-regex mew-use-highlight-url-regex)
58 (goto-char (point-min))
60 (if mew-highlight-url-max-size
62 (goto-char (+ mew-highlight-url-max-size (point)))
66 (while (re-search-forward url-regex bound t)
67 (setq overlay (mew-overlay-make (match-beginning 0)
69 (mew-overlay-put overlay 'face mew-highlight-url-face)
70 (mew-overlay-put overlay
71 'mouse-face mew-highlight-url-mouse-face)))))))
74 (defmacro mew-highlight-this-folder-p ()
75 '(and (or window-system mew-xemacs-p) mew-use-highlight-mark
76 (or (eq mew-highlight-mark-folder-list t)
77 (mew-folder-member (buffer-name)
78 mew-highlight-mark-folder-list))))
80 (defun mew-highlight-mark-region (beg end)
82 (if (mew-highlight-this-folder-p)
85 (let ((regex (concat mew-summary-message-regex "\\([^ ]\\)"))
88 (while (re-search-forward regex end t)
89 (setq face (cdr (assoc (string-to-char (mew-match 2))
90 mew-highlight-mark-keywords)))
93 (save-excursion (beginning-of-line) (point))
94 (save-excursion (end-of-line) (point))
97 (defun mew-highlight-mark-line (mark)
98 (if (mew-highlight-this-folder-p)
100 (let ((face (cdr (assoc mark mew-highlight-mark-keywords))))
103 (save-excursion (beginning-of-line) (point))
104 (save-excursion (end-of-line) (point))
107 (defun mew-highlight-unmark-line ()
108 (if (mew-highlight-this-folder-p)
109 (remove-text-properties
110 (save-excursion (beginning-of-line) (point))
111 (save-excursion (end-of-line) (point))
114 (defun mew-unhighlight-region (BEG END)
115 (mew-overlay-delete-region BEG END))
117 (defun mew-unhighlight-header ()
120 (mew-unhighlight-region (point-min) (mew-header-end))))
122 (defun mew-unhighlight-body ()
125 (mew-unhighlight-region
126 (+ (mew-header-end) (length mew-header-separator) 1)
127 (or (mew-attach-begin) (point-max)))))
129 (defun mew-highlight-header-region (BEG END)
130 "A function to highlight header in Message and Draft mode."
131 (if (and (or window-system mew-xemacs-p) mew-use-highlight-header)
133 (let ((defkey (intern-soft "mew-highlight-header-face-key"))
134 (defval (intern-soft "mew-highlight-header-face-marginal"))
135 key beg med n-spec overlay key-face val-face)
137 (mew-unhighlight-region BEG END)
139 (narrow-to-region BEG END)
140 (goto-char (point-min))
142 (if (not (looking-at mew-keyval))
144 (setq key (mew-match 1))
145 (setq beg (match-beginning 0))
146 (setq med (match-end 0))
148 (mew-header-goto-next)
149 (setq n-spec (mew-assoc-match3 key mew-field-spec 0))
150 (setq key-face (or (nth 3 n-spec) defkey))
151 (setq val-face (or (nth 4 n-spec) defval))
152 (setq overlay (mew-overlay-make beg med))
153 (mew-overlay-put overlay 'face key-face)
154 (setq overlay (mew-overlay-make med (point)))
155 (mew-overlay-put overlay 'face val-face)))))))))
157 (defun mew-highlight-header ()
160 (mew-highlight-header-region (point-min) (mew-header-end))))
162 (defun mew-highlight-body ()
163 "A function to highlight body in Message mode."
164 (if (and (or window-system mew-xemacs-p) mew-use-highlight-body)
168 (let ((keywords mew-highlight-body-keywords)
170 beg1 end1 overlay assoc key)
174 (mew-unhighlight-body)
175 (goto-char (mew-header-end))
176 (narrow-to-region (point)
177 (or (mew-attach-begin) (point-max)))))
178 (while (and (not (eobp)) (< line mew-highlight-body-max-line))
179 (if (looking-at mew-highlight-body-keywords-regex)
181 (setq beg1 (match-beginning 0))
182 (setq end1 (match-end 0))
183 (setq key (mew-match 0))
184 (if (setq assoc (mew-assoc-match2 key keywords 0))
186 (setq overlay (mew-overlay-make beg1 end1))
187 (mew-overlay-put overlay 'face (nth 1 assoc))))))
189 (setq line (1+ line)))))))))
195 ;; uncompface: ftp://ftp.cs.indiana.edu/pub/faces/xfaces/xfaces-<ver>.tar.Z
196 ;; icontopbm: ftp://ftp.x.org/R5contrib/netpbm-<ver>.tar.gz
198 (defun mew-highlight-x-face (beg end)
199 "A function to display X-Face."
200 (if (and mew-use-highlight-x-face mew-use-highlight-x-face-function)
201 (funcall mew-use-highlight-x-face-function beg end)))
205 ;;(autoload 'highlight-headers-x-face-to-pixmap "highlight-headers")
206 (if (mew-which-el "highlight-headers" load-path)
207 (require 'highlight-headers)) ;; due to the timing problem.
208 ;; now this is in the "mail-lib" package.
209 (defvar mew-use-highlight-x-face-function
210 (function (lambda (beg end)
212 (if (and (or window-system mew-xemacs-p)
213 (mew-which mew-prog-uncompface exec-path)
214 mew-use-highlight-x-face)
219 (while (re-search-forward
220 "^X-Face: *\\(.*\\(\n[ \t].*\\)*\\)\n" end t)
221 (setq overlay (mew-overlay-make (match-beginning 0)
223 (mew-overlay-put overlay 'invisible t)
224 (setq xface (highlight-headers-x-face-to-pixmap
229 (if (re-search-forward
230 (concat "^\\(" mew-from: "\\).*") end t)
232 (setq overlay (mew-overlay-make
233 (match-end 1) (match-end 1)))
234 (set-extent-begin-glyph overlay xface))))
237 (defvar mew-use-highlight-x-face-function nil
238 "*On Text Emacs, this function is called if mew-use-highlight-x-face
239 is *non-nil*. This is a temporary solution.")
240 (if (and mew-use-highlight-x-face
241 (mew-which mew-prog-uncompface exec-path)
242 (mew-which-el "bitmap" load-path)
243 (mew-which-el "mew-xface-mule" load-path))
244 (require 'mew-xface-mule))))
250 (defun mew-highlight-face-setup (flist)
251 "A function to create faces according to FLIST.
252 FLIST is a list of face name symbol and its name convention is
253 'mew-highlight-<word1>-face-<word2>'. A base face is copied from
254 'mew-highlight-<word1>-style-<word2>' then a color is set from
255 'mew-highlight-<word1>-color-<word2>'."
256 (if (or window-system mew-xemacs-p)
257 (let (fname str style color)
259 (setq fname (car flist))
260 (setq flist (cdr flist))
262 (setq str (symbol-name fname))
263 (string-match "^\\(mew-highlight-.*-\\)face\\(-.*\\)$" str)
264 (setq style (intern-soft
265 (concat (mew-match 1 str) "style" (mew-match 2 str))))
266 (setq color (intern-soft
267 (concat (mew-match 1 str) "color" (mew-match 2 str))))
268 (copy-face (symbol-value style) fname)
269 (set-face-foreground fname (symbol-value color))))))
271 (defun mew-highlight-make-keywords-regex ()
272 (setq mew-highlight-body-keywords-regex
273 (mapconcat (function car) mew-highlight-body-keywords "\\|")))
275 (provide 'mew-highlight)
277 ;;; Copyright Notice:
279 ;; Copyright (C) 1997, 1998, 1999 Mew developing team.
280 ;; All rights reserved.
282 ;; Redistribution and use in source and binary forms, with or without
283 ;; modification, are permitted provided that the following conditions
286 ;; 1. Redistributions of source code must retain the above copyright
287 ;; notice, this list of conditions and the following disclaimer.
288 ;; 2. Redistributions in binary form must reproduce the above copyright
289 ;; notice, this list of conditions and the following disclaimer in the
290 ;; documentation and/or other materials provided with the distribution.
291 ;; 3. Neither the name of the team nor the names of its contributors
292 ;; may be used to endorse or promote products derived from this software
293 ;; without specific prior written permission.
295 ;; THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND
296 ;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
297 ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
298 ;; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE
299 ;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
300 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
301 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
302 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
303 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
304 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
305 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
307 ;;; mew-highlight.el ends here