1 ;;; gnus-spec.el --- format spec functions for Gnus
3 ;; Copyright (C) 1996-2012 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
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 3 of the License, or
13 ;; (at your option) any later version.
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.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;; For Emacs <22.2 and XEmacs.
29 (unless (fboundp 'declare-function
) (defmacro declare-function
(&rest r
))))
30 (eval-when-compile (require 'cl
))
31 (defvar gnus-newsrc-file-version
)
35 (defcustom gnus-use-correct-string-widths
(featurep 'xemacs
)
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 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 evalled 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 (declare-function gnus-summary-from-or-to-or-newsgroups
"gnus-sum"
91 (header gnus-tmp-from
))
93 (defmacro gnus-lrm-string-p
(string)
94 (if (fboundp 'bidi-string-mark-left-to-right
)
95 ;; LRM, RLM, PDF characters as integers to avoid breaking Emacs
97 `(memq (aref ,string
(1- (length ,string
))) '(8206 8207 8236))
100 (defvar gnus-lrm-string
(if (ignore-errors (string 8206))
101 (propertize (string 8206) 'invisible t
)
104 (defun gnus-summary-line-format-spec ()
105 (insert gnus-tmp-unread gnus-tmp-replied
106 gnus-tmp-score-char gnus-tmp-indentation
)
107 (gnus-put-text-property
111 (format "%c%4s: %-23s%c" gnus-tmp-opening-bracket gnus-tmp-lines
114 (gnus-summary-from-or-to-or-newsgroups
115 gnus-tmp-header gnus-tmp-from
))))
116 (if (> (length val
) 23)
117 (if (gnus-lrm-string-p val
)
118 (concat (substring val
0 23) gnus-lrm-string
)
119 (substring val
0 23))
121 gnus-tmp-closing-bracket
))
123 gnus-mouse-face-prop gnus-mouse-face
)
124 (insert " " gnus-tmp-subject-or-nil
"\n"))
126 (defvar gnus-summary-line-format-spec
127 (gnus-byte-code 'gnus-summary-line-format-spec
))
129 (defun gnus-summary-dummy-line-format-spec ()
131 (gnus-put-text-property
136 gnus-mouse-face-prop gnus-mouse-face
)
137 (insert " " gnus-tmp-subject
"\n"))
139 (defvar gnus-summary-dummy-line-format-spec
140 (gnus-byte-code 'gnus-summary-dummy-line-format-spec
))
142 (defun gnus-group-line-format-spec ()
143 (insert gnus-tmp-marked-mark gnus-tmp-subscribed
144 gnus-tmp-process-marked
145 gnus-group-indentation
146 (format "%5s: " gnus-tmp-number-of-unread
))
147 (gnus-put-text-property
150 (insert gnus-tmp-group
"\n")
152 gnus-mouse-face-prop gnus-mouse-face
))
153 (defvar gnus-group-line-format-spec
154 (gnus-byte-code 'gnus-group-line-format-spec
))
156 (defvar gnus-format-specs
157 `((version .
,emacs-version
)
158 (gnus-version .
,(gnus-continuum-version))
159 (group "%M\%S\%p\%P\%5y: %(%g%)\n" ,gnus-group-line-format-spec
)
160 (summary-dummy "* %(: :%) %S\n"
161 ,gnus-summary-dummy-line-format-spec
)
162 (summary "%U%R%z%I%(%[%4L: %-23,23f%]%) %s\n"
163 ,gnus-summary-line-format-spec
))
164 "Alist of format specs.")
166 (defvar gnus-default-format-specs gnus-format-specs
)
168 (defvar gnus-article-mode-line-format-spec nil
)
169 (defvar gnus-summary-mode-line-format-spec nil
)
170 (defvar gnus-group-mode-line-format-spec nil
)
172 ;;; Phew. All that gruft is over with, fortunately.
175 (defun gnus-update-format (var)
176 "Update the format specification near point."
181 ;; Find the end of the current word.
182 (re-search-forward "[ \t\n]" nil t
)
184 (when (re-search-backward "\\(gnus-[-a-z]+-line-format\\)" nil t
)
186 (let* ((type (intern (progn (string-match "gnus-\\([-a-z]+\\)-line" var
)
187 (match-string 1 var
))))
188 (entry (assq type gnus-format-specs
))
191 (setq gnus-format-specs
(delq entry gnus-format-specs
)))
193 (intern (format "%s-spec" var
))
194 (gnus-parse-format (setq value
(symbol-value (intern var
)))
195 (symbol-value (intern (format "%s-alist" var
)))
196 (not (string-match "mode" var
))))
197 (setq spec
(symbol-value (intern (format "%s-spec" var
))))
198 (push (list type value spec
) gnus-format-specs
)
200 (pop-to-buffer "*Gnus Format*")
202 (lisp-interaction-mode)
203 (insert (gnus-pp-to-string spec
))))
205 (defun gnus-update-format-specifications (&optional force
&rest types
)
206 "Update all (necessary) format specifications.
207 Return a list of updated types."
208 ;; Make the indentation array.
209 ;; See whether all the stored info needs to be flushed.
211 (not gnus-newsrc-file-version
)
212 (not (equal (gnus-continuum-version)
213 (gnus-continuum-version gnus-newsrc-file-version
)))
214 (not (equal emacs-version
215 (cdr (assq 'version gnus-format-specs
)))))
216 (setq gnus-format-specs nil
))
217 ;; Flush the group format spec cache if there's the grouplens stuff
218 ;; or it doesn't support decoded group names.
219 (when (memq 'group types
)
220 (let* ((spec (assq 'group gnus-format-specs
))
221 (sspec (gnus-prin1-to-string (nth 2 spec
))))
222 (when (or (string-match " gnus-tmp-grouplens[ )]" sspec
)
223 (not (string-match " gnus-tmp-decoded-group[ )]" sspec
)))
224 (setq gnus-format-specs
(delq spec gnus-format-specs
)))))
226 ;; Go through all the formats and see whether they need updating.
227 (let (new-format entry type val updated
)
228 (while (setq type
(pop types
))
229 ;; Jump to the proper buffer to find out the value of the
230 ;; variable, if possible. (It may be buffer-local.)
232 (let ((buffer (intern (format "gnus-%s-buffer" type
))))
233 (when (and (boundp buffer
)
234 (setq val
(symbol-value buffer
))
235 (gnus-buffer-exists-p val
))
237 (setq new-format
(symbol-value
238 (intern (format "gnus-%s-line-format" type
)))))
239 (setq entry
(cdr (assq type gnus-format-specs
)))
241 (equal (car entry
) new-format
))
242 ;; Use the old format.
243 (set (intern (format "gnus-%s-line-format-spec" type
))
245 ;; This is a new format.
247 (if (not (stringp new-format
))
248 ;; This is a function call or something.
250 ;; This is a "real" format.
254 (intern (format "gnus-%s-line-format-alist" type
)))
255 (not (string-match "mode$" (symbol-name type
))))))
256 ;; Enter the new format spec into the list.
259 (setcar (cdr entry
) val
)
260 (setcar entry new-format
))
261 (push (list type new-format val
) gnus-format-specs
))
262 (set (intern (format "gnus-%s-line-format-spec" type
)) val
)
263 (push type updated
))))
265 (unless (assq 'version gnus-format-specs
)
266 (push (cons 'version emacs-version
) gnus-format-specs
))
269 (defcustom gnus-mouse-face-0
'highlight
270 "The \"%(hello%)\" face."
274 (defcustom gnus-mouse-face-1
'highlight
275 "The \"%1(hello%)\" face."
279 (defcustom gnus-mouse-face-2
'highlight
280 "The \"%2(hello%)\" face."
284 (defcustom gnus-mouse-face-3
'highlight
285 "The \"%3(hello%)\" face."
289 (defcustom gnus-mouse-face-4
'highlight
290 "The \"%4(hello%)\" face."
294 (defun gnus-mouse-face-function (form type
)
295 `(gnus-put-text-property
296 (point) (progn ,@form
(point))
300 `(quote ,(symbol-value (intern (format "gnus-mouse-face-%d" type
)))))))
302 (defcustom gnus-face-0
'bold
303 "The \"%{hello%}\" face."
307 (defcustom gnus-face-1
'italic
308 "The \"%1{hello%}\" face."
312 (defcustom gnus-face-2
'bold-italic
313 "The \"%2{hello%}\" face."
317 (defcustom gnus-face-3
'bold
318 "The \"%3{hello%}\" face."
322 (defcustom gnus-face-4
'bold
323 "The \"%4{hello%}\" face."
327 (defun gnus-face-face-function (form type
)
328 `(gnus-add-text-properties
329 (point) (progn ,@form
(point))
330 '(gnus-face t face
,(symbol-value (intern (format "gnus-face-%d" type
))))))
332 (defun gnus-balloon-face-function (form type
)
333 `(gnus-put-text-property
334 (point) (progn ,@form
(point))
335 ,(if (fboundp 'balloon-help-mode
)
338 ,(intern (format "gnus-balloon-face-%d" type
))))
340 (defun gnus-spec-tab (column)
342 `(insert-char ?
(max (- ,column
(current-column)) 0))
343 (let ((column (abs column
)))
344 `(if (> (current-column) ,column
)
346 (if (= (move-to-column ,column
) ,column
)
347 (delete-region (point) end
)
348 (delete-region (1- (point)) end
)
350 (insert-char ?
(max (- ,column
(current-column)) 0))))))
352 (defun gnus-correct-length (string)
353 "Return the correct width of STRING."
354 (apply #'+ (mapcar #'char-width string
)))
356 (defun gnus-correct-substring (string start
&optional end
)
361 (length (length string
))
362 (string (concat string
"\0")))
363 ;; Find the start position.
364 (while (and (< seek length
)
366 (incf wseek
(char-width (aref string seek
)))
369 ;; Find the end position.
370 (while (and (<= seek length
)
373 (incf wseek
(char-width (aref string seek
)))
376 (substring string wstart
(1- wend
))))
378 (defun gnus-string-width-function ()
380 (gnus-use-correct-string-widths
381 'gnus-correct-length
)
382 ((fboundp 'string-width
)
387 (defun gnus-substring-function ()
389 (gnus-use-correct-string-widths
390 'gnus-correct-substring
)
391 ((fboundp 'string-width
)
392 'gnus-correct-substring
)
396 (defun gnus-tilde-max-form (el max-width
)
397 "Return a form that limits EL to MAX-WIDTH."
398 (let ((max (abs max-width
))
399 (length-fun (gnus-string-width-function))
400 (substring-fun (gnus-substring-function)))
402 `(if (> (,length-fun
,el
) ,max
)
404 `(,substring-fun
,el
(- (,length-fun
,el
) ,max
))
405 `(if (gnus-lrm-string-p ,el
)
406 (concat (,substring-fun
,el
0 ,max
) ,gnus-lrm-string
)
407 (,substring-fun
,el
0 ,max
)))
409 `(let ((val (eval ,el
)))
410 (if (> (,length-fun val
) ,max
)
412 `(,substring-fun val
(- (,length-fun val
) ,max
))
413 `(if (gnus-lrm-string-p val
)
414 (concat (,substring-fun val
0 ,max
) ,gnus-lrm-string
)
415 (,substring-fun val
0 ,max
)))
418 (defun gnus-tilde-cut-form (el cut-width
)
419 "Return a form that cuts CUT-WIDTH off of EL."
420 (let ((cut (abs cut-width
))
421 (length-fun (gnus-string-width-function))
422 (substring-fun (gnus-substring-function)))
424 `(if (> (,length-fun
,el
) ,cut
)
426 `(,substring-fun
,el
0 (- (,length-fun
,el
) ,cut
))
427 `(,substring-fun
,el
,cut
))
429 `(let ((val (eval ,el
)))
430 (if (> (,length-fun val
) ,cut
)
432 `(,substring-fun val
0 (- (,length-fun val
) ,cut
))
433 `(,substring-fun val
,cut
))
436 (defun gnus-tilde-ignore-form (el ignore-value
)
437 "Return a form that is blank when EL is IGNORE-VALUE."
439 `(if (equal ,el
,ignore-value
)
441 `(let ((val (eval ,el
)))
442 (if (equal val
,ignore-value
)
445 (defun gnus-pad-form (el pad-width
)
446 "Return a form that pads EL to PAD-WIDTH accounting for multi-column
447 characters correctly. This is because `format' may pad to columns or to
448 characters when given a pad value."
449 (let ((pad (abs pad-width
))
450 (side (< 0 pad-width
))
451 (length-fun (gnus-string-width-function)))
453 `(let ((need (- ,pad
(,length-fun
,el
))))
455 (concat ,(when side
'(make-string need ?\
))
457 ,(when (not side
) '(make-string need ?\
)))
459 `(let* ((val (eval ,el
))
460 (need (- ,pad
(,length-fun val
))))
462 (concat ,(when side
'(make-string need ?\
))
464 ,(when (not side
) '(make-string need ?\
)))
467 (defun gnus-parse-format (format spec-alist
&optional insert
)
468 ;; This function parses the FORMAT string with the help of the
469 ;; SPEC-ALIST and returns a list that can be eval'ed to return the
470 ;; string. If the FORMAT string contains the specifiers %( and %)
471 ;; the text between them will have the mouse-face text property.
472 ;; If the FORMAT string contains the specifiers %[ and %], the text between
473 ;; them will have the balloon-help text property.
474 (let ((case-fold-search nil
))
476 "\\`\\(.*\\)%[0-9]?[{(«]\\(.*\\)%[0-9]?[»})]\\(.*\n?\\)\\'\\|%[-0-9]*=\\|%[-0-9]*\\*"
478 (gnus-parse-complex-format format spec-alist
)
479 ;; This is a simple format.
480 (gnus-parse-simple-format format spec-alist insert
))))
482 (defun gnus-parse-complex-format (format spec-alist
)
483 (let ((cursor-spec nil
))
485 (gnus-set-work-buffer)
487 (goto-char (point-min))
488 (while (re-search-forward "\"" nil t
)
489 (replace-match "\\\"" nil t
))
490 (goto-char (point-min))
492 ;; Convert all font specs into font spec lists.
493 (while (re-search-forward "%\\([0-9]+\\)?\\([«»{}()]\\)" nil t
)
494 (let ((number (if (match-beginning 1)
495 (match-string 1) "0"))
496 (delim (aref (match-string 2) 0)))
497 (if (or (= delim ?\
()
500 (replace-match (concat "\"("
501 (cond ((= delim ?\
() "mouse")
502 ((= delim ?\
{) "face")
506 (replace-match "\")\""))))
507 (goto-char (point-max))
509 ;; Convert point position commands.
510 (goto-char (point-min))
511 (let ((case-fold-search nil
))
512 (while (re-search-forward "%\\([-0-9]+\\)?\\*" nil t
)
513 (replace-match "\"(point)\"" t t
)
514 (setq cursor-spec t
)))
515 ;; Convert TAB commands.
516 (goto-char (point-min))
517 (while (re-search-forward "%\\([-0-9]+\\)=" nil t
)
518 (replace-match (format "\"(tab %s)\"" (match-string 1)) t t
))
519 ;; Convert the buffer into the spec.
520 (goto-char (point-min))
521 (let ((form (read (current-buffer))))
523 `(let (gnus-position)
524 ,@(gnus-complex-form-to-spec form spec-alist
)
526 (gnus-put-text-property gnus-position
(1+ gnus-position
)
529 ,@(gnus-complex-form-to-spec form spec-alist
)))))))
531 (defun gnus-complex-form-to-spec (form spec-alist
)
537 (gnus-parse-simple-format sform spec-alist t
))
538 ((eq (car sform
) 'point
)
539 '(setq gnus-position
(point)))
540 ((eq (car sform
) 'tab
)
541 (gnus-spec-tab (cadr sform
)))
543 (funcall (intern (format "gnus-%s-face-function" (car sform
)))
544 (gnus-complex-form-to-spec (cddr sform
) spec-alist
)
549 (defun gnus-xmas-format (fstring &rest args
)
550 "A version of `format' which preserves text properties.
552 Required for XEmacs, where the built in `format' function strips all text
553 properties from both the format string and any inserted strings.
555 Only supports the format sequence %s, and %% for inserting
556 literal % characters. A pad width and an optional - (to right pad)
557 are supported for %s."
558 (let ((re "%%\\|%\\(-\\)?\\([1-9][0-9]*\\)?s")
562 (goto-char (point-min))
563 (while (re-search-forward re nil t
)
564 (goto-char (match-end 0))
566 ((string= (match-string 0) "%%")
570 (error 'wrong-number-of-arguments
#'my-format n fstring
))
571 (let* ((minlen (string-to-number (or (match-string 2) "")))
573 (str (if (stringp arg
) arg
(format "%s" arg
)))
574 (lpad (null (match-string 1)))
575 (padlen (max 0 (- minlen
(length str
)))))
577 (if lpad
(insert-char ?\ padlen
))
579 (unless lpad
(insert-char ?\ padlen
))
580 (setq args
(cdr args
))))))
583 (defun gnus-parse-simple-format (format spec-alist
&optional insert
)
584 ;; This function parses the FORMAT string with the help of the
585 ;; SPEC-ALIST and returns a list that can be eval'ed to return a
588 spec flist fstring elem result dontinsert user-defined
589 type value pad-width spec-beg cut-width ignore-value
590 tilde-form tilde elem-type extended-spec
)
592 (gnus-set-work-buffer)
594 (goto-char (point-min))
595 (while (re-search-forward "%" nil t
)
596 (setq user-defined nil
604 (setq spec-beg
(1- (point)))
606 ;; Parse this spec fully.
609 ((looking-at "\\([-.0-9]+\\)\\(,[-0-9]+\\)?")
610 (setq pad-width
(string-to-number (match-string 1)))
611 (when (match-beginning 2)
612 (setq max-width
(string-to-number (buffer-substring
613 (1+ (match-beginning 2))
615 (goto-char (match-end 0)))
618 (setq tilde
(read (current-buffer))
622 ((memq type
'(pad pad-left
))
623 (setq pad-width value
))
624 ((eq type
'pad-right
)
625 (setq pad-width
(- value
)))
626 ((memq type
'(max-right max
))
627 (setq max-width value
))
629 (setq max-width
(- value
)))
630 ((memq type
'(cut cut-left
))
631 (setq cut-width value
))
632 ((eq type
'cut-right
)
633 (setq cut-width
(- value
)))
636 (if (stringp value
) value
(format "%s" value
))))
638 (setq tilde-form value
))
640 (error "Unknown tilde type: %s" tilde
)))
645 ;; User-defined spec -- find the spec name.
646 ((eq (setq spec
(char-after)) ?u
)
648 (when (and (eq (setq user-defined
(char-after)) ?
&)
649 (looking-at "&\\([^;]+\\);"))
650 (setq user-defined
(match-string 1))
651 (goto-char (match-end 1))))
653 ((and (eq spec ?
&) (looking-at "&\\([^;]+\\);"))
654 (setq extended-spec
(intern (match-string 1)))
655 (goto-char (match-end 1))))
657 (delete-region spec-beg
(point))
659 ;; Now we have all the relevant data on this spec, so
660 ;; we start doing stuff.
663 ;; "%%" just results in a "%".
668 (setq elem
(list tilde-form ?s
)))
669 ;; Treat user defined format specifiers specially.
673 (list (intern (format
674 (if (stringp user-defined
)
675 "gnus-user-format-function-%s"
676 "gnus-user-format-function-%c")
680 ;; Find the specification from `spec-alist'.
681 ((setq elem
(cdr (assq (or extended-spec spec
) spec-alist
))))
682 ;; We used to use "%l" for displaying the grouplens score.
684 (setq elem
'("" ?s
)))
686 (setq elem
'("*" ?s
))))
687 (setq elem-type
(cadr elem
))
688 ;; Insert the new format elements.
690 (not (and (featurep 'xemacs
)
691 gnus-use-correct-string-widths
)))
692 (insert (number-to-string pad-width
)))
693 ;; Create the form to be evalled.
694 (if (or max-width cut-width ignore-value
695 (and (featurep 'xemacs
)
696 gnus-use-correct-string-widths
))
699 (let ((el (car elem
)))
700 (cond ((= (cadr elem
) ?c
)
701 (setq el
(list 'char-to-string el
)))
703 (setq el
(list 'int-to-string el
))))
705 (setq el
(gnus-tilde-ignore-form el ignore-value
)))
707 (setq el
(gnus-tilde-cut-form el cut-width
)))
709 (setq el
(gnus-tilde-max-form el max-width
)))
711 (setq el
(gnus-pad-form el pad-width
)))
714 (push (car elem
) flist
))))
715 (setq fstring
(buffer-substring-no-properties (point-min) (point-max))))
717 ;; Do some postprocessing to increase efficiency.
722 ((string= fstring
"")
724 ;; Not a format string.
725 ((not (string-match "%" fstring
))
727 ;; A format string with just a single string spec.
728 ((string= fstring
"%s")
730 ;; A single character.
731 ((string= fstring
"%c")
734 ((string= fstring
"%d")
737 `(insert (int-to-string ,(car flist
)))
738 (list `(int-to-string ,(car flist
)))))
739 ;; Just lots of chars and strings.
740 ((string-match "\\`\\(%[cs]\\)+\\'" fstring
)
742 ;; A single string spec at the beginning of the spec.
743 ((string-match "\\`%[sc][^%]+\\'" fstring
)
744 (list (car flist
) (substring fstring
2)))
745 ;; A single string spec in the middle of the spec.
746 ((string-match "\\`\\([^%]+\\)%[sc]\\([^%]+\\)\\'" fstring
)
747 (list (match-string 1 fstring
) (car flist
) (match-string 2 fstring
)))
748 ;; A single string spec in the end of the spec.
749 ((string-match "\\`\\([^%]+\\)%[sc]\\'" fstring
)
750 (list (match-string 1 fstring
) (car flist
)))
751 ;; Only string (and %) specs (XEmacs only!)
752 ((and (featurep 'xemacs
)
753 gnus-make-format-preserve-properties
755 "\\`\\([^%]*\\(%%\\|%-?\\([1-9][0-9]*\\)?s\\)\\)*[^%]*\\'"
757 (list (cons 'gnus-xmas-format
(cons fstring
(nreverse flist
)))))
758 ;; A more complex spec.
760 (list (cons 'format
(cons fstring
(nreverse flist
)))))))
766 (cons 'insert result
)))
767 (cond ((stringp result
)
770 (cons 'concat result
))
773 (defun gnus-eval-format (format &optional alist props
)
774 "Eval the format variable FORMAT, using ALIST.
775 If PROPS, insert the result."
776 (let ((form (gnus-parse-format format alist props
)))
778 (gnus-add-text-properties (point) (progn (eval form
) (point)) props
)
781 (defun gnus-compile ()
782 "Byte-compile the user-defined format specs."
785 (let ((entries gnus-format-specs
)
786 (byte-compile-warnings '(unresolved callargs redefine
))
789 (gnus-message 7 "Compiling format specs...")
792 (setq entry
(pop entries
))
793 (if (memq (car entry
) '(gnus-version version
))
794 (setq gnus-format-specs
(delq entry gnus-format-specs
))
795 (let ((form (caddr entry
)))
796 (when (and (listp form
)
797 ;; Under GNU Emacs, it's (byte-code ...)
798 (not (eq 'byte-code
(car form
)))
799 ;; Under XEmacs, it's (funcall #<compiled-function ...>)
800 (not (and (eq 'funcall
(car form
))
801 (byte-code-function-p (cadr form
)))))
802 (defalias 'gnus-tmp-func
`(lambda () ,form
))
803 (byte-compile 'gnus-tmp-func
)
804 (setcar (cddr entry
) (gnus-byte-code 'gnus-tmp-func
))))))
806 (push (cons 'version emacs-version
) gnus-format-specs
)
807 ;; Mark the .newsrc.eld file as "dirty".
809 (gnus-message 7 "Compiling user specs...done"))))
811 (defun gnus-set-format (type &optional insertable
)
812 (set (intern (format "gnus-%s-line-format-spec" type
))
814 (symbol-value (intern (format "gnus-%s-line-format" type
)))
815 (symbol-value (intern (format "gnus-%s-line-format-alist" type
)))
821 ;; coding: iso-8859-1
824 ;;; gnus-spec.el ends here