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@gnus.org>
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 " " 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
82 (defun gnus-pick-make-menu-bar ()
83 (unless (boundp 'gnus-pick-menu)
85 gnus-pick-menu gnus-pick-mode-map ""
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])
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]))))
102 (defun gnus-pick-mode (&optional arg)
103 "Minor mode for providing a pick-and-read interface in Gnus summary buffers.
105 \\{gnus-pick-mode-map}"
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)
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))))
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)
131 (set-buffer gnus-summary-buffer)
134 '(gnus-configure-windows 'pick t) 'send 'exit 'postpone 'kill)))
136 (defvar gnus-pick-line-number 1)
137 (defun gnus-pick-line-number ()
138 "Return the current line number."
140 (setq gnus-pick-line-number 1)
141 (incf gnus-pick-line-number)))
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."
147 (if gnus-newsgroup-processable
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
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)
161 (gnus-summary-next-group)))
162 (error "No articles have been picked"))))
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."
169 (goto-char (point-min))
170 (when (zerop (forward-line (1- (prefix-numeric-value arg))))
173 (gnus-error 2 "No such line: %s" arg)
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."
181 (gnus-pick-goto-article arg))
182 (gnus-summary-mark-as-processable 1))
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."
190 (gnus-pick-goto-article arg))
191 (if gnus-thread-hide-subtree
192 (gnus-uu-mark-thread)
193 (gnus-summary-mark-as-processable 1)))
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."
201 (gnus-pick-goto-article arg))
202 (if gnus-thread-hide-subtree
203 (gnus-uu-unmark-thread)
204 (gnus-summary-unmark-as-processable 1)))
206 (defun gnus-pick-mouse-pick (e)
210 (gnus-summary-mark-as-processable 1)))
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."
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))
225 (bottom (if (window-minibuffer-p start-window)
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))
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)))
245 (setq event (cdr (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)
250 (setq end (event-end event)
251 end-point (posn-point end))
253 (setq last-end-point end-point))
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)
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)
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))))
278 (let ((mouse-row (cdr (cdr (mouse-position)))))
282 (mouse-scroll-subr start-window (- mouse-row top)))
283 ((>= mouse-row bottom)
284 (mouse-scroll-subr start-window
285 (1+ (- mouse-row bottom)))))))))))
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.
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
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))))))))
303 (defun gnus-pick-next-page ()
304 "Go to the next page. If at the end of the buffer, start reading articles."
306 (let ((scroll-in-place nil))
309 (end-of-buffer (gnus-pick-start-reading)))))
315 (defvar gnus-binary-mode nil
316 "Minor mode for providing a binary group interface in Gnus summary buffers.")
318 (defvar gnus-binary-mode-hook nil
319 "Hook run in summary binary mode buffers.")
321 (defvar gnus-binary-mode-map nil)
323 (unless gnus-binary-mode-map
324 (setq gnus-binary-mode-map (make-sparse-keymap))
328 "g" gnus-binary-show-article))
330 (defun gnus-binary-make-menu-bar ()
331 (unless (boundp 'gnus-binary-menu)
333 gnus-binary-menu gnus-binary-mode-map ""
335 ["Switch binary mode off" gnus-binary-mode t]))))
337 (defun gnus-binary-mode (&optional arg)
338 "Minor mode for providing a binary group interface in Gnus summary buffers."
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)
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))))
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))))
363 (defun gnus-binary-show-article (&optional arg)
364 "Bypass the binary functions and show the article."
366 (let (gnus-summary-display-article-function)
367 (gnus-summary-show-article arg)))
373 (defcustom gnus-tree-line-format "%(%[%3,3n%]%)"
374 "Format of tree elements."
376 :group 'gnus-summary-tree)
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
382 :type '(choice boolean
384 :group 'gnus-summary-tree)
386 (defcustom gnus-selected-tree-face 'modeline
387 "*Face used for highlighting selected articles in the thread tree."
389 :group 'gnus-summary-tree)
391 (defvar gnus-tree-brackets '((?\[ . ?\]) (?\( . ?\))
392 (?\{ . ?\}) (?< . ?>))
393 "Brackets used in tree nodes.")
395 (defvar gnus-tree-parent-child-edges '(?- ?\\ ?|)
396 "Characters used to connect parents with children.")
398 (defcustom gnus-tree-mode-line-format "Gnus: %%b %S %Z"
399 "*The format specification for the tree mode line."
401 :group 'gnus-summary-tree)
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)
412 (defcustom gnus-tree-mode-hook nil
413 "*Hook run in tree mode buffers."
415 :group 'gnus-summary-tree)
417 ;;; Internal variables.
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)))
427 (defvar gnus-tree-mode-line-format-alist gnus-summary-mode-line-format-alist)
429 (defvar gnus-tree-mode-line-format-spec nil)
430 (defvar gnus-tree-line-format-spec nil)
432 (defvar gnus-tree-node-length nil)
433 (defvar gnus-selected-tree-overlay nil)
435 (defvar gnus-tree-displayed-thread nil)
437 (defvar gnus-tree-mode-map nil)
438 (put 'gnus-tree-mode 'mode-class 'special)
440 (unless gnus-tree-mode-map
441 (setq gnus-tree-mode-map (make-keymap))
442 (suppress-keymap 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
450 "\C-c\C-i" gnus-info-find-node)
452 (substitute-key-definition
453 'undefined 'gnus-tree-read-summary-keys gnus-tree-mode-map))
455 (defun gnus-tree-make-menu-bar ()
456 (unless (boundp 'gnus-tree-menu)
458 gnus-tree-menu gnus-tree-mode-map ""
460 ["Select article" gnus-tree-select-article t]))))
462 (defun gnus-tree-mode ()
463 "Major mode for displaying thread trees."
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)
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))
483 (defun gnus-tree-read-summary-keys (&optional arg)
484 "Read a summary buffer key sequence and execute it."
486 (let ((buf (current-buffer))
488 (set-buffer gnus-article-buffer)
489 (gnus-article-read-summary-keys arg nil t)
490 (when (setq win (get-buffer-window buf))
492 (when gnus-selected-tree-overlay
493 (goto-char (or (gnus-overlay-end gnus-selected-tree-overlay) 1)))
494 (gnus-tree-minimize))))
496 (defun gnus-tree-show-summary ()
497 "Reconfigure windows to show summary buffer."
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)))
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)))
510 (set-buffer gnus-summary-buffer)
511 (gnus-summary-goto-article article))
512 (select-window (get-buffer-window buf)))))
514 (defun gnus-tree-pick-article (e)
515 "Select the article under the mouse pointer."
518 (gnus-tree-select-article (gnus-tree-article-number)))
520 (defun gnus-tree-article-number ()
521 (get-text-property (point) 'gnus-number))
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)))
527 (cons pos (next-single-property-change pos 'gnus-number)))))
529 (defun gnus-tree-goto-article (article)
530 (let ((pos (text-property-any (point-min) (point-max) 'gnus-number article)))
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)))
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)
545 (height (1- (window-height)))
546 (bottom (save-excursion (goto-char (point-max))
547 (forward-line (- height))
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.
553 tree-window (min bottom (save-excursion
554 (forward-line (- top)) (point)))))
555 (select-window selected))))
557 (defun gnus-get-tree-buffer ()
558 "Return the tree buffer properly initialized."
560 (set-buffer (get-buffer-create gnus-tree-buffer))
561 (unless (eq major-mode 'gnus-tree-mode)
562 (gnus-add-current-to-buffer-list)
566 (defun gnus-tree-minimize ()
567 (when (and gnus-tree-minimize-window
568 (not (one-window-p)))
571 (walk-windows (lambda (window) (incf windows)))
574 (* window-min-height (1- windows))
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)
582 (win (get-buffer-window (current-buffer)))
583 (wh (and win (1- (window-height win)))))
584 (setq tot (min tot tot-win-height))
587 (let ((selected (selected-window)))
588 (when (ignore-errors (select-window win))
589 (enlarge-window (- tot wh))
590 (select-window selected))))))))
592 ;;; Generating the tree.
594 (defun gnus-tree-node-insert (header sparse &optional adopted)
595 (let* ((dummy (stringp header))
596 (header (if (vectorp header) header
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)
603 (gnus-tmp-from (mail-header-from header))
604 (gnus-tmp-subject (mail-header-subject header))
605 (gnus-tmp-number (mail-header-number header))
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))
616 (substring gnus-tmp-from 0 beg))))
617 ((memq gnus-tmp-number sparse)
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)))
631 (cdaddr gnus-tree-brackets))
632 (t (cdar gnus-tree-brackets))))
633 (buffer-read-only nil)
635 (gnus-add-text-properties
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))))
642 (defun gnus-tree-highlight-node (article beg end)
643 "Highlight current line according to `gnus-summary-highlight'."
644 (let ((list gnus-summary-highlight)
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.
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
659 (if (boundp face) (symbol-value face) face)))))
661 (defun gnus-tree-indent (level)
662 (insert (make-string (1- (* (1+ gnus-tree-node-length) level)) ? )))
664 (defvar gnus-tmp-limit)
665 (defvar gnus-tmp-sparse)
666 (defvar gnus-tmp-indent)
668 (defun gnus-generate-tree (thread)
669 "Generate a thread tree for THREAD."
671 (set-buffer (gnus-get-tree-buffer))
672 (let ((buffer-read-only nil)
675 (funcall gnus-generate-tree-function thread 0)
676 (gnus-set-mode-line 'tree)
677 (goto-char (point-min))
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))))))
686 (defun gnus-generate-horizontal-tree (thread level &optional dummyp adopted)
687 "Generate a horizontal tree."
688 (let* ((dummy (stringp (car thread)))
691 (memq (mail-header-number (car thread))
695 ;; We don't want this article.
696 (setq thread (cdr thread))
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.
709 (= (following-char) ? ))
711 (insert (caddr gnus-tree-parent-child-edges)))
714 ;; Insert the article node.
715 (gnus-tree-node-insert (pop thread) gnus-tmp-sparse adopted))
717 ;; End of the thread, so we go to the next line.
720 ;; Recurse downwards in all children of this article.
722 (gnus-generate-horizontal-tree
723 (pop thread) (if do (1+ level) level)
724 (or dummyp dummy) dummy)))))
726 (defsubst gnus-tree-indent-vertical ()
727 (let ((len (- (* (1+ gnus-tree-node-length) gnus-tmp-indent)
728 (- (point) (gnus-point-at-bol)))))
730 (insert (make-string len ? )))))
732 (defsubst gnus-tree-forward-line (n)
733 (while (>= (decf n) 0)
734 (unless (zerop (forward-line 1))
739 (defun gnus-generate-vertical-tree (thread level &optional dummyp adopted)
740 "Generate a vertical tree."
741 (let* ((dummy (stringp (car thread)))
744 (memq (mail-header-number (car thread))
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 "-".
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)
762 (insert (cadr gnus-tree-parent-child-edges))
765 ;; Draw "-" lines leftwards.
766 (while (and (> (point) 1)
767 (= (char-after (1- (point))) ? ))
769 (insert (car gnus-tree-parent-child-edges))
772 (gnus-tree-forward-line 1)))
774 ;; Insert the article node.
775 (gnus-tree-indent-vertical)
776 (gnus-tree-node-insert (pop thread) gnus-tmp-sparse adopted)
777 (gnus-tree-forward-line 1))
779 ;; End of the thread, so we go to the next line.
781 (goto-char (point-min))
783 (incf gnus-tmp-indent))
784 ;; Recurse downwards in all children of this article.
786 (gnus-generate-vertical-tree
787 (pop thread) (if do (1+ level) level)
788 (or dummyp dummy) dummy)))))
790 ;;; Interface functions.
792 (defun gnus-possibly-generate-tree (article &optional force)
793 "Generate the thread tree for ARTICLE if it isn't displayed already."
794 (when (save-excursion
795 (set-buffer gnus-summary-buffer)
798 (vectorp (gnus-summary-article-header article))))
800 (let ((top (save-excursion
801 (set-buffer gnus-summary-buffer)
805 (gnus-summary-article-header article))
807 (gnus-tmp-limit gnus-newsgroup-limit)
808 (gnus-tmp-sparse gnus-newsgroup-sparse))
810 (not (eq top gnus-tree-displayed-thread)))
811 (gnus-generate-tree top)
812 (setq gnus-tree-displayed-thread top))))))
814 (defun gnus-tree-open (group)
815 (gnus-get-tree-buffer))
817 (defun gnus-tree-close (group)
818 (gnus-kill-buffer gnus-tree-buffer))
820 (defun gnus-highlight-selected-tree (article)
821 "Highlight the selected article in the tree."
822 (let ((buf (current-buffer))
824 (set-buffer gnus-tree-buffer)
825 (when (setq region (gnus-tree-article-region article))
826 (when (or (not gnus-selected-tree-overlay)
827 (gnus-extent-detached-p gnus-selected-tree-overlay))
828 ;; Create a new overlay.
830 (setq gnus-selected-tree-overlay (gnus-make-overlay 1 2))
831 'face gnus-selected-tree-face))
832 ;; Move the overlay to the article.
834 gnus-selected-tree-overlay (goto-char (car region)) (cdr region))
837 (let ((selected (selected-window)))
838 (when (get-buffer-window (set-buffer gnus-tree-buffer) t)
839 (select-window (get-buffer-window (set-buffer gnus-tree-buffer) t))
840 (gnus-horizontal-recenter)
841 (select-window selected))))
842 ;; If we remove this save-excursion, it updates the wrong mode lines?!?
844 (set-buffer gnus-tree-buffer)
845 (gnus-set-mode-line 'tree))
848 (defun gnus-tree-highlight-article (article face)
850 (set-buffer (gnus-get-tree-buffer))
852 (when (setq region (gnus-tree-article-region article))
853 (gnus-put-text-property (car region) (cdr region) 'face face)
855 (get-buffer-window (current-buffer) t) (cdr region))))))
861 (defvar gnus-carpal-group-buffer-buttons
862 '(("next" . gnus-group-next-unread-group)
863 ("prev" . gnus-group-prev-unread-group)
864 ("read" . gnus-group-read-group)
865 ("select" . gnus-group-select-group)
866 ("catch-up" . gnus-group-catchup-current)
867 ("new-news" . gnus-group-get-new-news-this-group)
868 ("toggle-sub" . gnus-group-unsubscribe-current-group)
869 ("subscribe" . gnus-group-unsubscribe-group)
870 ("kill" . gnus-group-kill-group)
871 ("yank" . gnus-group-yank-group)
872 ("describe" . gnus-group-describe-group)
874 ("subscribed" . gnus-group-list-groups)
875 ("all" . gnus-group-list-all-groups)
876 ("killed" . gnus-group-list-killed)
877 ("zombies" . gnus-group-list-zombies)
878 ("matching" . gnus-group-list-matching)
879 ("post" . gnus-group-post-news)
880 ("mail" . gnus-group-mail)
881 ("rescan" . gnus-group-get-new-news)
882 ("browse-foreign" . gnus-group-browse-foreign)
883 ("exit" . gnus-group-exit)))
885 (defvar gnus-carpal-summary-buffer-buttons
887 ("read" . gnus-summary-mark-as-read-forward)
888 ("tick" . gnus-summary-tick-article-forward)
889 ("clear" . gnus-summary-clear-mark-forward)
890 ("expirable" . gnus-summary-mark-as-expirable)
892 ("scroll" . gnus-summary-next-page)
893 ("next-unread" . gnus-summary-next-unread-article)
894 ("prev-unread" . gnus-summary-prev-unread-article)
895 ("first" . gnus-summary-first-unread-article)
896 ("best" . gnus-summary-best-unread-article)
898 ("headers" . gnus-summary-toggle-header)
899 ("uudecode" . gnus-uu-decode-uu)
900 ("enter-digest" . gnus-summary-enter-digest-group)
901 ("fetch-parent" . gnus-summary-refer-parent-article)
903 ("move" . gnus-summary-move-article)
904 ("copy" . gnus-summary-copy-article)
905 ("respool" . gnus-summary-respool-article)
907 ("lower" . gnus-summary-lower-thread)
908 ("kill" . gnus-summary-kill-thread)
910 ("post" . gnus-summary-post-news)
911 ("mail" . gnus-summary-mail)
912 ("followup" . gnus-summary-followup-with-original)
913 ("reply" . gnus-summary-reply-with-original)
914 ("cancel" . gnus-summary-cancel-article)
916 ("exit" . gnus-summary-exit)
917 ("fed-up" . gnus-summary-catchup-and-goto-next-group)))
919 (defvar gnus-carpal-server-buffer-buttons
920 '(("add" . gnus-server-add-server)
921 ("browse" . gnus-server-browse-server)
922 ("list" . gnus-server-list-servers)
923 ("kill" . gnus-server-kill-server)
924 ("yank" . gnus-server-yank-server)
925 ("copy" . gnus-server-copy-server)
926 ("exit" . gnus-server-exit)))
928 (defvar gnus-carpal-browse-buffer-buttons
929 '(("subscribe" . gnus-browse-unsubscribe-current-group)
930 ("exit" . gnus-browse-exit)))
932 (defvar gnus-carpal-group-buffer "*Carpal Group*")
933 (defvar gnus-carpal-summary-buffer "*Carpal Summary*")
934 (defvar gnus-carpal-server-buffer "*Carpal Server*")
935 (defvar gnus-carpal-browse-buffer "*Carpal Browse*")
937 (defvar gnus-carpal-attached-buffer nil)
939 (defvar gnus-carpal-mode-hook nil
940 "*Hook run in carpal mode buffers.")
942 (defvar gnus-carpal-button-face 'bold
943 "*Face used on carpal buttons.")
945 (defvar gnus-carpal-header-face 'bold-italic
946 "*Face used on carpal buffer headers.")
948 (defvar gnus-carpal-mode-map nil)
949 (put 'gnus-carpal-mode 'mode-class 'special)
951 (if gnus-carpal-mode-map
953 (setq gnus-carpal-mode-map (make-keymap))
954 (suppress-keymap gnus-carpal-mode-map)
955 (define-key gnus-carpal-mode-map " " 'gnus-carpal-select)
956 (define-key gnus-carpal-mode-map "\r" 'gnus-carpal-select)
957 (define-key gnus-carpal-mode-map gnus-mouse-2 'gnus-carpal-mouse-select))
959 (defun gnus-carpal-mode ()
960 "Major mode for clicking buttons.
962 All normal editing commands are switched off.
963 \\<gnus-carpal-mode-map>
964 The following commands are available:
966 \\{gnus-carpal-mode-map}"
968 (kill-all-local-variables)
969 (setq mode-line-modified (cdr gnus-mode-line-modified))
970 (setq major-mode 'gnus-carpal-mode)
971 (setq mode-name "Gnus Carpal")
972 (setq mode-line-process nil)
973 (use-local-map gnus-carpal-mode-map)
974 (buffer-disable-undo (current-buffer))
975 (setq buffer-read-only t)
976 (make-local-variable 'gnus-carpal-attached-buffer)
977 (gnus-run-hooks 'gnus-carpal-mode-hook))
979 (defun gnus-carpal-setup-buffer (type)
980 (let ((buffer (symbol-value (intern (format "gnus-carpal-%s-buffer" type)))))
981 (if (get-buffer buffer)
984 (set-buffer (get-buffer-create buffer))
986 (setq gnus-carpal-attached-buffer
987 (intern (format "gnus-%s-buffer" type)))
988 (gnus-add-current-to-buffer-list)
989 (let ((buttons (symbol-value
990 (intern (format "gnus-carpal-%s-buffer-buttons"
992 (buffer-read-only nil)
995 (setq button (car buttons)
996 buttons (cdr buttons))
998 (gnus-set-text-properties
1000 (prog2 (insert button) (point) (insert " "))
1001 (list 'face gnus-carpal-header-face))
1002 (gnus-set-text-properties
1004 (prog2 (insert (car button)) (point) (insert " "))
1005 (list 'gnus-callback (cdr button)
1006 'face gnus-carpal-button-face
1007 gnus-mouse-face-prop 'highlight))))
1008 (let ((fill-column (- (window-width) 2)))
1009 (fill-region (point-min) (point-max)))
1010 (set-window-point (get-buffer-window (current-buffer))
1013 (defun gnus-carpal-select ()
1014 "Select the button under point."
1016 (let ((func (get-text-property (point) 'gnus-callback)))
1019 (pop-to-buffer (symbol-value gnus-carpal-attached-buffer))
1020 (call-interactively func))))
1022 (defun gnus-carpal-mouse-select (event)
1023 "Select the button under the mouse pointer."
1025 (mouse-set-point event)
1026 (gnus-carpal-select))
1028 ;;; Allow redefinition of functions.
1031 (provide 'gnus-salt)
1033 ;;; gnus-salt.el ends here