1 ;;; gnus-salt.el --- alternate summary mode interfaces for Gnus
2 ;; Copyright (C) 1996,97,98,99 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))
81 (defun gnus-pick-make-menu-bar ()
82 (unless (boundp 'gnus-pick-menu)
84 gnus-pick-menu gnus-pick-mode-map ""
87 ["Article" gnus-summary-mark-as-processable t]
88 ["Thread" gnus-uu-mark-thread t]
89 ["Region" gnus-uu-mark-region t]
90 ["Regexp" gnus-uu-mark-by-regexp t]
91 ["Buffer" gnus-uu-mark-buffer t])
93 ["Article" gnus-summary-unmark-as-processable t]
94 ["Thread" gnus-uu-unmark-thread t]
95 ["Region" gnus-uu-unmark-region t]
96 ["Regexp" gnus-uu-unmark-by-regexp t]
97 ["Buffer" gnus-summary-unmark-all-processable t])
98 ["Start reading" gnus-pick-start-reading t]
99 ["Switch pick mode off" gnus-pick-mode gnus-pick-mode]))))
101 (defun gnus-pick-mode (&optional arg)
102 "Minor mode for providing a pick-and-read interface in Gnus summary buffers.
104 \\{gnus-pick-mode-map}"
106 (when (eq major-mode 'gnus-summary-mode)
107 (if (not (set (make-local-variable 'gnus-pick-mode)
108 (if (null arg) (not gnus-pick-mode)
109 (> (prefix-numeric-value arg) 0))))
110 (remove-hook 'gnus-message-setup-hook 'gnus-pick-setup-message)
111 ;; Make sure that we don't select any articles upon group entry.
112 (set (make-local-variable 'gnus-auto-select-first) nil)
113 ;; Change line format.
114 (setq gnus-summary-line-format gnus-summary-pick-line-format)
115 (setq gnus-summary-line-format-spec nil)
116 (gnus-update-format-specifications nil 'summary)
117 (gnus-update-summary-mark-positions)
118 (add-hook 'gnus-message-setup-hook 'gnus-pick-setup-message)
119 (set (make-local-variable 'gnus-summary-goto-unread) 'never)
121 (when (gnus-visual-p 'pick-menu 'menu)
122 (gnus-pick-make-menu-bar))
123 (gnus-add-minor-mode 'gnus-pick-mode " Pick" gnus-pick-mode-map)
124 (gnus-run-hooks 'gnus-pick-mode-hook))))
126 (defun gnus-pick-setup-message ()
127 "Make Message do the right thing on exit."
128 (when (and (gnus-buffer-live-p gnus-summary-buffer)
130 (set-buffer gnus-summary-buffer)
133 '(gnus-configure-windows ,gnus-current-window-configuration t)
134 '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
194 (gnus-uu-mark-thread))
196 (gnus-summary-mark-as-processable 1)))
198 (defun gnus-pick-unmark-article-or-thread (&optional arg)
199 "If gnus-thread-hide-subtree is t, then unmark the thread on current line.
200 Otherwise unmark the article on current line.
201 If ARG, unmark thread/article on that line instead."
204 (gnus-pick-goto-article arg))
205 (if gnus-thread-hide-subtree
207 (gnus-uu-unmark-thread))
208 (gnus-summary-unmark-as-processable 1)))
210 (defun gnus-pick-mouse-pick (e)
214 (gnus-summary-mark-as-processable 1)))
216 (defun gnus-pick-mouse-pick-region (start-event)
217 "Pick articles that the mouse is dragged over.
218 This must be bound to a button-down mouse event."
220 (mouse-minibuffer-check start-event)
221 (let* ((echo-keystrokes 0)
222 (start-posn (event-start start-event))
223 (start-point (posn-point start-posn))
224 (start-line (1+ (count-lines 1 start-point)))
225 (start-window (posn-window start-posn))
226 (bounds (gnus-window-edges start-window))
228 (bottom (if (window-minibuffer-p start-window)
230 ;; Don't count the mode line.
231 (1- (nth 3 bounds))))
232 (click-count (1- (event-click-count start-event))))
233 (setq mouse-selection-click-count click-count)
234 (setq mouse-selection-click-count-buffer (current-buffer))
235 (mouse-set-point start-event)
236 ;; In case the down click is in the middle of some intangible text,
237 ;; use the end of that text, and put it in START-POINT.
238 (when (< (point) start-point)
239 (goto-char start-point))
241 (setq start-point (point))
242 ;; end-of-range is used only in the single-click case.
243 ;; It is the place where the drag has reached so far
244 ;; (but not outside the window where the drag started).
245 (let (event end end-point (end-of-range (point)))
248 (setq event (cdr (gnus-read-event-char)))
249 (or (mouse-movement-p event)
250 (eq (car-safe event) 'switch-frame)))
251 (if (eq (car-safe event) 'switch-frame)
253 (setq end (event-end event)
254 end-point (posn-point end))
257 ;; Are we moving within the original window?
258 ((and (eq (posn-window end) start-window)
259 (integer-or-marker-p end-point))
260 ;; Go to START-POINT first, so that when we move to END-POINT,
261 ;; if it's in the middle of intangible text,
262 ;; point jumps in the direction away from START-POINT.
263 (goto-char start-point)
264 (goto-char end-point)
266 ;; In case the user moved his mouse really fast, pick
267 ;; articles on the line between this one and the last one.
268 (let* ((this-line (1+ (count-lines 1 end-point)))
269 (min-line (min this-line start-line))
270 (max-line (max this-line start-line)))
271 (while (< min-line max-line)
274 (setq min-line (1+ min-line)))
275 (setq start-line this-line))
276 (when (zerop (% click-count 3))
277 (setq end-of-range (point))))
279 (let ((mouse-row (cdr (cdr (mouse-position)))))
283 (mouse-scroll-subr start-window (- mouse-row top)))
284 ((>= mouse-row bottom)
285 (mouse-scroll-subr start-window
286 (1+ (- mouse-row bottom)))))))))))
288 (let ((fun (key-binding (vector (car event)))))
289 ;; Run the binding of the terminating up-event, if possible.
290 ;; In the case of a multiple click, it gives the wrong results,
291 ;; because it would fail to set up a region.
293 ;; (and (= (mod mouse-selection-click-count 3) 0) (fboundp fun))
294 ;; In this case, we can just let the up-event execute normally.
295 (let ((end (event-end event)))
296 ;; Set the position in the event before we replay it,
297 ;; because otherwise it may have a position in the wrong
299 (setcar (cdr end) end-of-range)
300 ;; Delete the overlay before calling the function,
301 ;; because delete-overlay increases buffer-modified-tick.
302 (push event unread-command-events))))))))
304 (defun gnus-pick-next-page ()
305 "Go to the next page. If at the end of the buffer, start reading articles."
307 (let ((scroll-in-place nil))
310 (end-of-buffer (gnus-pick-start-reading)))))
316 (defvar gnus-binary-mode nil
317 "Minor mode for providing a binary group interface in Gnus summary buffers.")
319 (defvar gnus-binary-mode-hook nil
320 "Hook run in summary binary mode buffers.")
322 (defvar gnus-binary-mode-map nil)
324 (unless gnus-binary-mode-map
325 (setq gnus-binary-mode-map (make-sparse-keymap))
329 "g" gnus-binary-show-article))
331 (defun gnus-binary-make-menu-bar ()
332 (unless (boundp 'gnus-binary-menu)
334 gnus-binary-menu gnus-binary-mode-map ""
336 ["Switch binary mode off" gnus-binary-mode t]))))
338 (defun gnus-binary-mode (&optional arg)
339 "Minor mode for providing a binary group interface in Gnus summary buffers."
341 (when (eq major-mode 'gnus-summary-mode)
342 (make-local-variable 'gnus-binary-mode)
343 (setq gnus-binary-mode
344 (if (null arg) (not gnus-binary-mode)
345 (> (prefix-numeric-value arg) 0)))
346 (when gnus-binary-mode
347 ;; Make sure that we don't select any articles upon group entry.
348 (make-local-variable 'gnus-auto-select-first)
349 (setq gnus-auto-select-first nil)
350 (make-local-variable 'gnus-summary-display-article-function)
351 (setq gnus-summary-display-article-function 'gnus-binary-display-article)
353 (when (gnus-visual-p 'binary-menu 'menu)
354 (gnus-binary-make-menu-bar))
355 (gnus-add-minor-mode 'gnus-binary-mode " Binary" gnus-binary-mode-map)
356 (gnus-run-hooks 'gnus-binary-mode-hook))))
358 (defun gnus-binary-display-article (article &optional all-header)
359 "Run ARTICLE through the binary decode functions."
360 (when (gnus-summary-goto-subject article)
361 (let ((gnus-view-pseudos 'automatic))
362 (gnus-uu-decode-uu))))
364 (defun gnus-binary-show-article (&optional arg)
365 "Bypass the binary functions and show the article."
367 (let (gnus-summary-display-article-function)
368 (gnus-summary-show-article arg)))
374 (defcustom gnus-tree-line-format "%(%[%3,3n%]%)"
375 "Format of tree elements."
377 :group 'gnus-summary-tree)
379 (defcustom gnus-tree-minimize-window t
380 "If non-nil, minimize the tree buffer window.
381 If a number, never let the tree buffer grow taller than that number of
383 :type '(choice boolean
385 :group 'gnus-summary-tree)
387 (defcustom gnus-selected-tree-face 'modeline
388 "*Face used for highlighting selected articles in the thread tree."
390 :group 'gnus-summary-tree)
392 (defvar gnus-tree-brackets '((?\[ . ?\]) (?\( . ?\))
393 (?\{ . ?\}) (?< . ?>))
394 "Brackets used in tree nodes.")
396 (defvar gnus-tree-parent-child-edges '(?- ?\\ ?|)
397 "Characters used to connect parents with children.")
399 (defcustom gnus-tree-mode-line-format "Gnus: %%b %S %Z"
400 "*The format specification for the tree mode line."
402 :group 'gnus-summary-tree)
404 (defcustom gnus-generate-tree-function 'gnus-generate-vertical-tree
405 "*Function for generating a thread tree.
406 Two predefined functions are available:
407 `gnus-generate-horizontal-tree' and `gnus-generate-vertical-tree'."
408 :type '(radio (function-item gnus-generate-vertical-tree)
409 (function-item gnus-generate-horizontal-tree)
410 (function :tag "Other" nil))
411 :group 'gnus-summary-tree)
413 (defcustom gnus-tree-mode-hook nil
414 "*Hook run in tree mode buffers."
416 :group 'gnus-summary-tree)
418 ;;; Internal variables.
420 (defvar gnus-tree-line-format-alist
421 `((?n gnus-tmp-name ?s)
422 (?f gnus-tmp-from ?s)
423 (?N gnus-tmp-number ?d)
424 (?\[ gnus-tmp-open-bracket ?c)
425 (?\] gnus-tmp-close-bracket ?c)
426 (?s gnus-tmp-subject ?s)))
428 (defvar gnus-tree-mode-line-format-alist gnus-summary-mode-line-format-alist)
430 (defvar gnus-tree-mode-line-format-spec nil)
431 (defvar gnus-tree-line-format-spec nil)
433 (defvar gnus-tree-node-length nil)
434 (defvar gnus-selected-tree-overlay nil)
436 (defvar gnus-tree-displayed-thread nil)
437 (defvar gnus-tree-inhibit nil)
439 (defvar gnus-tree-mode-map nil)
440 (put 'gnus-tree-mode 'mode-class 'special)
442 (unless gnus-tree-mode-map
443 (setq gnus-tree-mode-map (make-keymap))
444 (suppress-keymap gnus-tree-mode-map)
447 "\r" gnus-tree-select-article
448 gnus-mouse-2 gnus-tree-pick-article
449 "\C-?" gnus-tree-read-summary-keys
450 "h" gnus-tree-show-summary
452 "\C-c\C-i" gnus-info-find-node)
454 (substitute-key-definition
455 'undefined 'gnus-tree-read-summary-keys gnus-tree-mode-map))
457 (defun gnus-tree-make-menu-bar ()
458 (unless (boundp 'gnus-tree-menu)
460 gnus-tree-menu gnus-tree-mode-map ""
462 ["Select article" gnus-tree-select-article t]))))
464 (defun gnus-tree-mode ()
465 "Major mode for displaying thread trees."
467 (gnus-set-format 'tree-mode)
468 (gnus-set-format 'tree t)
469 (when (gnus-visual-p 'tree-menu 'menu)
470 (gnus-tree-make-menu-bar))
471 (kill-all-local-variables)
472 (gnus-simplify-mode-line)
473 (setq mode-name "Tree")
474 (setq major-mode 'gnus-tree-mode)
475 (use-local-map gnus-tree-mode-map)
476 (buffer-disable-undo)
477 (setq buffer-read-only t)
478 (setq truncate-lines t)
480 (gnus-set-work-buffer)
481 (gnus-tree-node-insert (make-mail-header "") nil)
482 (setq gnus-tree-node-length (1- (point))))
483 (gnus-run-hooks 'gnus-tree-mode-hook))
485 (defun gnus-tree-read-summary-keys (&optional arg)
486 "Read a summary buffer key sequence and execute it."
488 (unless gnus-tree-inhibit
489 (let ((buf (current-buffer))
490 (gnus-tree-inhibit t)
492 (set-buffer gnus-article-buffer)
493 (gnus-article-read-summary-keys arg nil t)
494 (when (setq win (get-buffer-window buf))
496 (when gnus-selected-tree-overlay
497 (goto-char (or (gnus-overlay-end gnus-selected-tree-overlay) 1)))
498 (gnus-tree-minimize)))))
500 (defun gnus-tree-show-summary ()
501 "Reconfigure windows to show summary buffer."
503 (if (not (gnus-buffer-live-p gnus-summary-buffer))
504 (error "There is no summary buffer for this tree buffer")
505 (gnus-configure-windows 'article)
506 (gnus-summary-goto-subject gnus-current-article)))
508 (defun gnus-tree-select-article (article)
509 "Select the article under point, if any."
510 (interactive (list (gnus-tree-article-number)))
511 (let ((buf (current-buffer)))
514 (set-buffer gnus-summary-buffer)
515 (gnus-summary-goto-article article))
516 (select-window (get-buffer-window buf)))))
518 (defun gnus-tree-pick-article (e)
519 "Select the article under the mouse pointer."
522 (gnus-tree-select-article (gnus-tree-article-number)))
524 (defun gnus-tree-article-number ()
525 (get-text-property (point) 'gnus-number))
527 (defun gnus-tree-article-region (article)
528 "Return a cons with BEG and END of the article region."
529 (let ((pos (text-property-any
530 (point-min) (point-max) 'gnus-number article)))
532 (cons pos (next-single-property-change pos 'gnus-number)))))
534 (defun gnus-tree-goto-article (article)
535 (let ((pos (text-property-any
536 (point-min) (point-max) 'gnus-number article)))
540 (defun gnus-tree-recenter ()
541 "Center point in the tree window."
542 (let ((selected (selected-window))
543 (tree-window (get-buffer-window gnus-tree-buffer t)))
545 (select-window tree-window)
546 (when gnus-selected-tree-overlay
547 (goto-char (or (gnus-overlay-end gnus-selected-tree-overlay) 1)))
548 (let* ((top (cond ((< (window-height) 4) 0)
549 ((< (window-height) 7) 1)
551 (height (1- (window-height)))
552 (bottom (save-excursion (goto-char (point-max))
553 (forward-line (- height))
555 ;; Set the window start to either `bottom', which is the biggest
556 ;; possible valid number, or the second line from the top,
557 ;; whichever is the least.
559 tree-window (min bottom (save-excursion
560 (forward-line (- top)) (point)))))
561 (select-window selected))))
563 (defun gnus-get-tree-buffer ()
564 "Return the tree buffer properly initialized."
566 (set-buffer (gnus-get-buffer-create gnus-tree-buffer))
567 (unless (eq major-mode 'gnus-tree-mode)
571 (defun gnus-tree-minimize ()
572 (when (and gnus-tree-minimize-window
573 (not (one-window-p)))
576 (walk-windows (lambda (window) (incf windows)))
579 (* window-min-height (1- windows))
581 (let* ((window-min-height 2)
582 (height (count-lines (point-min) (point-max)))
583 (min (max (1- window-min-height) height))
584 (tot (if (numberp gnus-tree-minimize-window)
585 (min gnus-tree-minimize-window min)
587 (win (get-buffer-window (current-buffer)))
588 (wh (and win (1- (window-height win)))))
589 (setq tot (min tot tot-win-height))
592 (let ((selected (selected-window)))
593 (when (ignore-errors (select-window win))
594 (enlarge-window (- tot wh))
595 (select-window selected))))))))
597 ;;; Generating the tree.
599 (defun gnus-tree-node-insert (header sparse &optional adopted)
600 (let* ((dummy (stringp header))
601 (header (if (vectorp header) header
603 (setq header (make-mail-header "*****"))
604 (mail-header-set-number header 0)
605 (mail-header-set-lines header 0)
606 (mail-header-set-chars header 0)
608 (gnus-tmp-from (mail-header-from header))
609 (gnus-tmp-subject (mail-header-subject header))
610 (gnus-tmp-number (mail-header-number header))
613 ((string-match "(.+)" gnus-tmp-from)
614 (substring gnus-tmp-from
615 (1+ (match-beginning 0)) (1- (match-end 0))))
616 ((string-match "<[^>]+> *$" gnus-tmp-from)
617 (let ((beg (match-beginning 0)))
618 (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
619 (substring gnus-tmp-from (1+ (match-beginning 0))
621 (substring gnus-tmp-from 0 beg))))
622 ((memq gnus-tmp-number sparse)
625 (gnus-tmp-open-bracket
626 (cond ((memq gnus-tmp-number sparse)
627 (caadr gnus-tree-brackets))
628 (dummy (caaddr gnus-tree-brackets))
629 (adopted (car (nth 3 gnus-tree-brackets)))
630 (t (caar gnus-tree-brackets))))
631 (gnus-tmp-close-bracket
632 (cond ((memq gnus-tmp-number sparse)
633 (cdadr gnus-tree-brackets))
634 (adopted (cdr (nth 3 gnus-tree-brackets)))
636 (cdaddr gnus-tree-brackets))
637 (t (cdar gnus-tree-brackets))))
638 (buffer-read-only nil)
640 (gnus-add-text-properties
642 (setq end (progn (eval gnus-tree-line-format-spec) (point)))
643 (list 'gnus-number gnus-tmp-number))
644 (when (or t (gnus-visual-p 'tree-highlight 'highlight))
645 (gnus-tree-highlight-node gnus-tmp-number beg end))))
647 (defun gnus-tree-highlight-node (article beg end)
648 "Highlight current line according to `gnus-summary-highlight'."
649 (let ((list gnus-summary-highlight)
652 (set-buffer gnus-summary-buffer)
653 (let* ((score (or (cdr (assq article gnus-newsgroup-scored))
654 gnus-summary-default-score 0))
655 (default gnus-summary-default-score)
656 (mark (or (gnus-summary-article-mark article) gnus-unread-mark)))
657 ;; Eval the cars of the lists until we find a match.
659 (not (eval (caar list))))
660 (setq list (cdr list)))))
661 (unless (eq (setq face (cdar list)) (get-text-property beg 'face))
662 (gnus-put-text-property-excluding-characters-with-faces
664 (if (boundp face) (symbol-value face) face)))))
666 (defun gnus-tree-indent (level)
667 (insert (make-string (1- (* (1+ gnus-tree-node-length) level)) ? )))
669 (defvar gnus-tmp-limit)
670 (defvar gnus-tmp-sparse)
671 (defvar gnus-tmp-indent)
673 (defun gnus-generate-tree (thread)
674 "Generate a thread tree for THREAD."
676 (set-buffer (gnus-get-tree-buffer))
677 (let ((buffer-read-only nil)
680 (funcall gnus-generate-tree-function thread 0)
681 (gnus-set-mode-line 'tree)
682 (goto-char (point-min))
685 (let ((selected (selected-window)))
686 (when (get-buffer-window (set-buffer gnus-tree-buffer) t)
687 (select-window (get-buffer-window (set-buffer gnus-tree-buffer) t))
688 (gnus-horizontal-recenter)
689 (select-window selected))))))
691 (defun gnus-generate-horizontal-tree (thread level &optional dummyp adopted)
692 "Generate a horizontal tree."
693 (let* ((dummy (stringp (car thread)))
696 (memq (mail-header-number (car thread))
700 ;; We don't want this article.
701 (setq thread (cdr thread))
703 ;; Not the first article on the line, so we insert a "-".
704 (insert (car gnus-tree-parent-child-edges))
705 ;; If the level isn't zero, then we insert some indentation.
706 (unless (zerop level)
707 (gnus-tree-indent level)
708 (insert (cadr gnus-tree-parent-child-edges))
709 (setq col (- (setq beg (point)) (gnus-point-at-bol) 1))
710 ;; Draw "|" lines upwards.
714 (eq (char-after) ? ))
716 (insert (caddr gnus-tree-parent-child-edges)))
719 ;; Insert the article node.
720 (gnus-tree-node-insert (pop thread) gnus-tmp-sparse adopted))
722 ;; End of the thread, so we go to the next line.
725 ;; Recurse downwards in all children of this article.
727 (gnus-generate-horizontal-tree
728 (pop thread) (if do (1+ level) level)
729 (or dummyp dummy) dummy)))))
731 (defsubst gnus-tree-indent-vertical ()
732 (let ((len (- (* (1+ gnus-tree-node-length) gnus-tmp-indent)
733 (- (point) (gnus-point-at-bol)))))
735 (insert (make-string len ? )))))
737 (defsubst gnus-tree-forward-line (n)
738 (while (>= (decf n) 0)
739 (unless (zerop (forward-line 1))
744 (defun gnus-generate-vertical-tree (thread level &optional dummyp adopted)
745 "Generate a vertical tree."
746 (let* ((dummy (stringp (car thread)))
749 (memq (mail-header-number (car thread))
753 ;; We don't want this article.
754 (setq thread (cdr thread))
755 (if (not (save-excursion (beginning-of-line) (bobp)))
756 ;; Not the first article on the line, so we insert a "-".
758 (gnus-tree-indent-vertical)
759 (insert (make-string (/ gnus-tree-node-length 2) ? ))
760 (insert (caddr gnus-tree-parent-child-edges))
761 (gnus-tree-forward-line 1))
762 ;; If the level isn't zero, then we insert some indentation.
763 (unless (zerop gnus-tmp-indent)
764 (gnus-tree-forward-line (1- (* 2 level)))
765 (gnus-tree-indent-vertical)
767 (insert (cadr gnus-tree-parent-child-edges))
770 ;; Draw "-" lines leftwards.
771 (while (and (> (point) 1)
772 (eq (char-after (1- (point))) ? ))
774 (insert (car gnus-tree-parent-child-edges))
777 (gnus-tree-forward-line 1)))
779 ;; Insert the article node.
780 (gnus-tree-indent-vertical)
781 (gnus-tree-node-insert (pop thread) gnus-tmp-sparse adopted)
782 (gnus-tree-forward-line 1))
784 ;; End of the thread, so we go to the next line.
786 (goto-char (point-min))
788 (incf gnus-tmp-indent))
789 ;; Recurse downwards in all children of this article.
791 (gnus-generate-vertical-tree
792 (pop thread) (if do (1+ level) level)
793 (or dummyp dummy) dummy)))))
795 ;;; Interface functions.
797 (defun gnus-possibly-generate-tree (article &optional force)
798 "Generate the thread tree for ARTICLE if it isn't displayed already."
799 (when (save-excursion
800 (set-buffer gnus-summary-buffer)
803 (vectorp (gnus-summary-article-header article))))
805 (let ((top (save-excursion
806 (set-buffer gnus-summary-buffer)
810 (gnus-summary-article-header article))
812 (gnus-tmp-limit gnus-newsgroup-limit)
813 (gnus-tmp-sparse gnus-newsgroup-sparse))
815 (not (eq top gnus-tree-displayed-thread)))
816 (gnus-generate-tree top)
817 (setq gnus-tree-displayed-thread top))))))
819 (defun gnus-tree-open (group)
820 (gnus-get-tree-buffer))
822 (defun gnus-tree-close (group)
823 (gnus-kill-buffer gnus-tree-buffer))
825 (defun gnus-highlight-selected-tree (article)
826 "Highlight the selected article in the tree."
827 (let ((buf (current-buffer))
829 (set-buffer gnus-tree-buffer)
830 (when (setq region (gnus-tree-article-region article))
831 (when (or (not gnus-selected-tree-overlay)
832 (gnus-extent-detached-p gnus-selected-tree-overlay))
833 ;; Create a new overlay.
835 (setq gnus-selected-tree-overlay (gnus-make-overlay 1 2))
836 'face gnus-selected-tree-face))
837 ;; Move the overlay to the article.
839 gnus-selected-tree-overlay (goto-char (car region)) (cdr region))
842 (let ((selected (selected-window)))
843 (when (get-buffer-window (set-buffer gnus-tree-buffer) t)
844 (select-window (get-buffer-window (set-buffer gnus-tree-buffer) t))
845 (gnus-horizontal-recenter)
846 (select-window selected))))
847 ;; If we remove this save-excursion, it updates the wrong mode lines?!?
849 (set-buffer gnus-tree-buffer)
850 (gnus-set-mode-line 'tree))
853 (defun gnus-tree-highlight-article (article face)
855 (set-buffer (gnus-get-tree-buffer))
857 (when (setq region (gnus-tree-article-region article))
858 (gnus-put-text-property (car region) (cdr region) 'face face)
860 (get-buffer-window (current-buffer) t) (cdr region))))))
866 (defvar gnus-carpal-group-buffer-buttons
867 '(("next" . gnus-group-next-unread-group)
868 ("prev" . gnus-group-prev-unread-group)
869 ("read" . gnus-group-read-group)
870 ("select" . gnus-group-select-group)
871 ("catch-up" . gnus-group-catchup-current)
872 ("new-news" . gnus-group-get-new-news-this-group)
873 ("toggle-sub" . gnus-group-unsubscribe-current-group)
874 ("subscribe" . gnus-group-unsubscribe-group)
875 ("kill" . gnus-group-kill-group)
876 ("yank" . gnus-group-yank-group)
877 ("describe" . gnus-group-describe-group)
879 ("subscribed" . gnus-group-list-groups)
880 ("all" . gnus-group-list-all-groups)
881 ("killed" . gnus-group-list-killed)
882 ("zombies" . gnus-group-list-zombies)
883 ("matching" . gnus-group-list-matching)
884 ("post" . gnus-group-post-news)
885 ("mail" . gnus-group-mail)
886 ("rescan" . gnus-group-get-new-news)
887 ("browse-foreign" . gnus-group-browse-foreign)
888 ("exit" . gnus-group-exit)))
890 (defvar gnus-carpal-summary-buffer-buttons
892 ("read" . gnus-summary-mark-as-read-forward)
893 ("tick" . gnus-summary-tick-article-forward)
894 ("clear" . gnus-summary-clear-mark-forward)
895 ("expirable" . gnus-summary-mark-as-expirable)
897 ("scroll" . gnus-summary-next-page)
898 ("next-unread" . gnus-summary-next-unread-article)
899 ("prev-unread" . gnus-summary-prev-unread-article)
900 ("first" . gnus-summary-first-unread-article)
901 ("best" . gnus-summary-best-unread-article)
903 ("headers" . gnus-summary-toggle-header)
904 ("uudecode" . gnus-uu-decode-uu)
905 ("enter-digest" . gnus-summary-enter-digest-group)
906 ("fetch-parent" . gnus-summary-refer-parent-article)
908 ("move" . gnus-summary-move-article)
909 ("copy" . gnus-summary-copy-article)
910 ("respool" . gnus-summary-respool-article)
912 ("lower" . gnus-summary-lower-thread)
913 ("kill" . gnus-summary-kill-thread)
915 ("post" . gnus-summary-post-news)
916 ("mail" . gnus-summary-mail)
917 ("followup" . gnus-summary-followup-with-original)
918 ("reply" . gnus-summary-reply-with-original)
919 ("cancel" . gnus-summary-cancel-article)
921 ("exit" . gnus-summary-exit)
922 ("fed-up" . gnus-summary-catchup-and-goto-next-group)))
924 (defvar gnus-carpal-server-buffer-buttons
925 '(("add" . gnus-server-add-server)
926 ("browse" . gnus-server-browse-server)
927 ("list" . gnus-server-list-servers)
928 ("kill" . gnus-server-kill-server)
929 ("yank" . gnus-server-yank-server)
930 ("copy" . gnus-server-copy-server)
931 ("exit" . gnus-server-exit)))
933 (defvar gnus-carpal-browse-buffer-buttons
934 '(("subscribe" . gnus-browse-unsubscribe-current-group)
935 ("exit" . gnus-browse-exit)))
937 (defvar gnus-carpal-group-buffer "*Carpal Group*")
938 (defvar gnus-carpal-summary-buffer "*Carpal Summary*")
939 (defvar gnus-carpal-server-buffer "*Carpal Server*")
940 (defvar gnus-carpal-browse-buffer "*Carpal Browse*")
942 (defvar gnus-carpal-attached-buffer nil)
944 (defvar gnus-carpal-mode-hook nil
945 "*Hook run in carpal mode buffers.")
947 (defvar gnus-carpal-button-face 'bold
948 "*Face used on carpal buttons.")
950 (defvar gnus-carpal-header-face 'bold-italic
951 "*Face used on carpal buffer headers.")
953 (defvar gnus-carpal-mode-map nil)
954 (put 'gnus-carpal-mode 'mode-class 'special)
956 (if gnus-carpal-mode-map
958 (setq gnus-carpal-mode-map (make-keymap))
959 (suppress-keymap gnus-carpal-mode-map)
960 (define-key gnus-carpal-mode-map " " 'gnus-carpal-select)
961 (define-key gnus-carpal-mode-map "\r" 'gnus-carpal-select)
962 (define-key gnus-carpal-mode-map gnus-mouse-2 'gnus-carpal-mouse-select))
964 (defun gnus-carpal-mode ()
965 "Major mode for clicking buttons.
967 All normal editing commands are switched off.
968 \\<gnus-carpal-mode-map>
969 The following commands are available:
971 \\{gnus-carpal-mode-map}"
973 (kill-all-local-variables)
974 (setq mode-line-modified (cdr gnus-mode-line-modified))
975 (setq major-mode 'gnus-carpal-mode)
976 (setq mode-name "Gnus Carpal")
977 (setq mode-line-process nil)
978 (use-local-map gnus-carpal-mode-map)
979 (buffer-disable-undo)
980 (setq buffer-read-only t)
981 (make-local-variable 'gnus-carpal-attached-buffer)
982 (gnus-run-hooks 'gnus-carpal-mode-hook))
984 (defun gnus-carpal-setup-buffer (type)
985 (let ((buffer (symbol-value (intern (format "gnus-carpal-%s-buffer" type)))))
986 (if (get-buffer buffer)
989 (set-buffer (gnus-get-buffer-create buffer))
991 (setq gnus-carpal-attached-buffer
992 (intern (format "gnus-%s-buffer" type)))
993 (let ((buttons (symbol-value
994 (intern (format "gnus-carpal-%s-buffer-buttons"
996 (buffer-read-only nil)
999 (setq button (car buttons)
1000 buttons (cdr buttons))
1001 (if (stringp button)
1002 (gnus-set-text-properties
1004 (prog2 (insert button) (point) (insert " "))
1005 (list 'face gnus-carpal-header-face))
1006 (gnus-set-text-properties
1008 (prog2 (insert (car button)) (point) (insert " "))
1009 (list 'gnus-callback (cdr button)
1010 'face gnus-carpal-button-face
1011 gnus-mouse-face-prop 'highlight))))
1012 (let ((fill-column (- (window-width) 2)))
1013 (fill-region (point-min) (point-max)))
1014 (set-window-point (get-buffer-window (current-buffer))
1017 (defun gnus-carpal-select ()
1018 "Select the button under point."
1020 (let ((func (get-text-property (point) 'gnus-callback)))
1023 (pop-to-buffer (symbol-value gnus-carpal-attached-buffer))
1024 (call-interactively func))))
1026 (defun gnus-carpal-mouse-select (event)
1027 "Select the button under the mouse pointer."
1029 (mouse-set-point event)
1030 (gnus-carpal-select))
1032 ;;; Allow redefinition of functions.
1035 (provide 'gnus-salt)
1037 ;;; gnus-salt.el ends here