1 ;;; gnus-spec.el --- format spec functions for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
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., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, 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."
41 (defcustom gnus-make-format-preserve-properties (featurep 'xemacs)
42 "*If non-nil, use a replacement `format' function which preserves
43 text properties. This is only needed on XEmacs, as FSF Emacs does this anyway."
48 ;;; Internal variables.
50 (defvar gnus-summary-mark-positions nil)
51 (defvar gnus-group-mark-positions nil)
52 (defvar gnus-group-indentation "")
54 ;; Format specs. The chunks below are the machine-generated forms
55 ;; that are to be evaled as the result of the default format strings.
56 ;; We write them in here to get them byte-compiled. That way the
57 ;; default actions will be quite fast, while still retaining the full
58 ;; flexibility of the user-defined format specs.
60 ;; First we have lots of dummy defvars to let the compiler know these
61 ;; are really dynamic variables.
63 (defvar gnus-tmp-unread)
64 (defvar gnus-tmp-replied)
65 (defvar gnus-tmp-score-char)
66 (defvar gnus-tmp-indentation)
67 (defvar gnus-tmp-opening-bracket)
68 (defvar gnus-tmp-lines)
69 (defvar gnus-tmp-name)
70 (defvar gnus-tmp-closing-bracket)
71 (defvar gnus-tmp-subject-or-nil)
72 (defvar gnus-tmp-subject)
73 (defvar gnus-tmp-marked)
74 (defvar gnus-tmp-marked-mark)
75 (defvar gnus-tmp-subscribed)
76 (defvar gnus-tmp-process-marked)
77 (defvar gnus-tmp-number-of-unread)
78 (defvar gnus-tmp-group-name)
79 (defvar gnus-tmp-group)
80 (defvar gnus-tmp-article-number)
81 (defvar gnus-tmp-unread-and-unselected)
82 (defvar gnus-tmp-news-method)
83 (defvar gnus-tmp-news-server)
84 (defvar gnus-tmp-article-number)
85 (defvar gnus-mouse-face)
86 (defvar gnus-mouse-face-prop)
87 (defvar gnus-tmp-header)
88 (defvar gnus-tmp-from)
90 (defun gnus-summary-line-format-spec ()
91 (insert gnus-tmp-unread gnus-tmp-replied
92 gnus-tmp-score-char gnus-tmp-indentation)
93 (gnus-put-text-property
97 (format "%c%4s: %-23s%c" gnus-tmp-opening-bracket gnus-tmp-lines
100 (gnus-summary-from-or-to-or-newsgroups
101 gnus-tmp-header gnus-tmp-from))))
102 (if (> (length val) 23)
105 gnus-tmp-closing-bracket))
107 gnus-mouse-face-prop gnus-mouse-face)
108 (insert " " gnus-tmp-subject-or-nil "\n"))
110 (defvar gnus-summary-line-format-spec
111 (gnus-byte-code 'gnus-summary-line-format-spec))
113 (defun gnus-summary-dummy-line-format-spec ()
115 (gnus-put-text-property
120 gnus-mouse-face-prop gnus-mouse-face)
121 (insert " " gnus-tmp-subject "\n"))
123 (defvar gnus-summary-dummy-line-format-spec
124 (gnus-byte-code 'gnus-summary-dummy-line-format-spec))
126 (defun gnus-group-line-format-spec ()
127 (insert gnus-tmp-marked-mark gnus-tmp-subscribed
128 gnus-tmp-process-marked
129 gnus-group-indentation
130 (format "%5s: " gnus-tmp-number-of-unread))
131 (gnus-put-text-property
134 (insert gnus-tmp-group "\n")
136 gnus-mouse-face-prop gnus-mouse-face))
137 (defvar gnus-group-line-format-spec
138 (gnus-byte-code 'gnus-group-line-format-spec))
140 (defvar gnus-format-specs
141 `((group ("%M\%S\%p\%P\%5y: %(%g%)\n" ,gnus-group-line-format-spec))
142 (summary-dummy ("* %(: :%) %S\n"
143 ,gnus-summary-dummy-line-format-spec))
144 (summary ("%U%R%z%I%(%[%4L: %-23,23f%]%) %s\n"
145 ,gnus-summary-line-format-spec)))
146 "Alist of format specs.")
148 (defvar gnus-default-format-specs gnus-format-specs)
150 (defvar gnus-format-specs-compiled nil
151 "Alist of compiled format specs. Each element should be the form:
152 \(TYPE (FORMAT-STRING-1 . COMPILED-FUNCTION-1)
154 (FORMAT-STRING-n . COMPILED-FUNCTION-n)).")
156 (defvar gnus-article-mode-line-format-spec nil)
157 (defvar gnus-summary-mode-line-format-spec nil)
158 (defvar gnus-group-mode-line-format-spec nil)
160 ;;; Phew. All that gruft is over with, fortunately.
163 (defun gnus-update-format (var)
164 "Update the format specification near point."
169 ;; Find the end of the current word.
170 (re-search-forward "[ \t\n]" nil t)
172 (when (re-search-backward "\\(gnus-[-a-z]+-line-format\\)" nil t)
174 (let* ((type (intern (progn (string-match "gnus-\\([-a-z]+\\)-line" var)
175 (match-string 1 var))))
176 (value (symbol-value (intern var)))
178 (intern (format "%s-spec" var))
180 value (symbol-value (intern (format "%s-alist" var)))
181 (not (string-match "mode" var)))))
182 (entry (assq type gnus-format-specs)))
184 (let ((elem (assoc value entry)))
187 (setcdr entry (cons (cons value elem) (cdr entry)))))
188 (push (list type (cons value spec)) gnus-format-specs))
189 (gnus-product-variable-touch 'gnus-format-specs)
191 (pop-to-buffer "*Gnus Format*")
193 (lisp-interaction-mode)
194 (insert (gnus-pp-to-string spec))))
196 (eval-when-compile (defvar unchanged))
198 (put 'gnus-search-or-regist-spec 'lisp-indent-function 4)
199 (defmacro gnus-search-or-regist-spec (specs type format val &rest body)
200 `(let* ((entry (assq ,type ,specs))
201 (elem (assoc ,format (cdr entry))))
202 ;; That `(cdr elem)' returns non-nil means the spec for `type'
203 ;; doesn't need to be updated.
205 ;; This variable is set beforehand.
207 ;; Update the spec. Where `body' will modify `val'. This
208 ;; section will be skipped if compiling the spec is disabled.
213 (setcdr entry (cons (cons ,format ,val) (cdr entry))))
214 (push (list ,type (cons ,format ,val)) ,specs))
215 (gnus-product-variable-touch (quote ,specs)))
216 ;; Return the new spec without compiling.
219 (defun gnus-update-format-specification-1 (type format val)
220 (set (intern (format "gnus-%s-line-format-spec" type))
221 (gnus-search-or-regist-spec
222 gnus-format-specs-compiled type format val
223 (when (and gnus-compile-user-specs val)
226 (fset 'gnus-tmp-func `(lambda () ,val))
228 (let (byte-compile-warnings)
229 (byte-compile 'gnus-tmp-func))
230 (gnus-byte-code 'gnus-tmp-func))
231 (when (get-buffer "*Compile-Log*")
232 (bury-buffer "*Compile-Log*"))
233 (when (get-buffer "*Compile-Log-Show*")
234 (bury-buffer "*Compile-Log-Show*"))))))))
236 (defun gnus-update-format-specifications (&optional force &rest types)
237 "Update all (necessary) format specifications.
238 Return a list of updated types."
239 ;; Make the indentation array.
240 ;; See whether all the stored info needs to be flushed.
242 (message "%s" "Force update format specs.")
243 (setq gnus-format-specs nil
244 gnus-format-specs-compiled nil)
245 (gnus-product-variable-touch 'gnus-format-specs
246 'gnus-format-specs-compiled))
247 ;; Flush the group format spec cache if there's the grouplens stuff
248 ;; or it doesn't support decoded group names.
249 (when (memq 'group types)
250 (let* ((spec (assq 'group gnus-format-specs))
251 (sspec (gnus-prin1-to-string (nth 2 spec))))
252 (when (or (string-match " gnus-tmp-grouplens[ )]" sspec)
253 (not (string-match " gnus-tmp-decoded-group[ )]" sspec)))
254 (setq gnus-format-specs (delq spec gnus-format-specs)
255 spec (assq 'group gnus-format-specs-compiled)
256 gnus-format-specs-compiled (delq spec
257 gnus-format-specs-compiled)))))
259 ;; Go through all the formats and see whether they need updating.
260 (let (new-format type val unchanged updated)
262 (while (setq type (pop types))
263 ;; Jump to the proper buffer to find out the value of the
264 ;; variable, if possible. (It may be buffer-local.)
265 (let ((buffer (intern (format "gnus-%s-buffer" type))))
266 (when (and (boundp buffer)
267 (setq val (symbol-value buffer))
268 (gnus-buffer-exists-p val))
270 (setq new-format (symbol-value
271 (intern (format "gnus-%s-line-format" type)))))
273 (or (gnus-update-format-specification-1 type new-format nil)
274 ;; This is a new format.
275 (gnus-update-format-specification-1
277 (gnus-search-or-regist-spec
278 gnus-format-specs type new-format val
279 (setq val (if (stringp new-format)
280 ;; This is a "real" format.
284 (intern (format "gnus-%s-line-format-alist"
286 (not (string-match "mode$"
287 (symbol-name type))))
288 ;; This is a function call or something.
291 (push type updated))))
294 (defvar gnus-mouse-face-0 'highlight)
295 (defvar gnus-mouse-face-1 'highlight)
296 (defvar gnus-mouse-face-2 'highlight)
297 (defvar gnus-mouse-face-3 'highlight)
298 (defvar gnus-mouse-face-4 'highlight)
300 (defun gnus-mouse-face-function (form type)
301 `(gnus-put-text-property
302 (point) (progn ,@form (point))
306 `(quote ,(symbol-value (intern (format "gnus-mouse-face-%d" type)))))))
308 (defvar gnus-face-0 'bold)
309 (defvar gnus-face-1 'italic)
310 (defvar gnus-face-2 'bold-italic)
311 (defvar gnus-face-3 'bold)
312 (defvar gnus-face-4 'bold)
314 (defun gnus-face-face-function (form type)
315 `(gnus-add-text-properties
316 (point) (progn ,@form (point))
317 '(gnus-face t face ,(symbol-value (intern (format "gnus-face-%d" type))))))
319 (defun gnus-balloon-face-function (form type)
320 `(gnus-put-text-property
321 (point) (progn ,@form (point))
322 ,(if (fboundp 'balloon-help-mode)
325 ,(intern (format "gnus-balloon-face-%d" type))))
327 (defun gnus-spec-tab (column)
329 `(insert-char ? (max (- ,column (current-column)) 0))
330 (let ((column (abs column)))
331 `(if (> (current-column) ,column)
333 (if (= (move-to-column ,column) ,column)
334 (delete-region (point) end)
335 (delete-region (1- (point)) end)
337 (insert-char ? (max (- ,column (current-column)) 0))))))
339 (defun gnus-correct-length (string)
340 "Return the correct width of STRING."
342 (mapcar (lambda (char) (incf length (char-width char))) string)
345 (defun gnus-correct-substring (string start &optional end)
350 (length (length string))
351 (string (concat string "\0")))
352 ;; Find the start position.
353 (while (and (< seek length)
355 (incf wseek (char-width (aref string seek)))
358 ;; Find the end position.
359 (while (and (<= seek length)
362 (incf wseek (char-width (aref string seek)))
365 (substring string wstart (1- wend))))
367 (defun gnus-string-width-function ()
369 (gnus-use-correct-string-widths
370 'gnus-correct-length)
371 ((fboundp 'string-width)
376 (defun gnus-substring-function ()
378 (gnus-use-correct-string-widths
379 'gnus-correct-substring)
380 ((fboundp 'string-width)
381 'gnus-correct-substring)
385 (defun gnus-tilde-max-form (el max-width)
386 "Return a form that limits EL to MAX-WIDTH."
387 (let ((max (abs max-width))
388 (length-fun (gnus-string-width-function))
389 (substring-fun (gnus-substring-function)))
391 `(if (> (,length-fun ,el) ,max)
393 `(,substring-fun ,el (- (,length-fun ,el) ,max))
394 `(,substring-fun ,el 0 ,max))
396 `(let ((val (eval ,el)))
397 (if (> (,length-fun val) ,max)
399 `(,substring-fun val (- (,length-fun val) ,max))
400 `(,substring-fun val 0 ,max))
403 (defun gnus-tilde-cut-form (el cut-width)
404 "Return a form that cuts CUT-WIDTH off of EL."
405 (let ((cut (abs cut-width))
406 (length-fun (gnus-string-width-function))
407 (substring-fun (gnus-substring-function)))
409 `(if (> (,length-fun ,el) ,cut)
411 `(,substring-fun ,el 0 (- (,length-fun ,el) ,cut))
412 `(,substring-fun ,el ,cut))
414 `(let ((val (eval ,el)))
415 (if (> (,length-fun val) ,cut)
417 `(,substring-fun val 0 (- (,length-fun val) ,cut))
418 `(,substring-fun val ,cut))
421 (defun gnus-tilde-ignore-form (el ignore-value)
422 "Return a form that is blank when EL is IGNORE-VALUE."
424 `(if (equal ,el ,ignore-value)
426 `(let ((val (eval ,el)))
427 (if (equal val ,ignore-value)
430 (defun gnus-pad-form (el pad-width)
431 "Return a form that pads EL to PAD-WIDTH accounting for multi-column
432 characters correctly. This is because `format' may pad to columns or to
433 characters when given a pad value."
434 (let ((pad (abs pad-width))
435 (side (< 0 pad-width))
436 (length-fun (gnus-string-width-function)))
438 `(let ((need (- ,pad (,length-fun ,el))))
440 (concat ,(when side '(make-string need ?\ ))
442 ,(when (not side) '(make-string need ?\ )))
444 `(let* ((val (eval ,el))
445 (need (- ,pad (,length-fun val))))
447 (concat ,(when side '(make-string need ?\ ))
449 ,(when (not side) '(make-string need ?\ )))
452 (defun gnus-parse-format (format spec-alist &optional insert)
453 ;; This function parses the FORMAT string with the help of the
454 ;; SPEC-ALIST and returns a list that can be eval'ed to return the
455 ;; string. If the FORMAT string contains the specifiers %( and %)
456 ;; the text between them will have the mouse-face text property.
457 ;; If the FORMAT string contains the specifiers %[ and %], the text between
458 ;; them will have the balloon-help text property.
459 (let ((case-fold-search nil))
461 "\\`\\(.*\\)%[0-9]?[{(«]\\(.*\\)%[0-9]?[»})]\\(.*\n?\\)\\'\\|%[-0-9]*=\\|%[-0-9]*\\*"
463 (gnus-parse-complex-format format spec-alist)
464 ;; This is a simple format.
465 (gnus-parse-simple-format format spec-alist insert))))
467 (defun gnus-parse-complex-format (format spec-alist)
468 (let ((cursor-spec nil))
470 (gnus-set-work-buffer)
472 (goto-char (point-min))
473 (while (re-search-forward "\"" nil t)
474 (replace-match "\\\"" nil t))
475 (goto-char (point-min))
477 ;; Convert all font specs into font spec lists.
478 (while (re-search-forward "%\\([0-9]+\\)?\\([«»{}()]\\)" nil t)
479 (let ((number (if (match-beginning 1)
480 (match-string 1) "0"))
481 (delim (aref (match-string 2) 0)))
482 (if (or (= delim ?\()
485 (replace-match (concat "\"("
486 (cond ((= delim ?\() "mouse")
487 ((= delim ?\{) "face")
491 (replace-match "\")\""))))
492 (goto-char (point-max))
494 ;; Convert point position commands.
495 (goto-char (point-min))
496 (let ((case-fold-search nil))
497 (while (re-search-forward "%\\([-0-9]+\\)?\\*" nil t)
498 (replace-match "\"(point)\"" t t)
499 (setq cursor-spec t)))
500 ;; Convert TAB commands.
501 (goto-char (point-min))
502 (while (re-search-forward "%\\([-0-9]+\\)=" nil t)
503 (replace-match (format "\"(tab %s)\"" (match-string 1)) t t))
504 ;; Convert the buffer into the spec.
505 (goto-char (point-min))
506 (let ((form (read (current-buffer))))
508 `(let (gnus-position)
509 ,@(gnus-complex-form-to-spec form spec-alist)
511 (gnus-put-text-property gnus-position (1+ gnus-position)
514 ,@(gnus-complex-form-to-spec form spec-alist)))))))
516 (defun gnus-complex-form-to-spec (form spec-alist)
522 (gnus-parse-simple-format sform spec-alist t))
523 ((eq (car sform) 'point)
524 '(setq gnus-position (point)))
525 ((eq (car sform) 'tab)
526 (gnus-spec-tab (cadr sform)))
528 (funcall (intern (format "gnus-%s-face-function" (car sform)))
529 (gnus-complex-form-to-spec (cddr sform) spec-alist)
534 (defun gnus-xmas-format (fstring &rest args)
535 "A version of `format' which preserves text properties.
537 Required for XEmacs, where the built in `format' function strips all text
538 properties from both the format string and any inserted strings.
540 Only supports the format sequence %s, and %% for inserting
541 literal % characters. A pad width and an optional - (to right pad)
542 are supported for %s."
543 (let ((re "%%\\|%\\(-\\)?\\([1-9][0-9]*\\)?s")
547 (goto-char (point-min))
548 (while (re-search-forward re nil t)
549 (goto-char (match-end 0))
551 ((string= (match-string 0) "%%")
555 (error 'wrong-number-of-arguments #'my-format n fstring))
556 (let* ((minlen (string-to-number (or (match-string 2) "")))
558 (str (if (stringp arg) arg (format "%s" arg)))
559 (lpad (null (match-string 1)))
560 (padlen (max 0 (- minlen (length str)))))
562 (if lpad (insert-char ?\ padlen))
564 (unless lpad (insert-char ?\ padlen))
565 (setq args (cdr args))))))
568 (defun gnus-parse-simple-format (format spec-alist &optional insert)
569 ;; This function parses the FORMAT string with the help of the
570 ;; SPEC-ALIST and returns a list that can be eval'ed to return a
573 spec flist fstring elem result dontinsert user-defined
574 type value pad-width spec-beg cut-width ignore-value
575 tilde-form tilde elem-type extended-spec)
577 (gnus-set-work-buffer)
579 (goto-char (point-min))
580 (while (search-forward "%" nil t)
581 (setq user-defined nil
589 (setq spec-beg (1- (point)))
591 ;; Parse this spec fully.
594 ((looking-at "\\([-.0-9]+\\)\\(,[-0-9]+\\)?")
595 (setq pad-width (string-to-number (match-string 1)))
596 (when (match-beginning 2)
597 (setq max-width (string-to-number (buffer-substring
598 (1+ (match-beginning 2))
600 (goto-char (match-end 0)))
603 (setq tilde (read (current-buffer))
607 ((memq type '(pad pad-left))
608 (setq pad-width value))
609 ((eq type 'pad-right)
610 (setq pad-width (- value)))
611 ((memq type '(max-right max))
612 (setq max-width value))
614 (setq max-width (- value)))
615 ((memq type '(cut cut-left))
616 (setq cut-width value))
617 ((eq type 'cut-right)
618 (setq cut-width (- value)))
621 (if (stringp value) value (format "%s" value))))
623 (setq tilde-form value))
625 (error "Unknown tilde type: %s" tilde)))
630 ;; User-defined spec -- find the spec name.
631 ((eq (setq spec (char-after)) ?u)
633 (when (and (eq (setq user-defined (char-after)) ?&)
634 (looking-at "&\\([^;]+\\);"))
635 (setq user-defined (match-string 1))
636 (goto-char (match-end 1))))
638 ((and (eq spec ?&) (looking-at "&\\([^;]+\\);"))
639 (setq extended-spec (intern (match-string 1)))
640 (goto-char (match-end 1))))
642 (delete-region spec-beg (point))
644 ;; Now we have all the relevant data on this spec, so
645 ;; we start doing stuff.
648 ;; "%%" just results in a "%".
653 (setq elem (list tilde-form ?s)))
654 ;; Treat user defined format specifiers specially.
658 (list (intern (format
659 (if (stringp user-defined)
660 "gnus-user-format-function-%s"
661 "gnus-user-format-function-%c")
665 ;; Find the specification from `spec-alist'.
666 ((setq elem (cdr (assq (or extended-spec spec) spec-alist))))
667 ;; We used to use "%l" for displaying the grouplens score.
669 (setq elem '("" ?s)))
671 (setq elem '("*" ?s))))
672 (setq elem-type (cadr elem))
673 ;; Insert the new format elements.
675 (not (and (featurep 'xemacs)
676 gnus-use-correct-string-widths)))
677 (insert (number-to-string pad-width)))
678 ;; Create the form to be evaled.
679 (if (or max-width cut-width ignore-value
680 (and (featurep 'xemacs)
681 gnus-use-correct-string-widths))
684 (let ((el (car elem)))
685 (cond ((= (cadr elem) ?c)
686 (setq el (list 'char-to-string el)))
688 (setq el (list 'int-to-string el))))
690 (setq el (gnus-tilde-ignore-form el ignore-value)))
692 (setq el (gnus-tilde-cut-form el cut-width)))
694 (setq el (gnus-tilde-max-form el max-width)))
696 (setq el (gnus-pad-form el pad-width)))
699 (push (car elem) flist))))
700 (setq fstring (buffer-substring-no-properties (point-min) (point-max))))
702 ;; Do some postprocessing to increase efficiency.
707 ((string= fstring "")
709 ;; Not a format string.
710 ((not (string-match "%" fstring))
712 ;; A format string with just a single string spec.
713 ((string= fstring "%s")
715 ;; A single character.
716 ((string= fstring "%c")
719 ((string= fstring "%d")
722 (list `(princ ,(car flist)))
723 (list `(int-to-string ,(car flist)))))
724 ;; Just lots of chars and strings.
725 ((string-match "\\`\\(%[cs]\\)+\\'" fstring)
727 ;; A single string spec at the beginning of the spec.
728 ((string-match "\\`%[sc][^%]+\\'" fstring)
729 (list (car flist) (substring fstring 2)))
730 ;; A single string spec in the middle of the spec.
731 ((string-match "\\`\\([^%]+\\)%[sc]\\([^%]+\\)\\'" fstring)
732 (list (match-string 1 fstring) (car flist) (match-string 2 fstring)))
733 ;; A single string spec in the end of the spec.
734 ((string-match "\\`\\([^%]+\\)%[sc]\\'" fstring)
735 (list (match-string 1 fstring) (car flist)))
736 ;; Only string (and %) specs (XEmacs only!)
737 ((and (featurep 'xemacs)
738 gnus-make-format-preserve-properties
740 "\\`\\([^%]*\\(%%\\|%-?\\([1-9][0-9]*\\)?s\\)\\)*[^%]*\\'"
742 (list (cons 'gnus-xmas-format (cons fstring (nreverse flist)))))
743 ;; A more complex spec.
745 (list (cons 'format (cons fstring (nreverse flist)))))))
751 (cons 'insert result)))
752 (cond ((stringp result)
755 (cons 'concat result))
758 (defun gnus-eval-format (format &optional alist props)
759 "Eval the format variable FORMAT, using ALIST.
760 If PROPS, insert the result."
761 (let ((form (gnus-parse-format format alist props)))
763 (gnus-add-text-properties (point) (progn (eval form) (point)) props)
766 (defun gnus-compile ()
767 "Byte-compile the user-defined format specs."
770 (let ((entries gnus-format-specs)
771 (byte-compile-warnings '(unresolved callargs redefine))
772 entry type compiled-function)
774 (gnus-message 7 "Compiling format specs...")
777 (setq entry (pop entries)
779 (if (memq type '(gnus-version version))
780 (setq gnus-format-specs (delq entry gnus-format-specs))
781 (let ((form (caddr entry)))
782 (when (and (listp form)
783 ;; Under GNU Emacs, it's (byte-code ...)
784 (not (eq 'byte-code (car form)))
785 ;; Under XEmacs, it's (funcall #<compiled-function ...>)
786 (not (and (eq 'funcall (car form))
787 (byte-code-function-p (cadr form)))))
788 (defalias 'gnus-tmp-func `(lambda () ,form))
789 (byte-compile 'gnus-tmp-func)
790 (setq compiled-function (gnus-byte-code 'gnus-tmp-func))
791 (set (intern (format "gnus-%s-line-format-spec" type))
793 (let ((elem (cdr (assq type gnus-format-specs-compiled))))
795 (set-alist 'elem (cadr entry) compiled-function)
796 (setq elem (list (cadr entry) compiled-function)))
797 (set-alist 'gnus-format-specs-compiled type elem))))))
799 (push (cons 'version emacs-version) gnus-format-specs)
800 (gnus-message 7 "Compiling user specs...done"))))
802 (defun gnus-set-format (type &optional insertable)
803 (set (intern (format "gnus-%s-line-format-spec" type))
805 (symbol-value (intern (format "gnus-%s-line-format" type)))
806 (symbol-value (intern (format "gnus-%s-line-format-alist" type)))
814 ;; coding: iso-8859-1
817 ;;; gnus-spec.el ends here