annotate lisp/gnus/gnus-spec.el @ 108:360340f9fd5f r20-1b6

Import from CVS: tag r20-1b6
author cvs
date Mon, 13 Aug 2007 09:18:39 +0200
parents ec9a17fef872
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
1 ;;; gnus-spec.el --- format spec functions for Gnus
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
3
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
5 ;; Keywords: news
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
6
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
8
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
12 ;; any later version.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
13
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
17 ;; GNU General Public License for more details.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
18
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
22 ;; Boston, MA 02111-1307, USA.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
23
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
24 ;;; Commentary:
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
25
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
26 ;;; Code:
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
27
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
28 (require 'gnus)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
29
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
30 ;;; Internal variables.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
31
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
32 (defvar gnus-summary-mark-positions nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
33 (defvar gnus-group-mark-positions nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
34 (defvar gnus-group-indentation "")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
35
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
36 ;; Format specs. The chunks below are the machine-generated forms
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
37 ;; that are to be evaled as the result of the default format strings.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
38 ;; We write them in here to get them byte-compiled. That way the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
39 ;; default actions will be quite fast, while still retaining the full
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
40 ;; flexibility of the user-defined format specs.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
41
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
42 ;; First we have lots of dummy defvars to let the compiler know these
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
43 ;; are really dynamic variables.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
44
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
45 (defvar gnus-tmp-unread)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
46 (defvar gnus-tmp-replied)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
47 (defvar gnus-tmp-score-char)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
48 (defvar gnus-tmp-indentation)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
49 (defvar gnus-tmp-opening-bracket)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
50 (defvar gnus-tmp-lines)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
51 (defvar gnus-tmp-name)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
52 (defvar gnus-tmp-closing-bracket)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
53 (defvar gnus-tmp-subject-or-nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
54 (defvar gnus-tmp-subject)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
55 (defvar gnus-tmp-marked)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
56 (defvar gnus-tmp-marked-mark)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
57 (defvar gnus-tmp-subscribed)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
58 (defvar gnus-tmp-process-marked)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
59 (defvar gnus-tmp-number-of-unread)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
60 (defvar gnus-tmp-group-name)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
61 (defvar gnus-tmp-group)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
62 (defvar gnus-tmp-article-number)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
63 (defvar gnus-tmp-unread-and-unselected)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
64 (defvar gnus-tmp-news-method)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
65 (defvar gnus-tmp-news-server)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
66 (defvar gnus-tmp-article-number)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
67 (defvar gnus-mouse-face)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
68 (defvar gnus-mouse-face-prop)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
69
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
70 (defun gnus-summary-line-format-spec ()
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
71 (insert gnus-tmp-unread gnus-tmp-replied
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
72 gnus-tmp-score-char gnus-tmp-indentation)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
73 (gnus-put-text-property
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
74 (point)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
75 (progn
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
76 (insert
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
77 gnus-tmp-opening-bracket
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
78 (format "%4d: %-20s"
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
79 gnus-tmp-lines
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
80 (if (> (length gnus-tmp-name) 20)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
81 (substring gnus-tmp-name 0 20)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
82 gnus-tmp-name))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
83 gnus-tmp-closing-bracket)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
84 (point))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
85 gnus-mouse-face-prop gnus-mouse-face)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
86 (insert " " gnus-tmp-subject-or-nil "\n"))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
87
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
88 (defvar gnus-summary-line-format-spec
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
89 (gnus-byte-code 'gnus-summary-line-format-spec))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
90
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
91 (defun gnus-summary-dummy-line-format-spec ()
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
92 (insert "* ")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
93 (gnus-put-text-property
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
94 (point)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
95 (progn
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
96 (insert ": :")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
97 (point))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
98 gnus-mouse-face-prop gnus-mouse-face)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
99 (insert " " gnus-tmp-subject "\n"))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
100
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
101 (defvar gnus-summary-dummy-line-format-spec
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
102 (gnus-byte-code 'gnus-summary-dummy-line-format-spec))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
103
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
104 (defun gnus-group-line-format-spec ()
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
105 (insert gnus-tmp-marked-mark gnus-tmp-subscribed
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
106 gnus-tmp-process-marked
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
107 gnus-group-indentation
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
108 (format "%5s: " gnus-tmp-number-of-unread))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
109 (gnus-put-text-property
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
110 (point)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
111 (progn
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
112 (insert gnus-tmp-group "\n")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
113 (1- (point)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
114 gnus-mouse-face-prop gnus-mouse-face))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
115 (defvar gnus-group-line-format-spec
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
116 (gnus-byte-code 'gnus-group-line-format-spec))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
117
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 16
diff changeset
118 (defvar gnus-format-specs
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
119 `((version . ,emacs-version)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
120 (group "%M\%S\%p\%P\%5y: %(%g%)%l\n" ,gnus-group-line-format-spec)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
121 (summary-dummy "* %(: :%) %S\n"
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
122 ,gnus-summary-dummy-line-format-spec)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 16
diff changeset
123 (summary "%U\%R\%z\%I\%(%[%4L: %-20,20n%]%) %s\n"
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
124 ,gnus-summary-line-format-spec))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
125 "Alist of format specs.")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
126
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
127 (defvar gnus-article-mode-line-format-spec nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
128 (defvar gnus-summary-mode-line-format-spec nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
129 (defvar gnus-group-mode-line-format-spec nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
130
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
131 ;;; Phew. All that gruft is over, fortunately.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
132
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
133 ;;;###autoload
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
134 (defun gnus-update-format (var)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
135 "Update the format specification near point."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
136 (interactive
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
137 (list
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
138 (save-excursion
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
139 (eval-defun nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
140 ;; Find the end of the current word.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
141 (re-search-forward "[ \t\n]" nil t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
142 ;; Search backward.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
143 (when (re-search-backward "\\(gnus-[-a-z]+-line-format\\)" nil t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
144 (match-string 1)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
145 (let* ((type (intern (progn (string-match "gnus-\\([-a-z]+\\)-line" var)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
146 (match-string 1 var))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
147 (entry (assq type gnus-format-specs))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
148 value spec)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
149 (when entry
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
150 (setq gnus-format-specs (delq entry gnus-format-specs)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
151 (set
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
152 (intern (format "%s-spec" var))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
153 (gnus-parse-format (setq value (symbol-value (intern var)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
154 (symbol-value (intern (format "%s-alist" var)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
155 (not (string-match "mode" var))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
156 (setq spec (symbol-value (intern (format "%s-spec" var))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
157 (push (list type value spec) gnus-format-specs)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
158
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
159 (pop-to-buffer "*Gnus Format*")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
160 (erase-buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
161 (lisp-interaction-mode)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
162 (insert (pp-to-string spec))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
163
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
164 (defun gnus-update-format-specifications (&optional force &rest types)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
165 "Update all (necessary) format specifications."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
166 ;; Make the indentation array.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
167 ;; See whether all the stored info needs to be flushed.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
168 (when (or force
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
169 (not (equal emacs-version
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
170 (cdr (assq 'version gnus-format-specs)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
171 (setq gnus-format-specs nil))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
172
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
173 ;; Go through all the formats and see whether they need updating.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
174 (let (new-format entry type val)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
175 (while (setq type (pop types))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
176 ;; Jump to the proper buffer to find out the value of
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
177 ;; the variable, if possible. (It may be buffer-local.)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
178 (save-excursion
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
179 (let ((buffer (intern (format "gnus-%s-buffer" type)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
180 val)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
181 (when (and (boundp buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
182 (setq val (symbol-value buffer))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
183 (get-buffer val)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
184 (buffer-name (get-buffer val)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
185 (set-buffer (get-buffer val)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
186 (setq new-format (symbol-value
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
187 (intern (format "gnus-%s-line-format" type)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
188 (setq entry (cdr (assq type gnus-format-specs)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
189 (if (and (car entry)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
190 (equal (car entry) new-format))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
191 ;; Use the old format.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
192 (set (intern (format "gnus-%s-line-format-spec" type))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
193 (cadr entry))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
194 ;; This is a new format.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
195 (setq val
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
196 (if (not (stringp new-format))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
197 ;; This is a function call or something.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
198 new-format
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
199 ;; This is a "real" format.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
200 (gnus-parse-format
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
201 new-format
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
202 (symbol-value
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
203 (intern (format "gnus-%s-line-format-alist"
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
204 (if (eq type 'article-mode)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
205 'summary-mode type))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
206 (not (string-match "mode$" (symbol-name type))))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
207 ;; Enter the new format spec into the list.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
208 (if entry
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
209 (progn
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
210 (setcar (cdr entry) val)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
211 (setcar entry new-format))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
212 (push (list type new-format val) gnus-format-specs))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
213 (set (intern (format "gnus-%s-line-format-spec" type)) val)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
214
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
215 (unless (assq 'version gnus-format-specs)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
216 (push (cons 'version emacs-version) gnus-format-specs)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
217
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
218 (defvar gnus-mouse-face-0 'highlight)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
219 (defvar gnus-mouse-face-1 'highlight)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
220 (defvar gnus-mouse-face-2 'highlight)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
221 (defvar gnus-mouse-face-3 'highlight)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
222 (defvar gnus-mouse-face-4 'highlight)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
223
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
224 (defun gnus-mouse-face-function (form type)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
225 `(gnus-put-text-property
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
226 (point) (progn ,@form (point))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
227 gnus-mouse-face-prop
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
228 ,(if (equal type 0)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
229 'gnus-mouse-face
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
230 `(quote ,(symbol-value (intern (format "gnus-mouse-face-%d" type)))))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
231
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
232 (defvar gnus-face-0 'bold)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
233 (defvar gnus-face-1 'italic)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
234 (defvar gnus-face-2 'bold-italic)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
235 (defvar gnus-face-3 'bold)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
236 (defvar gnus-face-4 'bold)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
237
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
238 (defun gnus-face-face-function (form type)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
239 `(gnus-put-text-property
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
240 (point) (progn ,@form (point))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
241 'face ',(symbol-value (intern (format "gnus-face-%d" type)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
242
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
243 (defun gnus-tilde-max-form (el max-width)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
244 "Return a form that limits EL to MAX-WIDTH."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
245 (let ((max (abs max-width)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
246 (if (symbolp el)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
247 `(if (> (length ,el) ,max)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
248 ,(if (< max-width 0)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
249 `(substring ,el (- (length el) ,max))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
250 `(substring ,el 0 ,max))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
251 ,el)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
252 `(let ((val (eval ,el)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
253 (if (> (length val) ,max)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
254 ,(if (< max-width 0)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
255 `(substring val (- (length val) ,max))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
256 `(substring val 0 ,max))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
257 val)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
258
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
259 (defun gnus-tilde-cut-form (el cut-width)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
260 "Return a form that cuts CUT-WIDTH off of EL."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
261 (let ((cut (abs cut-width)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
262 (if (symbolp el)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
263 `(if (> (length ,el) ,cut)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
264 ,(if (< cut-width 0)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
265 `(substring ,el 0 (- (length el) ,cut))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
266 `(substring ,el ,cut))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
267 ,el)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
268 `(let ((val (eval ,el)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
269 (if (> (length val) ,cut)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
270 ,(if (< cut-width 0)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
271 `(substring val 0 (- (length val) ,cut))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
272 `(substring val ,cut))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
273 val)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
274
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
275 (defun gnus-tilde-ignore-form (el ignore-value)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
276 "Return a form that is blank when EL is IGNORE-VALUE."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
277 (if (symbolp el)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
278 `(if (equal ,el ,ignore-value)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
279 "" ,el)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
280 `(let ((val (eval ,el)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
281 (if (equal val ,ignore-value)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
282 "" val))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
283
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
284 (defun gnus-parse-format (format spec-alist &optional insert)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
285 ;; This function parses the FORMAT string with the help of the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
286 ;; SPEC-ALIST and returns a list that can be eval'ed to return the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
287 ;; string. If the FORMAT string contains the specifiers %( and %)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
288 ;; the text between them will have the mouse-face text property.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
289 (if (string-match
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
290 "\\`\\(.*\\)%[0-9]?[{(]\\(.*\\)%[0-9]?[})]\\(.*\n?\\)\\'"
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
291 format)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
292 (gnus-parse-complex-format format spec-alist)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
293 ;; This is a simple format.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
294 (gnus-parse-simple-format format spec-alist insert)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
295
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
296 (defun gnus-parse-complex-format (format spec-alist)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
297 (save-excursion
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
298 (gnus-set-work-buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
299 (insert format)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
300 (goto-char (point-min))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
301 (while (re-search-forward "\"" nil t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
302 (replace-match "\\\"" nil t))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
303 (goto-char (point-min))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
304 (insert "(\"")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
305 (while (re-search-forward "%\\([0-9]+\\)?\\([{}()]\\)" nil t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
306 (let ((number (if (match-beginning 1)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
307 (match-string 1) "0"))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
308 (delim (aref (match-string 2) 0)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
309 (if (or (= delim ?\() (= delim ?\{))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
310 (replace-match (concat "\"(" (if (= delim ?\() "mouse" "face")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
311 " " number " \""))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
312 (replace-match "\")\""))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
313 (goto-char (point-max))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
314 (insert "\")")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
315 (goto-char (point-min))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
316 (let ((form (read (current-buffer))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
317 (cons 'progn (gnus-complex-form-to-spec form spec-alist)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
318
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
319 (defun gnus-complex-form-to-spec (form spec-alist)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
320 (delq nil
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
321 (mapcar
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
322 (lambda (sform)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
323 (if (stringp sform)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
324 (gnus-parse-simple-format sform spec-alist t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
325 (funcall (intern (format "gnus-%s-face-function" (car sform)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
326 (gnus-complex-form-to-spec (cddr sform) spec-alist)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
327 (nth 1 sform))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
328 form)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
329
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
330 (defun gnus-parse-simple-format (format spec-alist &optional insert)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
331 ;; This function parses the FORMAT string with the help of the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
332 ;; SPEC-ALIST and returns a list that can be eval'ed to return a
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
333 ;; string.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
334 (let ((max-width 0)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
335 spec flist fstring elem result dontinsert user-defined
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
336 type value pad-width spec-beg cut-width ignore-value
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
337 tilde-form tilde elem-type)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
338 (save-excursion
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
339 (gnus-set-work-buffer)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
340 (insert format)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
341 (goto-char (point-min))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
342 (while (re-search-forward "%" nil t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
343 (setq user-defined nil
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
344 spec-beg nil
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
345 pad-width nil
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
346 max-width nil
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
347 cut-width nil
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
348 ignore-value nil
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
349 tilde-form nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
350 (setq spec-beg (1- (point)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
351
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
352 ;; Parse this spec fully.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
353 (while
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 16
diff changeset
354 (cond
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
355 ((looking-at "\\([-.0-9]+\\)\\(,[-0-9]+\\)?")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
356 (setq pad-width (string-to-number (match-string 1)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
357 (when (match-beginning 2)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
358 (setq max-width (string-to-number (buffer-substring
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
359 (1+ (match-beginning 2))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
360 (match-end 2)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
361 (goto-char (match-end 0)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
362 ((looking-at "~")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
363 (forward-char 1)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
364 (setq tilde (read (current-buffer))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
365 type (car tilde)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
366 value (cadr tilde))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
367 (cond
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
368 ((memq type '(pad pad-left))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
369 (setq pad-width value))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
370 ((eq type 'pad-right)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
371 (setq pad-width (- value)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
372 ((memq type '(max-right max))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
373 (setq max-width value))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
374 ((eq type 'max-left)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
375 (setq max-width (- value)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
376 ((memq type '(cut cut-left))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
377 (setq cut-width value))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
378 ((eq type 'cut-right)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
379 (setq cut-width (- value)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
380 ((eq type 'ignore)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
381 (setq ignore-value
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
382 (if (stringp value) value (format "%s" value))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
383 ((eq type 'form)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
384 (setq tilde-form value))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
385 (t
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
386 (error "Unknown tilde type: %s" tilde)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
387 t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
388 (t
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
389 nil)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
390 ;; User-defined spec -- find the spec name.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
391 (when (= (setq spec (following-char)) ?u)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
392 (forward-char 1)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
393 (setq user-defined (following-char)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
394 (forward-char 1)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
395 (delete-region spec-beg (point))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
396
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
397 ;; Now we have all the relevant data on this spec, so
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
398 ;; we start doing stuff.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
399 (insert "%")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
400 (if (eq spec ?%)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
401 ;; "%%" just results in a "%".
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
402 (insert "%")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
403 (cond
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
404 ;; Do tilde forms.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
405 ((eq spec ?@)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
406 (setq elem (list tilde-form ?s)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
407 ;; Treat user defined format specifiers specially.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
408 (user-defined
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
409 (setq elem
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
410 (list
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
411 (list (intern (format "gnus-user-format-function-%c"
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
412 user-defined))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
413 'gnus-tmp-header)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
414 ?s)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
415 ;; Find the specification from `spec-alist'.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
416 ((setq elem (cdr (assq spec spec-alist))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
417 (t
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
418 (setq elem '("*" ?s))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
419 (setq elem-type (cadr elem))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
420 ;; Insert the new format elements.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
421 (when pad-width
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
422 (insert (number-to-string pad-width)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
423 ;; Create the form to be evaled.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
424 (if (or max-width cut-width ignore-value)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
425 (progn
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
426 (insert ?s)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
427 (let ((el (car elem)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
428 (cond ((= (cadr elem) ?c)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
429 (setq el (list 'char-to-string el)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
430 ((= (cadr elem) ?d)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
431 (setq el (list 'int-to-string el))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
432 (when ignore-value
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
433 (setq el (gnus-tilde-ignore-form el ignore-value)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
434 (when cut-width
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
435 (setq el (gnus-tilde-cut-form el cut-width)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
436 (when max-width
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
437 (setq el (gnus-tilde-max-form el max-width)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
438 (push el flist)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
439 (insert elem-type)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
440 (push (car elem) flist))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
441 (setq fstring (buffer-string)))
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 16
diff changeset
442
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
443 ;; Do some postprocessing to increase efficiency.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
444 (setq
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
445 result
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
446 (cond
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
447 ;; Emptyness.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
448 ((string= fstring "")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
449 nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
450 ;; Not a format string.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
451 ((not (string-match "%" fstring))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
452 (list fstring))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
453 ;; A format string with just a single string spec.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
454 ((string= fstring "%s")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
455 (list (car flist)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
456 ;; A single character.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
457 ((string= fstring "%c")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
458 (list (car flist)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
459 ;; A single number.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
460 ((string= fstring "%d")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
461 (setq dontinsert)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
462 (if insert
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
463 (list `(princ ,(car flist)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
464 (list `(int-to-string ,(car flist)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
465 ;; Just lots of chars and strings.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
466 ((string-match "\\`\\(%[cs]\\)+\\'" fstring)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
467 (nreverse flist))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
468 ;; A single string spec at the beginning of the spec.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
469 ((string-match "\\`%[sc][^%]+\\'" fstring)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
470 (list (car flist) (substring fstring 2)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
471 ;; A single string spec in the middle of the spec.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
472 ((string-match "\\`\\([^%]+\\)%[sc]\\([^%]+\\)\\'" fstring)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
473 (list (match-string 1 fstring) (car flist) (match-string 2 fstring)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
474 ;; A single string spec in the end of the spec.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
475 ((string-match "\\`\\([^%]+\\)%[sc]\\'" fstring)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
476 (list (match-string 1 fstring) (car flist)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
477 ;; A more complex spec.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
478 (t
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
479 (list (cons 'format (cons fstring (nreverse flist)))))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
480
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
481 (if insert
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
482 (when result
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
483 (if dontinsert
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
484 result
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
485 (cons 'insert result)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
486 (cond ((stringp result)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
487 result)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
488 ((consp result)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
489 (cons 'concat result))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
490 (t "")))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
491
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
492 (defun gnus-eval-format (format &optional alist props)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
493 "Eval the format variable FORMAT, using ALIST.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
494 If PROPS, insert the result."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
495 (let ((form (gnus-parse-format format alist props)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
496 (if props
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
497 (gnus-add-text-properties (point) (progn (eval form) (point)) props)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
498 (eval form))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
499
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
500 (defun gnus-compile ()
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
501 "Byte-compile the user-defined format specs."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
502 (interactive)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 16
diff changeset
503 (when gnus-xemacs
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 16
diff changeset
504 (error "Can't compile specs under XEmacs"))
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
505 (let ((entries gnus-format-specs)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
506 (byte-compile-warnings '(unresolved callargs redefine))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
507 entry gnus-tmp-func)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
508 (save-excursion
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
509 (gnus-message 7 "Compiling format specs...")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
510
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
511 (while entries
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
512 (setq entry (pop entries))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
513 (if (eq (car entry) 'version)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
514 (setq gnus-format-specs (delq entry gnus-format-specs))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
515 (when (and (listp (caddr entry))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
516 (not (eq 'byte-code (caaddr entry))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
517 (fset 'gnus-tmp-func `(lambda () ,(caddr entry)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
518 (byte-compile 'gnus-tmp-func)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
519 (setcar (cddr entry) (gnus-byte-code 'gnus-tmp-func)))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
520
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
521 (push (cons 'version emacs-version) gnus-format-specs)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
522 ;; Mark the .newsrc.eld file as "dirty".
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
523 (gnus-dribble-enter " ")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
524 (gnus-message 7 "Compiling user specs...done"))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
525
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
526 (provide 'gnus-spec)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
527
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents:
diff changeset
528 ;;; gnus-spec.el ends here