*** empty log message ***
[gnus] / lisp / gnus-salt.el
1 ;;; gnus-salt.el --- alternate summary mode interfaces for Gnus
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Keywords: news
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (eval-when-compile (require 'cl))
29
30 (require 'gnus)
31 (require 'gnus-sum)
32
33 ;;;
34 ;;; gnus-pick-mode
35 ;;;
36
37 (defvar gnus-pick-mode nil
38   "Minor mode for providing a pick-and-read interface in Gnus summary buffers.")
39
40 (defcustom gnus-pick-display-summary nil
41   "*Display summary while reading."
42   :type 'boolean
43   :group 'gnus-summary-pick)
44
45 (defcustom gnus-pick-mode-hook nil
46   "Hook run in summary pick mode buffers."
47   :type 'hook
48   :group 'gnus-summary-pick)
49
50 (defcustom gnus-mark-unpicked-articles-as-read nil
51   "*If non-nil, mark all unpicked articles as read."
52   :type 'boolean
53   :group 'gnus-summary-pick)
54
55 (defcustom gnus-pick-elegant-flow t
56   "If non-nil, gnus-pick-start-reading will run gnus-summary-next-group when no articles have been picked."
57   :type 'boolean
58   :group 'gnus-summary-pick)
59
60 (defcustom gnus-summary-pick-line-format
61   "%-5P %U\%R\%z\%I\%(%[%4L: %-20,20n%]%) %s\n"
62   "*The format specification of the lines in pick buffers.
63 It accepts the same format specs that `gnus-summary-line-format' does."
64   :type 'string
65   :group 'gnus-summary-pick)
66
67 ;;; Internal variables.
68
69 (defvar gnus-pick-mode-map nil)
70
71 (unless gnus-pick-mode-map
72   (setq gnus-pick-mode-map (make-sparse-keymap))
73
74   (gnus-define-keys gnus-pick-mode-map
75     " " gnus-pick-next-page
76     "u" gnus-pick-unmark-article-or-thread
77     "." gnus-pick-article-or-thread
78     gnus-down-mouse-2 gnus-pick-mouse-pick-region
79     "\r" gnus-pick-start-reading
80     ))
81
82 (defun gnus-pick-make-menu-bar ()
83   (unless (boundp 'gnus-pick-menu)
84     (easy-menu-define
85      gnus-pick-menu gnus-pick-mode-map ""
86      '("Pick"
87        ("Pick"
88         ["Article" gnus-summary-mark-as-processable t]
89         ["Thread" gnus-uu-mark-thread t]
90         ["Region" gnus-uu-mark-region t]
91         ["Regexp" gnus-uu-mark-by-regexp t]
92         ["Buffer" gnus-uu-mark-buffer t])
93        ("Unpick"
94         ["Article" gnus-summary-unmark-as-processable t]
95         ["Thread" gnus-uu-unmark-thread t]
96         ["Region" gnus-uu-unmark-region t]
97         ["Regexp" gnus-uu-unmark-by-regexp t]
98         ["Buffer" gnus-summary-unmark-all-processable t])
99        ["Start reading" gnus-pick-start-reading t]
100        ["Switch pick mode off" gnus-pick-mode gnus-pick-mode]))))
101
102 (defun gnus-pick-mode (&optional arg)
103   "Minor mode for providing a pick-and-read interface in Gnus summary buffers.
104
105 \\{gnus-pick-mode-map}"
106   (interactive "P")
107   (when (eq major-mode 'gnus-summary-mode)
108     (if (not (set (make-local-variable 'gnus-pick-mode)
109                   (if (null arg) (not gnus-pick-mode)
110                     (> (prefix-numeric-value arg) 0))))
111         (remove-hook 'gnus-message-setup-hook 'gnus-pick-setup-message)
112       ;; Make sure that we don't select any articles upon group entry.
113       (set (make-local-variable 'gnus-auto-select-first) nil)
114       ;; Change line format.
115       (setq gnus-summary-line-format gnus-summary-pick-line-format)
116       (setq gnus-summary-line-format-spec nil)
117       (gnus-update-format-specifications nil 'summary)
118       (gnus-update-summary-mark-positions)
119       (add-hook 'gnus-message-setup-hook 'gnus-pick-setup-message)
120       (set (make-local-variable 'gnus-summary-goto-unread) 'never)
121       ;; Set up the menu.
122       (when (gnus-visual-p 'pick-menu 'menu)
123         (gnus-pick-make-menu-bar))
124       (gnus-add-minor-mode 'gnus-pick-mode " Pick" gnus-pick-mode-map)
125       (gnus-run-hooks 'gnus-pick-mode-hook))))
126
127 (defun gnus-pick-setup-message ()
128   "Make Message do the right thing on exit."
129   (when (and (gnus-buffer-live-p gnus-summary-buffer)
130              (save-excursion
131                (set-buffer gnus-summary-buffer)
132                gnus-pick-mode))
133     (message-add-action
134      '(gnus-configure-windows 'pick t) 'send 'exit 'postpone 'kill)))
135
136 (defvar gnus-pick-line-number 1)
137 (defun gnus-pick-line-number ()
138   "Return the current line number."
139   (if (bobp)
140       (setq gnus-pick-line-number 1)
141     (incf gnus-pick-line-number)))
142
143 (defun gnus-pick-start-reading (&optional catch-up)
144   "Start reading the picked articles.
145 If given a prefix, mark all unpicked articles as read."
146   (interactive "P")
147   (if gnus-newsgroup-processable
148       (progn
149         (gnus-summary-limit-to-articles nil)
150         (when (or catch-up gnus-mark-unpicked-articles-as-read)
151           (gnus-summary-limit-mark-excluded-as-read))
152         (gnus-summary-first-article)
153         (gnus-configure-windows
154          (if gnus-pick-display-summary 'article 'pick) t))
155     (if gnus-pick-elegant-flow
156         (progn
157           (when (or catch-up gnus-mark-unpicked-articles-as-read)
158             (gnus-summary-catchup nil t))
159           (if (gnus-group-quit-config gnus-newsgroup-name)
160               (gnus-summary-exit)
161             (gnus-summary-next-group)))
162       (error "No articles have been picked"))))
163
164 (defun gnus-pick-goto-article (arg)
165   "Go to the article number indicated by ARG.  If ARG is an invalid
166 article number, then stay on current line."
167   (let (pos)
168     (save-excursion
169       (goto-char (point-min))
170       (when (zerop (forward-line (1- (prefix-numeric-value arg))))
171         (setq pos (point))))
172     (if (not pos)
173         (gnus-error 2 "No such line: %s" arg)
174       (goto-char pos))))
175     
176 (defun gnus-pick-article (&optional arg)
177     "Pick the article on the current line.
178 If ARG, pick the article on that line instead."
179   (interactive "P")
180   (when arg
181     (gnus-pick-goto-article arg))
182   (gnus-summary-mark-as-processable 1))
183
184 (defun gnus-pick-article-or-thread (&optional arg)
185   "If gnus-thread-hide-subtree is t, then pick the thread on the current line.
186 Otherwise pick the article on the current line.
187 If ARG, pick the article/thread on that line instead."
188   (interactive "P")
189   (when arg
190     (gnus-pick-goto-article arg))
191   (if gnus-thread-hide-subtree
192       (gnus-uu-mark-thread)
193     (gnus-summary-mark-as-processable 1)))
194                   
195 (defun gnus-pick-unmark-article-or-thread (&optional arg)
196   "If gnus-thread-hide-subtree is t, then unmark the thread on current line.
197 Otherwise unmark the article on current line.
198 If ARG, unmark thread/article on that line instead."
199   (interactive "P")
200   (when arg
201     (gnus-pick-goto-article arg))
202   (if gnus-thread-hide-subtree
203       (gnus-uu-unmark-thread)
204     (gnus-summary-unmark-as-processable 1)))
205   
206 (defun gnus-pick-mouse-pick (e)
207   (interactive "e")
208   (mouse-set-point e)
209   (save-excursion
210     (gnus-summary-mark-as-processable 1)))
211
212 (defun gnus-pick-mouse-pick-region (start-event)
213   "Pick articles that the mouse is dragged over.
214 This must be bound to a button-down mouse event."
215   (interactive "e")
216   (mouse-minibuffer-check start-event)
217   (let* ((echo-keystrokes 0)
218          (start-posn (event-start start-event))
219          (start-point (posn-point start-posn))
220          (start-line (1+ (count-lines 1 start-point)))
221          (start-window (posn-window start-posn))
222          (start-frame (window-frame start-window))
223          (bounds (gnus-window-edges start-window))
224          (top (nth 1 bounds))
225          (bottom (if (window-minibuffer-p start-window)
226                      (nth 3 bounds)
227                    ;; Don't count the mode line.
228                    (1- (nth 3 bounds))))
229          (click-count (1- (event-click-count start-event))))
230     (setq mouse-selection-click-count click-count)
231     (setq mouse-selection-click-count-buffer (current-buffer))
232     (mouse-set-point start-event)
233     ;; In case the down click is in the middle of some intangible text,
234     ;; use the end of that text, and put it in START-POINT.
235     (when (< (point) start-point)
236       (goto-char start-point))
237     (gnus-pick-article)
238     (setq start-point (point))
239     ;; end-of-range is used only in the single-click case.
240     ;; It is the place where the drag has reached so far
241     ;; (but not outside the window where the drag started).
242     (let (event end end-point last-end-point (end-of-range (point)))
243       (track-mouse
244        (while (progn
245                 (setq event (gnus-read-event-char))
246                 (or (mouse-movement-p event)
247                     (eq (car-safe event) 'switch-frame)))
248          (if (eq (car-safe event) 'switch-frame)
249              nil
250            (setq end (event-end event)
251                  end-point (posn-point end))
252            (when end-point
253              (setq last-end-point end-point))
254
255            (cond
256             ;; Are we moving within the original window?
257             ((and (eq (posn-window end) start-window)
258                   (integer-or-marker-p end-point))
259              ;; Go to START-POINT first, so that when we move to END-POINT,
260              ;; if it's in the middle of intangible text,
261              ;; point jumps in the direction away from START-POINT.
262              (goto-char start-point)
263              (goto-char end-point)
264              (gnus-pick-article)
265              ;; In case the user moved his mouse really fast, pick
266              ;; articles on the line between this one and the last one.
267              (let* ((this-line (1+ (count-lines 1 end-point)))
268                     (min-line (min this-line start-line))
269                     (max-line (max this-line start-line)))
270                (while (< min-line max-line)
271                  (goto-line min-line)
272                  (gnus-pick-article)
273                  (setq min-line (1+ min-line)))
274                (setq start-line this-line))
275              (when (zerop (% click-count 3))
276                (setq end-of-range (point))))
277             (t
278              (let ((mouse-row (cdr (cdr (mouse-position)))))
279                (cond
280                 ((null mouse-row))
281                 ((< mouse-row top)
282                  (mouse-scroll-subr start-window (- mouse-row top)))
283                 ((>= mouse-row bottom)
284                  (mouse-scroll-subr start-window
285                                     (1+ (- mouse-row bottom)))))))))))
286       (when (consp event)
287         (let ((fun (key-binding (vector (car event)))))
288           ;; Run the binding of the terminating up-event, if possible.
289           ;; In the case of a multiple click, it gives the wrong results,
290           ;; because it would fail to set up a region.
291           (when nil
292             ;; (and (= (mod mouse-selection-click-count 3) 0) (fboundp fun))
293             ;; In this case, we can just let the up-event execute normally.
294             (let ((end (event-end event)))
295               ;; Set the position in the event before we replay it,
296               ;; because otherwise it may have a position in the wrong
297               ;; buffer.
298               (setcar (cdr end) end-of-range)
299               ;; Delete the overlay before calling the function,
300               ;; because delete-overlay increases buffer-modified-tick.
301               (push event unread-command-events))))))))
302
303 (defun gnus-pick-next-page ()
304   "Go to the next page.  If at the end of the buffer, start reading articles."
305   (interactive)
306   (let ((scroll-in-place nil))
307     (condition-case nil
308         (scroll-up)
309       (end-of-buffer (gnus-pick-start-reading)))))
310
311 ;;;
312 ;;; gnus-binary-mode
313 ;;;
314
315 (defvar gnus-binary-mode nil
316   "Minor mode for providing a binary group interface in Gnus summary buffers.")
317
318 (defvar gnus-binary-mode-hook nil
319   "Hook run in summary binary mode buffers.")
320
321 (defvar gnus-binary-mode-map nil)
322
323 (unless gnus-binary-mode-map
324   (setq gnus-binary-mode-map (make-sparse-keymap))
325
326   (gnus-define-keys
327    gnus-binary-mode-map
328    "g" gnus-binary-show-article))
329
330 (defun gnus-binary-make-menu-bar ()
331   (unless (boundp 'gnus-binary-menu)
332     (easy-menu-define
333      gnus-binary-menu gnus-binary-mode-map ""
334      '("Pick"
335        ["Switch binary mode off" gnus-binary-mode t]))))
336
337 (defun gnus-binary-mode (&optional arg)
338   "Minor mode for providing a binary group interface in Gnus summary buffers."
339   (interactive "P")
340   (when (eq major-mode 'gnus-summary-mode)
341     (make-local-variable 'gnus-binary-mode)
342     (setq gnus-binary-mode
343           (if (null arg) (not gnus-binary-mode)
344             (> (prefix-numeric-value arg) 0)))
345     (when gnus-binary-mode
346       ;; Make sure that we don't select any articles upon group entry.
347       (make-local-variable 'gnus-auto-select-first)
348       (setq gnus-auto-select-first nil)
349       (make-local-variable 'gnus-summary-display-article-function)
350       (setq gnus-summary-display-article-function 'gnus-binary-display-article)
351       ;; Set up the menu.
352       (when (gnus-visual-p 'binary-menu 'menu)
353         (gnus-binary-make-menu-bar))
354       (gnus-add-minor-mode 'gnus-binary-mode " Binary" gnus-binary-mode-map)
355       (gnus-run-hooks 'gnus-binary-mode-hook))))
356
357 (defun gnus-binary-display-article (article &optional all-header)
358   "Run ARTICLE through the binary decode functions."
359   (when (gnus-summary-goto-subject article)
360     (let ((gnus-view-pseudos 'automatic))
361       (gnus-uu-decode-uu))))
362
363 (defun gnus-binary-show-article (&optional arg)
364   "Bypass the binary functions and show the article."
365   (interactive "P")
366   (let (gnus-summary-display-article-function)
367     (gnus-summary-show-article arg)))
368
369 ;;;
370 ;;; gnus-tree-mode
371 ;;;
372
373 (defcustom gnus-tree-line-format "%(%[%3,3n%]%)"
374   "Format of tree elements."
375   :type 'string
376   :group 'gnus-summary-tree)
377
378 (defcustom gnus-tree-minimize-window t
379   "If non-nil, minimize the tree buffer window.
380 If a number, never let the tree buffer grow taller than that number of
381 lines."
382   :type '(choice boolean
383                  integer)
384   :group 'gnus-summary-tree)
385
386 (defcustom gnus-selected-tree-face 'modeline
387   "*Face used for highlighting selected articles in the thread tree."
388   :type 'face
389   :group 'gnus-summary-tree)
390
391 (defvar gnus-tree-brackets '((?\[ . ?\]) (?\( . ?\))
392                              (?\{ . ?\}) (?< . ?>))
393   "Brackets used in tree nodes.")
394
395 (defvar gnus-tree-parent-child-edges '(?- ?\\ ?|)
396   "Characters used to connect parents with children.")
397
398 (defcustom gnus-tree-mode-line-format "Gnus: %%b %S %Z"
399   "*The format specification for the tree mode line."
400   :type 'string
401   :group 'gnus-summary-tree)
402
403 (defcustom gnus-generate-tree-function 'gnus-generate-vertical-tree
404   "*Function for generating a thread tree.
405 Two predefined functions are available:
406 `gnus-generate-horizontal-tree' and `gnus-generate-vertical-tree'."
407   :type '(radio (function-item gnus-generate-vertical-tree)
408                 (function-item gnus-generate-horizontal-tree)
409                 (function :tag "Other" nil))
410   :group 'gnus-summary-tree)
411
412 (defcustom gnus-tree-mode-hook nil
413   "*Hook run in tree mode buffers."
414   :type 'hook
415   :group 'gnus-summary-tree)
416
417 ;;; Internal variables.
418
419 (defvar gnus-tree-line-format-alist
420   `((?n gnus-tmp-name ?s)
421     (?f gnus-tmp-from ?s)
422     (?N gnus-tmp-number ?d)
423     (?\[ gnus-tmp-open-bracket ?c)
424     (?\] gnus-tmp-close-bracket ?c)
425     (?s gnus-tmp-subject ?s)))
426
427 (defvar gnus-tree-mode-line-format-alist gnus-summary-mode-line-format-alist)
428
429 (defvar gnus-tree-mode-line-format-spec nil)
430 (defvar gnus-tree-line-format-spec nil)
431
432 (defvar gnus-tree-node-length nil)
433 (defvar gnus-selected-tree-overlay nil)
434
435 (defvar gnus-tree-displayed-thread nil)
436
437 (defvar gnus-tree-mode-map nil)
438 (put 'gnus-tree-mode 'mode-class 'special)
439
440 (unless gnus-tree-mode-map
441   (setq gnus-tree-mode-map (make-keymap))
442   (suppress-keymap gnus-tree-mode-map)
443   (gnus-define-keys
444    gnus-tree-mode-map
445    "\r" gnus-tree-select-article
446    gnus-mouse-2 gnus-tree-pick-article
447    "\C-?" gnus-tree-read-summary-keys
448    "h" gnus-tree-show-summary
449
450    "\C-c\C-i" gnus-info-find-node)
451
452   (substitute-key-definition
453    'undefined 'gnus-tree-read-summary-keys gnus-tree-mode-map))
454
455 (defun gnus-tree-make-menu-bar ()
456   (unless (boundp 'gnus-tree-menu)
457     (easy-menu-define
458      gnus-tree-menu gnus-tree-mode-map ""
459      '("Tree"
460        ["Select article" gnus-tree-select-article t]))))
461
462 (defun gnus-tree-mode ()
463   "Major mode for displaying thread trees."
464   (interactive)
465   (gnus-set-format 'tree-mode)
466   (gnus-set-format 'tree t)
467   (when (gnus-visual-p 'tree-menu 'menu)
468     (gnus-tree-make-menu-bar))
469   (kill-all-local-variables)
470   (gnus-simplify-mode-line)
471   (setq mode-name "Tree")
472   (setq major-mode 'gnus-tree-mode)
473   (use-local-map gnus-tree-mode-map)
474   (buffer-disable-undo (current-buffer))
475   (setq buffer-read-only t)
476   (setq truncate-lines t)
477   (save-excursion
478     (gnus-set-work-buffer)
479     (gnus-tree-node-insert (make-mail-header "") nil)
480     (setq gnus-tree-node-length (1- (point))))
481   (gnus-run-hooks 'gnus-tree-mode-hook))
482
483 (defun gnus-tree-read-summary-keys (&optional arg)
484   "Read a summary buffer key sequence and execute it."
485   (interactive "P")
486   (let ((buf (current-buffer))
487         win)
488     (set-buffer gnus-article-buffer)      
489     (gnus-article-read-summary-keys arg nil t)
490     (when (setq win (get-buffer-window buf))
491       (select-window win)
492       (when gnus-selected-tree-overlay
493         (goto-char (or (gnus-overlay-end gnus-selected-tree-overlay) 1)))
494       (gnus-tree-minimize))))
495
496 (defun gnus-tree-show-summary ()
497   "Reconfigure windows to show summary buffer."
498   (interactive)
499   (if (not (gnus-buffer-live-p gnus-summary-buffer))
500       (error "There is no summary buffer for this tree buffer")
501     (gnus-configure-windows 'article)
502     (gnus-summary-goto-subject gnus-current-article)))
503
504 (defun gnus-tree-select-article (article)
505   "Select the article under point, if any."
506   (interactive (list (gnus-tree-article-number)))
507   (let ((buf (current-buffer)))
508     (when article
509       (save-excursion
510         (set-buffer gnus-summary-buffer)
511         (gnus-summary-goto-article article))
512       (select-window (get-buffer-window buf)))))
513
514 (defun gnus-tree-pick-article (e)
515   "Select the article under the mouse pointer."
516   (interactive "e")
517   (mouse-set-point e)
518   (gnus-tree-select-article (gnus-tree-article-number)))
519
520 (defun gnus-tree-article-number ()
521   (get-text-property (point) 'gnus-number))
522
523 (defun gnus-tree-article-region (article)
524   "Return a cons with BEG and END of the article region."
525   (let ((pos (text-property-any (point-min) (point-max) 'gnus-number article)))
526     (when pos
527       (cons pos (next-single-property-change pos 'gnus-number)))))
528
529 (defun gnus-tree-goto-article (article)
530   (let ((pos (text-property-any (point-min) (point-max) 'gnus-number article)))
531     (when pos
532       (goto-char pos))))
533
534 (defun gnus-tree-recenter ()
535   "Center point in the tree window."
536   (let ((selected (selected-window))
537         (tree-window (get-buffer-window gnus-tree-buffer t)))
538     (when tree-window
539       (select-window tree-window)
540       (when gnus-selected-tree-overlay
541         (goto-char (or (gnus-overlay-end gnus-selected-tree-overlay) 1)))
542       (let* ((top (cond ((< (window-height) 4) 0)
543                         ((< (window-height) 7) 1)
544                         (t 2)))
545              (height (1- (window-height)))
546              (bottom (save-excursion (goto-char (point-max))
547                                      (forward-line (- height))
548                                      (point))))
549         ;; Set the window start to either `bottom', which is the biggest
550         ;; possible valid number, or the second line from the top,
551         ;; whichever is the least.
552         (set-window-start
553          tree-window (min bottom (save-excursion
554                                    (forward-line (- top)) (point)))))
555       (select-window selected))))
556
557 (defun gnus-get-tree-buffer ()
558   "Return the tree buffer properly initialized."
559   (save-excursion
560     (set-buffer (get-buffer-create gnus-tree-buffer))
561     (unless (eq major-mode 'gnus-tree-mode)
562       (gnus-add-current-to-buffer-list)
563       (gnus-tree-mode))
564     (current-buffer)))
565
566 (defun gnus-tree-minimize ()
567   (when (and gnus-tree-minimize-window
568              (not (one-window-p)))
569     (let ((windows 0)
570           tot-win-height)
571       (walk-windows (lambda (window) (incf windows)))
572       (setq tot-win-height
573             (- (frame-height)
574                (* window-min-height (1- windows))
575                2))
576       (let* ((window-min-height 2)
577              (height (count-lines (point-min) (point-max)))
578              (min (max (1- window-min-height) height))
579              (tot (if (numberp gnus-tree-minimize-window)
580                       (min gnus-tree-minimize-window min)
581                     min))
582              (win (get-buffer-window (current-buffer)))
583              (wh (and win (1- (window-height win)))))
584         (setq tot (min tot tot-win-height))
585         (when (and win
586                    (not (eq tot wh)))
587           (let ((selected (selected-window)))
588             (when (ignore-errors (select-window win))
589               (enlarge-window (- tot wh))
590               (select-window selected))))))))
591
592 ;;; Generating the tree.
593
594 (defun gnus-tree-node-insert (header sparse &optional adopted)
595   (let* ((dummy (stringp header))
596          (header (if (vectorp header) header
597                    (progn
598                      (setq header (make-mail-header "*****"))
599                      (mail-header-set-number header 0)
600                      (mail-header-set-lines header 0)
601                      (mail-header-set-chars header 0)
602                      header)))
603          (gnus-tmp-from (mail-header-from header))
604          (gnus-tmp-subject (mail-header-subject header))
605          (gnus-tmp-number (mail-header-number header))
606          (gnus-tmp-name
607           (cond
608            ((string-match "(.+)" gnus-tmp-from)
609             (substring gnus-tmp-from
610                        (1+ (match-beginning 0)) (1- (match-end 0))))
611            ((string-match "<[^>]+> *$" gnus-tmp-from)
612             (let ((beg (match-beginning 0)))
613               (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
614                        (substring gnus-tmp-from (1+ (match-beginning 0))
615                                   (1- (match-end 0))))
616                   (substring gnus-tmp-from 0 beg))))
617            ((memq gnus-tmp-number sparse)
618             "***")
619            (t gnus-tmp-from)))
620          (gnus-tmp-open-bracket
621           (cond ((memq gnus-tmp-number sparse)
622                  (caadr gnus-tree-brackets))
623                 (dummy (caaddr gnus-tree-brackets))
624                 (adopted (car (nth 3 gnus-tree-brackets)))
625                 (t (caar gnus-tree-brackets))))
626          (gnus-tmp-close-bracket
627           (cond ((memq gnus-tmp-number sparse)
628                  (cdadr gnus-tree-brackets))
629                 (adopted (cdr (nth 3 gnus-tree-brackets)))
630                 (dummy
631                  (cdaddr gnus-tree-brackets))
632                 (t (cdar gnus-tree-brackets))))
633          (buffer-read-only nil)
634          beg end)
635     (gnus-add-text-properties
636      (setq beg (point))
637      (setq end (progn (eval gnus-tree-line-format-spec) (point)))
638      (list 'gnus-number gnus-tmp-number))
639     (when (or t (gnus-visual-p 'tree-highlight 'highlight))
640       (gnus-tree-highlight-node gnus-tmp-number beg end))))
641
642 (defun gnus-tree-highlight-node (article beg end)
643   "Highlight current line according to `gnus-summary-highlight'."
644   (let ((list gnus-summary-highlight)
645         face)
646     (save-excursion
647       (set-buffer gnus-summary-buffer)
648       (let* ((score (or (cdr (assq article gnus-newsgroup-scored))
649                         gnus-summary-default-score 0))
650              (default gnus-summary-default-score)
651              (mark (or (gnus-summary-article-mark article) gnus-unread-mark)))
652         ;; Eval the cars of the lists until we find a match.
653         (while (and list
654                     (not (eval (caar list))))
655           (setq list (cdr list)))))
656     (unless (eq (setq face (cdar list)) (get-text-property beg 'face))
657       (gnus-put-text-property-excluding-characters-with-faces
658        beg end 'face
659        (if (boundp face) (symbol-value face) face)))))
660
661 (defun gnus-tree-indent (level)
662   (insert (make-string (1- (* (1+ gnus-tree-node-length) level)) ? )))
663
664 (defvar gnus-tmp-limit)
665 (defvar gnus-tmp-sparse)
666 (defvar gnus-tmp-indent)
667
668 (defun gnus-generate-tree (thread)
669   "Generate a thread tree for THREAD."
670   (save-excursion
671     (set-buffer (gnus-get-tree-buffer))
672     (let ((buffer-read-only nil)
673           (gnus-tmp-indent 0))
674       (erase-buffer)
675       (funcall gnus-generate-tree-function thread 0)
676       (gnus-set-mode-line 'tree)
677       (goto-char (point-min))
678       (gnus-tree-minimize)
679       (gnus-tree-recenter)
680       (let ((selected (selected-window)))
681         (when (get-buffer-window (set-buffer gnus-tree-buffer) t)
682           (select-window (get-buffer-window (set-buffer gnus-tree-buffer) t))
683           (gnus-horizontal-recenter)
684           (select-window selected))))))
685
686 (defun gnus-generate-horizontal-tree (thread level &optional dummyp adopted)
687   "Generate a horizontal tree."
688   (let* ((dummy (stringp (car thread)))
689          (do (or dummy
690                  (and (car thread)
691                       (memq (mail-header-number (car thread))
692                             gnus-tmp-limit))))
693          col beg)
694     (if (not do)
695         ;; We don't want this article.
696         (setq thread (cdr thread))
697       (if (not (bolp))
698           ;; Not the first article on the line, so we insert a "-".
699           (insert (car gnus-tree-parent-child-edges))
700         ;; If the level isn't zero, then we insert some indentation.
701         (unless (zerop level)
702           (gnus-tree-indent level)
703           (insert (cadr gnus-tree-parent-child-edges))
704           (setq col (- (setq beg (point)) (gnus-point-at-bol) 1))
705           ;; Draw "|" lines upwards.
706           (while (progn
707                    (forward-line -1)
708                    (forward-char col)
709                    (= (following-char) ? ))
710             (delete-char 1)
711             (insert (caddr gnus-tree-parent-child-edges)))
712           (goto-char beg)))
713       (setq dummyp nil)
714       ;; Insert the article node.
715       (gnus-tree-node-insert (pop thread) gnus-tmp-sparse adopted))
716     (if (null thread)
717         ;; End of the thread, so we go to the next line.
718         (unless (bolp)
719           (insert "\n"))
720       ;; Recurse downwards in all children of this article.
721       (while thread
722         (gnus-generate-horizontal-tree
723          (pop thread) (if do (1+ level) level)
724          (or dummyp dummy) dummy)))))
725
726 (defsubst gnus-tree-indent-vertical ()
727   (let ((len (- (* (1+ gnus-tree-node-length) gnus-tmp-indent)
728                 (- (point) (gnus-point-at-bol)))))
729     (when (> len 0)
730       (insert (make-string len ? )))))
731
732 (defsubst gnus-tree-forward-line (n)
733   (while (>= (decf n) 0)
734     (unless (zerop (forward-line 1))
735       (end-of-line)
736       (insert "\n")))
737   (end-of-line))
738
739 (defun gnus-generate-vertical-tree (thread level &optional dummyp adopted)
740   "Generate a vertical tree."
741   (let* ((dummy (stringp (car thread)))
742          (do (or dummy
743                  (and (car thread)
744                       (memq (mail-header-number (car thread))
745                             gnus-tmp-limit))))
746          beg)
747     (if (not do)
748         ;; We don't want this article.
749         (setq thread (cdr thread))
750       (if (not (save-excursion (beginning-of-line) (bobp)))
751           ;; Not the first article on the line, so we insert a "-".
752           (progn
753             (gnus-tree-indent-vertical)
754             (insert (make-string (/ gnus-tree-node-length 2) ? ))
755             (insert (caddr gnus-tree-parent-child-edges))
756             (gnus-tree-forward-line 1))
757         ;; If the level isn't zero, then we insert some indentation.
758         (unless (zerop gnus-tmp-indent)
759           (gnus-tree-forward-line (1- (* 2 level)))
760           (gnus-tree-indent-vertical)
761           (delete-char -1)
762           (insert (cadr gnus-tree-parent-child-edges))
763           (setq beg (point))
764           (forward-char -1)
765           ;; Draw "-" lines leftwards.
766           (while (= (char-after (1- (point))) ? )
767             (delete-char -1)
768             (insert (car gnus-tree-parent-child-edges))
769             (forward-char -1))
770           (goto-char beg)
771           (gnus-tree-forward-line 1)))
772       (setq dummyp nil)
773       ;; Insert the article node.
774       (gnus-tree-indent-vertical)
775       (gnus-tree-node-insert (pop thread) gnus-tmp-sparse adopted)
776       (gnus-tree-forward-line 1))
777     (if (null thread)
778         ;; End of the thread, so we go to the next line.
779         (progn
780           (goto-char (point-min))
781           (end-of-line)
782           (incf gnus-tmp-indent))
783       ;; Recurse downwards in all children of this article.
784       (while thread
785         (gnus-generate-vertical-tree
786          (pop thread) (if do (1+ level) level)
787          (or dummyp dummy) dummy)))))
788
789 ;;; Interface functions.
790
791 (defun gnus-possibly-generate-tree (article &optional force)
792   "Generate the thread tree for ARTICLE if it isn't displayed already."
793   (when (save-excursion
794           (set-buffer gnus-summary-buffer)
795           (and gnus-use-trees
796                gnus-show-threads
797                (vectorp (gnus-summary-article-header article))))
798     (save-excursion
799       (let ((top (save-excursion
800                    (set-buffer gnus-summary-buffer)
801                    (gnus-cut-thread
802                     (gnus-remove-thread
803                      (mail-header-id
804                       (gnus-summary-article-header article))
805                      t))))
806             (gnus-tmp-limit gnus-newsgroup-limit)
807             (gnus-tmp-sparse gnus-newsgroup-sparse))
808         (when (or force
809                   (not (eq top gnus-tree-displayed-thread)))
810           (gnus-generate-tree top)
811           (setq gnus-tree-displayed-thread top))))))
812
813 (defun gnus-tree-open (group)
814   (gnus-get-tree-buffer))
815
816 (defun gnus-tree-close (group)
817   (gnus-kill-buffer gnus-tree-buffer))
818
819 (defun gnus-highlight-selected-tree (article)
820   "Highlight the selected article in the tree."
821   (let ((buf (current-buffer))
822         region)
823     (set-buffer gnus-tree-buffer)
824     (when (setq region (gnus-tree-article-region article))
825       (when (or (not gnus-selected-tree-overlay)
826                 (gnus-extent-detached-p gnus-selected-tree-overlay))
827         ;; Create a new overlay.
828         (gnus-overlay-put
829          (setq gnus-selected-tree-overlay (gnus-make-overlay 1 2))
830          'face gnus-selected-tree-face))
831       ;; Move the overlay to the article.
832       (gnus-move-overlay
833        gnus-selected-tree-overlay (goto-char (car region)) (cdr region))
834       (gnus-tree-minimize)
835       (gnus-tree-recenter)
836       (let ((selected (selected-window)))
837         (when (get-buffer-window (set-buffer gnus-tree-buffer) t)
838           (select-window (get-buffer-window (set-buffer gnus-tree-buffer) t))
839           (gnus-horizontal-recenter)
840           (select-window selected))))
841     ;; If we remove this save-excursion, it updates the wrong mode lines?!?
842     (save-excursion
843       (set-buffer gnus-tree-buffer)
844       (gnus-set-mode-line 'tree))
845     (set-buffer buf)))
846
847 (defun gnus-tree-highlight-article (article face)
848   (save-excursion
849     (set-buffer (gnus-get-tree-buffer))
850     (let (region)
851       (when (setq region (gnus-tree-article-region article))
852         (gnus-put-text-property (car region) (cdr region) 'face face)
853         (set-window-point
854          (get-buffer-window (current-buffer) t) (cdr region))))))
855
856 ;;;
857 ;;; gnus-carpal
858 ;;;
859
860 (defvar gnus-carpal-group-buffer-buttons
861   '(("next" . gnus-group-next-unread-group)
862     ("prev" . gnus-group-prev-unread-group)
863     ("read" . gnus-group-read-group)
864     ("select" . gnus-group-select-group)
865     ("catch-up" . gnus-group-catchup-current)
866     ("new-news" . gnus-group-get-new-news-this-group)
867     ("toggle-sub" . gnus-group-unsubscribe-current-group)
868     ("subscribe" . gnus-group-unsubscribe-group)
869     ("kill" . gnus-group-kill-group)
870     ("yank" . gnus-group-yank-group)
871     ("describe" . gnus-group-describe-group)
872     "list"
873     ("subscribed" . gnus-group-list-groups)
874     ("all" . gnus-group-list-all-groups)
875     ("killed" . gnus-group-list-killed)
876     ("zombies" . gnus-group-list-zombies)
877     ("matching" . gnus-group-list-matching)
878     ("post" . gnus-group-post-news)
879     ("mail" . gnus-group-mail)
880     ("rescan" . gnus-group-get-new-news)
881     ("browse-foreign" . gnus-group-browse-foreign)
882     ("exit" . gnus-group-exit)))
883
884 (defvar gnus-carpal-summary-buffer-buttons
885   '("mark"
886     ("read" . gnus-summary-mark-as-read-forward)
887     ("tick" . gnus-summary-tick-article-forward)
888     ("clear" . gnus-summary-clear-mark-forward)
889     ("expirable" . gnus-summary-mark-as-expirable)
890     "move"
891     ("scroll" . gnus-summary-next-page)
892     ("next-unread" . gnus-summary-next-unread-article)
893     ("prev-unread" . gnus-summary-prev-unread-article)
894     ("first" . gnus-summary-first-unread-article)
895     ("best" . gnus-summary-best-unread-article)
896     "article"
897     ("headers" . gnus-summary-toggle-header)
898     ("uudecode" . gnus-uu-decode-uu)
899     ("enter-digest" . gnus-summary-enter-digest-group)
900     ("fetch-parent" . gnus-summary-refer-parent-article)
901     "mail"
902     ("move" . gnus-summary-move-article)
903     ("copy" . gnus-summary-copy-article)
904     ("respool" . gnus-summary-respool-article)
905     "threads"
906     ("lower" . gnus-summary-lower-thread)
907     ("kill" . gnus-summary-kill-thread)
908     "post"
909     ("post" . gnus-summary-post-news)
910     ("mail" . gnus-summary-mail)
911     ("followup" . gnus-summary-followup-with-original)
912     ("reply" . gnus-summary-reply-with-original)
913     ("cancel" . gnus-summary-cancel-article)
914     "misc"
915     ("exit" . gnus-summary-exit)
916     ("fed-up" . gnus-summary-catchup-and-goto-next-group)))
917
918 (defvar gnus-carpal-server-buffer-buttons
919   '(("add" . gnus-server-add-server)
920     ("browse" . gnus-server-browse-server)
921     ("list" . gnus-server-list-servers)
922     ("kill" . gnus-server-kill-server)
923     ("yank" . gnus-server-yank-server)
924     ("copy" . gnus-server-copy-server)
925     ("exit" . gnus-server-exit)))
926
927 (defvar gnus-carpal-browse-buffer-buttons
928   '(("subscribe" . gnus-browse-unsubscribe-current-group)
929     ("exit" . gnus-browse-exit)))
930
931 (defvar gnus-carpal-group-buffer "*Carpal Group*")
932 (defvar gnus-carpal-summary-buffer "*Carpal Summary*")
933 (defvar gnus-carpal-server-buffer "*Carpal Server*")
934 (defvar gnus-carpal-browse-buffer "*Carpal Browse*")
935
936 (defvar gnus-carpal-attached-buffer nil)
937
938 (defvar gnus-carpal-mode-hook nil
939   "*Hook run in carpal mode buffers.")
940
941 (defvar gnus-carpal-button-face 'bold
942   "*Face used on carpal buttons.")
943
944 (defvar gnus-carpal-header-face 'bold-italic
945   "*Face used on carpal buffer headers.")
946
947 (defvar gnus-carpal-mode-map nil)
948 (put 'gnus-carpal-mode 'mode-class 'special)
949
950 (if gnus-carpal-mode-map
951     nil
952   (setq gnus-carpal-mode-map (make-keymap))
953   (suppress-keymap gnus-carpal-mode-map)
954   (define-key gnus-carpal-mode-map " " 'gnus-carpal-select)
955   (define-key gnus-carpal-mode-map "\r" 'gnus-carpal-select)
956   (define-key gnus-carpal-mode-map gnus-mouse-2 'gnus-carpal-mouse-select))
957
958 (defun gnus-carpal-mode ()
959   "Major mode for clicking buttons.
960
961 All normal editing commands are switched off.
962 \\<gnus-carpal-mode-map>
963 The following commands are available:
964
965 \\{gnus-carpal-mode-map}"
966   (interactive)
967   (kill-all-local-variables)
968   (setq mode-line-modified (cdr gnus-mode-line-modified))
969   (setq major-mode 'gnus-carpal-mode)
970   (setq mode-name "Gnus Carpal")
971   (setq mode-line-process nil)
972   (use-local-map gnus-carpal-mode-map)
973   (buffer-disable-undo (current-buffer))
974   (setq buffer-read-only t)
975   (make-local-variable 'gnus-carpal-attached-buffer)
976   (gnus-run-hooks 'gnus-carpal-mode-hook))
977
978 (defun gnus-carpal-setup-buffer (type)
979   (let ((buffer (symbol-value (intern (format "gnus-carpal-%s-buffer" type)))))
980     (if (get-buffer buffer)
981         ()
982       (save-excursion
983         (set-buffer (get-buffer-create buffer))
984         (gnus-carpal-mode)
985         (setq gnus-carpal-attached-buffer
986               (intern (format "gnus-%s-buffer" type)))
987         (gnus-add-current-to-buffer-list)
988         (let ((buttons (symbol-value
989                         (intern (format "gnus-carpal-%s-buffer-buttons"
990                                         type))))
991               (buffer-read-only nil)
992               button)
993           (while buttons
994             (setq button (car buttons)
995                   buttons (cdr buttons))
996             (if (stringp button)
997                 (gnus-set-text-properties
998                  (point)
999                  (prog2 (insert button) (point) (insert " "))
1000                  (list 'face gnus-carpal-header-face))
1001               (gnus-set-text-properties
1002                (point)
1003                (prog2 (insert (car button)) (point) (insert " "))
1004                (list 'gnus-callback (cdr button)
1005                      'face gnus-carpal-button-face
1006                      gnus-mouse-face-prop 'highlight))))
1007           (let ((fill-column (- (window-width) 2)))
1008             (fill-region (point-min) (point-max)))
1009           (set-window-point (get-buffer-window (current-buffer))
1010                             (point-min)))))))
1011
1012 (defun gnus-carpal-select ()
1013   "Select the button under point."
1014   (interactive)
1015   (let ((func (get-text-property (point) 'gnus-callback)))
1016     (if (null func)
1017         ()
1018       (pop-to-buffer (symbol-value gnus-carpal-attached-buffer))
1019       (call-interactively func))))
1020
1021 (defun gnus-carpal-mouse-select (event)
1022   "Select the button under the mouse pointer."
1023   (interactive "e")
1024   (mouse-set-point event)
1025   (gnus-carpal-select))
1026
1027 ;;; Allow redefinition of functions.
1028 (gnus-ems-redefine)
1029
1030 (provide 'gnus-salt)
1031
1032 ;;; gnus-salt.el ends here