1 ;;; gnus-salt.el --- alternate summary mode interfaces for Gnus
3 ;; Copyright (C) 1996-1999, 2001-2016 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
))
37 (defcustom gnus-pick-display-summary nil
38 "Display summary while reading."
40 :group
'gnus-summary-pick
)
42 (defcustom gnus-pick-mode-hook nil
43 "Hook run in summary pick mode buffers."
45 :group
'gnus-summary-pick
)
47 (defcustom gnus-mark-unpicked-articles-as-read nil
48 "If non-nil, mark all unpicked articles as read."
50 :group
'gnus-summary-pick
)
52 (defcustom gnus-pick-elegant-flow t
53 "If non-nil, `gnus-pick-start-reading' runs
54 `gnus-summary-next-group' when no articles have been picked."
56 :group
'gnus-summary-pick
)
58 (defcustom gnus-summary-pick-line-format
59 "%-5P %U\ %R\ %z\ %I\ %(%[%4L: %-23,23n%]%) %s\n"
60 "The format specification of the lines in pick buffers.
61 It accepts the same format specs that `gnus-summary-line-format' does."
63 :group
'gnus-summary-pick
)
65 ;;; Internal variables.
67 (defvar gnus-pick-mode-map
68 (let ((map (make-sparse-keymap)))
70 " " gnus-pick-next-page
71 "u" gnus-pick-unmark-article-or-thread
72 "." gnus-pick-article-or-thread
73 [down-mouse-2
] gnus-pick-mouse-pick-region
74 "\r" gnus-pick-start-reading
)
77 (defun gnus-pick-make-menu-bar ()
78 (unless (boundp 'gnus-pick-menu
)
80 gnus-pick-menu gnus-pick-mode-map
""
83 ["Article" gnus-summary-mark-as-processable t
]
84 ["Thread" gnus-uu-mark-thread t
]
85 ["Region" gnus-uu-mark-region t
]
86 ["Regexp" gnus-uu-mark-by-regexp t
]
87 ["Buffer" gnus-uu-mark-buffer t
])
89 ["Article" gnus-summary-unmark-as-processable t
]
90 ["Thread" gnus-uu-unmark-thread t
]
91 ["Region" gnus-uu-unmark-region t
]
92 ["Regexp" gnus-uu-unmark-by-regexp t
]
93 ["Buffer" gnus-summary-unmark-all-processable t
])
94 ["Start reading" gnus-pick-start-reading t
]
95 ["Switch pick mode off" gnus-pick-mode gnus-pick-mode
]))))
97 (define-minor-mode gnus-pick-mode
98 "Minor mode for providing a pick-and-read interface in Gnus summary buffers.
100 \\{gnus-pick-mode-map}"
101 :lighter
" Pick" :keymap gnus-pick-mode-map
103 ((not (derived-mode-p 'gnus-summary-mode
)) (setq gnus-pick-mode nil
))
104 ((not gnus-pick-mode
)
105 ;; FIXME: a buffer-local minor mode removing globally from a hook??
106 (remove-hook 'gnus-message-setup-hook
'gnus-pick-setup-message
))
108 ;; Make sure that we don't select any articles upon group entry.
109 (set (make-local-variable 'gnus-auto-select-first
) nil
)
110 ;; Change line format.
111 (setq gnus-summary-line-format gnus-summary-pick-line-format
)
112 (setq gnus-summary-line-format-spec nil
)
113 (gnus-update-format-specifications nil
'summary
)
114 (gnus-update-summary-mark-positions)
115 ;; FIXME: a buffer-local minor mode adding globally to a hook??
116 (add-hook 'gnus-message-setup-hook
'gnus-pick-setup-message
)
117 (set (make-local-variable 'gnus-summary-goto-unread
) 'never
)
119 (when (gnus-visual-p 'pick-menu
'menu
)
120 (gnus-pick-make-menu-bar)))))
122 (defun gnus-pick-setup-message ()
123 "Make Message do the right thing on exit."
124 (when (and (gnus-buffer-live-p gnus-summary-buffer
)
125 (with-current-buffer gnus-summary-buffer
128 `(gnus-configure-windows ,gnus-current-window-configuration t
)
129 'send
'exit
'postpone
'kill
)))
131 (defvar gnus-pick-line-number
1)
132 (defun gnus-pick-line-number ()
133 "Return the current line number."
135 (setq gnus-pick-line-number
1)
136 (incf gnus-pick-line-number
)))
138 (defun gnus-pick-start-reading (&optional catch-up
)
139 "Start reading the picked articles.
140 If given a prefix, mark all unpicked articles as read."
142 (if gnus-newsgroup-processable
144 (gnus-summary-limit-to-articles nil
)
145 (when (or catch-up gnus-mark-unpicked-articles-as-read
)
146 (gnus-summary-limit-mark-excluded-as-read))
147 (gnus-summary-first-article)
148 (gnus-configure-windows
149 (if gnus-pick-display-summary
'article
'pick
) t
))
150 (if gnus-pick-elegant-flow
152 (when (or catch-up gnus-mark-unpicked-articles-as-read
)
153 (gnus-summary-catchup nil t
))
154 (if (gnus-group-quit-config gnus-newsgroup-name
)
156 (gnus-summary-next-group)))
157 (error "No articles have been picked"))))
159 (defun gnus-pick-goto-article (arg)
160 "Go to the article number indicated by ARG.
161 If ARG is an invalid article number, then stay on current line."
164 (goto-char (point-min))
165 (when (zerop (forward-line (1- (prefix-numeric-value arg
))))
168 (gnus-error 2 "No such line: %s" arg
)
171 (defun gnus-pick-article (&optional arg
)
172 "Pick the article on the current line.
173 If ARG, pick the article on that line instead."
176 (gnus-pick-goto-article arg
))
177 (gnus-summary-mark-as-processable 1))
179 (defun gnus-pick-article-or-thread (&optional arg
)
180 "If `gnus-thread-hide-subtree' is t, then pick the thread on the current line.
181 Otherwise pick the article on the current line.
182 If ARG, pick the article/thread on that line instead."
185 (gnus-pick-goto-article arg
))
186 (if gnus-thread-hide-subtree
189 (gnus-uu-mark-thread))
191 (gnus-summary-mark-as-processable 1)))
193 (defun gnus-pick-unmark-article-or-thread (&optional arg
)
194 "If `gnus-thread-hide-subtree' is t, then unmark the thread on current line.
195 Otherwise unmark the article on current line.
196 If ARG, unmark thread/article on that line instead."
199 (gnus-pick-goto-article arg
))
200 (if gnus-thread-hide-subtree
202 (gnus-uu-unmark-thread))
203 (gnus-summary-unmark-as-processable 1)))
205 (defun gnus-pick-mouse-pick (e)
209 (gnus-summary-mark-as-processable 1)))
211 (defun gnus-pick-mouse-pick-region (start-event)
212 "Pick articles that the mouse is dragged over.
213 This must be bound to a button-down mouse event."
215 (mouse-minibuffer-check start-event
)
216 (let* ((echo-keystrokes 0)
217 (start-posn (event-start start-event
))
218 (start-point (posn-point start-posn
))
219 (start-line (1+ (count-lines (point-min) start-point
)))
220 (start-window (posn-window start-posn
))
221 (bounds (window-edges start-window
))
223 (bottom (if (window-minibuffer-p start-window
)
225 ;; Don't count the mode line.
226 (1- (nth 3 bounds
))))
227 (click-count (1- (event-click-count start-event
))))
228 (setq mouse-selection-click-count click-count
)
229 (setq mouse-selection-click-count-buffer
(current-buffer))
230 (mouse-set-point start-event
)
231 ;; In case the down click is in the middle of some intangible text,
232 ;; use the end of that text, and put it in START-POINT.
233 (when (< (point) start-point
)
234 (goto-char start-point
))
236 (setq start-point
(point))
237 ;; end-of-range is used only in the single-click case.
238 ;; It is the place where the drag has reached so far
239 ;; (but not outside the window where the drag started).
240 (let (event end end-point
(end-of-range (point)))
243 (setq event
(cdr (gnus-read-event-char)))
244 (or (mouse-movement-p event
)
245 (eq (car-safe event
) 'switch-frame
)))
246 (if (eq (car-safe event
) 'switch-frame
)
248 (setq end
(event-end event
)
249 end-point
(posn-point end
))
252 ;; Are we moving within the original window?
253 ((and (eq (posn-window end
) start-window
)
254 (integer-or-marker-p end-point
))
255 ;; Go to START-POINT first, so that when we move to END-POINT,
256 ;; if it's in the middle of intangible text,
257 ;; point jumps in the direction away from START-POINT.
258 (goto-char start-point
)
259 (goto-char end-point
)
261 ;; In case the user moved his mouse really fast, pick
262 ;; articles on the line between this one and the last one.
263 (let* ((this-line (1+ (count-lines (point-min) end-point
)))
264 (min-line (min this-line start-line
))
265 (max-line (max this-line start-line
)))
266 (while (< min-line max-line
)
267 (goto-char (point-min))
268 (forward-line (1- min-line
))
270 (setq min-line
(1+ min-line
)))
271 (setq start-line this-line
))
272 (when (zerop (% click-count
3))
273 (setq end-of-range
(point))))
275 (let ((mouse-row (cdr (cdr (mouse-position)))))
279 (mouse-scroll-subr start-window
(- mouse-row top
)))
280 ((>= mouse-row bottom
)
281 (mouse-scroll-subr start-window
282 (1+ (- mouse-row bottom
)))))))))))
284 (let (;; (fun (key-binding (vector (car event))))
286 ;; Run the binding of the terminating up-event, if possible.
287 ;; In the case of a multiple click, it gives the wrong results,
288 ;; because it would fail to set up a region.
290 ;; (and (= (mod mouse-selection-click-count 3) 0) (fboundp fun))
291 ;; In this case, we can just let the up-event execute normally.
292 (let ((end (event-end event
)))
293 ;; Set the position in the event before we replay it,
294 ;; because otherwise it may have a position in the wrong
296 (setcar (cdr end
) end-of-range
)
297 ;; Delete the overlay before calling the function,
298 ;; because delete-overlay increases buffer-modified-tick.
299 (push event unread-command-events
))))))))
301 (defvar scroll-in-place
)
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-hook nil
316 "Hook run in summary binary mode buffers.")
318 (defvar gnus-binary-mode-map
319 (let ((map (make-sparse-keymap)))
320 (gnus-define-keys map
321 "g" gnus-binary-show-article
)
324 (defun gnus-binary-make-menu-bar ()
325 (unless (boundp 'gnus-binary-menu
)
327 gnus-binary-menu gnus-binary-mode-map
""
329 ["Switch binary mode off" gnus-binary-mode t
]))))
331 (define-minor-mode gnus-binary-mode
332 "Minor mode for providing a binary group interface in Gnus summary buffers."
333 :lighter
" Binary" :keymap gnus-binary-mode-map
335 ((not (derived-mode-p 'gnus-summary-mode
)) (setq gnus-binary-mode nil
))
337 ;; Make sure that we don't select any articles upon group entry.
338 (make-local-variable 'gnus-auto-select-first
)
339 (setq gnus-auto-select-first nil
)
340 (make-local-variable 'gnus-summary-display-article-function
)
341 (setq gnus-summary-display-article-function
'gnus-binary-display-article
)
343 (when (gnus-visual-p 'binary-menu
'menu
)
344 (gnus-binary-make-menu-bar)))))
346 (defun gnus-binary-display-article (article &optional _all-header
)
347 "Run ARTICLE through the binary decode functions."
348 (when (gnus-summary-goto-subject article
)
349 (let ((gnus-view-pseudos (or gnus-view-pseudos
'automatic
)))
350 (gnus-uu-decode-uu))))
352 (defun gnus-binary-show-article (&optional arg
)
353 "Bypass the binary functions and show the article."
355 (let (gnus-summary-display-article-function)
356 (gnus-summary-show-article arg
)))
362 (defcustom gnus-tree-line-format
"%(%[%3,3n%]%)"
363 "Format of tree elements."
365 :group
'gnus-summary-tree
)
367 (defcustom gnus-tree-minimize-window t
368 "If non-nil, minimize the tree buffer window.
369 If a number, never let the tree buffer grow taller than that number of
371 :type
'(choice boolean
373 :group
'gnus-summary-tree
)
375 (defcustom gnus-selected-tree-face
'mode-line
376 "Face used for highlighting selected articles in the thread tree."
378 :group
'gnus-summary-tree
)
380 (defvar gnus-tree-brackets
'((?\
[ . ?\
]) (?\
( . ?\
))
381 (?\
{ . ?\
}) (?
< . ?
>))
382 "Brackets used in tree nodes.")
384 (defvar gnus-tree-parent-child-edges
'(?- ?
\\ ?|
)
385 "Characters used to connect parents with children.")
387 (defcustom gnus-tree-mode-line-format
"Gnus: %%b %S %Z"
388 "The format specification for the tree mode line."
390 :group
'gnus-summary-tree
)
392 (defcustom gnus-generate-tree-function
'gnus-generate-vertical-tree
393 "Function for generating a thread tree.
394 Two predefined functions are available:
395 `gnus-generate-horizontal-tree' and `gnus-generate-vertical-tree'."
396 :type
'(radio (function-item gnus-generate-vertical-tree
)
397 (function-item gnus-generate-horizontal-tree
)
398 (function :tag
"Other" nil
))
399 :group
'gnus-summary-tree
)
401 (defcustom gnus-tree-mode-hook nil
402 "Hook run in tree mode buffers."
404 :group
'gnus-summary-tree
)
406 ;;; Internal variables.
408 (defvar gnus-tmp-name
)
409 (defvar gnus-tmp-from
)
410 (defvar gnus-tmp-number
)
411 (defvar gnus-tmp-open-bracket
)
412 (defvar gnus-tmp-close-bracket
)
413 (defvar gnus-tmp-subject
)
415 (defvar gnus-tree-line-format-alist
416 `((?n gnus-tmp-name ?s
)
417 (?f gnus-tmp-from ?s
)
418 (?N gnus-tmp-number ?d
)
419 (?\
[ gnus-tmp-open-bracket ?c
)
420 (?\
] gnus-tmp-close-bracket ?c
)
421 (?s gnus-tmp-subject ?s
)))
423 (defvar gnus-tree-mode-line-format-alist gnus-summary-mode-line-format-alist
)
425 (defvar gnus-tree-mode-line-format-spec nil
)
426 (defvar gnus-tree-line-format-spec nil
)
428 (defvar gnus-tree-node-length nil
)
429 (defvar gnus-selected-tree-overlay nil
)
431 (defvar gnus-tree-displayed-thread nil
)
432 (defvar gnus-tree-inhibit nil
)
434 (defvar gnus-tree-mode-map
435 (let ((map (make-keymap)))
436 (suppress-keymap map
)
439 "\r" gnus-tree-select-article
440 [mouse-2
] gnus-tree-pick-article
441 "\C-?" gnus-tree-read-summary-keys
442 "h" gnus-tree-show-summary
444 "\C-c\C-i" gnus-info-find-node
)
446 (substitute-key-definition
447 'undefined
'gnus-tree-read-summary-keys map
)
450 (put 'gnus-tree-mode
'mode-class
'special
)
452 (defun gnus-tree-make-menu-bar ()
453 (unless (boundp 'gnus-tree-menu
)
455 gnus-tree-menu gnus-tree-mode-map
""
457 ["Select article" gnus-tree-select-article t
]))))
459 (define-derived-mode gnus-tree-mode fundamental-mode
"Tree"
460 "Major mode for displaying thread trees."
461 (gnus-set-format 'tree-mode
)
462 (gnus-set-format 'tree t
)
463 (when (gnus-visual-p 'tree-menu
'menu
)
464 (gnus-tree-make-menu-bar))
465 (gnus-simplify-mode-line)
466 (buffer-disable-undo)
467 (setq buffer-read-only t
)
468 (setq truncate-lines t
)
470 (gnus-set-work-buffer)
471 (gnus-tree-node-insert (make-mail-header "") nil
)
472 (setq gnus-tree-node-length
(1- (point)))))
474 (defun gnus-tree-read-summary-keys (&optional arg
)
475 "Read a summary buffer key sequence and execute it."
477 (unless gnus-tree-inhibit
478 (let ((buf (current-buffer))
479 (gnus-tree-inhibit t
)
481 (set-buffer gnus-article-buffer
)
482 (gnus-article-read-summary-keys arg nil t
)
483 (when (setq win
(get-buffer-window buf
))
485 (when gnus-selected-tree-overlay
486 (goto-char (or (overlay-end gnus-selected-tree-overlay
) 1)))
487 (gnus-tree-minimize)))))
489 (defun gnus-tree-show-summary ()
490 "Reconfigure windows to show summary buffer."
492 (if (not (gnus-buffer-live-p gnus-summary-buffer
))
493 (error "There is no summary buffer for this tree buffer")
494 (gnus-configure-windows 'article
)
495 (gnus-summary-goto-subject gnus-current-article
)))
497 (defun gnus-tree-select-article (article)
498 "Select the article under point, if any."
499 (interactive (list (gnus-tree-article-number)))
500 (let ((buf (current-buffer)))
502 (with-current-buffer gnus-summary-buffer
503 (gnus-summary-goto-article article
))
504 (select-window (get-buffer-window buf
)))))
506 (defun gnus-tree-pick-article (e)
507 "Select the article under the mouse pointer."
510 (gnus-tree-select-article (gnus-tree-article-number)))
512 (defun gnus-tree-article-number ()
513 (get-text-property (point) 'gnus-number
))
515 (defun gnus-tree-article-region (article)
516 "Return a cons with BEG and END of the article region."
517 (let ((pos (text-property-any
518 (point-min) (point-max) 'gnus-number article
)))
520 (cons pos
(next-single-property-change pos
'gnus-number
)))))
522 (defun gnus-tree-recenter ()
523 "Center point in the tree window."
524 (let ((selected (selected-window))
525 (tree-window (gnus-get-buffer-window gnus-tree-buffer t
)))
527 (select-window tree-window
)
528 (when gnus-selected-tree-overlay
529 (goto-char (or (overlay-end gnus-selected-tree-overlay
) 1)))
530 (let* ((top (cond ((< (window-height) 4) 0)
531 ((< (window-height) 7) 1)
533 (height (1- (window-height)))
534 (bottom (save-excursion (goto-char (point-max))
535 (forward-line (- height
))
537 ;; Set the window start to either `bottom', which is the biggest
538 ;; possible valid number, or the second line from the top,
539 ;; whichever is the least.
541 tree-window
(min bottom
(save-excursion
542 (forward-line (- top
)) (point)))))
543 (select-window selected
))))
545 (defun gnus-get-tree-buffer ()
546 "Return the tree buffer properly initialized."
547 (with-current-buffer (gnus-get-buffer-create gnus-tree-buffer
)
548 (unless (derived-mode-p 'gnus-tree-mode
)
552 (defun gnus-tree-minimize ()
553 (when (and gnus-tree-minimize-window
554 (not (one-window-p)))
557 (walk-windows (lambda (_window) (incf windows
)))
560 (* window-min-height
(1- windows
))
562 (let* ((window-min-height 2)
563 (height (count-lines (point-min) (point-max)))
564 (min (max (1- window-min-height
) height
))
565 (tot (if (numberp gnus-tree-minimize-window
)
566 (min gnus-tree-minimize-window min
)
568 (win (get-buffer-window (current-buffer)))
569 (wh (and win
(1- (window-height win
)))))
570 (setq tot
(min tot tot-win-height
))
573 (let ((selected (selected-window)))
574 (when (ignore-errors (select-window win
))
575 (enlarge-window (- tot wh
))
576 (select-window selected
))))))))
578 ;;; Generating the tree.
580 (defun gnus-tree-node-insert (header sparse
&optional adopted
)
581 (let* ((dummy (stringp header
))
582 (header (if (vectorp header
) header
584 (setq header
(make-mail-header "*****"))
585 (mail-header-set-number header
0)
586 (mail-header-set-lines header
0)
587 (mail-header-set-chars header
0)
589 (gnus-tmp-from (mail-header-from header
))
590 (gnus-tmp-subject (mail-header-subject header
))
591 (gnus-tmp-number (mail-header-number header
))
594 ((string-match "(.+)" gnus-tmp-from
)
595 (substring gnus-tmp-from
596 (1+ (match-beginning 0)) (1- (match-end 0))))
597 ((string-match "<[^>]+> *$" gnus-tmp-from
)
598 (let ((beg (match-beginning 0)))
599 (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from
)
600 (substring gnus-tmp-from
(1+ (match-beginning 0))
602 (substring gnus-tmp-from
0 beg
))))
603 ((memq gnus-tmp-number sparse
)
606 (gnus-tmp-open-bracket
607 (cond ((memq gnus-tmp-number sparse
)
608 (caadr gnus-tree-brackets
))
609 (dummy (caaddr gnus-tree-brackets
))
610 (adopted (car (nth 3 gnus-tree-brackets
)))
611 (t (caar gnus-tree-brackets
))))
612 (gnus-tmp-close-bracket
613 (cond ((memq gnus-tmp-number sparse
)
614 (cdadr gnus-tree-brackets
))
615 (adopted (cdr (nth 3 gnus-tree-brackets
)))
617 (cdaddr gnus-tree-brackets
))
618 (t (cdar gnus-tree-brackets
))))
619 (buffer-read-only nil
)
623 (setq end
(progn (eval gnus-tree-line-format-spec
) (point)))
624 (list 'gnus-number gnus-tmp-number
))
625 (when (or t
(gnus-visual-p 'tree-highlight
'highlight
))
626 (gnus-tree-highlight-node gnus-tmp-number beg end
))))
628 (defmacro gnus--let-eval
(bindings evalsym
&rest body
)
629 "Build an environment in which to evaluate expressions.
630 BINDINGS is a `let'-style list of bindings to use for the environment.
631 EVALSYM is then bound in BODY to a function that takes a sexp and evaluates
632 it in the environment specified by BINDINGS."
633 (declare (indent 2) (debug ((&rest
(sym form
)) sym body
)))
634 (if (ignore-errors (let ((x 3)) (eq (eval '(- x
1) '((x .
4))) x
)))
635 ;; Use lexical vars if possible.
636 `(let* ((env (list ,@(mapcar (lambda (binding)
637 `(cons ',(car binding
) ,(cadr binding
)))
639 (,evalsym
(lambda (exp) (eval exp env
))))
641 `(let (,@bindings
(,evalsym
#'eval
)) ,@body
)))
643 (defun gnus-tree-highlight-node (article beg end
)
644 "Highlight current line according to `gnus-summary-highlight'."
645 (let ((list gnus-summary-highlight
)
647 (with-current-buffer gnus-summary-buffer
648 (let ((uncached (memq article gnus-newsgroup-undownloaded
)))
650 ((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
)
656 (downloaded (not uncached
))
657 (mark (or (gnus-summary-article-mark article
) gnus-unread-mark
)))
659 ;; Eval the cars of the lists until we find a match.
661 (not (funcall evalfun
(caar list
))))
662 (setq list
(cdr list
))))))
663 (unless (eq (setq face
(cdar list
)) (gnus-get-text-property-excluding-characters-with-faces beg
'face
))
664 (gnus-put-text-property-excluding-characters-with-faces
666 (if (boundp face
) (symbol-value face
) face
)))))
668 (defun gnus-tree-indent (level)
669 (insert (make-string (1- (* (1+ gnus-tree-node-length
) level
)) ?
)))
671 (defvar gnus-tmp-limit
)
672 (defvar gnus-tmp-sparse
)
673 (defvar gnus-tmp-indent
)
675 (defun gnus-generate-tree (thread)
676 "Generate a thread tree for THREAD."
677 (with-current-buffer (gnus-get-tree-buffer)
678 (let ((buffer-read-only nil
)
681 (funcall gnus-generate-tree-function thread
0)
682 (gnus-set-mode-line 'tree
)
683 (goto-char (point-min))
686 (let ((selected (selected-window)))
687 (when (gnus-get-buffer-window (set-buffer gnus-tree-buffer
) t
)
688 (select-window (gnus-get-buffer-window (set-buffer gnus-tree-buffer
) t
))
689 (gnus-horizontal-recenter)
690 (select-window selected
))))))
692 (defun gnus-generate-horizontal-tree (thread level
&optional dummyp adopted
)
693 "Generate a horizontal tree."
694 (let* ((dummy (stringp (car thread
)))
697 (memq (mail-header-number (car thread
))
701 ;; We don't want this article.
702 (setq thread
(cdr thread
))
704 ;; Not the first article on the line, so we insert a "-".
705 (insert (car gnus-tree-parent-child-edges
))
706 ;; If the level isn't zero, then we insert some indentation.
707 (unless (zerop level
)
708 (gnus-tree-indent level
)
709 (insert (cadr gnus-tree-parent-child-edges
))
710 (setq col
(- (setq beg
(point)) (point-at-bol) 1))
711 ;; Draw "|" lines upwards.
715 (eq (char-after) ?
))
717 (insert (caddr gnus-tree-parent-child-edges
)))
720 ;; Insert the article node.
721 (gnus-tree-node-insert (pop thread
) gnus-tmp-sparse adopted
))
723 ;; End of the thread, so we go to the next line.
726 ;; Recurse downwards in all children of this article.
728 (gnus-generate-horizontal-tree
729 (pop thread
) (if do
(1+ level
) level
)
730 (or dummyp dummy
) dummy
)))))
732 (defsubst gnus-tree-indent-vertical
()
733 (let ((len (- (* (1+ gnus-tree-node-length
) gnus-tmp-indent
)
734 (- (point) (point-at-bol)))))
736 (insert (make-string len ?
)))))
738 (defsubst gnus-tree-forward-line
(n)
739 (while (>= (decf n
) 0)
740 (unless (zerop (forward-line 1))
745 (defun gnus-generate-vertical-tree (thread level
&optional dummyp adopted
)
746 "Generate a vertical tree."
747 (let* ((dummy (stringp (car thread
)))
750 (memq (mail-header-number (car thread
))
754 ;; We don't want this article.
755 (setq thread
(cdr thread
))
756 (if (not (save-excursion (beginning-of-line) (bobp)))
757 ;; Not the first article on the line, so we insert a "-".
759 (gnus-tree-indent-vertical)
760 (insert (make-string (/ gnus-tree-node-length
2) ?
))
761 (insert (caddr gnus-tree-parent-child-edges
))
762 (gnus-tree-forward-line 1))
763 ;; If the level isn't zero, then we insert some indentation.
764 (unless (zerop gnus-tmp-indent
)
765 (gnus-tree-forward-line (1- (* 2 level
)))
766 (gnus-tree-indent-vertical)
768 (insert (cadr gnus-tree-parent-child-edges
))
771 ;; Draw "-" lines leftwards.
772 (while (and (not (bobp))
773 (eq (char-after (1- (point))) ?
))
775 (insert (car gnus-tree-parent-child-edges
))
778 (gnus-tree-forward-line 1)))
780 ;; Insert the article node.
781 (gnus-tree-indent-vertical)
782 (gnus-tree-node-insert (pop thread
) gnus-tmp-sparse adopted
)
783 (gnus-tree-forward-line 1))
785 ;; End of the thread, so we go to the next line.
787 (goto-char (point-min))
789 (incf gnus-tmp-indent
))
790 ;; Recurse downwards in all children of this article.
792 (gnus-generate-vertical-tree
793 (pop thread
) (if do
(1+ level
) level
)
794 (or dummyp dummy
) dummy
)))))
796 ;;; Interface functions.
798 (defun gnus-possibly-generate-tree (article &optional force
)
799 "Generate the thread tree for ARTICLE if it isn't displayed already."
800 (when (with-current-buffer gnus-summary-buffer
803 (vectorp (gnus-summary-article-header article
))))
805 (let ((top (with-current-buffer gnus-summary-buffer
809 (gnus-summary-article-header article
))
811 (gnus-tmp-limit gnus-newsgroup-limit
)
812 (gnus-tmp-sparse gnus-newsgroup-sparse
))
814 (not (eq top gnus-tree-displayed-thread
)))
815 (gnus-generate-tree top
)
816 (setq gnus-tree-displayed-thread top
))))))
818 (defun gnus-tree-open ()
819 (gnus-get-tree-buffer))
821 (defun gnus-tree-close ()
822 (gnus-kill-buffer gnus-tree-buffer
))
824 (defun gnus-tree-perhaps-minimize ()
825 (when (and gnus-tree-minimize-window
826 (get-buffer gnus-tree-buffer
))
827 (with-current-buffer gnus-tree-buffer
828 (gnus-tree-minimize))))
830 (defun gnus-highlight-selected-tree (article)
831 "Highlight the selected article in the tree."
832 (when (buffer-live-p gnus-tree-buffer
)
833 (let ((buf (current-buffer))
835 (set-buffer gnus-tree-buffer
)
836 (when (setq region
(gnus-tree-article-region article
))
837 (when (not gnus-selected-tree-overlay
)
838 ;; Create a new overlay.
840 (setq gnus-selected-tree-overlay
841 (make-overlay (point-min) (1+ (point-min))))
842 'face gnus-selected-tree-face
))
843 ;; Move the overlay to the article.
845 gnus-selected-tree-overlay
(goto-char (car region
)) (cdr region
))
848 (let ((selected (selected-window)))
849 (when (gnus-get-buffer-window (set-buffer gnus-tree-buffer
) t
)
851 (gnus-get-buffer-window (set-buffer gnus-tree-buffer
) t
))
852 (gnus-horizontal-recenter)
853 (select-window selected
))))
854 ;; If we remove this save-excursion, it updates the wrong mode lines?!?
855 (with-current-buffer gnus-tree-buffer
856 (gnus-set-mode-line 'tree
))
859 (defun gnus-tree-highlight-article (article face
)
860 ;; The save-excursion here is apparently necessary because
861 ;; `set-window-point' somehow manages to alter the buffer position.
863 (with-current-buffer (gnus-get-tree-buffer)
865 (when (setq region
(gnus-tree-article-region article
))
866 (put-text-property (car region
) (cdr region
) 'face face
)
868 (gnus-get-buffer-window (current-buffer) t
) (cdr region
)))))))
872 ;;; gnus-salt.el ends here