annotate lisp/utils/highlight-headers.el @ 116:9f59509498e1 r20-1b10

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