annotate lisp/utils/highlight-headers.el @ 2:ac2d302a0011 r19-15b2

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