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