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