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