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