2001-09-15 Michael Welsh Duggan <md5i@cs.cmu.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 &optional end)
274   (let ((wstart 0)
275         (wend 0)
276         (wseek 0)
277         (seek 0)
278         (length (length string))
279         (string (concat string "\0"))) 
280     ;; Find the start position.
281     (while (and (< seek length)
282                 (< wseek start))
283       (incf wseek (gnus-char-width (aref string seek)))
284       (incf seek))
285     (setq wstart seek)
286     ;; Find the end position.
287     (while (and (<= seek length)
288                 (or (not end)
289                     (<= wseek end)))
290       (incf wseek (gnus-char-width (aref string seek)))
291       (incf seek))
292     (setq wend seek)
293     (substring string wstart (1- wend))))
294
295 (defun gnus-tilde-max-form (el max-width)
296   "Return a form that limits EL to MAX-WIDTH."
297   (let ((max (abs max-width))
298         (length-fun (if gnus-use-correct-string-widths
299                       'gnus-correct-length
300                     'length))
301         (substring-fun (if gnus-use-correct-string-widths
302                        'gnus-correct-substring
303                      'substring)))
304     (if (symbolp el)
305         `(if (> (,length-fun ,el) ,max)
306              ,(if (< max-width 0)
307                   `(,substring-fun ,el (- (,length-fun ,el) ,max))
308                 `(,substring-fun ,el 0 ,max))
309            ,el)
310       `(let ((val (eval ,el)))
311          (if (> (,length-fun val) ,max)
312              ,(if (< max-width 0)
313                   `(,substring-fun val (- (,length-fun val) ,max))
314                 `(,substring-fun val 0 ,max))
315            val)))))
316
317 (defun gnus-tilde-cut-form (el cut-width)
318   "Return a form that cuts CUT-WIDTH off of EL."
319   (let ((cut (abs cut-width))
320         (length-fun (if gnus-use-correct-string-widths
321                       'gnus-correct-length
322                     'length))
323         (substring-fun (if gnus-use-correct-string-widths
324                        'gnus-correct-substring
325                      'substring)))
326     (if (symbolp el)
327         `(if (> (,length-fun ,el) ,cut)
328              ,(if (< cut-width 0)
329                   `(,substring-fun ,el 0 (- (,length-fun ,el) ,cut))
330                 `(,substring-fun ,el ,cut))
331            ,el)
332       `(let ((val (eval ,el)))
333          (if (> (,length-fun val) ,cut)
334              ,(if (< cut-width 0)
335                   `(,substring-fun val 0 (- (,length-fun val) ,cut))
336                 `(,substring-fun val ,cut))
337            val)))))
338
339 (defun gnus-tilde-ignore-form (el ignore-value)
340   "Return a form that is blank when EL is IGNORE-VALUE."
341   (if (symbolp el)
342       `(if (equal ,el ,ignore-value)
343            "" ,el)
344     `(let ((val (eval ,el)))
345        (if (equal val ,ignore-value)
346            "" val))))
347
348 (defun gnus-correct-pad-form (el pad-width)
349   "Return a form that pads EL to PAD-WIDTH accounting for multi-column
350 characters correctly. This is because `format' may pad to columns or to
351 characters when given a pad value."
352   (let ((pad (abs pad-width))
353         (side (< 0 pad-width)))
354     (if (symbolp el)
355         `(let ((need (- ,pad (gnus-correct-length ,el))))
356            (if (> need 0)
357                (concat ,(when side '(make-string need ?\ ))
358                        ,el
359                        ,(when (not side) '(make-string need ?\ )))
360              ,el))
361       `(let* ((val (eval ,el))
362               (need (- ,pad (gnus-correct-length ,el))))
363          (if (> need 0)
364              (concat ,(when side '(make-string need ?\ ))
365                      ,el
366                      ,(when (not side) '(make-string need ?\ )))
367            ,el)))))
368
369 (defun gnus-parse-format (format spec-alist &optional insert)
370   ;; This function parses the FORMAT string with the help of the
371   ;; SPEC-ALIST and returns a list that can be eval'ed to return the
372   ;; string.  If the FORMAT string contains the specifiers %( and %)
373   ;; the text between them will have the mouse-face text property.
374   ;; If the FORMAT string contains the specifiers %[ and %], the text between
375   ;; them will have the balloon-help text property.
376   (let ((case-fold-search nil))
377     (if (string-match
378        "\\`\\(.*\\)%[0-9]?[{(«]\\(.*\\)%[0-9]?[»})]\\(.*\n?\\)\\'"
379        format)
380       (gnus-parse-complex-format format spec-alist)
381       ;; This is a simple format.
382       (gnus-parse-simple-format format spec-alist insert))))
383
384 (defun gnus-parse-complex-format (format spec-alist)
385   (save-excursion
386     (gnus-set-work-buffer)
387     (insert format)
388     (goto-char (point-min))
389     (while (re-search-forward "\"" nil t)
390       (replace-match "\\\"" nil t))
391     (goto-char (point-min))
392     (insert "(\"")
393     ;; Convert all font specs into font spec lists.
394     (while (re-search-forward "%\\([0-9]+\\)?\\([«»{}()]\\)" nil t)
395       (let ((number (if (match-beginning 1)
396                         (match-string 1) "0"))
397             (delim (aref (match-string 2) 0)))
398         (if (or (= delim ?\()
399                 (= delim ?\{)
400                 (= delim ?\«))
401             (replace-match (concat "\"("
402                                    (cond ((= delim ?\() "mouse")
403                                          ((= delim ?\{) "face")
404                                          (t "balloon"))
405                                    " " number " \"")
406                            t t)
407           (replace-match "\")\""))))
408     (goto-char (point-max))
409     (insert "\")")
410     ;; Convert point position commands.
411     (goto-char (point-min))
412     (while (re-search-forward "%\\([-0-9]+\\)?C" nil t)
413       (replace-match "\"(point)\"" t t))
414     ;; Convert TAB commands.
415     (goto-char (point-min))
416     (while (re-search-forward "%\\([-0-9]+\\)=" nil t)
417       (replace-match (format "\"(tab %s)\"" (match-string 1)) t t))
418     ;; Convert the buffer into the spec.
419     (goto-char (point-min))
420     (let ((form (read (current-buffer))))
421       ;; If the first element is '(point), we just remove it.
422       (when (equal (car form) '(point))
423         (pop form))
424       (cons 'progn (gnus-complex-form-to-spec form spec-alist)))))
425
426 (defun gnus-complex-form-to-spec (form spec-alist)
427   (delq nil
428         (mapcar
429          (lambda (sform)
430            (cond
431             ((stringp sform)
432              (gnus-parse-simple-format sform spec-alist t))
433             ((eq (car sform) 'point)
434              `(gnus-put-text-property (1- (point)) (point) 'gnus-position t))
435             ((eq (car sform) 'tab)
436              (gnus-spec-tab (cadr sform)))
437             (t
438              (funcall (intern (format "gnus-%s-face-function" (car sform)))
439                       (gnus-complex-form-to-spec (cddr sform) spec-alist)
440                       (nth 1 sform)))))
441          form)))
442
443 (defun gnus-parse-simple-format (format spec-alist &optional insert)
444   ;; This function parses the FORMAT string with the help of the
445   ;; SPEC-ALIST and returns a list that can be eval'ed to return a
446   ;; string.
447   (let ((max-width 0)
448         spec flist fstring elem result dontinsert user-defined
449         type value pad-width spec-beg cut-width ignore-value
450         tilde-form tilde elem-type)
451     (save-excursion
452       (gnus-set-work-buffer)
453       (insert format)
454       (goto-char (point-min))
455       (while (re-search-forward "%" nil t)
456         (setq user-defined nil
457               spec-beg nil
458               pad-width nil
459               max-width nil
460               cut-width nil
461               ignore-value nil
462               tilde-form nil)
463         (setq spec-beg (1- (point)))
464
465         ;; Parse this spec fully.
466         (while
467             (cond
468              ((looking-at "\\([-.0-9]+\\)\\(,[-0-9]+\\)?")
469               (setq pad-width (string-to-number (match-string 1)))
470               (when (match-beginning 2)
471                 (setq max-width (string-to-number (buffer-substring
472                                                    (1+ (match-beginning 2))
473                                                    (match-end 2)))))
474               (goto-char (match-end 0)))
475              ((looking-at "~")
476               (forward-char 1)
477               (setq tilde (read (current-buffer))
478                     type (car tilde)
479                     value (cadr tilde))
480               (cond
481                ((memq type '(pad pad-left))
482                 (setq pad-width value))
483                ((eq type 'pad-right)
484                 (setq pad-width (- value)))
485                ((memq type '(max-right max))
486                 (setq max-width value))
487                ((eq type 'max-left)
488                 (setq max-width (- value)))
489                ((memq type '(cut cut-left))
490                 (setq cut-width value))
491                ((eq type 'cut-right)
492                 (setq cut-width (- value)))
493                ((eq type 'ignore)
494                 (setq ignore-value
495                       (if (stringp value) value (format "%s" value))))
496                ((eq type 'form)
497                 (setq tilde-form value))
498                (t
499                 (error "Unknown tilde type: %s" tilde)))
500               t)
501              (t
502               nil)))
503         ;; User-defined spec -- find the spec name.
504         (when (eq (setq spec (char-after)) ?u)
505           (forward-char 1)
506           (setq user-defined (char-after)))
507         (forward-char 1)
508         (delete-region spec-beg (point))
509
510         ;; Now we have all the relevant data on this spec, so
511         ;; we start doing stuff.
512         (insert "%")
513         (if (eq spec ?%)
514             ;; "%%" just results in a "%".
515             (insert "%")
516           (cond
517            ;; Do tilde forms.
518            ((eq spec ?@)
519             (setq elem (list tilde-form ?s)))
520            ;; Treat user defined format specifiers specially.
521            (user-defined
522             (setq elem
523                   (list
524                    (list (intern (format "gnus-user-format-function-%c"
525                                          user-defined))
526                          'gnus-tmp-header)
527                    ?s)))
528            ;; Find the specification from `spec-alist'.
529            ((setq elem (cdr (assq spec spec-alist))))
530            (t
531             (setq elem '("*" ?s))))
532           (setq elem-type (cadr elem))
533           ;; Insert the new format elements.
534           (when (and pad-width
535                      (not (and (featurep 'xemacs)
536                                gnus-use-correct-string-widths)))
537             (insert (number-to-string pad-width)))
538           ;; Create the form to be evaled.
539           (if (or max-width cut-width ignore-value
540                   (and (featurep 'xemacs)
541                        gnus-use-correct-string-widths))
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                   (when pad-width
556                     (setq el (gnus-correct-pad-form el pad-width)))
557                   (push el flist)))
558             (insert elem-type)
559             (push (car elem) flist))))
560       (setq fstring (buffer-string)))
561
562     ;; Do some postprocessing to increase efficiency.
563     (setq
564      result
565      (cond
566       ;; Emptyness.
567       ((string= fstring "")
568        nil)
569       ;; Not a format string.
570       ((not (string-match "%" fstring))
571        (list fstring))
572       ;; A format string with just a single string spec.
573       ((string= fstring "%s")
574        (list (car flist)))
575       ;; A single character.
576       ((string= fstring "%c")
577        (list (car flist)))
578       ;; A single number.
579       ((string= fstring "%d")
580        (setq dontinsert)
581        (if insert
582            (list `(princ ,(car flist)))
583          (list `(int-to-string ,(car flist)))))
584       ;; Just lots of chars and strings.
585       ((string-match "\\`\\(%[cs]\\)+\\'" fstring)
586        (nreverse flist))
587       ;; A single string spec at the beginning of the spec.
588       ((string-match "\\`%[sc][^%]+\\'" fstring)
589        (list (car flist) (substring fstring 2)))
590       ;; A single string spec in the middle of the spec.
591       ((string-match "\\`\\([^%]+\\)%[sc]\\([^%]+\\)\\'" fstring)
592        (list (match-string 1 fstring) (car flist) (match-string 2 fstring)))
593       ;; A single string spec in the end of the spec.
594       ((string-match "\\`\\([^%]+\\)%[sc]\\'" fstring)
595        (list (match-string 1 fstring) (car flist)))
596       ;; A more complex spec.
597       (t
598        (list (cons 'format (cons fstring (nreverse flist)))))))
599
600     (if insert
601         (when result
602           (if dontinsert
603               result
604             (cons 'insert result)))
605       (cond ((stringp result)
606              result)
607             ((consp result)
608              (cons 'concat result))
609             (t "")))))
610
611 (defun gnus-eval-format (format &optional alist props)
612   "Eval the format variable FORMAT, using ALIST.
613 If PROPS, insert the result."
614   (let ((form (gnus-parse-format format alist props)))
615     (if props
616         (gnus-add-text-properties (point) (progn (eval form) (point)) props)
617       (eval form))))
618
619 (defun gnus-compile ()
620   "Byte-compile the user-defined format specs."
621   (interactive)
622   (require 'bytecomp)
623   (let ((entries gnus-format-specs)
624         (byte-compile-warnings '(unresolved callargs redefine))
625         entry gnus-tmp-func)
626     (save-excursion
627       (gnus-message 7 "Compiling format specs...")
628
629       (while entries
630         (setq entry (pop entries))
631         (if (memq (car entry) '(gnus-version version))
632             (setq gnus-format-specs (delq entry gnus-format-specs))
633           (let ((form (caddr entry)))
634             (when (and (listp form)
635                        ;; Under GNU Emacs, it's (byte-code ...)
636                        (not (eq 'byte-code (car form)))
637                        ;; Under XEmacs, it's (funcall #<compiled-function ...>)
638                        (not (and (eq 'funcall (car form))
639                                  (byte-code-function-p (cadr form)))))
640               (defalias 'gnus-tmp-func `(lambda () ,form))
641               (byte-compile 'gnus-tmp-func)
642               (setcar (cddr entry) (gnus-byte-code 'gnus-tmp-func))))))
643
644       (push (cons 'version emacs-version) gnus-format-specs)
645       ;; Mark the .newsrc.eld file as "dirty".
646       (gnus-dribble-touch)
647       (gnus-message 7 "Compiling user specs...done"))))
648
649 (defun gnus-set-format (type &optional insertable)
650   (set (intern (format "gnus-%s-line-format-spec" type))
651        (gnus-parse-format
652         (symbol-value (intern (format "gnus-%s-line-format" type)))
653         (symbol-value (intern (format "gnus-%s-line-format-alist" type)))
654         insertable)))
655
656 (provide 'gnus-spec)
657
658 ;; Local Variables:
659 ;; coding: iso-8859-1
660 ;; End:
661
662 ;;; gnus-spec.el ends here