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