1 ;;; gnus-salt.el --- alternate summary mode interfaces for Gnus
3 ;; Copyright (C) 1996-1999, 2001-2012 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 3 of the License, or
13 ;; (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
27 (eval-when-compile (require 'cl
))
29 (when (featurep 'xemacs
)
30 (require 'easy-mmode
))) ; for `define-minor-mode'
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 (when (featurep 'xemacs
)
51 (add-hook 'gnus-pick-mode-hook
'gnus-xmas-pick-menu-add
))
53 (defcustom gnus-mark-unpicked-articles-as-read nil
54 "*If non-nil, mark all unpicked articles as read."
56 :group
'gnus-summary-pick
)
58 (defcustom gnus-pick-elegant-flow t
59 "If non-nil, `gnus-pick-start-reading' runs
60 `gnus-summary-next-group' when no articles have been picked."
62 :group
'gnus-summary-pick
)
64 (defcustom gnus-summary-pick-line-format
65 "%-5P %U\%R\%z\%I\%(%[%4L: %-23,23n%]%) %s\n"
66 "*The format specification of the lines in pick buffers.
67 It accepts the same format specs that `gnus-summary-line-format' does."
69 :group
'gnus-summary-pick
)
71 ;;; Internal variables.
73 (defvar gnus-pick-mode-map
74 (let ((map (make-sparse-keymap)))
76 " " gnus-pick-next-page
77 "u" gnus-pick-unmark-article-or-thread
78 "." gnus-pick-article-or-thread
79 gnus-down-mouse-2 gnus-pick-mouse-pick-region
80 "\r" gnus-pick-start-reading
)
83 (defun gnus-pick-make-menu-bar ()
84 (unless (boundp 'gnus-pick-menu
)
86 gnus-pick-menu gnus-pick-mode-map
""
89 ["Article" gnus-summary-mark-as-processable t
]
90 ["Thread" gnus-uu-mark-thread t
]
91 ["Region" gnus-uu-mark-region t
]
92 ["Regexp" gnus-uu-mark-by-regexp t
]
93 ["Buffer" gnus-uu-mark-buffer t
])
95 ["Article" gnus-summary-unmark-as-processable t
]
96 ["Thread" gnus-uu-unmark-thread t
]
97 ["Region" gnus-uu-unmark-region t
]
98 ["Regexp" gnus-uu-unmark-by-regexp t
]
99 ["Buffer" gnus-summary-unmark-all-processable t
])
100 ["Start reading" gnus-pick-start-reading t
]
101 ["Switch pick mode off" gnus-pick-mode gnus-pick-mode
]))))
104 (when (featurep 'xemacs
)
105 (defvar gnus-pick-mode-on-hook
)
106 (defvar gnus-pick-mode-off-hook
)))
108 (define-minor-mode gnus-pick-mode
109 "Minor mode for providing a pick-and-read interface in Gnus summary buffers.
111 \\{gnus-pick-mode-map}"
112 :lighter
" Pick" :keymap gnus-pick-mode-map
114 ((not (derived-mode-p 'gnus-summary-mode
)) (setq gnus-pick-mode nil
))
115 ((not gnus-pick-mode
)
116 ;; FIXME: a buffer-local minor mode removing globally from a hook??
117 (remove-hook 'gnus-message-setup-hook
'gnus-pick-setup-message
))
119 ;; Make sure that we don't select any articles upon group entry.
120 (set (make-local-variable 'gnus-auto-select-first
) nil
)
121 ;; Change line format.
122 (setq gnus-summary-line-format gnus-summary-pick-line-format
)
123 (setq gnus-summary-line-format-spec nil
)
124 (gnus-update-format-specifications nil
'summary
)
125 (gnus-update-summary-mark-positions)
126 ;; FIXME: a buffer-local minor mode adding globally to a hook??
127 (add-hook 'gnus-message-setup-hook
'gnus-pick-setup-message
)
128 (set (make-local-variable 'gnus-summary-goto-unread
) 'never
)
130 (when (gnus-visual-p 'pick-menu
'menu
)
131 (gnus-pick-make-menu-bar)))))
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
)
136 (with-current-buffer gnus-summary-buffer
139 `(gnus-configure-windows ,gnus-current-window-configuration t
)
140 'send
'exit
'postpone
'kill
)))
142 (defvar gnus-pick-line-number
1)
143 (defun gnus-pick-line-number ()
144 "Return the current line number."
146 (setq gnus-pick-line-number
1)
147 (incf gnus-pick-line-number
)))
149 (defun gnus-pick-start-reading (&optional catch-up
)
150 "Start reading the picked articles.
151 If given a prefix, mark all unpicked articles as read."
153 (if gnus-newsgroup-processable
155 (gnus-summary-limit-to-articles nil
)
156 (when (or catch-up gnus-mark-unpicked-articles-as-read
)
157 (gnus-summary-limit-mark-excluded-as-read))
158 (gnus-summary-first-article)
159 (gnus-configure-windows
160 (if gnus-pick-display-summary
'article
'pick
) t
))
161 (if gnus-pick-elegant-flow
163 (when (or catch-up gnus-mark-unpicked-articles-as-read
)
164 (gnus-summary-catchup nil t
))
165 (if (gnus-group-quit-config gnus-newsgroup-name
)
167 (gnus-summary-next-group)))
168 (error "No articles have been picked"))))
170 (defun gnus-pick-goto-article (arg)
171 "Go to the article number indicated by ARG.
172 If ARG is an invalid article number, then stay on current line."
175 (goto-char (point-min))
176 (when (zerop (forward-line (1- (prefix-numeric-value arg
))))
179 (gnus-error 2 "No such line: %s" arg
)
182 (defun gnus-pick-article (&optional arg
)
183 "Pick the article on the current line.
184 If ARG, pick the article on that line instead."
187 (gnus-pick-goto-article arg
))
188 (gnus-summary-mark-as-processable 1))
190 (defun gnus-pick-article-or-thread (&optional arg
)
191 "If `gnus-thread-hide-subtree' is t, then pick the thread on the current line.
192 Otherwise pick the article on the current line.
193 If ARG, pick the article/thread on that line instead."
196 (gnus-pick-goto-article arg
))
197 (if gnus-thread-hide-subtree
200 (gnus-uu-mark-thread))
202 (gnus-summary-mark-as-processable 1)))
204 (defun gnus-pick-unmark-article-or-thread (&optional arg
)
205 "If `gnus-thread-hide-subtree' is t, then unmark the thread on current line.
206 Otherwise unmark the article on current line.
207 If ARG, unmark thread/article on that line instead."
210 (gnus-pick-goto-article arg
))
211 (if gnus-thread-hide-subtree
213 (gnus-uu-unmark-thread))
214 (gnus-summary-unmark-as-processable 1)))
216 (defun gnus-pick-mouse-pick (e)
220 (gnus-summary-mark-as-processable 1)))
222 (defun gnus-pick-mouse-pick-region (start-event)
223 "Pick articles that the mouse is dragged over.
224 This must be bound to a button-down mouse event."
226 (mouse-minibuffer-check start-event
)
227 (let* ((echo-keystrokes 0)
228 (start-posn (event-start start-event
))
229 (start-point (posn-point start-posn
))
230 (start-line (1+ (count-lines (point-min) start-point
)))
231 (start-window (posn-window start-posn
))
232 (bounds (gnus-window-edges start-window
))
234 (bottom (if (window-minibuffer-p start-window
)
236 ;; Don't count the mode line.
237 (1- (nth 3 bounds
))))
238 (click-count (1- (event-click-count start-event
))))
239 (setq mouse-selection-click-count click-count
)
240 (setq mouse-selection-click-count-buffer
(current-buffer))
241 (mouse-set-point start-event
)
242 ;; In case the down click is in the middle of some intangible text,
243 ;; use the end of that text, and put it in START-POINT.
244 (when (< (point) start-point
)
245 (goto-char start-point
))
247 (setq start-point
(point))
248 ;; end-of-range is used only in the single-click case.
249 ;; It is the place where the drag has reached so far
250 ;; (but not outside the window where the drag started).
251 (let (event end end-point
(end-of-range (point)))
254 (setq event
(cdr (gnus-read-event-char)))
255 (or (mouse-movement-p event
)
256 (eq (car-safe event
) 'switch-frame
)))
257 (if (eq (car-safe event
) 'switch-frame
)
259 (setq end
(event-end event
)
260 end-point
(posn-point end
))
263 ;; Are we moving within the original window?
264 ((and (eq (posn-window end
) start-window
)
265 (integer-or-marker-p end-point
))
266 ;; Go to START-POINT first, so that when we move to END-POINT,
267 ;; if it's in the middle of intangible text,
268 ;; point jumps in the direction away from START-POINT.
269 (goto-char start-point
)
270 (goto-char end-point
)
272 ;; In case the user moved his mouse really fast, pick
273 ;; articles on the line between this one and the last one.
274 (let* ((this-line (1+ (count-lines (point-min) end-point
)))
275 (min-line (min this-line start-line
))
276 (max-line (max this-line start-line
)))
277 (while (< min-line max-line
)
278 (goto-char (point-min))
279 (forward-line (1- min-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-hook nil
324 "Hook run in summary binary mode buffers.")
326 (defvar gnus-binary-mode-map
327 (let ((map (make-sparse-keymap)))
328 (gnus-define-keys map
329 "g" gnus-binary-show-article
)
332 (defun gnus-binary-make-menu-bar ()
333 (unless (boundp 'gnus-binary-menu
)
335 gnus-binary-menu gnus-binary-mode-map
""
337 ["Switch binary mode off" gnus-binary-mode t
]))))
340 (when (featurep 'xemacs
)
341 (defvar gnus-binary-mode-on-hook
)
342 (defvar gnus-binary-mode-off-hook
)))
344 (define-minor-mode gnus-binary-mode
345 "Minor mode for providing a binary group interface in Gnus summary buffers."
346 :lighter
" Binary" :keymap gnus-binary-mode-map
348 ((not (derived-mode-p 'gnus-summary-mode
)) (setq gnus-binary-mode nil
))
350 ;; Make sure that we don't select any articles upon group entry.
351 (make-local-variable 'gnus-auto-select-first
)
352 (setq gnus-auto-select-first nil
)
353 (make-local-variable 'gnus-summary-display-article-function
)
354 (setq gnus-summary-display-article-function
'gnus-binary-display-article
)
356 (when (gnus-visual-p 'binary-menu
'menu
)
357 (gnus-binary-make-menu-bar)))))
359 (defun gnus-binary-display-article (article &optional all-header
)
360 "Run ARTICLE through the binary decode functions."
361 (when (gnus-summary-goto-subject article
)
362 (let ((gnus-view-pseudos (or gnus-view-pseudos
'automatic
)))
363 (gnus-uu-decode-uu))))
365 (defun gnus-binary-show-article (&optional arg
)
366 "Bypass the binary functions and show the article."
368 (let (gnus-summary-display-article-function)
369 (gnus-summary-show-article arg
)))
375 (defcustom gnus-tree-line-format
"%(%[%3,3n%]%)"
376 "Format of tree elements."
378 :group
'gnus-summary-tree
)
380 (defcustom gnus-tree-minimize-window t
381 "If non-nil, minimize the tree buffer window.
382 If a number, never let the tree buffer grow taller than that number of
384 :type
'(choice boolean
386 :group
'gnus-summary-tree
)
388 (defcustom gnus-selected-tree-face
'modeline
389 "*Face used for highlighting selected articles in the thread tree."
391 :group
'gnus-summary-tree
)
393 (defvar gnus-tree-brackets
'((?\
[ . ?\
]) (?\
( . ?\
))
394 (?\
{ . ?\
}) (?
< . ?
>))
395 "Brackets used in tree nodes.")
397 (defvar gnus-tree-parent-child-edges
'(?- ?
\\ ?|
)
398 "Characters used to connect parents with children.")
400 (defcustom gnus-tree-mode-line-format
"Gnus: %%b %S %Z"
401 "*The format specification for the tree mode line."
403 :group
'gnus-summary-tree
)
405 (defcustom gnus-generate-tree-function
'gnus-generate-vertical-tree
406 "*Function for generating a thread tree.
407 Two predefined functions are available:
408 `gnus-generate-horizontal-tree' and `gnus-generate-vertical-tree'."
409 :type
'(radio (function-item gnus-generate-vertical-tree
)
410 (function-item gnus-generate-horizontal-tree
)
411 (function :tag
"Other" nil
))
412 :group
'gnus-summary-tree
)
414 (defcustom gnus-tree-mode-hook nil
415 "*Hook run in tree mode buffers."
417 :group
'gnus-summary-tree
)
419 (when (featurep 'xemacs
)
420 (add-hook 'gnus-tree-mode-hook
'gnus-xmas-tree-menu-add
)
421 (add-hook 'gnus-tree-mode-hook
'gnus-xmas-switch-horizontal-scrollbar-off
))
424 ;;; Internal variables.
426 (defvar gnus-tree-line-format-alist
427 `((?n gnus-tmp-name ?s
)
428 (?f gnus-tmp-from ?s
)
429 (?N gnus-tmp-number ?d
)
430 (?\
[ gnus-tmp-open-bracket ?c
)
431 (?\
] gnus-tmp-close-bracket ?c
)
432 (?s gnus-tmp-subject ?s
)))
434 (defvar gnus-tree-mode-line-format-alist gnus-summary-mode-line-format-alist
)
436 (defvar gnus-tree-mode-line-format-spec nil
)
437 (defvar gnus-tree-line-format-spec nil
)
439 (defvar gnus-tree-node-length nil
)
440 (defvar gnus-selected-tree-overlay nil
)
442 (defvar gnus-tree-displayed-thread nil
)
443 (defvar gnus-tree-inhibit nil
)
445 (defvar gnus-tree-mode-map nil
)
446 (put 'gnus-tree-mode
'mode-class
'special
)
448 (unless gnus-tree-mode-map
449 (setq gnus-tree-mode-map
(make-keymap))
450 (suppress-keymap gnus-tree-mode-map
)
453 "\r" gnus-tree-select-article
454 gnus-mouse-2 gnus-tree-pick-article
455 "\C-?" gnus-tree-read-summary-keys
456 "h" gnus-tree-show-summary
458 "\C-c\C-i" gnus-info-find-node
)
460 (substitute-key-definition
461 'undefined
'gnus-tree-read-summary-keys gnus-tree-mode-map
))
463 (defun gnus-tree-make-menu-bar ()
464 (unless (boundp 'gnus-tree-menu
)
466 gnus-tree-menu gnus-tree-mode-map
""
468 ["Select article" gnus-tree-select-article t
]))))
470 (defun gnus-tree-mode ()
471 "Major mode for displaying thread trees."
473 (gnus-set-format 'tree-mode
)
474 (gnus-set-format 'tree t
)
475 (when (gnus-visual-p 'tree-menu
'menu
)
476 (gnus-tree-make-menu-bar))
477 (kill-all-local-variables)
478 (gnus-simplify-mode-line)
479 (setq mode-name
"Tree")
480 (setq major-mode
'gnus-tree-mode
)
481 (use-local-map gnus-tree-mode-map
)
482 (buffer-disable-undo)
483 (setq buffer-read-only t
)
484 (setq truncate-lines t
)
486 (gnus-set-work-buffer)
487 (gnus-tree-node-insert (make-mail-header "") nil
)
488 (setq gnus-tree-node-length
(1- (point))))
489 (gnus-run-mode-hooks 'gnus-tree-mode-hook
))
491 (defun gnus-tree-read-summary-keys (&optional arg
)
492 "Read a summary buffer key sequence and execute it."
494 (unless gnus-tree-inhibit
495 (let ((buf (current-buffer))
496 (gnus-tree-inhibit t
)
498 (set-buffer gnus-article-buffer
)
499 (gnus-article-read-summary-keys arg nil t
)
500 (when (setq win
(get-buffer-window buf
))
502 (when gnus-selected-tree-overlay
503 (goto-char (or (gnus-overlay-end gnus-selected-tree-overlay
) 1)))
504 (gnus-tree-minimize)))))
506 (defun gnus-tree-show-summary ()
507 "Reconfigure windows to show summary buffer."
509 (if (not (gnus-buffer-live-p gnus-summary-buffer
))
510 (error "There is no summary buffer for this tree buffer")
511 (gnus-configure-windows 'article
)
512 (gnus-summary-goto-subject gnus-current-article
)))
514 (defun gnus-tree-select-article (article)
515 "Select the article under point, if any."
516 (interactive (list (gnus-tree-article-number)))
517 (let ((buf (current-buffer)))
519 (with-current-buffer gnus-summary-buffer
520 (gnus-summary-goto-article article
))
521 (select-window (get-buffer-window buf
)))))
523 (defun gnus-tree-pick-article (e)
524 "Select the article under the mouse pointer."
527 (gnus-tree-select-article (gnus-tree-article-number)))
529 (defun gnus-tree-article-number ()
530 (get-text-property (point) 'gnus-number
))
532 (defun gnus-tree-article-region (article)
533 "Return a cons with BEG and END of the article region."
534 (let ((pos (text-property-any
535 (point-min) (point-max) 'gnus-number article
)))
537 (cons pos
(next-single-property-change pos
'gnus-number
)))))
539 (defun gnus-tree-recenter ()
540 "Center point in the tree window."
541 (let ((selected (selected-window))
542 (tree-window (gnus-get-buffer-window gnus-tree-buffer t
)))
544 (select-window tree-window
)
545 (when gnus-selected-tree-overlay
546 (goto-char (or (gnus-overlay-end gnus-selected-tree-overlay
) 1)))
547 (let* ((top (cond ((< (window-height) 4) 0)
548 ((< (window-height) 7) 1)
550 (height (1- (window-height)))
551 (bottom (save-excursion (goto-char (point-max))
552 (forward-line (- height
))
554 ;; Set the window start to either `bottom', which is the biggest
555 ;; possible valid number, or the second line from the top,
556 ;; whichever is the least.
558 tree-window
(min bottom
(save-excursion
559 (forward-line (- top
)) (point)))))
560 (select-window selected
))))
562 (defun gnus-get-tree-buffer ()
563 "Return the tree buffer properly initialized."
564 (with-current-buffer (gnus-get-buffer-create gnus-tree-buffer
)
565 (unless (eq major-mode
'gnus-tree-mode
)
569 (defun gnus-tree-minimize ()
570 (when (and gnus-tree-minimize-window
571 (not (one-window-p)))
574 (walk-windows (lambda (window) (incf windows
)))
577 (* window-min-height
(1- windows
))
579 (let* ((window-min-height 2)
580 (height (count-lines (point-min) (point-max)))
581 (min (max (1- window-min-height
) height
))
582 (tot (if (numberp gnus-tree-minimize-window
)
583 (min gnus-tree-minimize-window min
)
585 (win (get-buffer-window (current-buffer)))
586 (wh (and win
(1- (window-height win
)))))
587 (setq tot
(min tot tot-win-height
))
590 (let ((selected (selected-window)))
591 (when (ignore-errors (select-window win
))
592 (enlarge-window (- tot wh
))
593 (select-window selected
))))))))
595 ;;; Generating the tree.
597 (defun gnus-tree-node-insert (header sparse
&optional adopted
)
598 (let* ((dummy (stringp header
))
599 (header (if (vectorp header
) header
601 (setq header
(make-mail-header "*****"))
602 (mail-header-set-number header
0)
603 (mail-header-set-lines header
0)
604 (mail-header-set-chars header
0)
606 (gnus-tmp-from (mail-header-from header
))
607 (gnus-tmp-subject (mail-header-subject header
))
608 (gnus-tmp-number (mail-header-number header
))
611 ((string-match "(.+)" gnus-tmp-from
)
612 (substring gnus-tmp-from
613 (1+ (match-beginning 0)) (1- (match-end 0))))
614 ((string-match "<[^>]+> *$" gnus-tmp-from
)
615 (let ((beg (match-beginning 0)))
616 (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from
)
617 (substring gnus-tmp-from
(1+ (match-beginning 0))
619 (substring gnus-tmp-from
0 beg
))))
620 ((memq gnus-tmp-number sparse
)
623 (gnus-tmp-open-bracket
624 (cond ((memq gnus-tmp-number sparse
)
625 (caadr gnus-tree-brackets
))
626 (dummy (caaddr gnus-tree-brackets
))
627 (adopted (car (nth 3 gnus-tree-brackets
)))
628 (t (caar gnus-tree-brackets
))))
629 (gnus-tmp-close-bracket
630 (cond ((memq gnus-tmp-number sparse
)
631 (cdadr gnus-tree-brackets
))
632 (adopted (cdr (nth 3 gnus-tree-brackets
)))
634 (cdaddr gnus-tree-brackets
))
635 (t (cdar gnus-tree-brackets
))))
636 (buffer-read-only nil
)
638 (gnus-add-text-properties
640 (setq end
(progn (eval gnus-tree-line-format-spec
) (point)))
641 (list 'gnus-number gnus-tmp-number
))
642 (when (or t
(gnus-visual-p 'tree-highlight
'highlight
))
643 (gnus-tree-highlight-node gnus-tmp-number beg end
))))
645 (defun gnus-tree-highlight-node (article beg end
)
646 "Highlight current line according to `gnus-summary-highlight'."
647 (let ((list gnus-summary-highlight
)
649 (with-current-buffer gnus-summary-buffer
650 (let* ((score (or (cdr (assq article gnus-newsgroup-scored
))
651 gnus-summary-default-score
0))
652 (default gnus-summary-default-score
)
653 (default-high gnus-summary-default-high-score
)
654 (default-low gnus-summary-default-low-score
)
655 (uncached (memq article gnus-newsgroup-undownloaded
))
656 (downloaded (not uncached
))
657 (mark (or (gnus-summary-article-mark article
) gnus-unread-mark
)))
658 ;; Eval the cars of the lists until we find a match.
660 (not (eval (caar list
))))
661 (setq list
(cdr list
)))))
662 (unless (eq (setq face
(cdar list
)) (get-text-property beg
'face
))
663 (gnus-put-text-property-excluding-characters-with-faces
665 (if (boundp face
) (symbol-value face
) face
)))))
667 (defun gnus-tree-indent (level)
668 (insert (make-string (1- (* (1+ gnus-tree-node-length
) level
)) ?
)))
670 (defvar gnus-tmp-limit
)
671 (defvar gnus-tmp-sparse
)
672 (defvar gnus-tmp-indent
)
674 (defun gnus-generate-tree (thread)
675 "Generate a thread tree for THREAD."
676 (with-current-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 (gnus-get-buffer-window (set-buffer gnus-tree-buffer
) t
)
687 (select-window (gnus-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)) (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) (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 (not (bobp))
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 (with-current-buffer gnus-summary-buffer
802 (vectorp (gnus-summary-article-header article
))))
804 (let ((top (with-current-buffer gnus-summary-buffer
808 (gnus-summary-article-header article
))
810 (gnus-tmp-limit gnus-newsgroup-limit
)
811 (gnus-tmp-sparse gnus-newsgroup-sparse
))
813 (not (eq top gnus-tree-displayed-thread
)))
814 (gnus-generate-tree top
)
815 (setq gnus-tree-displayed-thread top
))))))
817 (defun gnus-tree-open (group)
818 (gnus-get-tree-buffer))
820 (defun gnus-tree-close (group)
821 (gnus-kill-buffer gnus-tree-buffer
))
823 (defun gnus-tree-perhaps-minimize ()
824 (when (and gnus-tree-minimize-window
825 (get-buffer gnus-tree-buffer
))
826 (with-current-buffer gnus-tree-buffer
827 (gnus-tree-minimize))))
829 (defun gnus-highlight-selected-tree (article)
830 "Highlight the selected article in the tree."
831 (let ((buf (current-buffer))
833 (set-buffer gnus-tree-buffer
)
834 (when (setq region
(gnus-tree-article-region article
))
835 (when (or (not gnus-selected-tree-overlay
)
836 (gnus-extent-detached-p gnus-selected-tree-overlay
))
837 ;; Create a new overlay.
839 (setq gnus-selected-tree-overlay
840 (gnus-make-overlay (point-min) (1+ (point-min))))
841 'face gnus-selected-tree-face
))
842 ;; Move the overlay to the article.
844 gnus-selected-tree-overlay
(goto-char (car region
)) (cdr region
))
847 (let ((selected (selected-window)))
848 (when (gnus-get-buffer-window (set-buffer gnus-tree-buffer
) t
)
849 (select-window (gnus-get-buffer-window (set-buffer gnus-tree-buffer
) t
))
850 (gnus-horizontal-recenter)
851 (select-window selected
))))
852 ;; If we remove this save-excursion, it updates the wrong mode lines?!?
853 (with-current-buffer gnus-tree-buffer
854 (gnus-set-mode-line 'tree
))
857 (defun gnus-tree-highlight-article (article face
)
858 (with-current-buffer (gnus-get-tree-buffer)
860 (when (setq region
(gnus-tree-article-region article
))
861 (gnus-put-text-property (car region
) (cdr region
) 'face face
)
863 (gnus-get-buffer-window (current-buffer) t
) (cdr region
))))))
865 ;;; Allow redefinition of functions.
870 ;;; gnus-salt.el ends here