1 ;;; gnus-salt.el --- alternate summary mode interfaces for Gnus
3 ;; Copyright (C) 1996-1999, 2001-2015 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))))
297 ;; Run the binding of the terminating up-event, if possible.
298 ;; In the case of a multiple click, it gives the wrong results,
299 ;; because it would fail to set up a region.
301 ;; (and (= (mod mouse-selection-click-count 3) 0) (fboundp fun))
302 ;; In this case, we can just let the up-event execute normally.
303 (let ((end (event-end event
)))
304 ;; Set the position in the event before we replay it,
305 ;; because otherwise it may have a position in the wrong
307 (setcar (cdr end
) end-of-range
)
308 ;; Delete the overlay before calling the function,
309 ;; because delete-overlay increases buffer-modified-tick.
310 (push event unread-command-events
))))))))
312 (defvar scroll-in-place
)
314 (defun gnus-pick-next-page ()
315 "Go to the next page. If at the end of the buffer, start reading articles."
317 (let ((scroll-in-place nil
))
320 (end-of-buffer (gnus-pick-start-reading)))))
326 (defvar gnus-binary-mode-hook nil
327 "Hook run in summary binary mode buffers.")
329 (defvar gnus-binary-mode-map
330 (let ((map (make-sparse-keymap)))
331 (gnus-define-keys map
332 "g" gnus-binary-show-article
)
335 (defun gnus-binary-make-menu-bar ()
336 (unless (boundp 'gnus-binary-menu
)
338 gnus-binary-menu gnus-binary-mode-map
""
340 ["Switch binary mode off" gnus-binary-mode t
]))))
343 (when (featurep 'xemacs
)
344 (defvar gnus-binary-mode-on-hook
)
345 (defvar gnus-binary-mode-off-hook
)))
347 (define-minor-mode gnus-binary-mode
348 "Minor mode for providing a binary group interface in Gnus summary buffers."
349 :lighter
" Binary" :keymap gnus-binary-mode-map
351 ((not (derived-mode-p 'gnus-summary-mode
)) (setq gnus-binary-mode nil
))
353 ;; Make sure that we don't select any articles upon group entry.
354 (make-local-variable 'gnus-auto-select-first
)
355 (setq gnus-auto-select-first nil
)
356 (make-local-variable 'gnus-summary-display-article-function
)
357 (setq gnus-summary-display-article-function
'gnus-binary-display-article
)
359 (when (gnus-visual-p 'binary-menu
'menu
)
360 (gnus-binary-make-menu-bar)))))
362 (defun gnus-binary-display-article (article &optional _all-header
)
363 "Run ARTICLE through the binary decode functions."
364 (when (gnus-summary-goto-subject article
)
365 (let ((gnus-view-pseudos (or gnus-view-pseudos
'automatic
)))
366 (gnus-uu-decode-uu))))
368 (defun gnus-binary-show-article (&optional arg
)
369 "Bypass the binary functions and show the article."
371 (let (gnus-summary-display-article-function)
372 (gnus-summary-show-article arg
)))
378 (defcustom gnus-tree-line-format
"%(%[%3,3n%]%)"
379 "Format of tree elements."
381 :group
'gnus-summary-tree
)
383 (defcustom gnus-tree-minimize-window t
384 "If non-nil, minimize the tree buffer window.
385 If a number, never let the tree buffer grow taller than that number of
387 :type
'(choice boolean
389 :group
'gnus-summary-tree
)
391 (defcustom gnus-selected-tree-face
'mode-line
392 "*Face used for highlighting selected articles in the thread tree."
394 :group
'gnus-summary-tree
)
396 (defvar gnus-tree-brackets
'((?\
[ . ?\
]) (?\
( . ?\
))
397 (?\
{ . ?\
}) (?
< . ?
>))
398 "Brackets used in tree nodes.")
400 (defvar gnus-tree-parent-child-edges
'(?- ?
\\ ?|
)
401 "Characters used to connect parents with children.")
403 (defcustom gnus-tree-mode-line-format
"Gnus: %%b %S %Z"
404 "*The format specification for the tree mode line."
406 :group
'gnus-summary-tree
)
408 (defcustom gnus-generate-tree-function
'gnus-generate-vertical-tree
409 "*Function for generating a thread tree.
410 Two predefined functions are available:
411 `gnus-generate-horizontal-tree' and `gnus-generate-vertical-tree'."
412 :type
'(radio (function-item gnus-generate-vertical-tree
)
413 (function-item gnus-generate-horizontal-tree
)
414 (function :tag
"Other" nil
))
415 :group
'gnus-summary-tree
)
417 (defcustom gnus-tree-mode-hook nil
418 "*Hook run in tree mode buffers."
420 :group
'gnus-summary-tree
)
422 (when (featurep 'xemacs
)
423 (add-hook 'gnus-tree-mode-hook
'gnus-xmas-tree-menu-add
)
424 (add-hook 'gnus-tree-mode-hook
'gnus-xmas-switch-horizontal-scrollbar-off
))
427 ;;; Internal variables.
429 (defvar gnus-tmp-name
)
430 (defvar gnus-tmp-from
)
431 (defvar gnus-tmp-number
)
432 (defvar gnus-tmp-open-bracket
)
433 (defvar gnus-tmp-close-bracket
)
434 (defvar gnus-tmp-subject
)
436 (defvar gnus-tree-line-format-alist
437 `((?n gnus-tmp-name ?s
)
438 (?f gnus-tmp-from ?s
)
439 (?N gnus-tmp-number ?d
)
440 (?\
[ gnus-tmp-open-bracket ?c
)
441 (?\
] gnus-tmp-close-bracket ?c
)
442 (?s gnus-tmp-subject ?s
)))
444 (defvar gnus-tree-mode-line-format-alist gnus-summary-mode-line-format-alist
)
446 (defvar gnus-tree-mode-line-format-spec nil
)
447 (defvar gnus-tree-line-format-spec nil
)
449 (defvar gnus-tree-node-length nil
)
450 (defvar gnus-selected-tree-overlay nil
)
452 (defvar gnus-tree-displayed-thread nil
)
453 (defvar gnus-tree-inhibit nil
)
455 (defvar gnus-tree-mode-map
456 (let ((map (make-keymap)))
457 (suppress-keymap 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 map
)
471 (put 'gnus-tree-mode
'mode-class
'special
)
473 (defun gnus-tree-make-menu-bar ()
474 (unless (boundp 'gnus-tree-menu
)
476 gnus-tree-menu gnus-tree-mode-map
""
478 ["Select article" gnus-tree-select-article t
]))))
480 (define-derived-mode gnus-tree-mode fundamental-mode
"Tree"
481 "Major mode for displaying thread trees."
482 (gnus-set-format 'tree-mode
)
483 (gnus-set-format 'tree t
)
484 (when (gnus-visual-p 'tree-menu
'menu
)
485 (gnus-tree-make-menu-bar))
486 (gnus-simplify-mode-line)
487 (buffer-disable-undo)
488 (setq buffer-read-only t
)
489 (setq truncate-lines t
)
491 (gnus-set-work-buffer)
492 (gnus-tree-node-insert (make-mail-header "") nil
)
493 (setq gnus-tree-node-length
(1- (point)))))
495 (defun gnus-tree-read-summary-keys (&optional arg
)
496 "Read a summary buffer key sequence and execute it."
498 (unless gnus-tree-inhibit
499 (let ((buf (current-buffer))
500 (gnus-tree-inhibit t
)
502 (set-buffer gnus-article-buffer
)
503 (gnus-article-read-summary-keys arg nil t
)
504 (when (setq win
(get-buffer-window buf
))
506 (when gnus-selected-tree-overlay
507 (goto-char (or (overlay-end gnus-selected-tree-overlay
) 1)))
508 (gnus-tree-minimize)))))
510 (defun gnus-tree-show-summary ()
511 "Reconfigure windows to show summary buffer."
513 (if (not (gnus-buffer-live-p gnus-summary-buffer
))
514 (error "There is no summary buffer for this tree buffer")
515 (gnus-configure-windows 'article
)
516 (gnus-summary-goto-subject gnus-current-article
)))
518 (defun gnus-tree-select-article (article)
519 "Select the article under point, if any."
520 (interactive (list (gnus-tree-article-number)))
521 (let ((buf (current-buffer)))
523 (with-current-buffer gnus-summary-buffer
524 (gnus-summary-goto-article article
))
525 (select-window (get-buffer-window buf
)))))
527 (defun gnus-tree-pick-article (e)
528 "Select the article under the mouse pointer."
531 (gnus-tree-select-article (gnus-tree-article-number)))
533 (defun gnus-tree-article-number ()
534 (get-text-property (point) 'gnus-number
))
536 (defun gnus-tree-article-region (article)
537 "Return a cons with BEG and END of the article region."
538 (let ((pos (text-property-any
539 (point-min) (point-max) 'gnus-number article
)))
541 (cons pos
(next-single-property-change pos
'gnus-number
)))))
543 (defun gnus-tree-recenter ()
544 "Center point in the tree window."
545 (let ((selected (selected-window))
546 (tree-window (gnus-get-buffer-window gnus-tree-buffer t
)))
548 (select-window tree-window
)
549 (when gnus-selected-tree-overlay
550 (goto-char (or (overlay-end gnus-selected-tree-overlay
) 1)))
551 (let* ((top (cond ((< (window-height) 4) 0)
552 ((< (window-height) 7) 1)
554 (height (1- (window-height)))
555 (bottom (save-excursion (goto-char (point-max))
556 (forward-line (- height
))
558 ;; Set the window start to either `bottom', which is the biggest
559 ;; possible valid number, or the second line from the top,
560 ;; whichever is the least.
562 tree-window
(min bottom
(save-excursion
563 (forward-line (- top
)) (point)))))
564 (select-window selected
))))
566 (defun gnus-get-tree-buffer ()
567 "Return the tree buffer properly initialized."
568 (with-current-buffer (gnus-get-buffer-create gnus-tree-buffer
)
569 (unless (derived-mode-p 'gnus-tree-mode
)
573 (defun gnus-tree-minimize ()
574 (when (and gnus-tree-minimize-window
575 (not (one-window-p)))
578 (walk-windows (lambda (_window) (incf windows
)))
581 (* window-min-height
(1- windows
))
583 (let* ((window-min-height 2)
584 (height (count-lines (point-min) (point-max)))
585 (min (max (1- window-min-height
) height
))
586 (tot (if (numberp gnus-tree-minimize-window
)
587 (min gnus-tree-minimize-window min
)
589 (win (get-buffer-window (current-buffer)))
590 (wh (and win
(1- (window-height win
)))))
591 (setq tot
(min tot tot-win-height
))
594 (let ((selected (selected-window)))
595 (when (ignore-errors (select-window win
))
596 (enlarge-window (- tot wh
))
597 (select-window selected
))))))))
599 ;;; Generating the tree.
601 (defun gnus-tree-node-insert (header sparse
&optional adopted
)
602 (let* ((dummy (stringp header
))
603 (header (if (vectorp header
) header
605 (setq header
(make-mail-header "*****"))
606 (mail-header-set-number header
0)
607 (mail-header-set-lines header
0)
608 (mail-header-set-chars header
0)
610 (gnus-tmp-from (mail-header-from header
))
611 (gnus-tmp-subject (mail-header-subject header
))
612 (gnus-tmp-number (mail-header-number header
))
615 ((string-match "(.+)" gnus-tmp-from
)
616 (substring gnus-tmp-from
617 (1+ (match-beginning 0)) (1- (match-end 0))))
618 ((string-match "<[^>]+> *$" gnus-tmp-from
)
619 (let ((beg (match-beginning 0)))
620 (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from
)
621 (substring gnus-tmp-from
(1+ (match-beginning 0))
623 (substring gnus-tmp-from
0 beg
))))
624 ((memq gnus-tmp-number sparse
)
627 (gnus-tmp-open-bracket
628 (cond ((memq gnus-tmp-number sparse
)
629 (caadr gnus-tree-brackets
))
630 (dummy (caaddr gnus-tree-brackets
))
631 (adopted (car (nth 3 gnus-tree-brackets
)))
632 (t (caar gnus-tree-brackets
))))
633 (gnus-tmp-close-bracket
634 (cond ((memq gnus-tmp-number sparse
)
635 (cdadr gnus-tree-brackets
))
636 (adopted (cdr (nth 3 gnus-tree-brackets
)))
638 (cdaddr gnus-tree-brackets
))
639 (t (cdar gnus-tree-brackets
))))
640 (buffer-read-only nil
)
642 (gnus-add-text-properties
644 (setq end
(progn (eval gnus-tree-line-format-spec
) (point)))
645 (list 'gnus-number gnus-tmp-number
))
646 (when (or t
(gnus-visual-p 'tree-highlight
'highlight
))
647 (gnus-tree-highlight-node gnus-tmp-number beg end
))))
649 (defmacro gnus--let-eval
(bindings evalsym
&rest body
)
650 "Build an environment in which to evaluate expressions.
651 BINDINGS is a `let'-style list of bindings to use for the environment.
652 EVALSYM is then bound in BODY to a function that takes a sexp and evaluates
653 it in the environment specified by BINDINGS."
654 (declare (indent 2) (debug ((&rest
(sym form
)) sym body
)))
655 (if (ignore-errors (let ((x 3)) (eq (eval '(- x
1) '((x .
4))) x
)))
656 ;; Use lexical vars if possible.
657 `(let* ((env (list ,@(mapcar (lambda (binding)
658 `(cons ',(car binding
) ,(cadr binding
)))
660 (,evalsym
(lambda (exp) (eval exp env
))))
662 `(let (,@bindings
(,evalsym
#'eval
)) ,@body
)))
664 (defun gnus-tree-highlight-node (article beg end
)
665 "Highlight current line according to `gnus-summary-highlight'."
666 (let ((list gnus-summary-highlight
)
668 (with-current-buffer gnus-summary-buffer
669 (let ((uncached (memq article gnus-newsgroup-undownloaded
)))
671 ((score (or (cdr (assq article gnus-newsgroup-scored
))
672 gnus-summary-default-score
0))
673 (default gnus-summary-default-score
)
674 (default-high gnus-summary-default-high-score
)
675 (default-low gnus-summary-default-low-score
)
677 (downloaded (not uncached
))
678 (mark (or (gnus-summary-article-mark article
) gnus-unread-mark
)))
680 ;; Eval the cars of the lists until we find a match.
682 (not (funcall evalfun
(caar list
))))
683 (setq list
(cdr list
))))))
684 (unless (eq (setq face
(cdar list
)) (gnus-get-text-property-excluding-characters-with-faces beg
'face
))
685 (gnus-put-text-property-excluding-characters-with-faces
687 (if (boundp face
) (symbol-value face
) face
)))))
689 (defun gnus-tree-indent (level)
690 (insert (make-string (1- (* (1+ gnus-tree-node-length
) level
)) ?
)))
692 (defvar gnus-tmp-limit
)
693 (defvar gnus-tmp-sparse
)
694 (defvar gnus-tmp-indent
)
696 (defun gnus-generate-tree (thread)
697 "Generate a thread tree for THREAD."
698 (with-current-buffer (gnus-get-tree-buffer)
699 (let ((buffer-read-only nil
)
702 (funcall gnus-generate-tree-function thread
0)
703 (gnus-set-mode-line 'tree
)
704 (goto-char (point-min))
707 (let ((selected (selected-window)))
708 (when (gnus-get-buffer-window (set-buffer gnus-tree-buffer
) t
)
709 (select-window (gnus-get-buffer-window (set-buffer gnus-tree-buffer
) t
))
710 (gnus-horizontal-recenter)
711 (select-window selected
))))))
713 (defun gnus-generate-horizontal-tree (thread level
&optional dummyp adopted
)
714 "Generate a horizontal tree."
715 (let* ((dummy (stringp (car thread
)))
718 (memq (mail-header-number (car thread
))
722 ;; We don't want this article.
723 (setq thread
(cdr thread
))
725 ;; Not the first article on the line, so we insert a "-".
726 (insert (car gnus-tree-parent-child-edges
))
727 ;; If the level isn't zero, then we insert some indentation.
728 (unless (zerop level
)
729 (gnus-tree-indent level
)
730 (insert (cadr gnus-tree-parent-child-edges
))
731 (setq col
(- (setq beg
(point)) (point-at-bol) 1))
732 ;; Draw "|" lines upwards.
736 (eq (char-after) ?
))
738 (insert (caddr gnus-tree-parent-child-edges
)))
741 ;; Insert the article node.
742 (gnus-tree-node-insert (pop thread
) gnus-tmp-sparse adopted
))
744 ;; End of the thread, so we go to the next line.
747 ;; Recurse downwards in all children of this article.
749 (gnus-generate-horizontal-tree
750 (pop thread
) (if do
(1+ level
) level
)
751 (or dummyp dummy
) dummy
)))))
753 (defsubst gnus-tree-indent-vertical
()
754 (let ((len (- (* (1+ gnus-tree-node-length
) gnus-tmp-indent
)
755 (- (point) (point-at-bol)))))
757 (insert (make-string len ?
)))))
759 (defsubst gnus-tree-forward-line
(n)
760 (while (>= (decf n
) 0)
761 (unless (zerop (forward-line 1))
766 (defun gnus-generate-vertical-tree (thread level
&optional dummyp adopted
)
767 "Generate a vertical tree."
768 (let* ((dummy (stringp (car thread
)))
771 (memq (mail-header-number (car thread
))
775 ;; We don't want this article.
776 (setq thread
(cdr thread
))
777 (if (not (save-excursion (beginning-of-line) (bobp)))
778 ;; Not the first article on the line, so we insert a "-".
780 (gnus-tree-indent-vertical)
781 (insert (make-string (/ gnus-tree-node-length
2) ?
))
782 (insert (caddr gnus-tree-parent-child-edges
))
783 (gnus-tree-forward-line 1))
784 ;; If the level isn't zero, then we insert some indentation.
785 (unless (zerop gnus-tmp-indent
)
786 (gnus-tree-forward-line (1- (* 2 level
)))
787 (gnus-tree-indent-vertical)
789 (insert (cadr gnus-tree-parent-child-edges
))
792 ;; Draw "-" lines leftwards.
793 (while (and (not (bobp))
794 (eq (char-after (1- (point))) ?
))
796 (insert (car gnus-tree-parent-child-edges
))
799 (gnus-tree-forward-line 1)))
801 ;; Insert the article node.
802 (gnus-tree-indent-vertical)
803 (gnus-tree-node-insert (pop thread
) gnus-tmp-sparse adopted
)
804 (gnus-tree-forward-line 1))
806 ;; End of the thread, so we go to the next line.
808 (goto-char (point-min))
810 (incf gnus-tmp-indent
))
811 ;; Recurse downwards in all children of this article.
813 (gnus-generate-vertical-tree
814 (pop thread
) (if do
(1+ level
) level
)
815 (or dummyp dummy
) dummy
)))))
817 ;;; Interface functions.
819 (defun gnus-possibly-generate-tree (article &optional force
)
820 "Generate the thread tree for ARTICLE if it isn't displayed already."
821 (when (with-current-buffer gnus-summary-buffer
824 (vectorp (gnus-summary-article-header article
))))
826 (let ((top (with-current-buffer gnus-summary-buffer
830 (gnus-summary-article-header article
))
832 (gnus-tmp-limit gnus-newsgroup-limit
)
833 (gnus-tmp-sparse gnus-newsgroup-sparse
))
835 (not (eq top gnus-tree-displayed-thread
)))
836 (gnus-generate-tree top
)
837 (setq gnus-tree-displayed-thread top
))))))
839 (defun gnus-tree-open ()
840 (gnus-get-tree-buffer))
842 (defun gnus-tree-close ()
843 (gnus-kill-buffer gnus-tree-buffer
))
845 (defun gnus-tree-perhaps-minimize ()
846 (when (and gnus-tree-minimize-window
847 (get-buffer gnus-tree-buffer
))
848 (with-current-buffer gnus-tree-buffer
849 (gnus-tree-minimize))))
851 (defun gnus-highlight-selected-tree (article)
852 "Highlight the selected article in the tree."
853 (when (buffer-live-p gnus-tree-buffer
)
854 (let ((buf (current-buffer))
856 (set-buffer gnus-tree-buffer
)
857 (when (setq region
(gnus-tree-article-region article
))
858 (when (or (not gnus-selected-tree-overlay
)
859 (gnus-extent-detached-p gnus-selected-tree-overlay
))
860 ;; Create a new overlay.
862 (setq gnus-selected-tree-overlay
863 (make-overlay (point-min) (1+ (point-min))))
864 'face gnus-selected-tree-face
))
865 ;; Move the overlay to the article.
867 gnus-selected-tree-overlay
(goto-char (car region
)) (cdr region
))
870 (let ((selected (selected-window)))
871 (when (gnus-get-buffer-window (set-buffer gnus-tree-buffer
) t
)
873 (gnus-get-buffer-window (set-buffer gnus-tree-buffer
) t
))
874 (gnus-horizontal-recenter)
875 (select-window selected
))))
876 ;; If we remove this save-excursion, it updates the wrong mode lines?!?
877 (with-current-buffer gnus-tree-buffer
878 (gnus-set-mode-line 'tree
))
881 (defun gnus-tree-highlight-article (article face
)
882 ;; The save-excursion here is apparently necessary because
883 ;; `set-window-point' somehow manages to alter the buffer position.
885 (with-current-buffer (gnus-get-tree-buffer)
887 (when (setq region
(gnus-tree-article-region article
))
888 (gnus-put-text-property (car region
) (cdr region
) 'face face
)
890 (gnus-get-buffer-window (current-buffer) t
) (cdr region
)))))))
892 ;;; Allow redefinition of functions.
897 ;;; gnus-salt.el ends here