0
|
1 ;;; highlight-headers.el --- highlighting message headers.
|
|
2
|
|
3 ;; Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
|
|
4 ;; Copyright (C) 1995 Tinker Systems
|
|
5
|
|
6 ;; Keywords: mail, news
|
|
7
|
|
8 ;; This file is part of XEmacs.
|
|
9
|
|
10 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
11 ;; 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 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
18 ;; General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
16
|
21 ;; along with XEmacs; 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.
|
0
|
24
|
|
25 ;;; Synched up with: Not in FSF.
|
|
26
|
|
27 ;; This code is shared by RMAIL, VM, and GNUS.
|
|
28 ;;
|
|
29 ;; Faces:
|
|
30 ;;
|
|
31 ;; message-headers the part before the colon
|
|
32 ;; message-header-contents the part after the colon
|
|
33 ;; message-highlighted-header-contents contents of "special" headers
|
|
34 ;; message-cited-text quoted text from other messages
|
|
35 ;;
|
|
36 ;; Variables:
|
|
37 ;;
|
|
38 ;; highlight-headers-regexp what makes a "special" header
|
|
39 ;; highlight-headers-citation-regexp matches lines of quoted text
|
|
40 ;; highlight-headers-citation-header-regexp matches headers for quoted text
|
|
41
|
116
|
42 (defgroup highlight-headers nil
|
|
43 "Fancify rfc822 documents."
|
|
44 :group 'faces
|
|
45 :group 'mail
|
|
46 :group 'news)
|
0
|
47
|
116
|
48 (defface message-headers '((t (:bold t)))
|
|
49 "Face used for header part before colon."
|
|
50 :group 'highlight-headers)
|
0
|
51
|
116
|
52 (defface message-header-contents '((t (:italic t)))
|
|
53 "Face used for header part after colon."
|
|
54 :group 'highlight-headers)
|
|
55
|
|
56 (defface message-highlighted-header-contents '((t (:italic t :bold t)))
|
|
57 "Face used for contents of \"special\" headers."
|
|
58 :group 'highlight-headers)
|
0
|
59
|
116
|
60 (defface message-cited-text '((t (:italic t)))
|
|
61 "Face used for cited text."
|
|
62 :group 'highlight-headers)
|
0
|
63
|
116
|
64 (defface x-face '((t (:background "white" :foreground "black")))
|
|
65 "Face used for X-Face icon."
|
|
66 :group 'highlight-headers)
|
0
|
67
|
|
68 ;;(condition-case nil
|
|
69 ;; (face-name 'message-addresses)
|
|
70 ;; (wrong-type-argument
|
|
71 ;; (make-face 'message-addresses)
|
|
72 ;; (or (face-differs-from-default-p 'message-addresses)
|
|
73 ;; (progn
|
|
74 ;; (copy-face 'bold-italic 'message-addresses)
|
|
75 ;; (set-face-underline-p 'message-addresses
|
|
76 ;; (face-underline-p
|
|
77 ;; 'message-highlighted-header-contents))))))
|
|
78
|
|
79 (defvar highlight-headers-regexp "Subject[ \t]*:"
|
|
80 "*The headers whose contents should be emphasized more.
|
|
81 The contents of these headers will be displayed in the face
|
|
82 `message-highlighted-header-contents' instead of `message-header-contents'.")
|
|
83
|
|
84 (defvar highlight-headers-citation-regexp
|
|
85 (concat "^\\("
|
|
86 (mapconcat 'identity
|
|
87 '("[ \t]*[a-zA-Z0-9_]+>+" ; supercite
|
|
88 "[ \t]*[>]+" ; ">" with leading spaces
|
|
89 "[]}<>|:]+[ \t]*" ; other chars, no leading space
|
|
90 )
|
|
91 "\\|")
|
|
92 "\\)[ \t]*")
|
|
93 "*The pattern to match cited text.
|
|
94 Text in the body of a message which matches this will be displayed in
|
|
95 the face `message-cited-text'.")
|
|
96
|
|
97 (defvar highlight-headers-citation-header-regexp
|
|
98 (concat "^In article\\|^In message\\|"
|
|
99 "^[^ \t].*\\(writes\\|wrote\\|said\\):\n"
|
|
100 (substring highlight-headers-citation-regexp 1))
|
|
101 "*The pattern to match the prolog of a cited block.
|
|
102 Text in the body of a message which matches this will be displayed in
|
|
103 the `message-headers' face.")
|
|
104
|
|
105 (defvar highlight-headers-highlight-citation-too nil
|
|
106 "*Whether the whole citation line should go in the `mesage-cited-text' face.
|
|
107 If nil, the text matched by `highlight-headers-citation-regexp' is in the
|
|
108 default face, and the remainder of the line is in the message-cited-text face.")
|
|
109
|
|
110 (defvar highlight-headers-max-message-size 10000
|
|
111 "*If the message body is larger than this many chars, don't highlight it.
|
|
112 This is to prevent us from wasting time trying to fontify things like
|
|
113 uuencoded files and large digests. If this is nil, all messages will
|
|
114 be highlighted.")
|
|
115
|
|
116 (defvar highlight-headers-hack-x-face-p (featurep 'xface)
|
|
117 "*If true, then the bitmap in an X-Face header will be displayed
|
|
118 in the buffer. This assumes you have the `uncompface' and `icontopbm'
|
|
119 programs on your path.")
|
|
120
|
|
121 (defvar highlight-headers-convert-quietly nil
|
|
122 "*Non-nil inhibits the message that is normally displayed when external
|
|
123 filters are used to convert an X-Face header. This has no affect if
|
|
124 XEmacs is compiled with internal support for x-faces.")
|
|
125
|
|
126 (defvar highlight-headers-invert-x-face-data nil
|
|
127 "*If true, causes the foreground and background bits in an X-Face
|
|
128 header to be flipped before the image is displayed. If you use a
|
|
129 light foreground color on a dark background color, you probably want
|
|
130 to set this to t. This assumes that you have the `pnminvert' program
|
|
131 on your path. This doesn't presently work with internal xface support.")
|
|
132
|
|
133
|
|
134 ;;;###autoload
|
|
135 (defun highlight-headers (start end hack-sig)
|
|
136 "Highlight message headers between start and end.
|
|
137 Faces used:
|
|
138 message-headers the part before the colon
|
|
139 message-header-contents the part after the colon
|
|
140 message-highlighted-header-contents contents of \"special\" headers
|
|
141 message-cited-text quoted text from other messages
|
|
142
|
|
143 Variables used:
|
|
144
|
|
145 highlight-headers-regexp what makes a \"special\" header
|
|
146 highlight-headers-citation-regexp matches lines of quoted text
|
|
147 highlight-headers-citation-header-regexp matches headers for quoted text
|
|
148
|
|
149 If HACK-SIG is true,then we search backward from END for something that
|
|
150 looks like the beginning of a signature block, and don't consider that a
|
|
151 part of the message (this is because signatures are often incorrectly
|
|
152 interpreted as cited text.)"
|
|
153 (if (< end start)
|
|
154 (let ((s start)) (setq start end end s)))
|
|
155 (let* ((too-big (and highlight-headers-max-message-size
|
|
156 (> (- end start)
|
|
157 highlight-headers-max-message-size)))
|
|
158 (real-end end)
|
|
159 e p hend)
|
|
160 ;; delete previous highlighting
|
|
161 (map-extents (function (lambda (extent ignore)
|
|
162 (if (extent-property extent 'headers)
|
|
163 (delete-extent extent))
|
|
164 nil))
|
|
165 (current-buffer) start end)
|
|
166 (save-excursion
|
|
167 (save-restriction
|
|
168 (widen)
|
|
169 ;; take off signature
|
|
170 (if (and hack-sig (not too-big))
|
|
171 (save-excursion
|
|
172 (goto-char end)
|
|
173 (if (re-search-backward "\n--+ *\n" start t)
|
|
174 (if (eq (char-after (point)) ?\n)
|
|
175 (setq end (1+ (point)))
|
|
176 (setq end (point))))))
|
|
177 (narrow-to-region start end)
|
|
178
|
|
179 (save-restriction
|
|
180 ;; narrow down to just the headers...
|
|
181 (goto-char start)
|
|
182 ;; If this search fails then the narrowing performed above
|
|
183 ;; is sufficient
|
|
184 (if (re-search-forward "^$" nil t)
|
|
185 (narrow-to-region (point-min) (point)))
|
|
186 (goto-char start)
|
|
187 (while (not (eobp))
|
|
188 (cond
|
|
189 ((looking-at "^\\([^ \t\n:]+[ \t]*:\\) *\\(.*\\(\n[ \t].*\\)*\n\\)")
|
|
190 (setq hend (match-end 0))
|
|
191 (setq e (make-extent (match-beginning 1) (match-end 1)))
|
|
192 (set-extent-face e 'message-headers)
|
|
193 (set-extent-property e 'headers t)
|
|
194 (setq p (match-end 1))
|
|
195 (cond
|
|
196 ((and highlight-headers-hack-x-face-p
|
|
197 (save-match-data (looking-at "^X-Face: *")))
|
|
198 ;; make the whole header invisible
|
|
199 (setq e (make-extent (match-beginning 0) (match-end 0)))
|
|
200 (set-extent-property e 'invisible t)
|
|
201 (set-extent-property e 'headers t)
|
|
202 ;; now extract the xface and put it somewhere interesting
|
|
203 (let ((xface (highlight-headers-x-face-to-pixmap
|
|
204 (match-beginning 2)
|
|
205 (match-end 2))))
|
|
206 (if (not xface)
|
|
207 nil ; just leave the header invisible if
|
|
208 ; we can't convert the face for some
|
|
209 ; reason
|
|
210 (cond ((save-excursion
|
|
211 (goto-char (point-min))
|
|
212 (save-excursion (re-search-forward "^From: *"
|
|
213 nil t)))
|
|
214 (setq e (make-extent (match-end 0)
|
|
215 (match-end 0))))
|
|
216 (t
|
2
|
217 ;; okay, make the beginning of the invisible
|
0
|
218 ;; move forward to only hide the modem noise...
|
|
219 (set-extent-endpoints e
|
|
220 (match-beginning 2)
|
|
221 (1- (match-end 2)))
|
|
222 ;; kludge: if a zero-length extent exists at the
|
|
223 ;; starting point of an invisible extent, then
|
|
224 ;; it's invisible... even if the invisible extent
|
|
225 ;; is start-open.
|
|
226 (setq e (make-extent (1- (match-beginning 2))
|
|
227 (match-beginning 2)))
|
|
228 ))
|
|
229 (set-extent-property e 'headers t)
|
|
230 (set-extent-end-glyph e xface))
|
|
231 ))
|
|
232 ;;; I don't think this is worth the effort
|
|
233 ;;; ((looking-at "\\(From\\|Resent-From\\)[ \t]*:")
|
|
234 ;;; (setq current 'message-highlighted-header-contents)
|
|
235 ;;; (goto-char (match-end 0))
|
|
236 ;;; (or (looking-at ".*(\\(.*\\))")
|
|
237 ;;; (looking-at "\\(.*\\)<")
|
|
238 ;;; (looking-at "\\(.*\\)[@%]")
|
|
239 ;;; (looking-at "\\(.*\\)"))
|
|
240 ;;; (end-of-line)
|
|
241 ;;; (setq e (make-extent p (match-beginning 1)))
|
|
242 ;;; (set-extent-face e current)
|
|
243 ;;; (set-extent-property e 'headers t)
|
|
244 ;;; (setq e (make-extent (match-beginning 1) (match-end 1)))
|
|
245 ;;; (set-extent-face e 'message-addresses)
|
|
246 ;;; (set-extent-property e 'headers t)
|
|
247 ;;; (setq e (make-extent (match-end 1) (point)))
|
|
248 ;;; (set-extent-face e current)
|
|
249 ;;; (set-extent-property e 'headers t)
|
|
250 ;;; )
|
|
251 ((and highlight-headers-regexp
|
|
252 (save-match-data (looking-at highlight-headers-regexp)))
|
|
253 (setq e (make-extent (match-beginning 2) (match-end 2)))
|
|
254 (set-extent-face e 'message-highlighted-header-contents)
|
|
255 (set-extent-property e 'headers t))
|
|
256 (t
|
|
257 (setq e (make-extent (match-beginning 2) (match-end 2)))
|
|
258 (set-extent-face e 'message-header-contents)
|
|
259 (set-extent-property e 'headers t))
|
|
260 )
|
|
261 (goto-char hend))
|
|
262 ;; ignore non-header field name lines
|
|
263 (t (forward-line 1)))))
|
|
264
|
|
265 ;; now do the body, unless it's too big....
|
|
266 (if too-big
|
|
267 nil
|
|
268 (while (not (eobp))
|
|
269 (cond ((null highlight-headers-citation-regexp)
|
|
270 nil)
|
|
271 ((looking-at highlight-headers-citation-regexp)
|
|
272 (or highlight-headers-highlight-citation-too
|
|
273 (goto-char (match-end 0)))
|
|
274 (or (save-excursion
|
|
275 (beginning-of-line)
|
|
276 (let ((case-fold-search nil)) ; aaaaah, unix...
|
|
277 (looking-at "^>From ")))
|
|
278 (setq current 'message-cited-text)))
|
|
279 ;;; ((or (looking-at "^In article\\|^In message")
|
|
280 ;;; (looking-at
|
|
281 ;;; "^[^ \t].*\\(writes\\|wrote\\|said\\):\n[ \t]+[A-Z]*[]}<>|]"))
|
|
282 ;;; (setq current 'message-headers))
|
|
283 ((null highlight-headers-citation-header-regexp)
|
|
284 nil)
|
|
285 ((looking-at highlight-headers-citation-header-regexp)
|
|
286 (setq current 'message-headers))
|
|
287 (t (setq current nil)))
|
|
288 (cond (current
|
|
289 (setq p (point))
|
|
290 (forward-line 1) ; this is to put the \n in the face too
|
|
291 (setq e (make-extent p (point)))
|
|
292 (forward-char -1)
|
|
293 (set-extent-face e current)
|
|
294 (set-extent-property e 'headers t)
|
|
295 ))
|
|
296 (forward-line 1)))
|
|
297 ))
|
|
298 (save-excursion
|
|
299 (save-restriction
|
|
300 (widen)
|
|
301 (narrow-to-region start real-end)
|
|
302 (highlight-headers-mark-urls start real-end)))
|
|
303 ))
|
|
304
|
|
305
|
|
306 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
307 ;;;
|
|
308 ;;; X-Face header conversion:
|
|
309
|
|
310 ;;; This cache is only used if x-face conversion is done with external
|
|
311 ;;; filters. If XEmacs is compiled --with-xface, then it's better to
|
|
312 ;;; convert it twice than to suck up memory for a potentially large cache of
|
|
313 ;;; stuff that's not difficult to recreate.
|
|
314 (defvar highlight-headers-x-face-to-pixmap-cache nil)
|
|
315
|
|
316 (defun highlight-headers-x-face-to-pixmap (start end)
|
|
317 (let* ((string (if (stringp start) start (buffer-substring start end)))
|
|
318 (data (assoc string highlight-headers-x-face-to-pixmap-cache)))
|
|
319 (if (featurep 'xface)
|
|
320 (let ((new-face (make-glyph (concat "X-Face: " string))))
|
|
321 (set-glyph-face new-face 'x-face)
|
|
322 new-face)
|
|
323 ;; YUCK this is the old two-external-filters-plus-a-bunch-of-lisp method
|
|
324 (if data
|
|
325 (cdr data)
|
|
326 (setq data (cons string
|
|
327 (condition-case c
|
|
328 (highlight-headers-parse-x-face-data start end)
|
|
329 (error
|
|
330 (display-error c nil)
|
|
331 (sit-for 2)
|
|
332 nil))))
|
|
333 (setq highlight-headers-x-face-to-pixmap-cache
|
|
334 (cons data highlight-headers-x-face-to-pixmap-cache))
|
|
335 (cdr data)))
|
|
336 ))
|
|
337
|
|
338 ;;; Kludge kludge kludge for displaying the bitmap in the X-Face header.
|
|
339
|
|
340 ;;; This depends on the following programs: icontopbm, from the pbmplus
|
|
341 ;;; toolkit (available everywhere) and uncompface, which comes with
|
|
342 ;;; several faces-related packages, and can also be had at ftp.clark.net
|
|
343 ;;; in /pub/liebman/compface.tar.Z. See also xfaces 3.*. Not needed
|
|
344 ;;; for this, but a very nice xbiff replacment.
|
|
345
|
|
346 (defconst highlight-headers-x-face-bitrev
|
|
347 (purecopy
|
|
348 (eval-when-compile
|
|
349 (let* ((v (make-string 256 0))
|
|
350 (i (1- (length v))))
|
|
351 (while (>= i 0)
|
|
352 (let ((j 7)
|
|
353 (k 0))
|
|
354 (while (>= j 0)
|
|
355 (if (/= 0 (logand i (lsh 1 (- 7 j))))
|
|
356 (setq k (logior k (lsh 1 j))))
|
|
357 (setq j (1- j)))
|
|
358 (aset v i k))
|
|
359 (setq i (1- i)))
|
|
360 v))))
|
|
361
|
|
362 (defun highlight-headers-parse-x-face-data (start end)
|
|
363 (save-excursion
|
|
364 (let ((b (current-buffer))
|
|
365 (lines 0)
|
|
366 p)
|
|
367 (or highlight-headers-convert-quietly
|
|
368 (message "Converting X-Face header to pixmap ..."))
|
|
369 (set-buffer (get-buffer-create " *x-face-tmp*"))
|
|
370 (buffer-disable-undo (current-buffer))
|
|
371 (erase-buffer)
|
|
372 (if (stringp start)
|
|
373 (insert start)
|
|
374 (insert-buffer-substring b start end))
|
|
375 (while (search-forward "\n" nil t)
|
|
376 (skip-chars-backward " \t\n")
|
|
377 (setq p (point))
|
|
378 (skip-chars-forward " \t\n")
|
|
379 (delete-region p (point)))
|
|
380 (call-process-region (point-min) (point-max) "uncompface" t t nil)
|
|
381 (goto-char (point-min))
|
|
382 (while (not (eobp))
|
|
383 (or (looking-at "0x....,0x....,0x...., *$")
|
|
384 (error "unexpected uncompface output"))
|
|
385 (forward-line 1)
|
|
386 (setq lines (1+ lines))
|
|
387 (delete-char -1))
|
|
388 (goto-char (point-min))
|
|
389 (insert (format "/* Format_version=1, Width=%d, Height=%d" lines lines))
|
|
390 (insert ", Depth=1, Valid_bits_per_item=16\n */\n")
|
|
391 (while (not (eobp))
|
|
392 (insert ?\t)
|
|
393 (forward-char 56) ; 7 groups per line
|
|
394 (insert ?\n))
|
|
395 (forward-char -1)
|
|
396 (delete-char -1) ; take off last comma
|
|
397 ;;
|
|
398 ;; Ok, now we've got the format that "icontopbm" knows about.
|
|
399 (call-process-region (point-min) (point-max) "icontopbm" t t nil)
|
|
400 ;; Invert the image if the user wants us to...
|
|
401 (if highlight-headers-invert-x-face-data
|
|
402 (call-process-region (point-min) (point-max) "pnminvert" t t nil))
|
|
403 ;;
|
|
404 ;; If PBM is using binary mode, we're winning.
|
|
405 (goto-char (point-min))
|
|
406 (let ((new-face))
|
|
407 (cond ((looking-at "P4\n")
|
|
408 (forward-line 2)
|
|
409 (delete-region (point-min) (point))
|
|
410 (while (not (eobp))
|
|
411 (insert (aref highlight-headers-x-face-bitrev
|
|
412 (following-char)))
|
|
413 (delete-char 1))
|
|
414 (setq new-face (make-glyph
|
|
415 (vector 'xbm :data
|
|
416 (list lines lines (prog1 (buffer-string)
|
|
417 (erase-buffer))))))
|
|
418 (set-glyph-image new-face "[xface]" 'global 'tty)
|
|
419 (set-glyph-face new-face 'x-face))
|
|
420 (t ; fix me
|
|
421 (error "I only understand binary-format PBM...")))
|
|
422 (or highlight-headers-convert-quietly
|
|
423 (message "Converting X-Face header to pixmap ... done."))
|
|
424 new-face)
|
|
425 )))
|
|
426
|
|
427
|
|
428 ;;; "The Internet's new BBS!" -Boardwatch Magazine
|
|
429 ;;; URL support by jwz@netscape.com
|
|
430
|
|
431 (defvar highlight-headers-mark-urls (string-match "XEmacs" emacs-version)
|
|
432 "*Whether to make URLs clickable in message bodies.")
|
|
433
|
|
434 (defvar highlight-headers-follow-url-function 'w3-fetch
|
|
435 "The function to invoke to follow a URL.
|
|
436 Possible values that work out of the box are:
|
|
437
|
|
438 'w3-fetch == Use emacs-w3
|
|
439 'highlight-headers-follow-url-netscape == Use Netscape 1.1
|
|
440 'highlight-headers-follow-url-mosaic == Use Mosaic")
|
|
441
|
|
442 (defvar highlight-headers-follow-url-netscape-auto-raise t
|
|
443 "*Whether to make Netscape auto-raise when a URL is sent to it.")
|
|
444
|
|
445 (defvar highlight-headers-follow-url-netscape-new-window nil
|
|
446 "*Whether to make Netscape create a new window when a URL is sent to it.")
|
|
447
|
|
448 ;;;###autoload
|
|
449 (defun highlight-headers-follow-url-netscape (url)
|
|
450 (message "Sending URL to Netscape...")
|
|
451 (save-excursion
|
|
452 (set-buffer (get-buffer-create "*Shell Command Output*"))
|
|
453 (erase-buffer)
|
|
454 (if (equal
|
|
455 0
|
|
456 (apply 'call-process "netscape" nil t nil
|
|
457 "-remote"
|
|
458 (nconc
|
|
459 (and (not highlight-headers-follow-url-netscape-auto-raise)
|
|
460 (list "-noraise"))
|
|
461 (list
|
|
462 (concat "openURL(" url
|
|
463 (if highlight-headers-follow-url-netscape-new-window
|
|
464 ",new-window)" ")"))))))
|
|
465 ;; it worked
|
|
466 nil
|
|
467 ;; it didn't work, so start a new Netscape process.
|
|
468 (call-process "netscape" nil 0 nil url)))
|
|
469 (message "Sending URL to Netscape... done"))
|
|
470
|
|
471 ;;;###autoload
|
|
472 (defun highlight-headers-follow-url-mosaic (url)
|
|
473 (message "Sending URL to Mosaic...")
|
|
474 (let ((pid-file "~/.mosaicpid")
|
|
475 (work-buffer " *mosaic work*")
|
|
476 (pid nil))
|
|
477 (cond ((file-readable-p pid-file)
|
|
478 (set-buffer (get-buffer-create work-buffer))
|
|
479 (erase-buffer)
|
|
480 (insert-file-contents pid-file)
|
|
481 (setq pid (int-to-string (string-to-int (buffer-string))))
|
|
482 (erase-buffer)
|
|
483 (insert "goto" ?\n)
|
|
484 (insert url ?\n)
|
|
485 (write-region (point-min) (point-max)
|
|
486 (concat "/tmp/Mosaic." pid)
|
|
487 nil 0)
|
|
488 (set-buffer-modified-p nil)
|
|
489 (kill-buffer work-buffer)))
|
|
490 (cond ((or (null pid)
|
|
491 (not (equal 0 (call-process "kill" nil nil nil "-USR1" pid))))
|
|
492 (call-process "Mosaic" nil 0 nil url))))
|
|
493 (message "Sending URL to Mosaic... done"))
|
|
494
|
|
495 (defvar highlight-headers-url-keymap
|
|
496 (let ((m (make-sparse-keymap)))
|
|
497 (set-keymap-name m 'highlight-headers-url-keymap)
|
|
498 (if (string-match "XEmacs" emacs-version)
|
|
499 (progn
|
|
500 (define-key m 'button2 'highlight-headers-follow-url)
|
|
501 ))
|
|
502 m))
|
|
503
|
|
504 ;;;###autoload
|
|
505 (defun highlight-headers-follow-url (event)
|
|
506 (interactive "e")
|
|
507 (let* ((p (event-point event))
|
|
508 (buffer (window-buffer (event-window event)))
|
|
509 (extent (and p (extent-at p buffer 'highlight)))
|
|
510 (url (and extent
|
|
511 (save-excursion
|
|
512 (set-buffer buffer)
|
|
513 (buffer-substring (extent-start-position extent)
|
|
514 (extent-end-position extent))))))
|
|
515 (if (and url (string-match "\\`<\\([^>]+\\)>\\'" url))
|
|
516 (setq url (concat "news:"
|
|
517 (substring url (match-beginning 1) (match-end 1)))))
|
|
518 (if url
|
|
519 (funcall highlight-headers-follow-url-function url)
|
|
520 (beep))))
|
|
521
|
|
522
|
|
523 (defconst highlight-headers-url-pattern
|
|
524 (concat
|
|
525 "\\b\\(s?https?\\|ftp\\|file\\|gopher\\|s?news\\|telnet\\|mailbox\\):"
|
|
526 "\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?"
|
|
527 "[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]+"
|
|
528 ))
|
|
529
|
|
530 (defun highlight-headers-mark-urls (start end)
|
|
531 (cond
|
|
532 (highlight-headers-mark-urls
|
|
533 (save-excursion
|
|
534 (goto-char start)
|
|
535 (while (re-search-forward highlight-headers-url-pattern nil t)
|
|
536 (let ((s (match-beginning 0))
|
|
537 e
|
|
538 extent)
|
|
539 (goto-char (match-end 0))
|
|
540 ;(skip-chars-forward "^ \t\n\r")
|
|
541 (skip-chars-backward ".?#!*()")
|
|
542 (setq e (point))
|
|
543 (setq extent (make-extent s e))
|
|
544 (set-extent-face extent 'bold)
|
|
545 (set-extent-property extent 'highlight t)
|
|
546 (set-extent-property extent 'headers t)
|
|
547 (set-extent-property extent 'keymap highlight-headers-url-keymap)
|
|
548 ))
|
|
549
|
|
550 (goto-char start)
|
|
551 (while (re-search-forward "^Message-ID: \\(<[^>\n]+>\\)" nil t)
|
|
552 (let ((s (match-beginning 1))
|
|
553 (e (match-end 1))
|
|
554 extent)
|
|
555 (setq extent (make-extent s e))
|
|
556 (set-extent-face extent 'bold)
|
|
557 (set-extent-property extent 'highlight t)
|
|
558 (set-extent-property extent 'headers t)
|
|
559 (set-extent-property extent 'keymap highlight-headers-url-keymap)))
|
|
560 ))))
|
|
561
|
|
562
|
|
563 (provide 'highlight-headers)
|