7730b4e86925dd07de233337d517a06f18f67dba
[gnus] / lisp / gnus-vis.el
1 ;;; gnus-vis.el --- display-oriented parts of Gnus
2 ;; Copyright (C) 1995 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;;      Per Abrahamsen <abraham@iesd.auc.dk>
6 ;; Keywords: news
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 'gnus)
29 (require gnus-easymenu)
30
31 ;;; summary highligts
32
33 (defvar gnus-summary-selected-face 'underline
34   "*Face used for highlighting the current article in the summary buffer.")
35
36 (defvar gnus-summary-highlight
37   '(((> score default) . bold)
38     ((< score default) . italic))
39   "*Alist of `(FORM . FACE)'.
40 Summary lines are highlighted with the FACE for the first FORM which
41 evaluate to a non-nil value.  
42
43 Point will be at the beginning of the line when FORM is evaluated.
44 The following can be used for convenience:
45
46 score:   (gnus-summary-article-score)
47 default: gnus-summary-default-score
48 below:   gnus-summary-mark-below
49
50 To check for marks, e.g. to underline replied articles, use
51 `gnus-summary-article-mark': 
52
53    ((= (gnus-summary-article-mark) gnus-replied-mark) . underline)")
54
55 ;;; article highlights
56
57 (defvar gnus-make-foreground t
58   "Non nil means foreground color to highlight citations.")
59
60 (defvar gnus-article-button-face 'bold
61   "Face used for text buttons.")
62
63 (defvar gnus-article-mouse-face (if (boundp 'gnus-mouse-face)
64                                     gnus-mouse-face
65                                   'highlight)
66   "Face used when the mouse is over the button.")
67
68 (defvar gnus-header-face-alist '(("" bold italic))
69   "Alist of headers and faces used for highlighting them.
70 The entries in the list has the form `(REGEXP NAME CONTENT)', where
71 REGEXP is a regeular expression matching the beginning of the header,
72 NAME is the face used for highlighting the header name and CONTENT is
73 the face used for highlighting the header content. 
74
75 The first non-nil NAME or CONTENT with a matching REGEXP in the list
76 will be used.") 
77
78 (defvar gnus-signature-face 'italic
79   "Face used for signature.")
80
81 (defvar gnus-button-alist 
82   '(("in\\( +article\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" 2 
83      (assq (count-lines (point-min) (match-end 0)) 
84            gnus-cite-attribution-alist)
85      gnus-button-message-id 3)
86     ;; This is how URLs _should_ be embedded in text...
87     ("<URL:\\([^\n\r>]*\\)>" 0 t gnus-button-url 1)
88     ;; Next regexp stolen from highlight-headers.el
89     ("\\b\\(s?https?\\|ftp\\|file\\|gopher\\|news\\|telnet\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]+" 0 t
90      gnus-button-url 0))
91   "Alist of regexps matching buttons in an article.
92
93 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
94 REGEXP: is the string matching text around the button,
95 BUTTON: is the number of the regexp grouping actually matching the button,
96 FORM: is a lisp expression which must eval to true for the button to
97 be added, 
98 CALLBACK: is the function to call when the user push this button, and each
99 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
100
101 CALLBACK can also be a variable, in that case the value of that
102 variable it the real callback function.")
103
104 (defvar gnus-button-url (cond ((fboundp 'w3-fetch)
105                                'w3-fetch)
106                               ((fboundp 'highlight-headers-follow-url-netscape)
107                                'highlight-headers-follow-url-netscape)
108                               (t nil))
109   "Function to fetch URL.  
110 The function will be called with one argument, the URL to fetch.
111 Useful values of this function are:
112
113 w3-fetch: 
114    defined in the w3 emacs package by William M. Perry.
115 highlight-headers-follow-url-netscape: 
116    from `highlight-headers.el' for loading NetScape 1.1.")
117
118 \f
119
120 (eval-and-compile
121   (autoload 'nnkiboze-generate-groups "nnkiboze")
122   (autoload 'gnus-cite-parse-maybe "gnus-cite" nil t))
123
124 ;;;
125 ;;; gnus-menu
126 ;;;
127
128 ;; Newsgroup buffer
129
130 (defun gnus-group-make-menu-bar ()
131   (easy-menu-define
132    gnus-group-reading-menu
133    gnus-group-mode-map
134    ""
135    '("Group"
136      ["Read" gnus-group-read-group t]
137      ["Select" gnus-group-select-group t]
138      ["Catch up" gnus-group-catchup-current t]
139      ["Catch up all articles" gnus-group-catchup-current-all t]
140      ["Check for new articles" gnus-group-get-new-news-this-group t]
141      ["Toggle subscription" gnus-group-unsubscribe-current-group t]
142      ["Kill" gnus-group-kill-group t]
143      ["Yank" gnus-group-yank-group t]
144      ["Describe" gnus-group-describe-group t]
145      ["Fetch FAQ" gnus-group-fetch-faq t]
146      ["Edit kill file" gnus-group-edit-local-kill t]
147      ["Expire articles" gnus-group-expire-articles t]
148      ["Set group level" gnus-group-set-current-level t]
149      ))
150   
151   (easy-menu-define
152    gnus-group-group-menu
153    gnus-group-mode-map
154    ""
155    '("Groups"
156      ("Listing"
157       ["List subscribed groups" gnus-group-list-groups t]
158       ["List all groups" gnus-group-list-all-groups t]
159       ["List groups matching..." gnus-group-list-matching t]
160       ["List killed groups" gnus-group-list-killed t]
161       ["List zombie groups" gnus-group-list-zombies t]
162       ["Describe all groups" gnus-group-describe-all-groups t]
163       ["Group apropos" gnus-group-apropos t]
164       ["Group and description apropos" gnus-group-description-apropos t]
165       ["List groups matching..." gnus-group-list-matching t])
166      ("Mark"
167       ["Mark group" gnus-group-mark-group t]
168       ["Unmark group" gnus-group-unmark-group t]
169       ["Mark region" gnus-group-mark-region t])
170      ("Subscribe"
171       ["Subscribe to random group" gnus-group-unsubscribe-group t]
172       ["Kill all newsgroups in region" gnus-group-kill-region t]
173       ["Kill all zombie groups" gnus-group-kill-all-zombies t])
174      ("Foreign groups"
175       ["Make a foreign group" gnus-group-make-group t]
176       ["Edit a group entry" gnus-group-edit-group t]
177       ["Add a directory group" gnus-group-make-directory-group t]
178       ["Add the help group" gnus-group-make-help-group t]
179       ["Add the archive group" gnus-group-make-archive-group t]
180       ["Make a kiboze group" gnus-group-make-kiboze-group t])
181      ["Jump to group" gnus-group-jump-to-group t]
182      ["Best unread group" gnus-group-best-unread-group t]
183      ))
184
185   (easy-menu-define
186    gnus-group-post-menu
187    gnus-group-mode-map
188    ""
189    '("Post"
190      ["Send a mail" gnus-group-mail t]
191      ["Post an article" gnus-group-post-news t]
192      ))
193   
194   (easy-menu-define
195    gnus-group-misc-menu
196    gnus-group-mode-map
197    ""
198    '("Misc"
199      ["Send a bug report" gnus-bug t]
200      ["Check for new news" gnus-group-get-new-news t]     
201      ["Delete bogus groups" gnus-group-check-bogus-groups t]
202      ["Find new newsgroups" gnus-find-new-newsgroups t]
203      ["Restart Gnus" gnus-group-restart t]
204      ["Read init file" gnus-group-read-init-file t]
205      ["Browse foreign server" gnus-group-browse-foreign-server t]
206      ["Enter server buffer" gnus-group-enter-server-mode t]
207      ["Edit the global kill file" gnus-group-edit-global-kill t]
208      ["Expire all expirable articles" gnus-group-expire-all-groups t]
209      ["Generate any kiboze groups" nnkiboze-generate-groups t]
210      ["Gnus version" gnus-version t]
211      ["Save .newsrc files" gnus-group-save-newsrc t]
212      ["Suspend Gnus" gnus-group-suspend t]
213      ["Clear dribble buffer" gnus-group-clear-dribble t]
214      ["Exit from Gnus" gnus-group-exit t]
215      ["Exit without saving" gnus-group-quit t]
216      ["Sort group buffer" gnus-group-sort-groups t]
217      ["Edit global KILL file" gnus-group-edit-global-kill t]
218      ))
219
220   )
221
222 ;; Server mode
223 (defun gnus-server-make-menu-bar ()
224   (easy-menu-define
225    gnus-server-menu
226    gnus-server-mode-map
227    ""
228    '("Server"
229      ["Add" gnus-server-add-server t]
230      ["Browse" gnus-server-read-server t]
231      ["List" gnus-server-list-servers t]
232      ["Kill" gnus-server-kill-server t]
233      ["Yank" gnus-server-yank-server t]
234      ["Copy" gnus-server-copy-server t]
235      ["Edit" gnus-server-edit-server t]
236      ["Exit" gnus-server-exit t]
237      )))
238
239 ;; Browse mode
240 (defun gnus-browse-make-menu-bar ()
241   (easy-menu-define
242    gnus-browse-menu
243    gnus-browse-mode-map
244    ""
245    '("Browse"
246      ["Subscribe" gnus-browse-unsubscribe-current-group t]
247      ["Exit" gnus-browse-exit t]
248      )))
249
250 ;; Summary buffer
251 (defun gnus-summary-make-menu-bar ()
252
253   (easy-menu-define
254    gnus-summary-mark-menu
255    gnus-summary-mode-map
256    ""
257    '("Mark"
258      ("Read"
259       ["Mark as read" gnus-summary-mark-as-read-forward t]
260       ["Mark same subject and select" gnus-summary-kill-same-subject-and-select t]
261       ["Mark same subject" gnus-summary-kill-same-subject t]
262       ["Catchup" gnus-summary-catchup t]
263       ["Catchup all" gnus-summary-catchup-all t]
264       ["Catchup to here" gnus-summary-catchup-to-here t]
265       ["Catchup region" gnus-summary-mark-region-as-read t])
266      ("Various"
267       ["Tick" gnus-summary-tick-article-forward t]
268       ["Mark as dormant" gnus-summary-mark-as-dormant t]
269       ["Remove marks" gnus-summary-clear-mark-forward t]
270       ["Set expirable mark" gnus-summary-mark-as-expirable t]
271       ["Set bookmark" gnus-summary-set-bookmark t]
272       ["Remove bookmark" gnus-summary-remove-bookmark t])
273      ("Score"
274       ["Enter score" gnus-summary-score-entry t]
275       ["Raise score" gnus-summary-raise-score t]
276       ["Lower score" gnus-summary-lower-score t]
277       ["Current score" gnus-summary-current-score t]
278       ["Set score" gnus-summary-set-score t])
279      ("Display"
280       ["Remove lines marked as read" gnus-summary-remove-lines-marked-as-read t]
281       ["Remove lines marked with..." gnus-summary-remove-lines-marked-with t]
282       ["Show dormant articles" gnus-summary-show-all-dormant t]
283       ["Hide dormant articles" gnus-summary-hide-all-dormant t]
284       ["Show expunged articles" gnus-summary-show-all-expunged t])
285      ("Process mark"
286       ["Set mark" gnus-summary-mark-as-processable t]
287       ["Remove mark" gnus-summary-unmark-as-processable t]
288       ["Remove all marks" gnus-summary-unmark-all-processable t]
289       ["Mark series" gnus-uu-mark-series t]
290       ["Mark region" gnus-uu-mark-region t]
291       ["Mark by regexp" gnus-uu-mark-by-regexp t]
292       ["Mark all" gnus-uu-mark-all t]
293       ["Mark sparse" gnus-uu-mark-sparse t]
294       ["Mark thread" gnus-uu-mark-thread t]
295       )
296      ))
297
298   (easy-menu-define
299    gnus-summary-move-menu
300    gnus-summary-mode-map
301    ""
302    '("Move"
303      ["Scroll article forwards" gnus-summary-next-page t]
304      ["Next unread article" gnus-summary-next-unread-article t]
305      ["Previous unread article" gnus-summary-prev-unread-article t]
306      ["Next article" gnus-summary-next-article t]
307      ["Previous article" gnus-summary-prev-article t]
308      ["Next article same subject" gnus-summary-next-same-subject t]
309      ["Previous article same subject" gnus-summary-prev-same-subject t]
310      ["First unread article" gnus-summary-first-unread-article t]
311      ["Go to subject number..." gnus-summary-goto-subject t]
312      ["Go to the last article" gnus-summary-goto-last-article t]
313      ["Pop article off history" gnus-summary-pop-article t]
314      ))
315
316   (easy-menu-define
317    gnus-summary-article-menu
318    gnus-summary-mode-map
319    ""
320    '("Article"
321      ("Hide"
322       ("Date"
323        ["Local" gnus-article-date-local t]
324        ["UT" gnus-article-date-local t]
325        ["Lapsed" gnus-article-date-local t])
326       ["Headers" gnus-article-hide-headers t]
327       ["Signature" gnus-article-hide-signature t]
328       ["Citation" gnus-article-hide-citation t]
329       ["Overstrike" gnus-article-treat-overstrike t]
330       ["Word wrap" gnus-article-word-wrap t]
331       ["CR" gnus-article-remove-cr t]
332       ["Show X-Face" gnus-article-display-x-face t]
333       ["Quoted-Printable" gnus-article-de-quoted-unreadable t])
334      ("Extract"
335       ["Uudecode" gnus-uu-decode-uu t]
336       ["Uudecode and save" gnus-uu-decode-uu-and-save t]
337       ["Unshar" gnus-uu-decode-unshar t]
338       ["Unshar and save" gnus-uu-decode-unshar-and-save t]
339       ["Save" gnus-uu-decode-save t]
340       ["Binhex" gnus-uu-decode-binhex t])
341      ["Enter digest buffer" gnus-summary-enter-digest-group t]
342      ["Isearch article" gnus-summary-isearch-article t]
343      ["Search all articles" gnus-summary-search-article-forward t]
344      ["Beginning of the article" gnus-summary-beginning-of-article t]
345      ["End of the article" gnus-summary-end-of-article t]
346      ["Fetch parent of article" gnus-summary-refer-parent-article t]
347      ["Fetch article with id..." gnus-summary-refer-article t]
348      ["Stop page breaking" gnus-summary-stop-page-breaking t]
349      ["Caesar rotate" gnus-summary-caesar-message t]
350      ["Redisplay" gnus-summary-show-article t]
351      ["Toggle header" gnus-summary-toggle-header t]
352      ["Toggle MIME" gnus-summary-toggle-mime t]
353      ["Save" gnus-summary-save-article t]
354      ["Save in mail format" gnus-summary-save-article-mail t]
355      ["Pipe through a filter" gnus-summary-pipe-output t]
356      ("Mail articles"
357       ["Respool article" gnus-summary-respool-article t]
358       ["Move article" gnus-summary-move-article t]
359       ["Copy article" gnus-summary-copy-article t]
360       ["Edit article" gnus-summary-edit-article t]
361       ["Delete article" gnus-summary-delete-article t])
362      ))
363
364   (easy-menu-define
365    gnus-summary-thread-menu
366    gnus-summary-mode-map
367    ""
368    '("Threads"
369      ["Toggle threading" gnus-summary-toggle-threads t]
370      ["Display hidden thread" gnus-summary-show-thread t]
371      ["Hide thread" gnus-summary-hide-thread t]
372      ["Go to next thread" gnus-summary-next-thread t]
373      ["Go to previous thread" gnus-summary-prev-thread t]
374      ["Go down thread" gnus-summary-down-thread t]
375      ["Go up thread" gnus-summary-up-thread t]
376      ["Mark thread as read" gnus-summary-kill-thread t]
377      ["Lower thread score" gnus-summary-lower-thread t]
378      ["Raise thread score" gnus-summary-raise-thread t]
379      ))
380
381   (easy-menu-define
382    gnus-summary-misc-menu
383    gnus-summary-mode-map
384    ""
385    '("Misc"
386      ("Sort"
387       ["Sort by number" gnus-summary-sort-by-number t]
388       ["Sort by author" gnus-summary-sort-by-author t]
389       ["Sort by subject" gnus-summary-sort-by-subject t]
390       ["Sort by date" gnus-summary-sort-by-date t]
391       ["Sort by score" gnus-summary-sort-by-score t])
392      ("Exit"
393       ["Catchup and exit" gnus-summary-catchup-and-exit t]
394       ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
395       ["Exit group" gnus-summary-exit t]
396       ["Exit group without updating" gnus-summary-quit t]
397       ["Reselect group" gnus-summary-reselect-current-group t]
398       ["Rescan group" gnus-summary-rescan-group t])
399      ["Fetch group FAQ" gnus-summary-fetch-faq t]
400      ["Filter articles" gnus-summary-execute-command t]
401      ["Toggle line truncation" gnus-summary-toggle-truncation t]
402      ["Expire expirable articles" gnus-summary-expire-articles t]
403      ["Describe group" gnus-summary-describe-group t]
404      ["Edit local kill file" gnus-summary-edit-local-kill t]
405      ["Edit global kill file" gnus-summary-edit-global-kill t]
406      ))
407
408   (easy-menu-define
409    gnus-summary-post-menu
410    gnus-summary-mode-map
411    ""
412    '("Post"
413      ["Post an article" gnus-summary-post-news t]
414      ["Followup" gnus-summary-followup t]
415      ["Followup and yank" gnus-summary-followup-with-original t]
416      ["Supersede article" gnus-summary-supersede-article t]
417      ["Cancel article" gnus-summary-cancel-article t]
418      ["Reply" gnus-summary-reply t]
419      ["Reply and yank" gnus-summary-reply-with-original t]
420      ["Mail forward" gnus-summary-mail-forward t]
421      ["Post forward" gnus-summary-post-forward t]
422      ["Digest and mail" gnus-uu-digest-mail-forward t]
423      ["Digest and post" gnus-uu-digest-post-forward t]
424      ["Send a mail" gnus-summary-mail-other-window t]
425      ["Reply & followup" gnus-summary-followup-and-reply t]
426      ["Reply & followup and yank" gnus-summary-followup-and-reply-with-original t]
427      ["Uuencode and post" gnus-uu-post-news t]
428      ))
429
430   (easy-menu-define
431    gnus-summary-kill-menu
432    gnus-summary-mode-map
433    ""
434    '("Score"
435      ("Score file"
436       ["Switch current score file" gnus-score-change-score-file t]
437       ["Set mark below" gnus-score-set-mark-below t]
438       ["Set expunge below" gnus-score-set-expunge-below t]
439       ["Edit current score file" gnus-score-edit-alist t]
440       ["Edit score file" gnus-score-edit-file t]
441       ["Trace score" gnus-score-find-trace t])
442      ))
443   )
444  
445 ;; Article buffer
446 (defun gnus-article-make-menu-bar ()
447
448  (easy-menu-define
449    gnus-article-article-menu
450    gnus-article-mode-map
451    ""
452    '("Article"
453      ["Scroll forwards" gnus-article-next-page t]
454      ["Scroll backwards" gnus-article-prev-page t]
455      ["Show summary" gnus-article-show-summary t]
456      ["Fetch Message-ID at point" gnus-article-refer-article t]
457      ["Mail to address at point" gnus-article-mail t]
458      ["Mail to address at point and include original"
459       gnus-article-mail-with-original t]
460      ))
461
462  (easy-menu-define
463    gnus-article-treatment-menu
464    gnus-article-mode-map
465    ""
466    '("Treatment"
467      ["Hide headers" gnus-article-hide-headers t]
468      ["Hide signature" gnus-article-hide-signature t]
469      ["Hide citation" gnus-article-hide-citation t]
470      ["Treat overstrike" gnus-article-treat-overstrike t]
471      ["Remove carriage return" gnus-article-remove-cr t]
472      ["Remove quoted-unreadble" gnus-article-de-quoted-unreadable t]
473      ))
474  )
475
476 ;;;
477 ;;; summary highlights
478 ;;;
479
480 (defun gnus-highlight-selected-summary ()
481     ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
482     ;; Highlight selected article in summary buffer
483     (if gnus-summary-selected-face
484         (save-excursion
485           (let* ((beg (progn (beginning-of-line) (point)))
486                  (end (progn (end-of-line) (point)))
487                  ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
488                  (from (if (get-text-property beg 'mouse-face) 
489                            beg
490                          (next-single-property-change
491                           beg 'mouse-face nil end)))
492                  (to (next-single-property-change
493                       from 'mouse-face nil end)))
494             (if (< to beg)
495                 (progn
496                   (setq from beg)
497                   (setq to end)))
498             (if gnus-newsgroup-selected-overlay
499                 (move-overlay gnus-newsgroup-selected-overlay 
500                               from to (current-buffer))
501               (setq gnus-newsgroup-selected-overlay (make-overlay from to))
502               (overlay-put gnus-newsgroup-selected-overlay 'face 
503                            gnus-summary-selected-face))))))
504
505
506 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
507 (defun gnus-summary-highlight-line ()
508   "Highlight current line according to `gnus-summary-highlight'."
509   (let* ((list gnus-summary-highlight)
510          (p (point))
511          (end (progn (end-of-line) (point)))
512          ;; now find out where the line starts and leave point there.
513          (beg (progn (beginning-of-line) (point)))
514          (score (or (cdr (assq (or (car (get-text-property beg 'gnus))
515                                    gnus-current-article)
516                                gnus-newsgroup-scored))
517                     gnus-summary-default-score 0))
518          (default gnus-summary-default-score)
519          (mark (car (cdr (get-text-property beg 'gnus))))
520          (inhibit-read-only t))
521     (while (and list (not (eval (car (car list)))))
522       (setq list (cdr list)))
523     (let ((face (and list (cdr (car list)))))
524       ;; BUG! For some reason the text properties of the first
525       ;; characters get mangled.
526       (or (eobp)
527           (eq face (get-text-property beg 'face))
528           (put-text-property beg end 'face face)))
529     (goto-char p)))
530
531 ;;;
532 ;;; gnus-carpal
533 ;;;
534
535 (defvar gnus-carpal-group-buffer-buttons
536   '(("next" . gnus-group-next-unread-group)
537     ("prev" . gnus-group-prev-unread-group)
538     ("read" . gnus-group-read-group)
539     ("select" . gnus-group-select-group)
540     ("catch up" . gnus-group-catchup-current)
541     ("new news" . gnus-group-get-new-news-this-group)
542     ("toggle sub" . gnus-group-unsubscribe-current-group)
543     ("subscribe" . gnus-group-unsubscribe-group)
544     ("kill" . gnus-group-kill-group)
545     ("yank" . gnus-group-yank-group)
546     ("describe" . gnus-group-describe-group)
547     "list"
548     ("subscribed" . gnus-group-list-groups)
549     ("all" . gnus-group-list-all-groups)
550     ("killed" . gnus-group-list-killed)
551     ("zombies" . gnus-group-list-zombies)
552     ("matching" . gnus-group-list-matching)
553     ("post" . gnus-group-post-news)
554     ("mail" . gnus-group-mail)
555     ("new news" . gnus-group-get-new-news)
556     ("browse foreign" . gnus-group-browse-foreign)
557     ("exit" . gnus-group-exit)))
558
559 (defvar gnus-carpal-summary-buffer-buttons
560   '("mark" 
561     ("read" . gnus-summary-mark-as-read-forward)
562     ("tick" . gnus-summary-tick-article-forward)
563     ("clear" . gnus-summary-clear-mark-forward)
564     ("expirable" . gnus-summary-mark-as-expirable)
565     "move"
566     ("scroll" . gnus-summary-next-page)
567     ("next unread" . gnus-summary-next-unread-article)
568     ("prev unread" . gnus-summary-prev-unread-article)
569     ("first" . gnus-summary-first-unread-article)
570     ("best" . gnus-summary-best-unread-article)
571     "article"
572     ("headers" . gnus-summary-toggle-header)
573     ("uudecode" . gnus-uu-decode-uu)
574     ("enter digest" . gnus-summary-enter-digest-group)
575     ("fetch parent" . gnus-summary-refer-parent-article)
576     "mail"
577     ("move" . gnus-summary-move-article)
578     ("copy" . gnus-summary-copy-article)
579     ("respool" . gnus-summary-respool-article)
580     "threads"
581     ("lower" . gnus-summary-lower-thread)
582     ("kill" . gnus-summary-kill-thread)
583     "post"
584     ("post" . gnus-summary-post-news)
585     ("mail" . gnus-summary-mail)
586     ("followup" . gnus-summary-followup-with-original)
587     ("reply" . gnus-summary-reply-with-original)
588     ("cancel" . gnus-summary-cancel-article)
589     "misc"
590     ("exit" . gnus-summary-exit)
591     ("fed up" . gnus-summary-catchup-and-goto-next)))
592
593 (defvar gnus-carpal-server-buffer-buttons 
594   '(("add" . gnus-server-add-server)
595     ("browse" . gnus-server-browse-server)
596     ("list" . gnus-server-list-servers)
597     ("kill" . gnus-server-kill-server)
598     ("yank" . gnus-server-yank-server)
599     ("copy" . gnus-server-copy-server)
600     ("exit" . gnus-server-exit)))
601
602 (defvar gnus-carpal-browse-buffer-buttons
603   '(("subscribe" . gnus-browse-unsubscribe-current-group)
604     ("exit" . gnus-browse-exit)))
605
606 (defvar gnus-carpal-group-buffer "*Carpal Group*")
607 (defvar gnus-carpal-summary-buffer "*Carpal Summary*")
608 (defvar gnus-carpal-server-buffer "*Carpal Server*")
609 (defvar gnus-carpal-browse-buffer "*Carpal Browse*")
610
611 (defvar gnus-carpal-attached-buffer nil)
612
613 (defvar gnus-carpal-mode-hook nil
614   "*Hook run in carpal mode buffers.")
615
616 (defvar gnus-carpal-button-face 'bold
617   "*Face used on carpal buttons.")
618
619 (defvar gnus-carpal-header-face 'bold-italic
620   "*Face used on carpal buffer headers.")
621
622 (defvar gnus-carpal-mode-map nil)
623 (put 'gnus-carpal-mode 'mode-class 'special)
624
625 (if gnus-carpal-mode-map
626     nil
627   (setq gnus-carpal-mode-map (make-keymap))
628   (suppress-keymap gnus-carpal-mode-map)
629   (define-key gnus-carpal-mode-map " " 'gnus-carpal-select)
630   (define-key gnus-carpal-mode-map "\r" 'gnus-carpal-select)
631   (define-key gnus-carpal-mode-map [mouse-2] 'gnus-carpal-mouse-select))
632
633 (defun gnus-carpal-mode ()
634   "Major mode clicking buttons.
635
636 All normal editing commands are switched off.
637 \\<gnus-carpal-mode-map>
638 The following commands are available:
639
640 \\{gnus-carpal-mode-map}"
641   (interactive)
642   (kill-all-local-variables)
643   (setq mode-line-modified "-- ")
644   (setq major-mode 'gnus-carpal-mode)
645   (setq mode-name "Gnus Carpal")
646   (setq mode-line-process nil)
647   (use-local-map gnus-carpal-mode-map)
648   (buffer-disable-undo (current-buffer))
649   (setq buffer-read-only t)
650   (make-local-variable 'gnus-carpal-attached-buffer)
651   (run-hooks 'gnus-carpal-mode-hook))
652
653 (defun gnus-carpal-setup-buffer (type)
654   (let ((buffer (symbol-value (intern (format "gnus-carpal-%s-buffer" type)))))
655     (if (get-buffer buffer)
656         ()
657       (save-excursion
658         (set-buffer (get-buffer-create buffer))
659         (gnus-carpal-mode)
660         (setq gnus-carpal-attached-buffer 
661               (intern (format "gnus-%s-buffer" type)))
662         (gnus-add-current-to-buffer-list)
663         (let ((buttons (symbol-value 
664                         (intern (format "gnus-carpal-%s-buffer-buttons"
665                                         type))))
666               (buffer-read-only nil)
667               button)
668           (while buttons
669             (setq button (car buttons)
670                   buttons (cdr buttons))
671             (if (stringp button)
672                 (set-text-properties
673                  (point)
674                  (prog2 (insert button) (point) (insert " "))
675                  (list 'face gnus-carpal-header-face))
676               (set-text-properties
677                (point)
678                (prog2 (insert (car button)) (point) (insert " "))
679                (list 'gnus-callback (cdr button)
680                      'face gnus-carpal-button-face
681                      'mouse-face 'highlight))))
682           (let ((fill-column (- (window-width) 2)))
683             (fill-region (point-min) (point-max)))
684           (set-window-point (get-buffer-window (current-buffer)) 
685                             (point-min)))))))
686
687 (defun gnus-carpal-select ()
688   "Select the button under point."
689   (interactive)
690   (let ((func (get-text-property (point) 'gnus-callback)))
691     (if (null func)
692         ()
693       (pop-to-buffer (symbol-value gnus-carpal-attached-buffer))
694       (call-interactively func))))
695
696 (defun gnus-carpal-mouse-select (event)
697   "Select the button under the mouse pointer."
698   (interactive "e")
699   (mouse-set-point event)
700   (gnus-carpal-select))
701
702 ;;; 
703 ;;; article highlights
704 ;;;
705
706 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
707
708 ;;; Internal Variables:
709
710 (defvar gnus-button-regexp nil)
711 ;; Regexp matching any of the regexps from `gnus-button-alist'.
712
713 (defvar gnus-button-last nil)
714 ;; The value of `gnus-button-alist' when `gnus-button-regexp' was build.
715
716 ;;; Commands:
717
718 (defun gnus-article-push-button (event)
719   "Check text under the mouse pointer for a callback function.
720 If the text under the mouse pointer has a `gnus-callback' property,
721 call it with the value of the `gnus-data' text property."
722   (interactive "e")
723   (set-buffer (window-buffer (posn-window (event-start event))))
724   (let* ((pos (posn-point (event-start event)))
725          (data (get-text-property pos 'gnus-data))
726          (fun (get-text-property pos 'gnus-callback)))
727       (if fun (funcall fun data))))
728
729 (defun gnus-article-press-button ()
730   "Check text at point for a callback function.
731 If the text at point has a `gnus-callback' property,
732 call it with the value of the `gnus-data' text property."
733   (interactive)
734   (let* ((data (get-text-property (point) 'gnus-data))
735          (fun (get-text-property (point) 'gnus-callback)))
736       (if fun (funcall fun data))))
737
738 ;; Suggested by Arne Elofsson <arne@hodgkin.mbi.ucla.edu>
739 (defun gnus-article-next-button ()
740   "Move point to next button."
741   (interactive)
742   (if (get-text-property (point) 'gnus-callback)
743       (goto-char (next-single-property-change (point) 'gnus-callback
744                                        nil (point-max))))
745   (let ((pos (next-single-property-change (point) 'gnus-callback)))
746     (if pos
747         (goto-char pos)
748       (setq pos (next-single-property-change (point-min) 'gnus-callback))
749       (if pos
750           (goto-char pos)
751         (error "No buttons found")))))
752
753 (defun gnus-article-highlight ()
754   "Highlight current article.
755 This function calls `gnus-article-highlight-headers',
756 `gnus-article-highlight-citation', 
757 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
758 do the highlighting.  See the documentation for those functions."
759   (interactive)
760   (gnus-article-highlight-headers)
761   (gnus-article-highlight-citation)
762   (gnus-article-highlight-signature)
763   (gnus-article-add-buttons))
764
765 (defun gnus-article-hide ()
766   "Hide current article.
767 This function calls `gnus-article-hide-headers',
768 `gnus-article-hide-citation-maybe', and `gnus-article-hide-signature'
769 to do the hiding.  See the documentation for those functions." 
770   (interactive)
771   (gnus-article-hide-headers)
772   (gnus-article-hide-citation-maybe)
773   (gnus-article-hide-signature))
774
775 (defun gnus-article-highlight-headers ()
776   "Highlight article headers as specified by `gnus-header-face-alist'."
777   (interactive)
778   (save-excursion
779     (set-buffer gnus-article-buffer)
780     (goto-char (point-min))
781     (search-forward "\n\n")
782     (beginning-of-line 0)
783     (while (not (bobp))
784       (let ((alist gnus-header-face-alist)
785             (buffer-read-only nil)
786             (case-fold-search t)
787             (end (point))
788             (inhibit-point-motion-hooks t)
789             begin entry regexp header-face field-face header-found field-found)
790         (re-search-backward "^[^ \t]" nil t)
791         (setq begin (point))
792         (while alist
793           (setq entry (car alist)
794                 regexp (nth 0 entry)
795                 header-face (nth 1 entry)
796                 field-face (nth 2 entry)
797                 alist (cdr alist))
798           (if (looking-at regexp)
799               (let ((from (point)))
800                 (skip-chars-forward "^:\n")
801                 (and (not header-found)
802                      header-face
803                      (progn
804                        (put-text-property  from (point) 'face header-face)
805                        (setq header-found t)))
806                 (and (not field-found)
807                      field-face
808                      (progn 
809                        (skip-chars-forward ": \t")
810                        (let ((from (point)))
811                          (goto-char end)
812                          (skip-chars-backward " \t")
813                          (put-text-property from (point) 'face field-face)
814                          (setq field-found t))))))
815           (goto-char begin))))))
816
817 (defun gnus-article-highlight-signature ()
818   "Highlight the signature in an article.
819 It does this by highlighting everything after
820 `gnus-signature-separator' using `gnus-signature-face'." 
821   (interactive)
822   (save-excursion
823     (set-buffer gnus-article-buffer)
824     (let ((buffer-read-only nil)
825           (inhibit-point-motion-hooks t))
826       (goto-char (point-max))
827       (and (re-search-backward gnus-signature-separator nil t)
828            gnus-signature-face
829            (let ((start (match-beginning 0))
830                  (end (match-end 0)))
831              (gnus-article-add-button start end 'gnus-signature-toggle end)
832              (overlay-put (make-overlay end (point-max))
833                           'face gnus-signature-face))))))
834
835 (defun gnus-article-hide-signature ()
836   "Hide the signature in an article.
837 It does this by making everything after `gnus-signature-separator' invisible."
838   (interactive)
839   (save-excursion
840     (set-buffer gnus-article-buffer)
841     (let ((buffer-read-only nil))
842       (goto-char (point-max))
843       (and (re-search-backward gnus-signature-separator nil t)
844            gnus-signature-face
845            (add-text-properties (match-end 0) (point-max)
846                                 gnus-hidden-properties)))))
847
848 (defun gnus-article-add-buttons ()
849   "Find external references in article and make them to buttons.
850
851 External references are things like message-ids and URLs, as specified by 
852 `gnus-button-alist'."
853   (interactive)
854   (if (eq gnus-button-last gnus-button-alist)
855       ()
856     (setq gnus-button-regexp (mapconcat 'car gnus-button-alist  "\\|")
857           gnus-button-last gnus-button-alist))
858   (save-excursion
859     (set-buffer gnus-article-buffer)
860     (gnus-cite-parse-maybe)
861     (let ((buffer-read-only nil)
862           (inhibit-point-motion-hooks t)
863           (case-fold-search t))
864       (goto-char (point-min))
865       (search-forward "\n\n")
866       (while (re-search-forward gnus-button-regexp nil t)
867         (goto-char (match-beginning 0))
868         (let* ((from (point))
869                (entry (gnus-button-entry))
870                (start (and entry (match-beginning (nth 1 entry))))
871                (end (and entry (match-end (nth 1 entry))))
872                (form (nth 2 entry))
873                marker)
874           (if (not entry)
875               ()
876             (goto-char (match-end 0))
877             (if (eval form)
878                 (gnus-article-add-button start end 'gnus-button-push
879                                          (set-marker (make-marker)
880                                                      from)))))))))
881
882 ;;; External functions:
883
884 (defun gnus-article-add-button (from to fun &optional data)
885   "Create a button between FROM and TO with callback FUN and data DATA."
886   (add-text-properties from to
887                        (append (if gnus-article-button-face
888                                    (list 'face gnus-article-button-face))
889                                (if gnus-article-mouse-face
890                                    (list 'mouse-face gnus-article-mouse-face))
891                                (list 'gnus-callback fun)
892                                (if data (list 'gnus-data data)))))
893
894 ;;; Internal functions:
895
896 (defun gnus-signature-toggle (end)
897   (save-excursion
898     (set-buffer gnus-article-buffer)
899     (let ((buffer-read-only nil))
900       (if (get-text-property end 'invisible)
901           (remove-text-properties end (point-max) gnus-hidden-properties)
902         (add-text-properties end (point-max) gnus-hidden-properties)))))
903
904 (defun gnus-make-face (color)
905   ;; Create entry for face with background COLOR.
906   (let ((name (intern (concat "gnus " color))))
907     (make-face name)
908     (if gnus-make-foreground
909         (set-face-foreground name color)
910       (set-face-background name color))
911     name))
912
913 (defun gnus-button-entry ()
914   ;; Return the first entry in `gnus-button-alist' matching this place.
915   (let ((alist gnus-button-alist)
916         (entry nil))
917     (while alist
918       (setq entry (car alist)
919             alist (cdr alist))
920       (if (looking-at (car entry))
921           (setq alist nil)
922         (setq entry nil)))
923     entry))
924
925 (defun gnus-button-push (marker)
926   ;; Push button starting at MARKER.
927   (save-excursion
928     (set-buffer gnus-article-buffer)
929     (goto-char marker)
930     (let* ((entry (gnus-button-entry))
931            (inhibit-point-motion-hooks t)
932            (fun (nth 3 entry))
933            (args (mapcar (lambda (group) 
934                            (let ((string (buffer-substring
935                                           (match-beginning group)
936                                           (match-end group))))
937                            (set-text-properties 0 (length string) nil string)
938                            string))
939                          (nthcdr 4 entry))))
940       (cond ((fboundp fun)
941              (apply fun args))
942             ((and (boundp fun)
943                   (fboundp (symbol-value fun)))
944              (apply (symbol-value fun) args))
945             (t
946              (message "You must define `%S' to use this button"
947                       (cons fun args)))))))
948
949 (defun gnus-button-message-id (message-id)
950   ;; Push on MESSAGE-ID.
951   (save-excursion
952     (set-buffer gnus-summary-buffer)
953     (gnus-summary-refer-article message-id)))
954
955 ;;; Compatibility Functions:
956
957 (or (fboundp 'rassoc)
958     ;; Introduced in Emacs 19.29.
959     (defun rassoc (elt list)
960       "Return non-nil if ELT is `equal' to the cdr of an element of LIST.
961 The value is actually the element of LIST whose cdr is ELT."
962       (let (result)
963         (while list
964           (setq result (car list))
965           (if (equal (cdr result) elt)
966               (setq list nil)
967             (setq result nil
968                   list (cdr list))))
969         result)))
970
971 (provide 'gnus-vis)
972
973 ;;; gnus-vis.el ends here