annotate lisp/utils/highlight-headers.el @ 16:0293115a14e9 r19-15b91

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