1 ;;; gnus-spec.el --- format spec functions for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Katsumi Yamaoka <yamaoka@jpl.org>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (eval-when-compile (require 'cl))
35 (defcustom gnus-use-correct-string-widths t
36 "*If non-nil, use correct functions for dealing with wide characters."
40 (defcustom gnus-make-format-preserve-properties (featurep 'xemacs)
41 "*If non-nil, use a replacement `format' function which preserves
42 text properties. This is only needed on XEmacs, as FSF Emacs does this anyway."
46 ;;; Internal variables.
48 (defvar gnus-summary-mark-positions nil)
49 (defvar gnus-group-mark-positions nil)
50 (defvar gnus-group-indentation "")
52 ;; Format specs. The chunks below are the machine-generated forms
53 ;; that are to be evaled as the result of the default format strings.
54 ;; We write them in here to get them byte-compiled. That way the
55 ;; default actions will be quite fast, while still retaining the full
56 ;; flexibility of the user-defined format specs.
58 ;; First we have lots of dummy defvars to let the compiler know these
59 ;; are really dynamic variables.
61 (defvar gnus-tmp-unread)
62 (defvar gnus-tmp-replied)
63 (defvar gnus-tmp-score-char)
64 (defvar gnus-tmp-indentation)
65 (defvar gnus-tmp-opening-bracket)
66 (defvar gnus-tmp-lines)
67 (defvar gnus-tmp-name)
68 (defvar gnus-tmp-closing-bracket)
69 (defvar gnus-tmp-subject-or-nil)
70 (defvar gnus-tmp-subject)
71 (defvar gnus-tmp-marked)
72 (defvar gnus-tmp-marked-mark)
73 (defvar gnus-tmp-subscribed)
74 (defvar gnus-tmp-process-marked)
75 (defvar gnus-tmp-number-of-unread)
76 (defvar gnus-tmp-group-name)
77 (defvar gnus-tmp-group)
78 (defvar gnus-tmp-article-number)
79 (defvar gnus-tmp-unread-and-unselected)
80 (defvar gnus-tmp-news-method)
81 (defvar gnus-tmp-news-server)
82 (defvar gnus-tmp-article-number)
83 (defvar gnus-mouse-face)
84 (defvar gnus-mouse-face-prop)
85 (defvar gnus-tmp-header)
86 (defvar gnus-tmp-from)
88 (defun gnus-summary-line-format-spec ()
89 (insert gnus-tmp-unread gnus-tmp-replied
90 gnus-tmp-score-char gnus-tmp-indentation)
91 (gnus-put-text-property
95 (format "%c%4s: %-23s%c" gnus-tmp-opening-bracket gnus-tmp-lines
98 (gnus-summary-from-or-to-or-newsgroups
99 gnus-tmp-header gnus-tmp-from))))
100 (if (> (length val) 23)
103 gnus-tmp-closing-bracket))
105 gnus-mouse-face-prop gnus-mouse-face)
106 (insert " " gnus-tmp-subject-or-nil "\n"))
108 (defvar gnus-summary-line-format-spec
109 (gnus-byte-code 'gnus-summary-line-format-spec))
111 (defun gnus-summary-dummy-line-format-spec ()
113 (gnus-put-text-property
118 gnus-mouse-face-prop gnus-mouse-face)
119 (insert " " gnus-tmp-subject "\n"))
121 (defvar gnus-summary-dummy-line-format-spec
122 (gnus-byte-code 'gnus-summary-dummy-line-format-spec))
124 (defun gnus-group-line-format-spec ()
125 (insert gnus-tmp-marked-mark gnus-tmp-subscribed
126 gnus-tmp-process-marked
127 gnus-group-indentation
128 (format "%5s: " gnus-tmp-number-of-unread))
129 (gnus-put-text-property
132 (insert gnus-tmp-group "\n")
134 gnus-mouse-face-prop gnus-mouse-face))
135 (defvar gnus-group-line-format-spec
136 (gnus-byte-code 'gnus-group-line-format-spec))
138 (defvar gnus-format-specs
139 `((group ("%M\%S\%p\%P\%5y: %(%g%)\n" ,gnus-group-line-format-spec))
140 (summary-dummy ("* %(: :%) %S\n"
141 ,gnus-summary-dummy-line-format-spec))
142 (summary ("%U%R%z%I%(%[%4L: %-23,23f%]%) %s\n"
143 ,gnus-summary-line-format-spec)))
144 "Alist of format specs.")
146 (defvar gnus-default-format-specs gnus-format-specs)
148 (defvar gnus-format-specs-compiled nil
149 "Alist of compiled format specs. Each element should be the form:
150 \(TYPE (FORMAT-STRING-1 . COMPILED-FUNCTION-1)
152 (FORMAT-STRING-n . COMPILED-FUNCTION-n)).")
154 (defvar gnus-article-mode-line-format-spec nil)
155 (defvar gnus-summary-mode-line-format-spec nil)
156 (defvar gnus-group-mode-line-format-spec nil)
158 ;;; Phew. All that gruft is over with, fortunately.
161 (defun gnus-update-format (var)
162 "Update the format specification near point."
167 ;; Find the end of the current word.
168 (re-search-forward "[ \t\n]" nil t)
170 (when (re-search-backward "\\(gnus-[-a-z]+-line-format\\)" nil t)
172 (let* ((type (intern (progn (string-match "gnus-\\([-a-z]+\\)-line" var)
173 (match-string 1 var))))
174 (value (symbol-value (intern var)))
176 (intern (format "%s-spec" var))
178 value (symbol-value (intern (format "%s-alist" var)))
179 (not (string-match "mode" var)))))
180 (entry (assq type gnus-format-specs)))
182 (let ((elem (assoc value entry)))
185 (setcdr entry (cons (cons value elem) (cdr entry)))))
186 (push (list type (cons value spec)) gnus-format-specs))
187 (gnus-product-variable-touch 'gnus-format-specs)
189 (pop-to-buffer "*Gnus Format*")
191 (lisp-interaction-mode)
192 (insert (gnus-pp-to-string spec))))
194 (eval-when-compile (defvar unchanged))
196 (put 'gnus-search-or-regist-spec 'lisp-indent-function 4)
197 (defmacro gnus-search-or-regist-spec (specs type format val &rest body)
198 `(let* ((entry (assq ,type ,specs))
199 (elem (assoc ,format (cdr entry))))
200 ;; That `(cdr elem)' returns non-nil means the spec for `type'
201 ;; doesn't need to be updated.
203 ;; This variable is set beforehand.
205 ;; Update the spec. Where `body' will modify `val'. This
206 ;; section will be skipped if compiling the spec is disabled.
211 (setcdr entry (cons (cons ,format ,val) (cdr entry))))
212 (push (list ,type (cons ,format ,val)) ,specs))
213 (gnus-product-variable-touch (quote ,specs)))
214 ;; Return the new spec without compiling.
217 (defun gnus-update-format-specification-1 (type format val)
218 (set (intern (format "gnus-%s-line-format-spec" type))
219 (gnus-search-or-regist-spec
220 gnus-format-specs-compiled type format val
221 (when (and gnus-compile-user-specs val)
224 (fset 'gnus-tmp-func `(lambda () ,val))
226 (let (byte-compile-warnings)
227 (byte-compile 'gnus-tmp-func))
228 (gnus-byte-code 'gnus-tmp-func))
229 (when (get-buffer "*Compile-Log*")
230 (bury-buffer "*Compile-Log*"))
231 (when (get-buffer "*Compile-Log-Show*")
232 (bury-buffer "*Compile-Log-Show*"))))))))
234 (defun gnus-update-format-specifications (&optional force &rest types)
235 "Update all (necessary) format specifications.
236 Return a list of updated types."
237 ;; Make the indentation array.
238 ;; See whether all the stored info needs to be flushed.
240 (message "%s" "Force update format specs.")
241 (setq gnus-format-specs nil
242 gnus-format-specs-compiled nil)
243 (gnus-product-variable-touch 'gnus-format-specs
244 'gnus-format-specs-compiled))
245 ;; Flush the group format spec cache if there's the grouplens stuff.
246 (let ((spec (assq 'group gnus-format-specs)))
247 (when (and (memq 'group types)
248 (string-match " gnus-tmp-grouplens[ )]"
249 (gnus-prin1-to-string (cdr spec))))
250 (setq gnus-format-specs (delq spec gnus-format-specs)
251 spec (assq 'group gnus-format-specs-compiled)
252 gnus-format-specs-compiled (delq spec gnus-format-specs-compiled))))
254 ;; Go through all the formats and see whether they need updating.
255 (let (new-format type val unchanged updated)
257 (while (setq type (pop types))
258 ;; Jump to the proper buffer to find out the value of the
259 ;; variable, if possible. (It may be buffer-local.)
260 (let ((buffer (intern (format "gnus-%s-buffer" type))))
261 (when (and (boundp buffer)
262 (setq val (symbol-value buffer))
263 (gnus-buffer-exists-p val))
265 (setq new-format (symbol-value
266 (intern (format "gnus-%s-line-format" type)))))
268 (or (gnus-update-format-specification-1 type new-format nil)
269 ;; This is a new format.
270 (gnus-update-format-specification-1
272 (gnus-search-or-regist-spec
273 gnus-format-specs type new-format val
274 (setq val (if (stringp new-format)
275 ;; This is a "real" format.
279 (intern (format "gnus-%s-line-format-alist"
281 (not (string-match "mode$"
282 (symbol-name type))))
283 ;; This is a function call or something.
286 (push type updated))))
289 (defvar gnus-mouse-face-0 'highlight)
290 (defvar gnus-mouse-face-1 'highlight)
291 (defvar gnus-mouse-face-2 'highlight)
292 (defvar gnus-mouse-face-3 'highlight)
293 (defvar gnus-mouse-face-4 'highlight)
295 (defun gnus-mouse-face-function (form type)
296 `(gnus-put-text-property
297 (point) (progn ,@form (point))
301 `(quote ,(symbol-value (intern (format "gnus-mouse-face-%d" type)))))))
303 (defvar gnus-face-0 'bold)
304 (defvar gnus-face-1 'italic)
305 (defvar gnus-face-2 'bold-italic)
306 (defvar gnus-face-3 'bold)
307 (defvar gnus-face-4 'bold)
309 (defun gnus-face-face-function (form type)
310 `(gnus-add-text-properties
311 (point) (progn ,@form (point))
312 '(gnus-face t face ,(symbol-value (intern (format "gnus-face-%d" type))))))
314 (defun gnus-balloon-face-function (form type)
315 `(gnus-put-text-property
316 (point) (progn ,@form (point))
317 ,(if (fboundp 'balloon-help-mode)
320 ,(intern (format "gnus-balloon-face-%d" type))))
322 (defun gnus-spec-tab (column)
324 `(insert (make-string (max (- ,column (current-column)) 0) ? ))
325 (let ((column (abs column)))
326 (if gnus-use-correct-string-widths
328 (if (> (current-column) ,column)
330 (delete-backward-char 1)
331 (> (current-column) ,column))))
332 (insert (make-string (max (- ,column (current-column)) 0) ? )))
334 (if (> (current-column) ,column)
335 (delete-region (point)
336 (- (point) (- (current-column) ,column)))
337 (insert (make-string (max (- ,column (current-column)) 0)
340 (defun gnus-correct-length (string)
341 "Return the correct width of STRING."
343 (mapcar (lambda (char) (incf length (char-width char))) string)
346 (defun gnus-correct-substring (string start &optional end)
351 (length (length string))
352 (string (concat string "\0")))
353 ;; Find the start position.
354 (while (and (< seek length)
356 (incf wseek (char-width (aref string seek)))
359 ;; Find the end position.
360 (while (and (<= seek length)
363 (incf wseek (char-width (aref string seek)))
366 (substring string wstart (1- wend))))
368 (defun gnus-string-width-function ()
370 (gnus-use-correct-string-widths
371 'gnus-correct-length)
372 ((fboundp 'string-width)
377 (defun gnus-substring-function ()
379 (gnus-use-correct-string-widths
380 'gnus-correct-substring)
381 ((fboundp 'string-width)
382 'gnus-correct-substring)
386 (defun gnus-tilde-max-form (el max-width)
387 "Return a form that limits EL to MAX-WIDTH."
388 (let ((max (abs max-width))
389 (length-fun (gnus-string-width-function))
390 (substring-fun (gnus-substring-function)))
392 `(if (> (,length-fun ,el) ,max)
394 `(,substring-fun ,el (- (,length-fun ,el) ,max))
395 `(,substring-fun ,el 0 ,max))
397 `(let ((val (eval ,el)))
398 (if (> (,length-fun val) ,max)
400 `(,substring-fun val (- (,length-fun val) ,max))
401 `(,substring-fun val 0 ,max))
404 (defun gnus-tilde-cut-form (el cut-width)
405 "Return a form that cuts CUT-WIDTH off of EL."
406 (let ((cut (abs cut-width))
407 (length-fun (gnus-string-width-function))
408 (substring-fun (gnus-substring-function)))
410 `(if (> (,length-fun ,el) ,cut)
412 `(,substring-fun ,el 0 (- (,length-fun ,el) ,cut))
413 `(,substring-fun ,el ,cut))
415 `(let ((val (eval ,el)))
416 (if (> (,length-fun val) ,cut)
418 `(,substring-fun val 0 (- (,length-fun val) ,cut))
419 `(,substring-fun val ,cut))
422 (defun gnus-tilde-ignore-form (el ignore-value)
423 "Return a form that is blank when EL is IGNORE-VALUE."
425 `(if (equal ,el ,ignore-value)
427 `(let ((val (eval ,el)))
428 (if (equal val ,ignore-value)
431 (defun gnus-pad-form (el pad-width)
432 "Return a form that pads EL to PAD-WIDTH accounting for multi-column
433 characters correctly. This is because `format' may pad to columns or to
434 characters when given a pad value."
435 (let ((pad (abs pad-width))
436 (side (< 0 pad-width))
437 (length-fun (gnus-string-width-function)))
439 `(let ((need (- ,pad (,length-fun ,el))))
441 (concat ,(when side '(make-string need ?\ ))
443 ,(when (not side) '(make-string need ?\ )))
445 `(let* ((val (eval ,el))
446 (need (- ,pad (,length-fun val))))
448 (concat ,(when side '(make-string need ?\ ))
450 ,(when (not side) '(make-string need ?\ )))
453 (defun gnus-parse-format (format spec-alist &optional insert)
454 ;; This function parses the FORMAT string with the help of the
455 ;; SPEC-ALIST and returns a list that can be eval'ed to return the
456 ;; string. If the FORMAT string contains the specifiers %( and %)
457 ;; the text between them will have the mouse-face text property.
458 ;; If the FORMAT string contains the specifiers %[ and %], the text between
459 ;; them will have the balloon-help text property.
460 (let ((case-fold-search nil))
462 "\\`\\(.*\\)%[0-9]?[{(«]\\(.*\\)%[0-9]?[»})]\\(.*\n?\\)\\'\\|%[-0-9]*=\\|%[-0-9]*\\*"
464 (gnus-parse-complex-format format spec-alist)
465 ;; This is a simple format.
466 (gnus-parse-simple-format format spec-alist insert))))
468 (defun gnus-parse-complex-format (format spec-alist)
469 (let ((cursor-spec nil))
471 (gnus-set-work-buffer)
473 (goto-char (point-min))
474 (while (re-search-forward "\"" nil t)
475 (replace-match "\\\"" nil t))
476 (goto-char (point-min))
478 ;; Convert all font specs into font spec lists.
479 (while (re-search-forward "%\\([0-9]+\\)?\\([«»{}()]\\)" nil t)
480 (let ((number (if (match-beginning 1)
481 (match-string 1) "0"))
482 (delim (aref (match-string 2) 0)))
483 (if (or (= delim ?\()
486 (replace-match (concat "\"("
487 (cond ((= delim ?\() "mouse")
488 ((= delim ?\{) "face")
492 (replace-match "\")\""))))
493 (goto-char (point-max))
495 ;; Convert point position commands.
496 (goto-char (point-min))
497 (let ((case-fold-search nil))
498 (while (re-search-forward "%\\([-0-9]+\\)?\\*" nil t)
499 (replace-match "\"(point)\"" t t)
500 (setq cursor-spec t)))
501 ;; Convert TAB commands.
502 (goto-char (point-min))
503 (while (re-search-forward "%\\([-0-9]+\\)=" nil t)
504 (replace-match (format "\"(tab %s)\"" (match-string 1)) t t))
505 ;; Convert the buffer into the spec.
506 (goto-char (point-min))
507 (let ((form (read (current-buffer))))
509 `(let (gnus-position)
510 ,@(gnus-complex-form-to-spec form spec-alist)
512 (gnus-put-text-property gnus-position (1+ gnus-position)
515 ,@(gnus-complex-form-to-spec form spec-alist)))))))
517 (defun gnus-complex-form-to-spec (form spec-alist)
523 (gnus-parse-simple-format sform spec-alist t))
524 ((eq (car sform) 'point)
525 '(setq gnus-position (point)))
526 ((eq (car sform) 'tab)
527 (gnus-spec-tab (cadr sform)))
529 (funcall (intern (format "gnus-%s-face-function" (car sform)))
530 (gnus-complex-form-to-spec (cddr sform) spec-alist)
535 (defun gnus-xmas-format (fstring &rest args)
536 "A version of `format' which preserves text properties.
538 Required for XEmacs, where the built in `format' function strips all text
539 properties from both the format string and any inserted strings.
541 Only supports the format sequence %s, and %% for inserting
542 literal % characters. A pad width and an optional - (to right pad)
543 are supported for %s."
544 (let ((re "%%\\|%\\(-\\)?\\([1-9][0-9]*\\)?s")
548 (goto-char (point-min))
549 (while (re-search-forward re nil t)
550 (goto-char (match-end 0))
552 ((string= (match-string 0) "%%")
556 (error 'wrong-number-of-arguments #'my-format n fstring))
557 (let* ((minlen (string-to-int (or (match-string 2) "")))
559 (str (if (stringp arg) arg (format "%s" arg)))
560 (lpad (null (match-string 1)))
561 (padlen (max 0 (- minlen (length str)))))
563 (if lpad (insert-char ?\ padlen))
565 (unless lpad (insert-char ?\ padlen))
566 (setq args (cdr args))))))
569 (defun gnus-parse-simple-format (format spec-alist &optional insert)
570 ;; This function parses the FORMAT string with the help of the
571 ;; SPEC-ALIST and returns a list that can be eval'ed to return a
574 spec flist fstring elem result dontinsert user-defined
575 type value pad-width spec-beg cut-width ignore-value
576 tilde-form tilde elem-type extended-spec)
578 (gnus-set-work-buffer)
580 (goto-char (point-min))
581 (while (search-forward "%" nil t)
582 (setq user-defined nil
590 (setq spec-beg (1- (point)))
592 ;; Parse this spec fully.
595 ((looking-at "\\([-.0-9]+\\)\\(,[-0-9]+\\)?")
596 (setq pad-width (string-to-number (match-string 1)))
597 (when (match-beginning 2)
598 (setq max-width (string-to-number (buffer-substring
599 (1+ (match-beginning 2))
601 (goto-char (match-end 0)))
604 (setq tilde (read (current-buffer))
608 ((memq type '(pad pad-left))
609 (setq pad-width value))
610 ((eq type 'pad-right)
611 (setq pad-width (- value)))
612 ((memq type '(max-right max))
613 (setq max-width value))
615 (setq max-width (- value)))
616 ((memq type '(cut cut-left))
617 (setq cut-width value))
618 ((eq type 'cut-right)
619 (setq cut-width (- value)))
622 (if (stringp value) value (format "%s" value))))
624 (setq tilde-form value))
626 (error "Unknown tilde type: %s" tilde)))
631 ;; User-defined spec -- find the spec name.
632 ((eq (setq spec (char-after)) ?u)
634 (when (and (eq (setq user-defined (char-after)) ?&)
635 (looking-at "&\\([^;]+\\);"))
636 (setq user-defined (match-string 1))
637 (goto-char (match-end 1))))
639 ((and (eq spec ?&) (looking-at "&\\([^;]+\\);"))
640 (setq extended-spec (intern (match-string 1)))
641 (goto-char (match-end 1))))
643 (delete-region spec-beg (point))
645 ;; Now we have all the relevant data on this spec, so
646 ;; we start doing stuff.
649 ;; "%%" just results in a "%".
654 (setq elem (list tilde-form ?s)))
655 ;; Treat user defined format specifiers specially.
659 (list (intern (format
660 (if (stringp user-defined)
661 "gnus-user-format-function-%s"
662 "gnus-user-format-function-%c")
666 ;; Find the specification from `spec-alist'.
667 ((setq elem (cdr (assq (or extended-spec spec) spec-alist))))
668 ;; We used to use "%l" for displaying the grouplens score.
670 (setq elem '("" ?s)))
672 (setq elem '("*" ?s))))
673 (setq elem-type (cadr elem))
674 ;; Insert the new format elements.
676 (not (and (featurep 'xemacs)
677 gnus-use-correct-string-widths)))
678 (insert (number-to-string pad-width)))
679 ;; Create the form to be evaled.
680 (if (or max-width cut-width ignore-value
681 (and (featurep 'xemacs)
682 gnus-use-correct-string-widths))
685 (let ((el (car elem)))
686 (cond ((= (cadr elem) ?c)
687 (setq el (list 'char-to-string el)))
689 (setq el (list 'int-to-string el))))
691 (setq el (gnus-tilde-ignore-form el ignore-value)))
693 (setq el (gnus-tilde-cut-form el cut-width)))
695 (setq el (gnus-tilde-max-form el max-width)))
697 (setq el (gnus-pad-form el pad-width)))
700 (push (car elem) flist))))
701 (setq fstring (buffer-substring-no-properties (point-min) (point-max))))
703 ;; Do some postprocessing to increase efficiency.
708 ((string= fstring "")
710 ;; Not a format string.
711 ((not (string-match "%" fstring))
713 ;; A format string with just a single string spec.
714 ((string= fstring "%s")
716 ;; A single character.
717 ((string= fstring "%c")
720 ((string= fstring "%d")
723 (list `(princ ,(car flist)))
724 (list `(int-to-string ,(car flist)))))
725 ;; Just lots of chars and strings.
726 ((string-match "\\`\\(%[cs]\\)+\\'" fstring)
728 ;; A single string spec at the beginning of the spec.
729 ((string-match "\\`%[sc][^%]+\\'" fstring)
730 (list (car flist) (substring fstring 2)))
731 ;; A single string spec in the middle of the spec.
732 ((string-match "\\`\\([^%]+\\)%[sc]\\([^%]+\\)\\'" fstring)
733 (list (match-string 1 fstring) (car flist) (match-string 2 fstring)))
734 ;; A single string spec in the end of the spec.
735 ((string-match "\\`\\([^%]+\\)%[sc]\\'" fstring)
736 (list (match-string 1 fstring) (car flist)))
737 ;; Only string (and %) specs (XEmacs only!)
738 ((and (featurep 'xemacs)
739 gnus-make-format-preserve-properties
741 "\\`\\([^%]*\\(%%\\|%-?\\([1-9][0-9]*\\)?s\\)\\)*[^%]*\\'"
743 (list (cons 'gnus-xmas-format (cons fstring (nreverse flist)))))
744 ;; A more complex spec.
746 (list (cons 'format (cons fstring (nreverse flist)))))))
752 (cons 'insert result)))
753 (cond ((stringp result)
756 (cons 'concat result))
759 (defun gnus-eval-format (format &optional alist props)
760 "Eval the format variable FORMAT, using ALIST.
761 If PROPS, insert the result."
762 (let ((form (gnus-parse-format format alist props)))
764 (gnus-add-text-properties (point) (progn (eval form) (point)) props)
767 (defun gnus-compile ()
768 "Byte-compile the user-defined format specs."
771 (let ((entries gnus-format-specs)
772 (byte-compile-warnings '(unresolved callargs redefine))
773 entry type compiled-function)
775 (gnus-message 7 "Compiling format specs...")
778 (setq entry (pop entries)
780 (if (memq type '(gnus-version version))
781 (setq gnus-format-specs (delq entry gnus-format-specs))
782 (let ((form (caddr entry)))
783 (when (and (listp form)
784 ;; Under GNU Emacs, it's (byte-code ...)
785 (not (eq 'byte-code (car form)))
786 ;; Under XEmacs, it's (funcall #<compiled-function ...>)
787 (not (and (eq 'funcall (car form))
788 (byte-code-function-p (cadr form)))))
789 (defalias 'gnus-tmp-func `(lambda () ,form))
790 (byte-compile 'gnus-tmp-func)
791 (setq compiled-function (gnus-byte-code 'gnus-tmp-func))
792 (set (intern (format "gnus-%s-line-format-spec" type))
794 (let ((elem (cdr (assq type gnus-format-specs-compiled))))
796 (set-alist 'elem (cadr entry) compiled-function)
797 (setq elem (list (cadr entry) compiled-function)))
798 (set-alist 'gnus-format-specs-compiled type elem))))))
800 (push (cons 'version emacs-version) gnus-format-specs)
801 (gnus-message 7 "Compiling user specs...done"))))
803 (defun gnus-set-format (type &optional insertable)
804 (set (intern (format "gnus-%s-line-format-spec" type))
806 (symbol-value (intern (format "gnus-%s-line-format" type)))
807 (symbol-value (intern (format "gnus-%s-line-format-alist" type)))
815 ;; coding: iso-8859-1
818 ;;; gnus-spec.el ends here