1 ;;; gnus-salt.el --- alternate summary mode interfaces for Gnus
2 ;; Copyright (C) 1996,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
7 ;; This file is part of GNU Emacs.
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)
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.
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.
28 (eval-when-compile (require 'cl))
37 (defvar gnus-pick-mode nil
38 "Minor mode for providing a pick-and-read interface in Gnus summary buffers.")
40 (defcustom gnus-pick-display-summary nil
41 "*Display summary while reading."
43 :group 'gnus-summary-pick)
45 (defcustom gnus-pick-mode-hook nil
46 "Hook run in summary pick mode buffers."
48 :group 'gnus-summary-pick)
50 (defcustom gnus-mark-unpicked-articles-as-read nil
51 "*If non-nil, mark all unpicked articles as read."
53 :group 'gnus-summary-pick)
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."
58 :group 'gnus-summary-pick)
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."
65 :group 'gnus-summary-pick)
67 ;;; Internal variables.
69 (defvar gnus-pick-mode-map nil)
71 (unless gnus-pick-mode-map
72 (setq gnus-pick-mode-map (make-sparse-keymap))
74 (gnus-define-keys gnus-pick-mode-map
75 "t" gnus-uu-mark-thread
76 "T" gnus-uu-unmark-thread
77 " " gnus-pick-next-page
78 "u" gnus-summary-unmark-as-processable
79 "U" gnus-summary-unmark-all-processable
81 "r" gnus-uu-mark-region
82 "R" gnus-uu-unmark-region
83 "e" gnus-uu-mark-by-regexp
84 "E" gnus-uu-mark-by-regexp
85 "b" gnus-uu-mark-buffer
86 "B" gnus-uu-unmark-buffer
88 gnus-down-mouse-2 gnus-pick-mouse-pick-region
89 ;;gnus-mouse-2 gnus-pick-mouse-pick
90 "X" gnus-pick-start-reading
91 "\r" gnus-pick-start-reading))
93 (defun gnus-pick-make-menu-bar ()
94 (unless (boundp 'gnus-pick-menu)
96 gnus-pick-menu gnus-pick-mode-map ""
99 ["Article" gnus-summary-mark-as-processable t]
100 ["Thread" gnus-uu-mark-thread t]
101 ["Region" gnus-uu-mark-region t]
102 ["Regexp" gnus-uu-mark-regexp t]
103 ["Buffer" gnus-uu-mark-buffer t])
105 ["Article" gnus-summary-unmark-as-processable t]
106 ["Thread" gnus-uu-unmark-thread t]
107 ["Region" gnus-uu-unmark-region t]
108 ["Regexp" gnus-uu-unmark-regexp t]
109 ["Buffer" gnus-uu-unmark-buffer t])
110 ["Start reading" gnus-pick-start-reading t]
111 ["Switch pick mode off" gnus-pick-mode gnus-pick-mode]))))
113 (defun gnus-pick-mode (&optional arg)
114 "Minor mode for providing a pick-and-read interface in Gnus summary buffers.
116 \\{gnus-pick-mode-map}"
118 (when (eq major-mode 'gnus-summary-mode)
119 (if (not (set (make-local-variable 'gnus-pick-mode)
120 (if (null arg) (not gnus-pick-mode)
121 (> (prefix-numeric-value arg) 0))))
122 (remove-hook 'gnus-message-setup-hook 'gnus-pick-setup-message)
123 ;; Make sure that we don't select any articles upon group entry.
124 (set (make-local-variable 'gnus-auto-select-first) nil)
125 ;; Change line format.
126 (setq gnus-summary-line-format gnus-summary-pick-line-format)
127 (setq gnus-summary-line-format-spec nil)
128 (gnus-update-format-specifications nil 'summary)
129 (gnus-update-summary-mark-positions)
130 (add-hook 'gnus-message-setup-hook 'gnus-pick-setup-message)
131 (set (make-local-variable 'gnus-summary-goto-unread) 'never)
133 (when (gnus-visual-p 'pick-menu 'menu)
134 (gnus-pick-make-menu-bar))
135 (gnus-add-minor-mode 'gnus-pick-mode " Pick" gnus-pick-mode-map)
136 (gnus-run-hooks 'gnus-pick-mode-hook))))
138 (defun gnus-pick-setup-message ()
139 "Make Message do the right thing on exit."
140 (when (and (gnus-buffer-live-p gnus-summary-buffer)
142 (set-buffer gnus-summary-buffer)
145 '(gnus-configure-windows 'pick t) 'send 'exit 'postpone 'kill)))
147 (defvar gnus-pick-line-number 1)
148 (defun gnus-pick-line-number ()
149 "Return the current line number."
151 (setq gnus-pick-line-number 1)
152 (incf gnus-pick-line-number)))
154 (defun gnus-pick-start-reading (&optional catch-up)
155 "Start reading the picked articles.
156 If given a prefix, mark all unpicked articles as read."
158 (if gnus-newsgroup-processable
160 (gnus-summary-limit-to-articles nil)
161 (when (or catch-up gnus-mark-unpicked-articles-as-read)
162 (gnus-summary-limit-mark-excluded-as-read))
163 (gnus-summary-first-article)
164 (gnus-configure-windows
165 (if gnus-pick-display-summary 'article 'pick) t))
166 (if gnus-pick-elegant-flow
168 (when (or catch-up gnus-mark-unpicked-articles-as-read)
169 (gnus-summary-catchup nil t))
170 (if (gnus-group-quit-config gnus-newsgroup-name)
172 (gnus-summary-next-group)))
173 (error "No articles have been picked"))))
175 (defun gnus-pick-article (&optional arg)
176 "Pick the article on the current line.
177 If ARG, pick the article on that line instead."
182 (goto-char (point-min))
183 (when (zerop (forward-line (1- (prefix-numeric-value arg))))
186 (gnus-error 2 "No such line: %s" arg)
188 (gnus-summary-mark-as-processable 1))
190 (defun gnus-pick-mouse-pick (e)
194 (gnus-summary-mark-as-processable 1)))
196 (defun gnus-pick-mouse-pick-region (start-event)
197 "Pick articles that the mouse is dragged over.
198 This must be bound to a button-down mouse event."
200 (mouse-minibuffer-check start-event)
201 (let* ((echo-keystrokes 0)
202 (start-posn (event-start start-event))
203 (start-point (posn-point start-posn))
204 (start-line (1+ (count-lines 1 start-point)))
205 (start-window (posn-window start-posn))
206 (start-frame (window-frame start-window))
207 (bounds (gnus-window-edges start-window))
209 (bottom (if (window-minibuffer-p start-window)
211 ;; Don't count the mode line.
212 (1- (nth 3 bounds))))
213 (click-count (1- (event-click-count start-event))))
214 (setq mouse-selection-click-count click-count)
215 (setq mouse-selection-click-count-buffer (current-buffer))
216 (mouse-set-point start-event)
217 ;; In case the down click is in the middle of some intangible text,
218 ;; use the end of that text, and put it in START-POINT.
219 (when (< (point) start-point)
220 (goto-char start-point))
222 (setq start-point (point))
223 ;; end-of-range is used only in the single-click case.
224 ;; It is the place where the drag has reached so far
225 ;; (but not outside the window where the drag started).
226 (let (event end end-point last-end-point (end-of-range (point)))
229 (setq event (read-event))
230 (or (mouse-movement-p event)
231 (eq (car-safe event) 'switch-frame)))
232 (if (eq (car-safe event) 'switch-frame)
234 (setq end (event-end event)
235 end-point (posn-point end))
237 (setq last-end-point end-point))
240 ;; Are we moving within the original window?
241 ((and (eq (posn-window end) start-window)
242 (integer-or-marker-p end-point))
243 ;; Go to START-POINT first, so that when we move to END-POINT,
244 ;; if it's in the middle of intangible text,
245 ;; point jumps in the direction away from START-POINT.
246 (goto-char start-point)
247 (goto-char end-point)
249 ;; In case the user moved his mouse really fast, pick
250 ;; articles on the line between this one and the last one.
251 (let* ((this-line (1+ (count-lines 1 end-point)))
252 (min-line (min this-line start-line))
253 (max-line (max this-line start-line)))
254 (while (< min-line max-line)
257 (setq min-line (1+ min-line)))
258 (setq start-line this-line))
259 (when (zerop (% click-count 3))
260 (setq end-of-range (point))))
262 (let ((mouse-row (cdr (cdr (mouse-position)))))
266 (mouse-scroll-subr start-window (- mouse-row top)))
267 ((>= mouse-row bottom)
268 (mouse-scroll-subr start-window
269 (1+ (- mouse-row bottom)))))))))))
271 (let ((fun (key-binding (vector (car event)))))
272 ;; Run the binding of the terminating up-event, if possible.
273 ;; In the case of a multiple click, it gives the wrong results,
274 ;; because it would fail to set up a region.
276 ;; (and (= (mod mouse-selection-click-count 3) 0) (fboundp fun))
277 ;; In this case, we can just let the up-event execute normally.
278 (let ((end (event-end event)))
279 ;; Set the position in the event before we replay it,
280 ;; because otherwise it may have a position in the wrong
282 (setcar (cdr end) end-of-range)
283 ;; Delete the overlay before calling the function,
284 ;; because delete-overlay increases buffer-modified-tick.
285 (push event unread-command-events))))))))
287 (defun gnus-pick-next-page ()
288 "Go to the next page. If at the end of the buffer, start reading articles."
290 (let ((scroll-in-place nil))
293 (end-of-buffer (gnus-pick-start-reading)))))
299 (defvar gnus-binary-mode nil
300 "Minor mode for providing a binary group interface in Gnus summary buffers.")
302 (defvar gnus-binary-mode-hook nil
303 "Hook run in summary binary mode buffers.")
305 (defvar gnus-binary-mode-map nil)
307 (unless gnus-binary-mode-map
308 (setq gnus-binary-mode-map (make-sparse-keymap))
312 "g" gnus-binary-show-article))
314 (defun gnus-binary-make-menu-bar ()
315 (unless (boundp 'gnus-binary-menu)
317 gnus-binary-menu gnus-binary-mode-map ""
319 ["Switch binary mode off" gnus-binary-mode t]))))
321 (defun gnus-binary-mode (&optional arg)
322 "Minor mode for providing a binary group interface in Gnus summary buffers."
324 (when (eq major-mode 'gnus-summary-mode)
325 (make-local-variable 'gnus-binary-mode)
326 (setq gnus-binary-mode
327 (if (null arg) (not gnus-binary-mode)
328 (> (prefix-numeric-value arg) 0)))
329 (when gnus-binary-mode
330 ;; Make sure that we don't select any articles upon group entry.
331 (make-local-variable 'gnus-auto-select-first)
332 (setq gnus-auto-select-first nil)
333 (make-local-variable 'gnus-summary-display-article-function)
334 (setq gnus-summary-display-article-function 'gnus-binary-display-article)
336 (when (gnus-visual-p 'binary-menu 'menu)
337 (gnus-binary-make-menu-bar))
338 (gnus-add-minor-mode 'gnus-binary-mode " Binary" gnus-binary-mode-map)
339 (gnus-run-hooks 'gnus-binary-mode-hook))))
341 (defun gnus-binary-display-article (article &optional all-header)
342 "Run ARTICLE through the binary decode functions."
343 (when (gnus-summary-goto-subject article)
344 (let ((gnus-view-pseudos 'automatic))
345 (gnus-uu-decode-uu))))
347 (defun gnus-binary-show-article (&optional arg)
348 "Bypass the binary functions and show the article."
350 (let (gnus-summary-display-article-function)
351 (gnus-summary-show-article arg)))
357 (defcustom gnus-tree-line-format "%(%[%3,3n%]%)"
358 "Format of tree elements."
360 :group 'gnus-summary-tree)
362 (defcustom gnus-tree-minimize-window t
363 "If non-nil, minimize the tree buffer window.
364 If a number, never let the tree buffer grow taller than that number of
367 :group 'gnus-summary-tree)
369 (defcustom gnus-selected-tree-face 'modeline
370 "*Face used for highlighting selected articles in the thread tree."
372 :group 'gnus-summary-tree)
374 (defvar gnus-tree-brackets '((?\[ . ?\]) (?\( . ?\))
375 (?\{ . ?\}) (?< . ?>))
376 "Brackets used in tree nodes.")
378 (defvar gnus-tree-parent-child-edges '(?- ?\\ ?|)
379 "Characters used to connect parents with children.")
381 (defcustom gnus-tree-mode-line-format "Gnus: %%b %S %Z"
382 "*The format specification for the tree mode line."
384 :group 'gnus-summary-tree)
386 (defcustom gnus-generate-tree-function 'gnus-generate-vertical-tree
387 "*Function for generating a thread tree.
388 Two predefined functions are available:
389 `gnus-generate-horizontal-tree' and `gnus-generate-vertical-tree'."
390 :type '(radio (function-item gnus-generate-vertical-tree)
391 (function-item gnus-generate-horizontal-tree)
392 (function :tag "Other" nil))
393 :group 'gnus-summary-tree)
395 (defcustom gnus-tree-mode-hook nil
396 "*Hook run in tree mode buffers."
398 :group 'gnus-summary-tree)
400 ;;; Internal variables.
402 (defvar gnus-tree-line-format-alist
403 `((?n gnus-tmp-name ?s)
404 (?f gnus-tmp-from ?s)
405 (?N gnus-tmp-number ?d)
406 (?\[ gnus-tmp-open-bracket ?c)
407 (?\] gnus-tmp-close-bracket ?c)
408 (?s gnus-tmp-subject ?s)))
410 (defvar gnus-tree-mode-line-format-alist gnus-summary-mode-line-format-alist)
412 (defvar gnus-tree-mode-line-format-spec nil)
413 (defvar gnus-tree-line-format-spec nil)
415 (defvar gnus-tree-node-length nil)
416 (defvar gnus-selected-tree-overlay nil)
418 (defvar gnus-tree-displayed-thread nil)
420 (defvar gnus-tree-mode-map nil)
421 (put 'gnus-tree-mode 'mode-class 'special)
423 (unless gnus-tree-mode-map
424 (setq gnus-tree-mode-map (make-keymap))
425 (suppress-keymap gnus-tree-mode-map)
428 "\r" gnus-tree-select-article
429 gnus-mouse-2 gnus-tree-pick-article
430 "\C-?" gnus-tree-read-summary-keys
431 "h" gnus-tree-show-summary
433 "\C-c\C-i" gnus-info-find-node)
435 (substitute-key-definition
436 'undefined 'gnus-tree-read-summary-keys gnus-tree-mode-map))
438 (defun gnus-tree-make-menu-bar ()
439 (unless (boundp 'gnus-tree-menu)
441 gnus-tree-menu gnus-tree-mode-map ""
443 ["Select article" gnus-tree-select-article t]))))
445 (defun gnus-tree-mode ()
446 "Major mode for displaying thread trees."
448 (gnus-set-format 'tree-mode)
449 (gnus-set-format 'tree t)
450 (when (gnus-visual-p 'tree-menu 'menu)
451 (gnus-tree-make-menu-bar))
452 (kill-all-local-variables)
453 (gnus-simplify-mode-line)
454 (setq mode-name "Tree")
455 (setq major-mode 'gnus-tree-mode)
456 (use-local-map gnus-tree-mode-map)
457 (buffer-disable-undo (current-buffer))
458 (setq buffer-read-only t)
459 (setq truncate-lines t)
461 (gnus-set-work-buffer)
462 (gnus-tree-node-insert (make-mail-header "") nil)
463 (setq gnus-tree-node-length (1- (point))))
464 (gnus-run-hooks 'gnus-tree-mode-hook))
466 (defun gnus-tree-read-summary-keys (&optional arg)
467 "Read a summary buffer key sequence and execute it."
469 (let ((buf (current-buffer))
471 (set-buffer gnus-article-buffer)
472 (gnus-article-read-summary-keys arg nil t)
473 (when (setq win (get-buffer-window buf))
475 (when gnus-selected-tree-overlay
476 (goto-char (or (gnus-overlay-end gnus-selected-tree-overlay) 1)))
477 (gnus-tree-minimize))))
479 (defun gnus-tree-show-summary ()
480 "Reconfigure windows to show summary buffer."
482 (if (not (gnus-buffer-live-p gnus-summary-buffer))
483 (error "There is no summary buffer for this tree buffer")
484 (gnus-configure-windows 'article)
485 (gnus-summary-goto-subject gnus-current-article)))
487 (defun gnus-tree-select-article (article)
488 "Select the article under point, if any."
489 (interactive (list (gnus-tree-article-number)))
490 (let ((buf (current-buffer)))
493 (set-buffer gnus-summary-buffer)
494 (gnus-summary-goto-article article))
495 (select-window (get-buffer-window buf)))))
497 (defun gnus-tree-pick-article (e)
498 "Select the article under the mouse pointer."
501 (gnus-tree-select-article (gnus-tree-article-number)))
503 (defun gnus-tree-article-number ()
504 (get-text-property (point) 'gnus-number))
506 (defun gnus-tree-article-region (article)
507 "Return a cons with BEG and END of the article region."
508 (let ((pos (text-property-any (point-min) (point-max) 'gnus-number article)))
510 (cons pos (next-single-property-change pos 'gnus-number)))))
512 (defun gnus-tree-goto-article (article)
513 (let ((pos (text-property-any (point-min) (point-max) 'gnus-number article)))
517 (defun gnus-tree-recenter ()
518 "Center point in the tree window."
519 (let ((selected (selected-window))
520 (tree-window (get-buffer-window gnus-tree-buffer t)))
522 (select-window tree-window)
523 (when gnus-selected-tree-overlay
524 (goto-char (or (gnus-overlay-end gnus-selected-tree-overlay) 1)))
525 (let* ((top (cond ((< (window-height) 4) 0)
526 ((< (window-height) 7) 1)
528 (height (1- (window-height)))
529 (bottom (save-excursion (goto-char (point-max))
530 (forward-line (- height))
532 ;; Set the window start to either `bottom', which is the biggest
533 ;; possible valid number, or the second line from the top,
534 ;; whichever is the least.
536 tree-window (min bottom (save-excursion
537 (forward-line (- top)) (point)))))
538 (select-window selected))))
540 (defun gnus-get-tree-buffer ()
541 "Return the tree buffer properly initialized."
543 (set-buffer (get-buffer-create gnus-tree-buffer))
544 (unless (eq major-mode 'gnus-tree-mode)
545 (gnus-add-current-to-buffer-list)
549 (defun gnus-tree-minimize ()
550 (when (and gnus-tree-minimize-window
551 (not (one-window-p)))
554 (walk-windows (lambda (window) (incf windows)))
557 (* window-min-height (1- windows))
559 (let* ((window-min-height 2)
560 (height (count-lines (point-min) (point-max)))
561 (min (max (1- window-min-height) height))
562 (tot (if (numberp gnus-tree-minimize-window)
563 (min gnus-tree-minimize-window min)
565 (win (get-buffer-window (current-buffer)))
566 (wh (and win (1- (window-height win)))))
567 (setq tot (min tot tot-win-height))
570 (let ((selected (selected-window)))
571 (when (ignore-errors (select-window win))
572 (enlarge-window (- tot wh))
573 (select-window selected))))))))
575 ;;; Generating the tree.
577 (defun gnus-tree-node-insert (header sparse &optional adopted)
578 (let* ((dummy (stringp header))
579 (header (if (vectorp header) header
581 (setq header (make-mail-header "*****"))
582 (mail-header-set-number header 0)
583 (mail-header-set-lines header 0)
584 (mail-header-set-chars header 0)
586 (gnus-tmp-from (mail-header-from header))
587 (gnus-tmp-subject (mail-header-subject header))
588 (gnus-tmp-number (mail-header-number header))
591 ((string-match "(.+)" gnus-tmp-from)
592 (substring gnus-tmp-from
593 (1+ (match-beginning 0)) (1- (match-end 0))))
594 ((string-match "<[^>]+> *$" gnus-tmp-from)
595 (let ((beg (match-beginning 0)))
596 (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
597 (substring gnus-tmp-from (1+ (match-beginning 0))
599 (substring gnus-tmp-from 0 beg))))
600 ((memq gnus-tmp-number sparse)
603 (gnus-tmp-open-bracket
604 (cond ((memq gnus-tmp-number sparse)
605 (caadr gnus-tree-brackets))
606 (dummy (caaddr gnus-tree-brackets))
607 (adopted (car (nth 3 gnus-tree-brackets)))
608 (t (caar gnus-tree-brackets))))
609 (gnus-tmp-close-bracket
610 (cond ((memq gnus-tmp-number sparse)
611 (cdadr gnus-tree-brackets))
612 (adopted (cdr (nth 3 gnus-tree-brackets)))
614 (cdaddr gnus-tree-brackets))
615 (t (cdar gnus-tree-brackets))))
616 (buffer-read-only nil)
618 (gnus-add-text-properties
620 (setq end (progn (eval gnus-tree-line-format-spec) (point)))
621 (list 'gnus-number gnus-tmp-number))
622 (when (or t (gnus-visual-p 'tree-highlight 'highlight))
623 (gnus-tree-highlight-node gnus-tmp-number beg end))))
625 (defun gnus-tree-highlight-node (article beg end)
626 "Highlight current line according to `gnus-summary-highlight'."
627 (let ((list gnus-summary-highlight)
630 (set-buffer gnus-summary-buffer)
631 (let* ((score (or (cdr (assq article gnus-newsgroup-scored))
632 gnus-summary-default-score 0))
633 (default gnus-summary-default-score)
634 (mark (or (gnus-summary-article-mark article) gnus-unread-mark)))
635 ;; Eval the cars of the lists until we find a match.
637 (not (eval (caar list))))
638 (setq list (cdr list)))))
639 (unless (eq (setq face (cdar list)) (get-text-property beg 'face))
640 (gnus-put-text-property
642 (if (boundp face) (symbol-value face) face)))))
644 (defun gnus-tree-indent (level)
645 (insert (make-string (1- (* (1+ gnus-tree-node-length) level)) ? )))
647 (defvar gnus-tmp-limit)
648 (defvar gnus-tmp-sparse)
649 (defvar gnus-tmp-indent)
651 (defun gnus-generate-tree (thread)
652 "Generate a thread tree for THREAD."
654 (set-buffer (gnus-get-tree-buffer))
655 (let ((buffer-read-only nil)
658 (funcall gnus-generate-tree-function thread 0)
659 (gnus-set-mode-line 'tree)
660 (goto-char (point-min))
663 (let ((selected (selected-window)))
664 (when (get-buffer-window (set-buffer gnus-tree-buffer) t)
665 (select-window (get-buffer-window (set-buffer gnus-tree-buffer) t))
666 (gnus-horizontal-recenter)
667 (select-window selected))))))
669 (defun gnus-generate-horizontal-tree (thread level &optional dummyp adopted)
670 "Generate a horizontal tree."
671 (let* ((dummy (stringp (car thread)))
674 (memq (mail-header-number (car thread))
678 ;; We don't want this article.
679 (setq thread (cdr thread))
681 ;; Not the first article on the line, so we insert a "-".
682 (insert (car gnus-tree-parent-child-edges))
683 ;; If the level isn't zero, then we insert some indentation.
684 (unless (zerop level)
685 (gnus-tree-indent level)
686 (insert (cadr gnus-tree-parent-child-edges))
687 (setq col (- (setq beg (point)) (gnus-point-at-bol) 1))
688 ;; Draw "|" lines upwards.
692 (= (following-char) ? ))
694 (insert (caddr gnus-tree-parent-child-edges)))
697 ;; Insert the article node.
698 (gnus-tree-node-insert (pop thread) gnus-tmp-sparse adopted))
700 ;; End of the thread, so we go to the next line.
703 ;; Recurse downwards in all children of this article.
705 (gnus-generate-horizontal-tree
706 (pop thread) (if do (1+ level) level)
707 (or dummyp dummy) dummy)))))
709 (defsubst gnus-tree-indent-vertical ()
710 (let ((len (- (* (1+ gnus-tree-node-length) gnus-tmp-indent)
711 (- (point) (gnus-point-at-bol)))))
713 (insert (make-string len ? )))))
715 (defsubst gnus-tree-forward-line (n)
716 (while (>= (decf n) 0)
717 (unless (zerop (forward-line 1))
722 (defun gnus-generate-vertical-tree (thread level &optional dummyp adopted)
723 "Generate a vertical tree."
724 (let* ((dummy (stringp (car thread)))
727 (memq (mail-header-number (car thread))
731 ;; We don't want this article.
732 (setq thread (cdr thread))
733 (if (not (save-excursion (beginning-of-line) (bobp)))
734 ;; Not the first article on the line, so we insert a "-".
736 (gnus-tree-indent-vertical)
737 (insert (make-string (/ gnus-tree-node-length 2) ? ))
738 (insert (caddr gnus-tree-parent-child-edges))
739 (gnus-tree-forward-line 1))
740 ;; If the level isn't zero, then we insert some indentation.
741 (unless (zerop gnus-tmp-indent)
742 (gnus-tree-forward-line (1- (* 2 level)))
743 (gnus-tree-indent-vertical)
745 (insert (cadr gnus-tree-parent-child-edges))
748 ;; Draw "-" lines leftwards.
749 (while (= (char-after (1- (point))) ? )
751 (insert (car gnus-tree-parent-child-edges))
754 (gnus-tree-forward-line 1)))
756 ;; Insert the article node.
757 (gnus-tree-indent-vertical)
758 (gnus-tree-node-insert (pop thread) gnus-tmp-sparse adopted)
759 (gnus-tree-forward-line 1))
761 ;; End of the thread, so we go to the next line.
763 (goto-char (point-min))
765 (incf gnus-tmp-indent))
766 ;; Recurse downwards in all children of this article.
768 (gnus-generate-vertical-tree
769 (pop thread) (if do (1+ level) level)
770 (or dummyp dummy) dummy)))))
772 ;;; Interface functions.
774 (defun gnus-possibly-generate-tree (article &optional force)
775 "Generate the thread tree for ARTICLE if it isn't displayed already."
776 (when (save-excursion
777 (set-buffer gnus-summary-buffer)
780 (vectorp (gnus-summary-article-header article))))
782 (let ((top (save-excursion
783 (set-buffer gnus-summary-buffer)
787 (gnus-summary-article-header article))
789 (gnus-tmp-limit gnus-newsgroup-limit)
790 (gnus-tmp-sparse gnus-newsgroup-sparse))
792 (not (eq top gnus-tree-displayed-thread)))
793 (gnus-generate-tree top)
794 (setq gnus-tree-displayed-thread top))))))
796 (defun gnus-tree-open (group)
797 (gnus-get-tree-buffer))
799 (defun gnus-tree-close (group)
800 (gnus-kill-buffer gnus-tree-buffer))
802 (defun gnus-highlight-selected-tree (article)
803 "Highlight the selected article in the tree."
804 (let ((buf (current-buffer))
806 (set-buffer gnus-tree-buffer)
807 (when (setq region (gnus-tree-article-region article))
808 (when (or (not gnus-selected-tree-overlay)
809 (gnus-extent-detached-p gnus-selected-tree-overlay))
810 ;; Create a new overlay.
812 (setq gnus-selected-tree-overlay (gnus-make-overlay 1 2))
813 'face gnus-selected-tree-face))
814 ;; Move the overlay to the article.
816 gnus-selected-tree-overlay (goto-char (car region)) (cdr region))
819 (let ((selected (selected-window)))
820 (when (get-buffer-window (set-buffer gnus-tree-buffer) t)
821 (select-window (get-buffer-window (set-buffer gnus-tree-buffer) t))
822 (gnus-horizontal-recenter)
823 (select-window selected))))
824 ;; If we remove this save-excursion, it updates the wrong mode lines?!?
826 (set-buffer gnus-tree-buffer)
827 (gnus-set-mode-line 'tree))
830 (defun gnus-tree-highlight-article (article face)
832 (set-buffer (gnus-get-tree-buffer))
834 (when (setq region (gnus-tree-article-region article))
835 (gnus-put-text-property (car region) (cdr region) 'face face)
837 (get-buffer-window (current-buffer) t) (cdr region))))))
843 (defvar gnus-carpal-group-buffer-buttons
844 '(("next" . gnus-group-next-unread-group)
845 ("prev" . gnus-group-prev-unread-group)
846 ("read" . gnus-group-read-group)
847 ("select" . gnus-group-select-group)
848 ("catch-up" . gnus-group-catchup-current)
849 ("new-news" . gnus-group-get-new-news-this-group)
850 ("toggle-sub" . gnus-group-unsubscribe-current-group)
851 ("subscribe" . gnus-group-unsubscribe-group)
852 ("kill" . gnus-group-kill-group)
853 ("yank" . gnus-group-yank-group)
854 ("describe" . gnus-group-describe-group)
856 ("subscribed" . gnus-group-list-groups)
857 ("all" . gnus-group-list-all-groups)
858 ("killed" . gnus-group-list-killed)
859 ("zombies" . gnus-group-list-zombies)
860 ("matching" . gnus-group-list-matching)
861 ("post" . gnus-group-post-news)
862 ("mail" . gnus-group-mail)
863 ("rescan" . gnus-group-get-new-news)
864 ("browse-foreign" . gnus-group-browse-foreign)
865 ("exit" . gnus-group-exit)))
867 (defvar gnus-carpal-summary-buffer-buttons
869 ("read" . gnus-summary-mark-as-read-forward)
870 ("tick" . gnus-summary-tick-article-forward)
871 ("clear" . gnus-summary-clear-mark-forward)
872 ("expirable" . gnus-summary-mark-as-expirable)
874 ("scroll" . gnus-summary-next-page)
875 ("next-unread" . gnus-summary-next-unread-article)
876 ("prev-unread" . gnus-summary-prev-unread-article)
877 ("first" . gnus-summary-first-unread-article)
878 ("best" . gnus-summary-best-unread-article)
880 ("headers" . gnus-summary-toggle-header)
881 ("uudecode" . gnus-uu-decode-uu)
882 ("enter-digest" . gnus-summary-enter-digest-group)
883 ("fetch-parent" . gnus-summary-refer-parent-article)
885 ("move" . gnus-summary-move-article)
886 ("copy" . gnus-summary-copy-article)
887 ("respool" . gnus-summary-respool-article)
889 ("lower" . gnus-summary-lower-thread)
890 ("kill" . gnus-summary-kill-thread)
892 ("post" . gnus-summary-post-news)
893 ("mail" . gnus-summary-mail)
894 ("followup" . gnus-summary-followup-with-original)
895 ("reply" . gnus-summary-reply-with-original)
896 ("cancel" . gnus-summary-cancel-article)
898 ("exit" . gnus-summary-exit)
899 ("fed-up" . gnus-summary-catchup-and-goto-next-group)))
901 (defvar gnus-carpal-server-buffer-buttons
902 '(("add" . gnus-server-add-server)
903 ("browse" . gnus-server-browse-server)
904 ("list" . gnus-server-list-servers)
905 ("kill" . gnus-server-kill-server)
906 ("yank" . gnus-server-yank-server)
907 ("copy" . gnus-server-copy-server)
908 ("exit" . gnus-server-exit)))
910 (defvar gnus-carpal-browse-buffer-buttons
911 '(("subscribe" . gnus-browse-unsubscribe-current-group)
912 ("exit" . gnus-browse-exit)))
914 (defvar gnus-carpal-group-buffer "*Carpal Group*")
915 (defvar gnus-carpal-summary-buffer "*Carpal Summary*")
916 (defvar gnus-carpal-server-buffer "*Carpal Server*")
917 (defvar gnus-carpal-browse-buffer "*Carpal Browse*")
919 (defvar gnus-carpal-attached-buffer nil)
921 (defvar gnus-carpal-mode-hook nil
922 "*Hook run in carpal mode buffers.")
924 (defvar gnus-carpal-button-face 'bold
925 "*Face used on carpal buttons.")
927 (defvar gnus-carpal-header-face 'bold-italic
928 "*Face used on carpal buffer headers.")
930 (defvar gnus-carpal-mode-map nil)
931 (put 'gnus-carpal-mode 'mode-class 'special)
933 (if gnus-carpal-mode-map
935 (setq gnus-carpal-mode-map (make-keymap))
936 (suppress-keymap gnus-carpal-mode-map)
937 (define-key gnus-carpal-mode-map " " 'gnus-carpal-select)
938 (define-key gnus-carpal-mode-map "\r" 'gnus-carpal-select)
939 (define-key gnus-carpal-mode-map gnus-mouse-2 'gnus-carpal-mouse-select))
941 (defun gnus-carpal-mode ()
942 "Major mode for clicking buttons.
944 All normal editing commands are switched off.
945 \\<gnus-carpal-mode-map>
946 The following commands are available:
948 \\{gnus-carpal-mode-map}"
950 (kill-all-local-variables)
951 (setq mode-line-modified (cdr gnus-mode-line-modified))
952 (setq major-mode 'gnus-carpal-mode)
953 (setq mode-name "Gnus Carpal")
954 (setq mode-line-process nil)
955 (use-local-map gnus-carpal-mode-map)
956 (buffer-disable-undo (current-buffer))
957 (setq buffer-read-only t)
958 (make-local-variable 'gnus-carpal-attached-buffer)
959 (gnus-run-hooks 'gnus-carpal-mode-hook))
961 (defun gnus-carpal-setup-buffer (type)
962 (let ((buffer (symbol-value (intern (format "gnus-carpal-%s-buffer" type)))))
963 (if (get-buffer buffer)
966 (set-buffer (get-buffer-create buffer))
968 (setq gnus-carpal-attached-buffer
969 (intern (format "gnus-%s-buffer" type)))
970 (gnus-add-current-to-buffer-list)
971 (let ((buttons (symbol-value
972 (intern (format "gnus-carpal-%s-buffer-buttons"
974 (buffer-read-only nil)
977 (setq button (car buttons)
978 buttons (cdr buttons))
980 (gnus-set-text-properties
982 (prog2 (insert button) (point) (insert " "))
983 (list 'face gnus-carpal-header-face))
984 (gnus-set-text-properties
986 (prog2 (insert (car button)) (point) (insert " "))
987 (list 'gnus-callback (cdr button)
988 'face gnus-carpal-button-face
989 gnus-mouse-face-prop 'highlight))))
990 (let ((fill-column (- (window-width) 2)))
991 (fill-region (point-min) (point-max)))
992 (set-window-point (get-buffer-window (current-buffer))
995 (defun gnus-carpal-select ()
996 "Select the button under point."
998 (let ((func (get-text-property (point) 'gnus-callback)))
1001 (pop-to-buffer (symbol-value gnus-carpal-attached-buffer))
1002 (call-interactively func))))
1004 (defun gnus-carpal-mouse-select (event)
1005 "Select the button under the mouse pointer."
1007 (mouse-set-point event)
1008 (gnus-carpal-select))
1010 ;;; Allow redefinition of functions.
1013 (provide 'gnus-salt)
1015 ;;; gnus-salt.el ends here