*** empty log message ***
[gnus] / lisp / gnus-cus.el
1 ;;; gnus-cus.el --- User friendly customization of Gnus
2 ;; Copyright (C) 1995,96 Free Software Foundation, Inc.
3 ;;
4 ;; Author: Per Abrahamsen <abraham@iesd.auc.dk>
5 ;; Keywords: help, news
6 ;; Version: 0.1
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 (require 'custom)
30 (require 'gnus-ems)
31 (require 'browse-url)
32 (eval-when-compile (require 'cl))
33
34 ;; The following is just helper functions and data, not meant to be set
35 ;; by the user.
36 (defun gnus-make-face (color)
37   ;; Create entry for face with COLOR.
38   (custom-face-lookup color nil nil nil nil nil))
39
40 (defvar gnus-face-light-name-list
41   '("light blue" "light cyan" "light yellow" "light pink"
42     "pale green" "beige" "orange" "magenta" "violet" "medium purple"
43     "turquoise"))
44
45 (defvar gnus-face-dark-name-list
46   '("dark blue" "firebrick" "dark green" "OrangeRed" 
47     "dark khaki" "dark violet" "SteelBlue4"))
48 ; CornflowerBlue SeaGreen OrangeRed SteelBlue4 DeepPink3
49 ; DarkOlviveGreen4 
50
51 (custom-declare '()
52   '((tag . "Gnus")
53     (doc . "\
54 The coffee-brewing, all singing, all dancing, kitchen sink newsreader.")
55     (type . group)
56     (data
57      ((tag . "Visual")
58       (doc . "\
59 Gnus can be made colorful and fun or grey and dull as you wish.")
60       (type . group)
61       (data
62        ((tag . "Visual")
63         (doc . "Enable visual features.
64 If `visual' is disabled, there will be no menus and few faces.  Most of
65 the visual customization options below will be ignored.  Gnus will use
66 less space and be faster as a result.")
67         (default . 
68           (summary-highlight group-highlight
69                              article-highlight 
70                              mouse-face
71                              summary-menu group-menu article-menu
72                              tree-highlight menu highlight
73                              browse-menu server-menu
74                              page-marker tree-menu binary-menu pick-menu
75                              grouplens-menu))
76         (name . gnus-visual)
77         (type . sexp))
78        ((tag . "WWW Browser")
79         (doc . "\
80 WWW Browser to call when clicking on an URL button in the article buffer.
81
82 You can choose between one of the predefined browsers, or `Other'.")
83         (name . browse-url-browser-function)
84         (calculate . (cond ((boundp 'browse-url-browser-function)
85                             browse-url-browser-function)
86                            ((fboundp 'w3-fetch) 
87                             'w3-fetch)
88                            ((eq window-system 'x) 
89                             'gnus-netscape-open-url)))
90         (type . choice)
91         (data
92          ((tag . "W3")
93           (type . const)
94           (default . w3-fetch))
95          ((tag . "Netscape")
96           (type . const)
97           (default . browse-url-netscape))
98          ((prompt . "Other")
99           (doc . "\
100 You must specify the name of a Lisp function here.  The lisp function
101 should open a WWW browser when called with an URL (a string).
102 ")
103           (default . __uninitialized__)
104           (type . symbol))))
105        ((tag . "Mouse Face")
106         (doc . "\
107 Face used for group or summary buffer mouse highlighting.
108 The line beneath the mouse pointer will be highlighted with this
109 face.")
110         (name . gnus-mouse-face)
111         (calculate . (if (gnus-visual-p 'mouse-face 'highlight)
112                          (if (boundp 'gnus-mouse-face)
113                              gnus-mouse-face
114                            'highlight)
115                        'default))
116         (type . face))
117        ((tag . "Article Display")
118         (doc . "Controls how the article buffer will look.
119
120 If you leave the list empty, the article will appear exactly as it is
121 stored on the disk.  The list entries will hide or highlight various
122 parts of the article, making it easier to find the information you
123 want.")
124         (name . gnus-article-display-hook)
125         (type . list)
126         (default . (gnus-article-hide-headers-if-wanted
127                     gnus-article-hide-boring-headers
128                     gnus-article-treat-overstrike
129                     gnus-article-maybe-highlight))
130         (data 
131          ((type . repeat)
132           (header . nil)
133           (data
134            (tag . "Filter")
135            (type . choice)
136            (data
137             ((tag . "Treat Overstrike")
138              (doc . "\
139 Convert use of overstrike into bold and underline.
140
141 Two identical letters separated by a backspace are displayed as a
142 single bold letter, while a letter followed by a backspace and an
143 underscore will be displayed as a single underlined letter.  This
144 technique was developed for old line printers (think about it), and is
145 still in use on some newsgroups, in particular the ClariNet
146 hierarchy.
147 ")
148              (type . const)
149              (default . 
150                gnus-article-treat-overstrike))
151             ((tag . "Word Wrap")
152              (doc . "\
153 Format too long lines.
154 ")
155              (type . const)
156              (default . gnus-article-word-wrap))
157             ((tag . "Remove CR")
158              (doc . "\
159 Remove carriage returns from an article.
160 ")
161              (type . const)
162              (default . gnus-article-remove-cr))
163             ((tag . "Display X-Face")
164              (doc . "\
165 Look for an X-Face header and display it if present.
166
167 See also `X Face Command' for a definition of the external command
168 used for decoding and displaying the face.
169 ")
170              (type . const)
171              (default . gnus-article-display-x-face))
172             ((tag . "Unquote Printable")
173              (doc . "\
174 Transform MIME quoted printable into 8-bit characters.
175
176 Quoted printable is often seen by strings like `=EF' where you would
177 expect a non-English letter.
178 ")
179              (type . const)
180              (default .
181                gnus-article-de-quoted-unreadable))
182             ((tag . "Universal Time")
183              (doc . "\
184 Convert date header to universal time.
185 ")
186              (type . const)
187              (default . gnus-article-date-ut))
188             ((tag . "Local Time")
189              (doc . "\
190 Convert date header to local timezone.
191 ")
192              (type . const)
193              (default . gnus-article-date-local))
194             ((tag . "Lapsed Time")
195              (doc . "\
196 Replace date header with a header showing the articles age.
197 ")
198              (type . const)
199              (default . gnus-article-date-lapsed))
200             ((tag . "Highlight")
201              (doc . "\
202 Highlight headers, citations, signature, and buttons.
203 ")
204              (type . const)
205              (default . gnus-article-highlight))
206             ((tag . "Maybe Highlight")
207              (doc . "\
208 Highlight headers, signature, and buttons if `Visual' is turned on.
209 ")
210              (type . const)
211              (default . 
212                gnus-article-maybe-highlight))
213             ((tag . "Highlight Some")
214              (doc . "\
215 Highlight headers, signature, and buttons.
216 ")
217              (type . const)
218              (default . gnus-article-highlight-some))
219             ((tag . "Highlight Headers")
220              (doc . "\
221 Highlight headers as specified by `Article Header Highlighting'.
222 ")
223              (type . const)
224              (default .
225                gnus-article-highlight-headers))
226             ((tag . "Highlight Signature")
227              (doc . "\
228 Highlight the signature as specified by `Article Signature Face'.
229 ")
230              (type . const)
231              (default .
232                gnus-article-highlight-signature))
233             ((tag . "Citation")
234              (doc . "\
235 Highlight the citations as specified by `Citation Faces'.
236 ")
237              (type . const)
238              (default . 
239                gnus-article-highlight-citation))
240             ((tag . "Hide")
241              (doc . "\
242 Hide unwanted headers, excess citation, and the signature.
243 ")
244              (type . const)
245              (default . gnus-article-hide))
246             ((tag . "Hide Headers If Wanted")
247              (doc . "\
248 Hide headers, but allow user to display them with `t' or `v'.
249 ")
250              (type . const)
251              (default . 
252                gnus-article-hide-headers-if-wanted))
253             ((tag . "Hide Headers")
254              (doc . "\
255 Hide unwanted headers and possibly sort them as well.
256 Most likely you want to use `Hide Headers If Wanted' instead.
257 ")
258              (type . const)
259              (default . gnus-article-hide-headers))
260             ((tag . "Hide Signature")
261              (doc . "\
262 Hide the signature.
263 ")
264              (type . const)
265              (default . gnus-article-hide-signature))
266             ((tag . "Hide Excess Citations")
267              (doc . "\
268 Hide excess citation.
269
270 Excess is defined by `Citation Hide Percentage' and `Citation Hide Absolute'.
271 ")
272              (type . const)
273              (default . 
274                gnus-article-hide-citation-maybe))
275             ((tag . "Hide Citations")
276              (doc . "\
277 Hide all cited text.
278 ")
279              (type . const)
280              (default . gnus-article-hide-citation))
281             ((tag . "Add Buttons")
282              (doc . "\
283 Make URL's into clickable buttons.
284 ")
285              (type . const)
286              (default . gnus-article-add-buttons))
287             ((prompt . "Other")
288              (doc . "\
289 Name of Lisp function to call.
290
291 Push the `Filter' button to select one of the predefined filters.
292 ")
293              (type . symbol)))))))
294        ((tag . "Article Button Face")
295         (doc . "\
296 Face used for highlighting buttons in the article buffer.
297
298 An article button is a piece of text that you can activate by pressing
299 `RET' or `mouse-2' above it.")
300         (name . gnus-article-button-face)
301         (default . bold)
302         (type . face))
303        ((tag . "Article Mouse Face")
304         (doc . "\
305 Face used for mouse highlighting in the article buffer.
306
307 Article buttons will be displayed in this face when the cursor is
308 above them.")
309         (name . gnus-article-mouse-face)
310         (default . highlight)
311         (type . face))
312        ((tag . "Article Signature Face")
313         (doc . "\
314 Face used for highlighting a signature in the article buffer.")
315         (name . gnus-signature-face)
316         (default . italic)
317         (type . face))
318        ((tag . "Article Header Highlighting")
319         (doc . "\
320 Controls highlighting of article header.
321
322 Below is a list of article header names, and the faces used for
323 displaying the name and content of the header.  The `Header' field
324 should contain the name of the header.  The field actually contains a
325 regular expression that should match the beginning of the header line,
326 but if you don't know what a regular expression is, just write the
327 name of the header.  The second field is the `Name' field, which
328 determines how the the header name (i.e. the part of the header left
329 of the `:') is displayed.  The third field is the `Content' field,
330 which determines how the content (i.e. the part of the header right of
331 the `:') is displayed.  
332
333 If you leave the last `Header' field in the list empty, the `Name' and
334 `Content' fields will determine how headers not listed above are
335 displayed.  
336
337 If you only want to change the display of the name part for a specific
338 header, specify `None' in the `Content' field.  Similarly, specify
339 `None' in the `Name' field if you only want to leave the name part
340 alone.")
341         (name . gnus-header-face-alist)
342         (type . list)
343         (calculate
344          . (cond 
345             ((not (eq gnus-display-type 'color))
346              '(("" bold italic)))
347             ((eq gnus-background-mode 'dark)
348              (list 
349               (list "From" nil 
350                     (custom-face-lookup "light blue" nil nil t t nil))
351               (list "Subject" nil 
352                     (custom-face-lookup "pink" nil nil t t nil))
353               (list "Newsgroups:.*," nil
354                     (custom-face-lookup "yellow" nil nil t t nil))
355               (list 
356                "" 
357                (custom-face-lookup "cyan" nil nil t nil nil)
358                (custom-face-lookup "forestgreen" nil nil nil t 
359                                    nil))))
360             (t
361              (list
362               (list "From" nil
363                     (custom-face-lookup "MidnightBlue" nil nil t t nil))
364               (list "Subject" nil 
365                     (custom-face-lookup "firebrick" nil nil t t nil))
366               (list "Newsgroups:.*," nil
367                     (custom-face-lookup "indianred" nil nil t t nil))
368               (list ""
369                     (custom-face-lookup 
370                      "DarkGreen" nil nil t nil nil)
371                     (custom-face-lookup "DarkGreen" nil nil
372                                         nil t nil))))))
373         (data
374          ((type . repeat)
375           (header . nil)
376           (data 
377            (type . list)
378            (compact . t)
379            (data
380             ((type . string)
381              (prompt . "Header")
382              (tag . "Header "))
383             "\n            "
384             ((type . face)
385              (prompt . "Name")
386              (tag . "Name   "))
387             "\n            "
388             ((type . face)
389              (tag . "Content"))
390             "\n")))))
391        ((tag . "Attribution Face")
392         (doc . "\
393 Face used for attribution lines.
394 It is merged with the face for the cited text belonging to the attribution.")
395         (name . gnus-cite-attribution-face)
396         (default . underline)
397         (type . face))
398        ((tag . "Citation Faces")
399         (doc . "\
400 List of faces used for highlighting citations. 
401
402 When there are citations from multiple articles in the same message,
403 Gnus will try to give each citation from each article its own face.
404 This should make it easier to see who wrote what.")
405         (name . gnus-cite-face-list)
406         (import . gnus-custom-import-cite-face-list)
407         (type . list)
408         (calculate . (cond ((not (eq gnus-display-type 'color))
409                             '(italic))
410                            ((eq gnus-background-mode 'dark)
411                             (mapcar 'gnus-make-face 
412                                     gnus-face-light-name-list))
413                            (t 
414                             (mapcar 'gnus-make-face 
415                                     gnus-face-dark-name-list))))
416         (data
417          ((type . repeat)
418           (header . nil)
419           (data (type . face)
420                 (tag . "Face")))))
421        ((tag . "Citation Hide Percentage")
422         (doc . "\
423 Only hide excess citation if above this percentage of the body.")
424         (name . gnus-cite-hide-percentage)
425         (default . 50)
426         (type . integer))
427        ((tag . "Citation Hide Absolute")
428         (doc . "\
429 Only hide excess citation if above this number of lines in the body.")
430         (name . gnus-cite-hide-absolute)
431         (default . 10)
432         (type . integer))
433        ((tag . "Summary Selected Face")
434         (doc . "\
435 Face used for highlighting the current article in the summary buffer.")
436         (name . gnus-summary-selected-face)
437         (default . underline)
438         (type . face))
439        ((tag . "Summary Line Highlighting")
440         (doc . "\
441 Controls the highlighting of summary buffer lines. 
442
443 Below is a list of `Form'/`Face' pairs.  When deciding how a a
444 particular summary line should be displayed, each form is
445 evaluated. The content of the face field after the first true form is
446 used.  You can change how those summary lines are displayed, by
447 editing the face field.  
448
449 It is also possible to change and add form fields, but currently that
450 requires an understanding of Lisp expressions.  Hopefully this will
451 change in a future release.  For now, you can use the following
452 variables in the Lisp expression:
453
454 score:   The article's score
455 default: The default article score.
456 below:   The score below which articles are automatically marked as read. 
457 mark:    The article's mark.")
458         (name . gnus-summary-highlight)
459         (type . list)
460         (calculate 
461          . (cond
462             ((not (eq gnus-display-type 'color))
463              '(((> score default) . bold)
464                ((< score default) . italic)))
465             ((eq gnus-background-mode 'dark)
466              (list
467               (cons 
468                '(= mark gnus-canceled-mark)
469                (custom-face-lookup "yellow" "black" nil
470                                    nil nil nil))
471               (cons '(and (> score default) 
472                           (or (= mark gnus-dormant-mark)
473                               (= mark gnus-ticked-mark)))
474                     (custom-face-lookup 
475                      "pink" nil nil t nil nil))
476               (cons '(and (< score default) 
477                           (or (= mark gnus-dormant-mark)
478                               (= mark gnus-ticked-mark)))
479                     (custom-face-lookup "pink" nil nil 
480                                         nil t nil))
481               (cons '(or (= mark gnus-dormant-mark)
482                          (= mark gnus-ticked-mark))
483                     (custom-face-lookup 
484                      "pink" nil nil nil nil nil))
485
486               (cons
487                '(and (> score default) (= mark gnus-ancient-mark))
488                (custom-face-lookup "medium blue" nil nil t
489                                    nil nil))
490               (cons 
491                '(and (< score default) (= mark gnus-ancient-mark))
492                (custom-face-lookup "SkyBlue" nil nil
493                                    nil t nil))
494               (cons 
495                '(= mark gnus-ancient-mark)
496                (custom-face-lookup "SkyBlue" nil nil
497                                    nil nil nil))
498               (cons '(and (> score default) (= mark gnus-unread-mark))
499                     (custom-face-lookup "white" nil nil t
500                                         nil nil))
501               (cons '(and (< score default) (= mark gnus-unread-mark))
502                     (custom-face-lookup "white" nil nil
503                                         nil t nil))
504               (cons '(= mark gnus-unread-mark)
505                     (custom-face-lookup
506                      "white" nil nil nil nil nil))
507
508               (cons '(> score default) 'bold)
509               (cons '(< score default) 'italic)))
510             (t
511              (list
512               (cons
513                '(= mark gnus-canceled-mark)
514                (custom-face-lookup
515                 "yellow" "black" nil nil nil nil))
516               (cons '(and (> score default) 
517                           (or (= mark gnus-dormant-mark)
518                               (= mark gnus-ticked-mark)))
519                     (custom-face-lookup "firebrick" nil nil
520                                         t nil nil))
521               (cons '(and (< score default) 
522                           (or (= mark gnus-dormant-mark)
523                               (= mark gnus-ticked-mark)))
524                     (custom-face-lookup "firebrick" nil nil
525                                         nil t nil))
526               (cons 
527                '(or (= mark gnus-dormant-mark)
528                     (= mark gnus-ticked-mark))
529                (custom-face-lookup 
530                 "firebrick" nil nil nil nil nil))
531
532               (cons '(and (> score default) (= mark gnus-ancient-mark))
533                     (custom-face-lookup "RoyalBlue" nil nil
534                                         t nil nil))
535               (cons '(and (< score default) (= mark gnus-ancient-mark))
536                     (custom-face-lookup "RoyalBlue" nil nil
537                                         nil t nil))
538               (cons 
539                '(= mark gnus-ancient-mark)
540                (custom-face-lookup
541                 "RoyalBlue" nil nil nil nil nil))
542
543               (cons '(and (> score default) (/= mark gnus-unread-mark))
544                     (custom-face-lookup "DarkGreen" nil nil
545                                         t nil nil))
546               (cons '(and (< score default) (/= mark gnus-unread-mark))
547                     (custom-face-lookup "DarkGreen" nil nil
548                                         nil t nil))
549               (cons
550                '(/= mark gnus-unread-mark)
551                (custom-face-lookup "DarkGreen" nil nil 
552                                    nil nil nil))
553
554               (cons '(> score default) 'bold)
555               (cons '(< score default) 'italic)))))
556         (data
557          ((type . repeat)
558           (header . nil)
559           (data (type . pair)
560                 (compact . t)
561                 (data ((type . sexp)
562                        (width . 60)
563                        (tag . "Form"))
564                       "\n            "
565                       ((type . face)
566                        (tag . "Face"))
567                       "\n")))))
568
569        ((tag . "Group Line Highlighting")
570         (doc . "\
571 Controls the highlighting of group buffer lines. 
572
573 Below is a list of `Form'/`Face' pairs.  When deciding how a a
574 particular group line should be displayed, each form is
575 evaluated. The content of the face field after the first true form is
576 used.  You can change how those group lines are displayed by
577 editing the face field.  
578
579 It is also possible to change and add form fields, but currently that
580 requires an understanding of Lisp expressions.  Hopefully this will
581 change in a future release.  For now, you can use the following
582 variables in the Lisp expression:
583
584 group: The name of the group.
585 unread: The number of unread articles in the group.
586 method: The select method used.
587 mailp: Whether it's a mail group or not.
588 level: The level of the group.
589 score: The score of the group.
590 ticked: The number of ticked articles.")
591         (name . gnus-group-highlight)
592         (type . list)
593         (calculate 
594          . (cond 
595             ((not (eq gnus-display-type 'color))
596              '((mailp . bold)
597                ((= unread 0) . italic)))
598             ((eq gnus-background-mode 'dark)
599              `(((and (not mailp) (eq level 1)) .
600                 ,(custom-face-lookup "PaleTurquoise" nil nil t))
601                ((and (not mailp) (eq level 2)) .
602                 ,(custom-face-lookup "turquoise" nil nil t))
603                ((and (not mailp) (eq level 3)) .
604                 ,(custom-face-lookup "MediumTurquoise" nil nil t))
605                ((and (not mailp) (>= level 4)) .
606                 ,(custom-face-lookup "DarkTurquoise" nil nil t))
607                ((and mailp (eq level 1)) .
608                 ,(custom-face-lookup "aquamarine1" nil nil t))
609                ((and mailp (eq level 2)) .
610                 ,(custom-face-lookup "aquamarine2" nil nil t))
611                ((and mailp (eq level 3)) .
612                 ,(custom-face-lookup "aquamarine3" nil nil t))
613                ((and mailp (>= level 4)) .
614                 ,(custom-face-lookup "aquamarine4" nil nil t))
615                ))
616             (t
617              `(((and (not mailp) (<= level 3)) .
618                 ,(custom-face-lookup "ForestGreen" nil nil t))
619                ((and (not mailp) (eq level 4)) .
620                 ,(custom-face-lookup "DarkGreen" nil nil t))
621                ((and (not mailp) (eq level 5)) .
622                 ,(custom-face-lookup "CadetBlue4" nil nil t))
623                ((and mailp (eq level 1)) .
624                 ,(custom-face-lookup "DeepPink3" nil nil t))
625                ((and mailp (eq level 2)) .
626                 ,(custom-face-lookup "HotPink3" nil nil t))
627                ((and mailp (eq level 3)) .
628                 ,(custom-face-lookup "dark magenta" nil nil t))
629                ((and mailp (eq level 4)) .
630                 ,(custom-face-lookup "DeepPink4" nil nil t))
631                ((and mailp (> level 4)) .
632                 ,(custom-face-lookup "DarkOrchid4" nil nil t))
633                ))))
634         (data
635          ((type . repeat)
636           (header . nil)
637           (data (type . pair)
638                 (compact . t)
639                 (data ((type . sexp)
640                        (width . 60)
641                        (tag . "Form"))
642                       "\n            "
643                       ((type . face)
644                        (tag . "Face"))
645                       "\n")))))
646
647        ;; Do not define `gnus-button-alist' before we have
648        ;; some `complexity' attribute so we can hide it from
649        ;; beginners. 
650        )))))
651
652 (defun gnus-custom-import-cite-face-list (custom alist)
653   ;; Backward compatible grokking of light and dark.
654   (cond ((eq alist 'light)
655          (setq alist (mapcar 'gnus-make-face gnus-face-light-name-list)))
656         ((eq alist 'dark)
657          (setq alist (mapcar 'gnus-make-face gnus-face-dark-name-list))))
658   (funcall (custom-super custom 'import) custom alist))
659
660 (provide 'gnus-cus)
661
662 ;;; gnus-cus.el ends here