1 ;;; gnus-salt.el --- alternate summary mode interfaces for Gnus
3 ;; Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (eval-when-compile (require 'cl))
38 (defvar gnus-pick-mode nil
39 "Minor mode for providing a pick-and-read interface in Gnus
42 (defcustom gnus-pick-display-summary nil
43 "*Display summary while reading."
45 :group 'gnus-summary-pick)
47 (defcustom gnus-pick-mode-hook nil
48 "Hook run in summary pick mode buffers."
50 :group 'gnus-summary-pick)
52 (when (featurep 'xemacs)
53 (add-hook 'gnus-pick-mode-hook 'gnus-xmas-pick-menu-add))
55 (defcustom gnus-mark-unpicked-articles-as-read nil
56 "*If non-nil, mark all unpicked articles as read."
58 :group 'gnus-summary-pick)
60 (defcustom gnus-pick-elegant-flow t
61 "If non-nil, `gnus-pick-start-reading' runs
62 `gnus-summary-next-group' when no articles have been picked."
64 :group 'gnus-summary-pick)
66 (defcustom gnus-summary-pick-line-format
67 "%-5P %U\%R\%z\%I\%(%[%4L: %-20,20n%]%) %s\n"
68 "*The format specification of the lines in pick buffers.
69 It accepts the same format specs that `gnus-summary-line-format' does."
71 :group 'gnus-summary-pick)
73 ;;; Internal variables.
75 (defvar gnus-pick-mode-map nil)
77 (unless gnus-pick-mode-map
78 (setq gnus-pick-mode-map (make-sparse-keymap))
80 (gnus-define-keys gnus-pick-mode-map
81 " " gnus-pick-next-page
82 "u" gnus-pick-unmark-article-or-thread
83 "." gnus-pick-article-or-thread
84 gnus-down-mouse-2 gnus-pick-mouse-pick-region
85 "\r" gnus-pick-start-reading))
87 (defun gnus-pick-make-menu-bar ()
88 (unless (boundp 'gnus-pick-menu)
90 gnus-pick-menu gnus-pick-mode-map ""
93 ["Article" gnus-summary-mark-as-processable t]
94 ["Thread" gnus-uu-mark-thread t]
95 ["Region" gnus-uu-mark-region t]
96 ["Regexp" gnus-uu-mark-by-regexp t]
97 ["Buffer" gnus-uu-mark-buffer t])
99 ["Article" gnus-summary-unmark-as-processable t]
100 ["Thread" gnus-uu-unmark-thread t]
101 ["Region" gnus-uu-unmark-region t]
102 ["Regexp" gnus-uu-unmark-by-regexp t]
103 ["Buffer" gnus-summary-unmark-all-processable t])
104 ["Start reading" gnus-pick-start-reading t]
105 ["Switch pick mode off" gnus-pick-mode gnus-pick-mode]))))
107 (defun gnus-pick-mode (&optional arg)
108 "Minor mode for providing a pick-and-read interface in Gnus summary buffers.
110 \\{gnus-pick-mode-map}"
112 (when (eq major-mode 'gnus-summary-mode)
113 (if (not (set (make-local-variable 'gnus-pick-mode)
114 (if (null arg) (not gnus-pick-mode)
115 (> (prefix-numeric-value arg) 0))))
116 (remove-hook 'gnus-message-setup-hook 'gnus-pick-setup-message)
117 ;; Make sure that we don't select any articles upon group entry.
118 (set (make-local-variable 'gnus-auto-select-first) nil)
119 ;; Change line format.
120 (setq gnus-summary-line-format gnus-summary-pick-line-format)
121 (setq gnus-summary-line-format-spec nil)
122 (gnus-update-format-specifications nil 'summary)
123 (gnus-update-summary-mark-positions)
124 (add-hook 'gnus-message-setup-hook 'gnus-pick-setup-message)
125 (set (make-local-variable 'gnus-summary-goto-unread) 'never)
127 (when (gnus-visual-p 'pick-menu 'menu)
128 (gnus-pick-make-menu-bar))
129 (gnus-add-minor-mode 'gnus-pick-mode " Pick" gnus-pick-mode-map
131 (gnus-run-hooks 'gnus-pick-mode-hook))))
133 (defun gnus-pick-setup-message ()
134 "Make Message do the right thing on exit."
135 (when (and (gnus-buffer-live-p gnus-summary-buffer)
137 (set-buffer gnus-summary-buffer)
140 '(gnus-configure-windows ,gnus-current-window-configuration t)
141 'send 'exit 'postpone 'kill)))
143 (defvar gnus-pick-line-number 1)
144 (defun gnus-pick-line-number ()
145 "Return the current line number."
147 (setq gnus-pick-line-number 1)
148 (incf gnus-pick-line-number)))
150 (defun gnus-pick-start-reading (&optional catch-up)
151 "Start reading the picked articles.
152 If given a prefix, mark all unpicked articles as read."
154 (if gnus-newsgroup-processable
156 (gnus-summary-limit-to-articles nil)
157 (when (or catch-up gnus-mark-unpicked-articles-as-read)
158 (gnus-summary-limit-mark-excluded-as-read))
159 (gnus-summary-first-article)
160 (gnus-configure-windows
161 (if gnus-pick-display-summary 'article 'pick) t))
162 (if gnus-pick-elegant-flow
164 (when (or catch-up gnus-mark-unpicked-articles-as-read)
165 (gnus-summary-catchup nil t))
166 (if (gnus-group-quit-config gnus-newsgroup-name)
168 (gnus-summary-next-group)))
169 (error "No articles have been picked"))))
171 (defun gnus-pick-goto-article (arg)
172 "Go to the article number indicated by ARG.
173 If ARG is an invalid article number, then stay on current line."
176 (goto-char (point-min))
177 (when (zerop (forward-line (1- (prefix-numeric-value arg))))
180 (gnus-error 2 "No such line: %s" arg)
183 (defun gnus-pick-article (&optional arg)
184 "Pick the article on the current line.
185 If ARG, pick the article on that line instead."
188 (gnus-pick-goto-article arg))
189 (gnus-summary-mark-as-processable 1))
191 (defun gnus-pick-article-or-thread (&optional arg)
192 "If `gnus-thread-hide-subtree' is t, then pick the thread on the current line.
193 Otherwise pick the article on the current line.
194 If ARG, pick the article/thread on that line instead."
197 (gnus-pick-goto-article arg))
198 (if gnus-thread-hide-subtree
201 (gnus-uu-mark-thread))
203 (gnus-summary-mark-as-processable 1)))
205 (defun gnus-pick-unmark-article-or-thread (&optional arg)
206 "If `gnus-thread-hide-subtree' is t, then unmark the thread on current line.
207 Otherwise unmark the article on current line.
208 If ARG, unmark thread/article on that line instead."
211 (gnus-pick-goto-article arg))
212 (if gnus-thread-hide-subtree
214 (gnus-uu-unmark-thread))
215 (gnus-summary-unmark-as-processable 1)))
217 (defun gnus-pick-mouse-pick (e)
221 (gnus-summary-mark-as-processable 1)))
223 (defun gnus-pick-mouse-pick-region (start-event)
224 "Pick articles that the mouse is dragged over.
225 This must be bound to a button-down mouse event."
227 (mouse-minibuffer-check start-event)
228 (let* ((echo-keystrokes 0)
229 (start-posn (event-start start-event))
230 (start-point (posn-point start-posn))
231 (start-line (1+ (count-lines 1 start-point)))
232 (start-window (posn-window start-posn))
233 (bounds (gnus-window-edges start-window))
235 (bottom (if (window-minibuffer-p start-window)
237 ;; Don't count the mode line.
238 (1- (nth 3 bounds))))
239 (click-count (1- (event-click-count start-event))))
240 (setq mouse-selection-click-count click-count)
241 (setq mouse-selection-click-count-buffer (current-buffer))
242 (mouse-set-point start-event)
243 ;; In case the down click is in the middle of some intangible text,
244 ;; use the end of that text, and put it in START-POINT.
245 (when (< (point) start-point)
246 (goto-char start-point))
248 (setq start-point (point))
249 ;; end-of-range is used only in the single-click case.
250 ;; It is the place where the drag has reached so far
251 ;; (but not outside the window where the drag started).
252 (let (event end end-point (end-of-range (point)))
255 (setq event (cdr (gnus-read-event-char)))
256 (or (mouse-movement-p event)
257 (eq (car-safe event) 'switch-frame)))
258 (if (eq (car-safe event) 'switch-frame)
260 (setq end (event-end event)
261 end-point (posn-point end))
264 ;; Are we moving within the original window?
265 ((and (eq (posn-window end) start-window)
266 (integer-or-marker-p end-point))
267 ;; Go to START-POINT first, so that when we move to END-POINT,
268 ;; if it's in the middle of intangible text,
269 ;; point jumps in the direction away from START-POINT.
270 (goto-char start-point)
271 (goto-char end-point)
273 ;; In case the user moved his mouse really fast, pick
274 ;; articles on the line between this one and the last one.
275 (let* ((this-line (1+ (count-lines 1 end-point)))
276 (min-line (min this-line start-line))
277 (max-line (max this-line start-line)))
278 (while (< min-line max-line)
281 (setq min-line (1+ min-line)))
282 (setq start-line this-line))
283 (when (zerop (% click-count 3))
284 (setq end-of-range (point))))
286 (let ((mouse-row (cdr (cdr (mouse-position)))))
290 (mouse-scroll-subr start-window (- mouse-row top)))
291 ((>= mouse-row bottom)
292 (mouse-scroll-subr start-window
293 (1+ (- mouse-row bottom)))))))))))
295 (let ((fun (key-binding (vector (car event)))))
296 ;; Run the binding of the terminating up-event, if possible.
297 ;; In the case of a multiple click, it gives the wrong results,
298 ;; because it would fail to set up a region.
300 ;; (and (= (mod mouse-selection-click-count 3) 0) (fboundp fun))
301 ;; In this case, we can just let the up-event execute normally.
302 (let ((end (event-end event)))
303 ;; Set the position in the event before we replay it,
304 ;; because otherwise it may have a position in the wrong
306 (setcar (cdr end) end-of-range)
307 ;; Delete the overlay before calling the function,
308 ;; because delete-overlay increases buffer-modified-tick.
309 (push event unread-command-events))))))))
311 (defun gnus-pick-next-page ()
312 "Go to the next page. If at the end of the buffer, start reading articles."
314 (let ((scroll-in-place nil))
317 (end-of-buffer (gnus-pick-start-reading)))))
323 (defvar gnus-binary-mode nil
324 "Minor mode for providing a binary group interface in Gnus summary buffers.")
326 (defvar gnus-binary-mode-hook nil
327 "Hook run in summary binary mode buffers.")
329 (defvar gnus-binary-mode-map nil)
331 (unless gnus-binary-mode-map
332 (setq gnus-binary-mode-map (make-sparse-keymap))
336 "g" gnus-binary-show-article))
338 (defun gnus-binary-make-menu-bar ()
339 (unless (boundp 'gnus-binary-menu)
341 gnus-binary-menu gnus-binary-mode-map ""
343 ["Switch binary mode off" gnus-binary-mode t]))))
345 (defun gnus-binary-mode (&optional arg)
346 "Minor mode for providing a binary group interface in Gnus summary buffers."
348 (when (eq major-mode 'gnus-summary-mode)
349 (make-local-variable 'gnus-binary-mode)
350 (setq gnus-binary-mode
351 (if (null arg) (not gnus-binary-mode)
352 (> (prefix-numeric-value arg) 0)))
353 (when gnus-binary-mode
354 ;; Make sure that we don't select any articles upon group entry.
355 (make-local-variable 'gnus-auto-select-first)
356 (setq gnus-auto-select-first nil)
357 (make-local-variable 'gnus-summary-display-article-function)
358 (setq gnus-summary-display-article-function 'gnus-binary-display-article)
360 (when (gnus-visual-p 'binary-menu 'menu)
361 (gnus-binary-make-menu-bar))
362 (gnus-add-minor-mode 'gnus-binary-mode " Binary"
363 gnus-binary-mode-map nil 'gnus-binary-mode)
364 (gnus-run-hooks 'gnus-binary-mode-hook))))
366 (defun gnus-binary-display-article (article &optional all-header)
367 "Run ARTICLE through the binary decode functions."
368 (when (gnus-summary-goto-subject article)
369 (let ((gnus-view-pseudos 'automatic))
370 (gnus-uu-decode-uu))))
372 (defun gnus-binary-show-article (&optional arg)
373 "Bypass the binary functions and show the article."
375 (let (gnus-summary-display-article-function)
376 (gnus-summary-show-article arg)))
382 (defcustom gnus-tree-line-format "%(%[%3,3n%]%)"
383 "Format of tree elements."
385 :group 'gnus-summary-tree)
387 (defcustom gnus-tree-minimize-window t
388 "If non-nil, minimize the tree buffer window.
389 If a number, never let the tree buffer grow taller than that number of
391 :type '(choice boolean
393 :group 'gnus-summary-tree)
395 (defcustom gnus-selected-tree-face 'modeline
396 "*Face used for highlighting selected articles in the thread tree."
398 :group 'gnus-summary-tree)
400 (defvar gnus-tree-brackets '((?\[ . ?\]) (?\( . ?\))
401 (?\{ . ?\}) (?< . ?>))
402 "Brackets used in tree nodes.")
404 (defvar gnus-tree-parent-child-edges '(?- ?\\ ?|)
405 "Characters used to connect parents with children.")
407 (defcustom gnus-tree-mode-line-format "Gnus: %%b %S %Z"
408 "*The format specification for the tree mode line."
410 :group 'gnus-summary-tree)
412 (defcustom gnus-generate-tree-function 'gnus-generate-vertical-tree
413 "*Function for generating a thread tree.
414 Two predefined functions are available:
415 `gnus-generate-horizontal-tree' and `gnus-generate-vertical-tree'."
416 :type '(radio (function-item gnus-generate-vertical-tree)
417 (function-item gnus-generate-horizontal-tree)
418 (function :tag "Other" nil))
419 :group 'gnus-summary-tree)
421 (defcustom gnus-tree-mode-hook nil
422 "*Hook run in tree mode buffers."
424 :group 'gnus-summary-tree)
426 (when (featurep 'xemacs)
427 (add-hook 'gnus-tree-mode-hook 'gnus-xmas-tree-menu-add)
428 (add-hook 'gnus-tree-mode-hook 'gnus-xmas-switch-horizontal-scrollbar-off))
431 ;;; Internal variables.
433 (defvar gnus-tree-line-format-alist
434 `((?n gnus-tmp-name ?s)
435 (?f gnus-tmp-from ?s)
436 (?N gnus-tmp-number ?d)
437 (?\[ gnus-tmp-open-bracket ?c)
438 (?\] gnus-tmp-close-bracket ?c)
439 (?s gnus-tmp-subject ?s)))
441 (defvar gnus-tree-mode-line-format-alist gnus-summary-mode-line-format-alist)
443 (defvar gnus-tree-mode-line-format-spec nil)
444 (defvar gnus-tree-line-format-spec nil)
446 (defvar gnus-tree-node-length nil)
447 (defvar gnus-selected-tree-overlay nil)
449 (defvar gnus-tree-displayed-thread nil)
450 (defvar gnus-tree-inhibit nil)
452 (defvar gnus-tree-mode-map nil)
453 (put 'gnus-tree-mode 'mode-class 'special)
455 (unless gnus-tree-mode-map
456 (setq gnus-tree-mode-map (make-keymap))
457 (suppress-keymap gnus-tree-mode-map)
460 "\r" gnus-tree-select-article
461 gnus-mouse-2 gnus-tree-pick-article
462 "\C-?" gnus-tree-read-summary-keys
463 "h" gnus-tree-show-summary
465 "\C-c\C-i" gnus-info-find-node)
467 (substitute-key-definition
468 'undefined 'gnus-tree-read-summary-keys gnus-tree-mode-map))
470 (defun gnus-tree-make-menu-bar ()
471 (unless (boundp 'gnus-tree-menu)
473 gnus-tree-menu gnus-tree-mode-map ""
475 ["Select article" gnus-tree-select-article t]))))
477 (defun gnus-tree-mode ()
478 "Major mode for displaying thread trees."
480 (gnus-set-format 'tree-mode)
481 (gnus-set-format 'tree t)
482 (when (gnus-visual-p 'tree-menu 'menu)
483 (gnus-tree-make-menu-bar))
484 (kill-all-local-variables)
485 (gnus-simplify-mode-line)
486 (setq mode-name "Tree")
487 (setq major-mode 'gnus-tree-mode)
488 (use-local-map gnus-tree-mode-map)
489 (buffer-disable-undo)
490 (setq buffer-read-only t)
491 (setq truncate-lines t)
493 (gnus-set-work-buffer)
494 (gnus-tree-node-insert (make-mail-header "") nil)
495 (setq gnus-tree-node-length (1- (point))))
496 (gnus-run-hooks 'gnus-tree-mode-hook))
498 (defun gnus-tree-read-summary-keys (&optional arg)
499 "Read a summary buffer key sequence and execute it."
501 (unless gnus-tree-inhibit
502 (let ((buf (current-buffer))
503 (gnus-tree-inhibit t)
505 (set-buffer gnus-article-buffer)
506 (gnus-article-read-summary-keys arg nil t)
507 (when (setq win (get-buffer-window buf))
509 (when gnus-selected-tree-overlay
510 (goto-char (or (gnus-overlay-end gnus-selected-tree-overlay) 1)))
511 (gnus-tree-minimize)))))
513 (defun gnus-tree-show-summary ()
514 "Reconfigure windows to show summary buffer."
516 (if (not (gnus-buffer-live-p gnus-summary-buffer))
517 (error "There is no summary buffer for this tree buffer")
518 (gnus-configure-windows 'article)
519 (gnus-summary-goto-subject gnus-current-article)))
521 (defun gnus-tree-select-article (article)
522 "Select the article under point, if any."
523 (interactive (list (gnus-tree-article-number)))
524 (let ((buf (current-buffer)))
527 (set-buffer gnus-summary-buffer)
528 (gnus-summary-goto-article article))
529 (select-window (get-buffer-window buf)))))
531 (defun gnus-tree-pick-article (e)
532 "Select the article under the mouse pointer."
535 (gnus-tree-select-article (gnus-tree-article-number)))
537 (defun gnus-tree-article-number ()
538 (get-text-property (point) 'gnus-number))
540 (defun gnus-tree-article-region (article)
541 "Return a cons with BEG and END of the article region."
542 (let ((pos (text-property-any
543 (point-min) (point-max) 'gnus-number article)))
545 (cons pos (next-single-property-change pos 'gnus-number)))))
547 (defun gnus-tree-goto-article (article)
548 (let ((pos (text-property-any
549 (point-min) (point-max) 'gnus-number article)))
553 (defun gnus-tree-recenter ()
554 "Center point in the tree window."
555 (let ((selected (selected-window))
556 (tree-window (get-buffer-window gnus-tree-buffer t)))
558 (select-window tree-window)
559 (when gnus-selected-tree-overlay
560 (goto-char (or (gnus-overlay-end gnus-selected-tree-overlay) 1)))
561 (let* ((top (cond ((< (window-height) 4) 0)
562 ((< (window-height) 7) 1)
564 (height (1- (window-height)))
565 (bottom (save-excursion (goto-char (point-max))
566 (forward-line (- height))
568 ;; Set the window start to either `bottom', which is the biggest
569 ;; possible valid number, or the second line from the top,
570 ;; whichever is the least.
572 tree-window (min bottom (save-excursion
573 (forward-line (- top)) (point)))))
574 (select-window selected))))
576 (defun gnus-get-tree-buffer ()
577 "Return the tree buffer properly initialized."
579 (set-buffer (gnus-get-buffer-create gnus-tree-buffer))
580 (unless (eq major-mode 'gnus-tree-mode)
584 (defun gnus-tree-minimize ()
585 (when (and gnus-tree-minimize-window
586 (not (one-window-p)))
589 (walk-windows (lambda (window) (incf windows)))
592 (* window-min-height (1- windows))
594 (let* ((window-min-height 2)
595 (height (count-lines (point-min) (point-max)))
596 (min (max (1- window-min-height) height))
597 (tot (if (numberp gnus-tree-minimize-window)
598 (min gnus-tree-minimize-window min)
600 (win (get-buffer-window (current-buffer)))
601 (wh (and win (1- (window-height win)))))
602 (setq tot (min tot tot-win-height))
605 (let ((selected (selected-window)))
606 (when (ignore-errors (select-window win))
607 (enlarge-window (- tot wh))
608 (select-window selected))))))))
610 ;;; Generating the tree.
612 (defun gnus-tree-node-insert (header sparse &optional adopted)
613 (let* ((dummy (stringp header))
614 (header (if (vectorp header) header
616 (setq header (make-mail-header "*****"))
617 (mail-header-set-number header 0)
618 (mail-header-set-lines header 0)
619 (mail-header-set-chars header 0)
621 (gnus-tmp-from (mail-header-from header))
622 (gnus-tmp-subject (mail-header-subject header))
623 (gnus-tmp-number (mail-header-number header))
626 ((string-match "(.+)" gnus-tmp-from)
627 (substring gnus-tmp-from
628 (1+ (match-beginning 0)) (1- (match-end 0))))
629 ((string-match "<[^>]+> *$" gnus-tmp-from)
630 (let ((beg (match-beginning 0)))
631 (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
632 (substring gnus-tmp-from (1+ (match-beginning 0))
634 (substring gnus-tmp-from 0 beg))))
635 ((memq gnus-tmp-number sparse)
638 (gnus-tmp-open-bracket
639 (cond ((memq gnus-tmp-number sparse)
640 (caadr gnus-tree-brackets))
641 (dummy (caaddr gnus-tree-brackets))
642 (adopted (car (nth 3 gnus-tree-brackets)))
643 (t (caar gnus-tree-brackets))))
644 (gnus-tmp-close-bracket
645 (cond ((memq gnus-tmp-number sparse)
646 (cdadr gnus-tree-brackets))
647 (adopted (cdr (nth 3 gnus-tree-brackets)))
649 (cdaddr gnus-tree-brackets))
650 (t (cdar gnus-tree-brackets))))
651 (buffer-read-only nil)
653 (gnus-add-text-properties
655 (setq end (progn (eval gnus-tree-line-format-spec) (point)))
656 (list 'gnus-number gnus-tmp-number))
657 (when (or t (gnus-visual-p 'tree-highlight 'highlight))
658 (gnus-tree-highlight-node gnus-tmp-number beg end))))
660 (defun gnus-tree-highlight-node (article beg end)
661 "Highlight current line according to `gnus-summary-highlight'."
662 (let ((list gnus-summary-highlight)
665 (set-buffer gnus-summary-buffer)
666 (let* ((score (or (cdr (assq article gnus-newsgroup-scored))
667 gnus-summary-default-score 0))
668 (default gnus-summary-default-score)
669 (default-high gnus-summary-default-high-score)
670 (default-low gnus-summary-default-low-score)
671 (mark (or (gnus-summary-article-mark article) gnus-unread-mark)))
672 ;; Eval the cars of the lists until we find a match.
674 (not (eval (caar list))))
675 (setq list (cdr list)))))
676 (unless (eq (setq face (cdar list)) (get-text-property beg 'face))
677 (gnus-put-text-property-excluding-characters-with-faces
679 (if (boundp face) (symbol-value face) face)))))
681 (defun gnus-tree-indent (level)
682 (insert (make-string (1- (* (1+ gnus-tree-node-length) level)) ? )))
684 (defvar gnus-tmp-limit)
685 (defvar gnus-tmp-sparse)
686 (defvar gnus-tmp-indent)
688 (defun gnus-generate-tree (thread)
689 "Generate a thread tree for THREAD."
691 (set-buffer (gnus-get-tree-buffer))
692 (let ((buffer-read-only nil)
695 (funcall gnus-generate-tree-function thread 0)
696 (gnus-set-mode-line 'tree)
697 (goto-char (point-min))
700 (let ((selected (selected-window)))
701 (when (get-buffer-window (set-buffer gnus-tree-buffer) t)
702 (select-window (get-buffer-window (set-buffer gnus-tree-buffer) t))
703 (gnus-horizontal-recenter)
704 (select-window selected))))))
706 (defun gnus-generate-horizontal-tree (thread level &optional dummyp adopted)
707 "Generate a horizontal tree."
708 (let* ((dummy (stringp (car thread)))
711 (memq (mail-header-number (car thread))
715 ;; We don't want this article.
716 (setq thread (cdr thread))
718 ;; Not the first article on the line, so we insert a "-".
719 (insert (car gnus-tree-parent-child-edges))
720 ;; If the level isn't zero, then we insert some indentation.
721 (unless (zerop level)
722 (gnus-tree-indent level)
723 (insert (cadr gnus-tree-parent-child-edges))
724 (setq col (- (setq beg (point)) (gnus-point-at-bol) 1))
725 ;; Draw "|" lines upwards.
729 (eq (char-after) ? ))
731 (insert (caddr gnus-tree-parent-child-edges)))
734 ;; Insert the article node.
735 (gnus-tree-node-insert (pop thread) gnus-tmp-sparse adopted))
737 ;; End of the thread, so we go to the next line.
740 ;; Recurse downwards in all children of this article.
742 (gnus-generate-horizontal-tree
743 (pop thread) (if do (1+ level) level)
744 (or dummyp dummy) dummy)))))
746 (defsubst gnus-tree-indent-vertical ()
747 (let ((len (- (* (1+ gnus-tree-node-length) gnus-tmp-indent)
748 (- (point) (gnus-point-at-bol)))))
750 (insert (make-string len ? )))))
752 (defsubst gnus-tree-forward-line (n)
753 (while (>= (decf n) 0)
754 (unless (zerop (forward-line 1))
759 (defun gnus-generate-vertical-tree (thread level &optional dummyp adopted)
760 "Generate a vertical tree."
761 (let* ((dummy (stringp (car thread)))
764 (memq (mail-header-number (car thread))
768 ;; We don't want this article.
769 (setq thread (cdr thread))
770 (if (not (save-excursion (beginning-of-line) (bobp)))
771 ;; Not the first article on the line, so we insert a "-".
773 (gnus-tree-indent-vertical)
774 (insert (make-string (/ gnus-tree-node-length 2) ? ))
775 (insert (caddr gnus-tree-parent-child-edges))
776 (gnus-tree-forward-line 1))
777 ;; If the level isn't zero, then we insert some indentation.
778 (unless (zerop gnus-tmp-indent)
779 (gnus-tree-forward-line (1- (* 2 level)))
780 (gnus-tree-indent-vertical)
782 (insert (cadr gnus-tree-parent-child-edges))
785 ;; Draw "-" lines leftwards.
786 (while (and (> (point) 1)
787 (eq (char-after (1- (point))) ? ))
789 (insert (car gnus-tree-parent-child-edges))
792 (gnus-tree-forward-line 1)))
794 ;; Insert the article node.
795 (gnus-tree-indent-vertical)
796 (gnus-tree-node-insert (pop thread) gnus-tmp-sparse adopted)
797 (gnus-tree-forward-line 1))
799 ;; End of the thread, so we go to the next line.
801 (goto-char (point-min))
803 (incf gnus-tmp-indent))
804 ;; Recurse downwards in all children of this article.
806 (gnus-generate-vertical-tree
807 (pop thread) (if do (1+ level) level)
808 (or dummyp dummy) dummy)))))
810 ;;; Interface functions.
812 (defun gnus-possibly-generate-tree (article &optional force)
813 "Generate the thread tree for ARTICLE if it isn't displayed already."
814 (when (save-excursion
815 (set-buffer gnus-summary-buffer)
818 (vectorp (gnus-summary-article-header article))))
820 (let ((top (save-excursion
821 (set-buffer gnus-summary-buffer)
825 (gnus-summary-article-header article))
827 (gnus-tmp-limit gnus-newsgroup-limit)
828 (gnus-tmp-sparse gnus-newsgroup-sparse))
830 (not (eq top gnus-tree-displayed-thread)))
831 (gnus-generate-tree top)
832 (setq gnus-tree-displayed-thread top))))))
834 (defun gnus-tree-open (group)
835 (gnus-get-tree-buffer))
837 (defun gnus-tree-close (group)
838 (gnus-kill-buffer gnus-tree-buffer))
840 (defun gnus-highlight-selected-tree (article)
841 "Highlight the selected article in the tree."
842 (let ((buf (current-buffer))
844 (set-buffer gnus-tree-buffer)
845 (when (setq region (gnus-tree-article-region article))
846 (when (or (not gnus-selected-tree-overlay)
847 (gnus-extent-detached-p gnus-selected-tree-overlay))
848 ;; Create a new overlay.
850 (setq gnus-selected-tree-overlay (gnus-make-overlay 1 2))
851 'face gnus-selected-tree-face))
852 ;; Move the overlay to the article.
854 gnus-selected-tree-overlay (goto-char (car region)) (cdr region))
857 (let ((selected (selected-window)))
858 (when (get-buffer-window (set-buffer gnus-tree-buffer) t)
859 (select-window (get-buffer-window (set-buffer gnus-tree-buffer) t))
860 (gnus-horizontal-recenter)
861 (select-window selected))))
862 ;; If we remove this save-excursion, it updates the wrong mode lines?!?
864 (set-buffer gnus-tree-buffer)
865 (gnus-set-mode-line 'tree))
868 (defun gnus-tree-highlight-article (article face)
870 (set-buffer (gnus-get-tree-buffer))
872 (when (setq region (gnus-tree-article-region article))
873 (gnus-put-text-property (car region) (cdr region) 'face face)
875 (get-buffer-window (current-buffer) t) (cdr region))))))
881 (defvar gnus-carpal-group-buffer-buttons
882 '(("next" . gnus-group-next-unread-group)
883 ("prev" . gnus-group-prev-unread-group)
884 ("read" . gnus-group-read-group)
885 ("select" . gnus-group-select-group)
886 ("catch-up" . gnus-group-catchup-current)
887 ("new-news" . gnus-group-get-new-news-this-group)
888 ("toggle-sub" . gnus-group-unsubscribe-current-group)
889 ("subscribe" . gnus-group-unsubscribe-group)
890 ("kill" . gnus-group-kill-group)
891 ("yank" . gnus-group-yank-group)
892 ("describe" . gnus-group-describe-group)
894 ("subscribed" . gnus-group-list-groups)
895 ("all" . gnus-group-list-all-groups)
896 ("killed" . gnus-group-list-killed)
897 ("zombies" . gnus-group-list-zombies)
898 ("matching" . gnus-group-list-matching)
899 ("post" . gnus-group-post-news)
900 ("mail" . gnus-group-mail)
901 ("rescan" . gnus-group-get-new-news)
902 ("browse-foreign" . gnus-group-browse-foreign)
903 ("exit" . gnus-group-exit)))
905 (defvar gnus-carpal-summary-buffer-buttons
907 ("read" . gnus-summary-mark-as-read-forward)
908 ("tick" . gnus-summary-tick-article-forward)
909 ("clear" . gnus-summary-clear-mark-forward)
910 ("expirable" . gnus-summary-mark-as-expirable)
912 ("scroll" . gnus-summary-next-page)
913 ("next-unread" . gnus-summary-next-unread-article)
914 ("prev-unread" . gnus-summary-prev-unread-article)
915 ("first" . gnus-summary-first-unread-article)
916 ("best" . gnus-summary-best-unread-article)
918 ("headers" . gnus-summary-toggle-header)
919 ("uudecode" . gnus-uu-decode-uu)
920 ("enter-digest" . gnus-summary-enter-digest-group)
921 ("fetch-parent" . gnus-summary-refer-parent-article)
923 ("move" . gnus-summary-move-article)
924 ("copy" . gnus-summary-copy-article)
925 ("respool" . gnus-summary-respool-article)
927 ("lower" . gnus-summary-lower-thread)
928 ("kill" . gnus-summary-kill-thread)
930 ("post" . gnus-summary-post-news)
931 ("mail" . gnus-summary-mail)
932 ("followup" . gnus-summary-followup-with-original)
933 ("reply" . gnus-summary-reply-with-original)
934 ("cancel" . gnus-summary-cancel-article)
936 ("exit" . gnus-summary-exit)
937 ("fed-up" . gnus-summary-catchup-and-goto-next-group)))
939 (defvar gnus-carpal-server-buffer-buttons
940 '(("add" . gnus-server-add-server)
941 ("browse" . gnus-server-browse-server)
942 ("list" . gnus-server-list-servers)
943 ("kill" . gnus-server-kill-server)
944 ("yank" . gnus-server-yank-server)
945 ("copy" . gnus-server-copy-server)
946 ("exit" . gnus-server-exit)))
948 (defvar gnus-carpal-browse-buffer-buttons
949 '(("subscribe" . gnus-browse-unsubscribe-current-group)
950 ("exit" . gnus-browse-exit)))
952 (defvar gnus-carpal-group-buffer "*Carpal Group*")
953 (defvar gnus-carpal-summary-buffer "*Carpal Summary*")
954 (defvar gnus-carpal-server-buffer "*Carpal Server*")
955 (defvar gnus-carpal-browse-buffer "*Carpal Browse*")
957 (defvar gnus-carpal-attached-buffer nil)
959 (defvar gnus-carpal-mode-hook nil
960 "*Hook run in carpal mode buffers.")
962 (defvar gnus-carpal-button-face 'bold
963 "*Face used on carpal buttons.")
965 (defvar gnus-carpal-header-face 'bold-italic
966 "*Face used on carpal buffer headers.")
968 (defvar gnus-carpal-mode-map nil)
969 (put 'gnus-carpal-mode 'mode-class 'special)
971 (if gnus-carpal-mode-map
973 (setq gnus-carpal-mode-map (make-keymap))
974 (suppress-keymap gnus-carpal-mode-map)
975 (define-key gnus-carpal-mode-map " " 'gnus-carpal-select)
976 (define-key gnus-carpal-mode-map "\r" 'gnus-carpal-select)
977 (define-key gnus-carpal-mode-map gnus-mouse-2 'gnus-carpal-mouse-select))
979 (defun gnus-carpal-mode ()
980 "Major mode for clicking buttons.
982 All normal editing commands are switched off.
983 \\<gnus-carpal-mode-map>
984 The following commands are available:
986 \\{gnus-carpal-mode-map}"
988 (kill-all-local-variables)
989 (setq mode-line-modified (cdr gnus-mode-line-modified))
990 (setq major-mode 'gnus-carpal-mode)
991 (setq mode-name "Gnus Carpal")
992 (setq mode-line-process nil)
993 (use-local-map gnus-carpal-mode-map)
994 (buffer-disable-undo)
995 (setq buffer-read-only t)
996 (make-local-variable 'gnus-carpal-attached-buffer)
997 (gnus-run-hooks 'gnus-carpal-mode-hook))
999 (defun gnus-carpal-setup-buffer (type)
1000 (let ((buffer (symbol-value (intern (format "gnus-carpal-%s-buffer" type)))))
1001 (if (get-buffer buffer)
1004 (set-buffer (gnus-get-buffer-create buffer))
1006 (setq gnus-carpal-attached-buffer
1007 (intern (format "gnus-%s-buffer" type)))
1008 (let ((buttons (symbol-value
1009 (intern (format "gnus-carpal-%s-buffer-buttons"
1011 (buffer-read-only nil)
1014 (setq button (car buttons)
1015 buttons (cdr buttons))
1016 (if (stringp button)
1017 (gnus-set-text-properties
1019 (prog2 (insert button) (point) (insert " "))
1020 (list 'face gnus-carpal-header-face))
1021 (gnus-set-text-properties
1023 (prog2 (insert (car button)) (point) (insert " "))
1024 (list 'gnus-callback (cdr button)
1025 'face gnus-carpal-button-face
1026 gnus-mouse-face-prop 'highlight))))
1027 (let ((fill-column (- (window-width) 2)))
1028 (fill-region (point-min) (point-max)))
1029 (set-window-point (get-buffer-window (current-buffer))
1032 (defun gnus-carpal-select ()
1033 "Select the button under point."
1035 (let ((func (get-text-property (point) 'gnus-callback)))
1038 (pop-to-buffer (symbol-value gnus-carpal-attached-buffer))
1039 (call-interactively func))))
1041 (defun gnus-carpal-mouse-select (event)
1042 "Select the button under the mouse pointer."
1044 (mouse-set-point event)
1045 (gnus-carpal-select))
1047 ;;; Allow redefinition of functions.
1050 (provide 'gnus-salt)
1052 ;;; gnus-salt.el ends here