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