* net/shr.el (shr-browse-url): Use an external browser if given a prefix.
[emacs.git] / lisp / gnus / gnus-salt.el
blob6b8e105e6b899580d87ee85cb7b1479fadfc9a3e
1 ;;; gnus-salt.el --- alternate summary mode interfaces for Gnus
3 ;; Copyright (C) 1996-1999, 2001-2013 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
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/>.
23 ;;; Commentary:
25 ;;; Code:
27 (eval-when-compile (require 'cl))
28 (eval-when-compile
29 (when (featurep 'xemacs)
30 (require 'easy-mmode))) ; for `define-minor-mode'
32 (require 'gnus)
33 (require 'gnus-sum)
34 (require 'gnus-win)
36 ;;;
37 ;;; gnus-pick-mode
38 ;;;
40 (defcustom gnus-pick-display-summary nil
41 "*Display summary while reading."
42 :type 'boolean
43 :group 'gnus-summary-pick)
45 (defcustom gnus-pick-mode-hook nil
46 "Hook run in summary pick mode buffers."
47 :type 'hook
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."
55 :type 'boolean
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."
61 :type 'boolean
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."
68 :type 'string
69 :group 'gnus-summary-pick)
71 ;;; Internal variables.
73 (defvar gnus-pick-mode-map
74 (let ((map (make-sparse-keymap)))
75 (gnus-define-keys map
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)
81 map))
83 (defun gnus-pick-make-menu-bar ()
84 (unless (boundp 'gnus-pick-menu)
85 (easy-menu-define
86 gnus-pick-menu gnus-pick-mode-map ""
87 '("Pick"
88 ("Pick"
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])
94 ("Unpick"
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]))))
103 (eval-when-compile
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
113 (cond
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)
129 ;; Set up the menu.
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
137 gnus-pick-mode))
138 (message-add-action
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."
145 (if (bobp)
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."
152 (interactive "P")
153 (if gnus-newsgroup-processable
154 (progn
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
162 (progn
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)
166 (gnus-summary-exit)
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."
173 (let (pos)
174 (save-excursion
175 (goto-char (point-min))
176 (when (zerop (forward-line (1- (prefix-numeric-value arg))))
177 (setq pos (point))))
178 (if (not pos)
179 (gnus-error 2 "No such line: %s" arg)
180 (goto-char pos))))
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."
185 (interactive "P")
186 (when arg
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."
194 (interactive "P")
195 (when arg
196 (gnus-pick-goto-article arg))
197 (if gnus-thread-hide-subtree
198 (progn
199 (save-excursion
200 (gnus-uu-mark-thread))
201 (forward-line 1))
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."
208 (interactive "P")
209 (when arg
210 (gnus-pick-goto-article arg))
211 (if gnus-thread-hide-subtree
212 (save-excursion
213 (gnus-uu-unmark-thread))
214 (gnus-summary-unmark-as-processable 1)))
216 (defun gnus-pick-mouse-pick (e)
217 (interactive "e")
218 (mouse-set-point e)
219 (save-excursion
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."
225 (interactive "e")
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))
233 (top (nth 1 bounds))
234 (bottom (if (window-minibuffer-p start-window)
235 (nth 3 bounds)
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))
246 (gnus-pick-article)
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)))
252 (track-mouse
253 (while (progn
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))
262 (cond
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)
271 (gnus-pick-article)
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))
280 (gnus-pick-article)
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)))))
287 (cond
288 ((null mouse-row))
289 ((< mouse-row top)
290 (mouse-scroll-subr start-window (- mouse-row top)))
291 ((>= mouse-row bottom)
292 (mouse-scroll-subr start-window
293 (1+ (- mouse-row bottom)))))))))))
294 (when (consp event)
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.
299 (when nil
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
305 ;; buffer.
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."
313 (interactive)
314 (let ((scroll-in-place nil))
315 (condition-case nil
316 (scroll-up)
317 (end-of-buffer (gnus-pick-start-reading)))))
320 ;;; gnus-binary-mode
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)
330 map))
332 (defun gnus-binary-make-menu-bar ()
333 (unless (boundp 'gnus-binary-menu)
334 (easy-menu-define
335 gnus-binary-menu gnus-binary-mode-map ""
336 '("Pick"
337 ["Switch binary mode off" gnus-binary-mode t]))))
339 (eval-when-compile
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
347 (cond
348 ((not (derived-mode-p 'gnus-summary-mode)) (setq gnus-binary-mode nil))
349 (gnus-binary-mode
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)
355 ;; Set up the menu.
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."
367 (interactive "P")
368 (let (gnus-summary-display-article-function)
369 (gnus-summary-show-article arg)))
372 ;;; gnus-tree-mode
375 (defcustom gnus-tree-line-format "%(%[%3,3n%]%)"
376 "Format of tree elements."
377 :type 'string
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
383 lines."
384 :type '(choice boolean
385 integer)
386 :group 'gnus-summary-tree)
388 (defcustom gnus-selected-tree-face 'mode-line
389 "*Face used for highlighting selected articles in the thread tree."
390 :type 'face
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."
402 :type 'string
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."
416 :type 'hook
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)
451 (gnus-define-keys
452 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)
465 (easy-menu-define
466 gnus-tree-menu gnus-tree-mode-map ""
467 '("Tree"
468 ["Select article" gnus-tree-select-article t]))))
470 (defun gnus-tree-mode ()
471 "Major mode for displaying thread trees."
472 (interactive)
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)
485 (save-excursion
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."
493 (interactive "P")
494 (unless gnus-tree-inhibit
495 (let ((buf (current-buffer))
496 (gnus-tree-inhibit t)
497 win)
498 (set-buffer gnus-article-buffer)
499 (gnus-article-read-summary-keys arg nil t)
500 (when (setq win (get-buffer-window buf))
501 (select-window win)
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."
508 (interactive)
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)))
518 (when article
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."
525 (interactive "e")
526 (mouse-set-point e)
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)))
536 (when pos
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)))
543 (when tree-window
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)
549 (t 2)))
550 (height (1- (window-height)))
551 (bottom (save-excursion (goto-char (point-max))
552 (forward-line (- height))
553 (point))))
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.
557 (set-window-start
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)
566 (gnus-tree-mode))
567 (current-buffer)))
569 (defun gnus-tree-minimize ()
570 (when (and gnus-tree-minimize-window
571 (not (one-window-p)))
572 (let ((windows 0)
573 tot-win-height)
574 (walk-windows (lambda (window) (incf windows)))
575 (setq tot-win-height
576 (- (frame-height)
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)
584 min))
585 (win (get-buffer-window (current-buffer)))
586 (wh (and win (1- (window-height win)))))
587 (setq tot (min tot tot-win-height))
588 (when (and win
589 (not (eq tot wh)))
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
600 (progn
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)
605 header)))
606 (gnus-tmp-from (mail-header-from header))
607 (gnus-tmp-subject (mail-header-subject header))
608 (gnus-tmp-number (mail-header-number header))
609 (gnus-tmp-name
610 (cond
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))
618 (1- (match-end 0))))
619 (substring gnus-tmp-from 0 beg))))
620 ((memq gnus-tmp-number sparse)
621 "***")
622 (t gnus-tmp-from)))
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)))
633 (dummy
634 (cdaddr gnus-tree-brackets))
635 (t (cdar gnus-tree-brackets))))
636 (buffer-read-only nil)
637 beg end)
638 (gnus-add-text-properties
639 (setq beg (point))
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)
648 face)
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.
659 (while (and list
660 (not (eval (caar list))))
661 (setq list (cdr list)))))
662 (unless (eq (setq face (cdar list)) (gnus-get-text-property-excluding-characters-with-faces beg 'face))
663 (gnus-put-text-property-excluding-characters-with-faces
664 beg end 'face
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)
678 (gnus-tmp-indent 0))
679 (erase-buffer)
680 (funcall gnus-generate-tree-function thread 0)
681 (gnus-set-mode-line 'tree)
682 (goto-char (point-min))
683 (gnus-tree-minimize)
684 (gnus-tree-recenter)
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)))
694 (do (or dummy
695 (and (car thread)
696 (memq (mail-header-number (car thread))
697 gnus-tmp-limit))))
698 col beg)
699 (if (not do)
700 ;; We don't want this article.
701 (setq thread (cdr thread))
702 (if (not (bolp))
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.
711 (while (progn
712 (forward-line -1)
713 (forward-char col)
714 (eq (char-after) ? ))
715 (delete-char 1)
716 (insert (caddr gnus-tree-parent-child-edges)))
717 (goto-char beg)))
718 (setq dummyp nil)
719 ;; Insert the article node.
720 (gnus-tree-node-insert (pop thread) gnus-tmp-sparse adopted))
721 (if (null thread)
722 ;; End of the thread, so we go to the next line.
723 (unless (bolp)
724 (insert "\n"))
725 ;; Recurse downwards in all children of this article.
726 (while thread
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)))))
734 (when (> len 0)
735 (insert (make-string len ? )))))
737 (defsubst gnus-tree-forward-line (n)
738 (while (>= (decf n) 0)
739 (unless (zerop (forward-line 1))
740 (end-of-line)
741 (insert "\n")))
742 (end-of-line))
744 (defun gnus-generate-vertical-tree (thread level &optional dummyp adopted)
745 "Generate a vertical tree."
746 (let* ((dummy (stringp (car thread)))
747 (do (or dummy
748 (and (car thread)
749 (memq (mail-header-number (car thread))
750 gnus-tmp-limit))))
751 beg)
752 (if (not do)
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 "-".
757 (progn
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)
766 (delete-char -1)
767 (insert (cadr gnus-tree-parent-child-edges))
768 (setq beg (point))
769 (forward-char -1)
770 ;; Draw "-" lines leftwards.
771 (while (and (not (bobp))
772 (eq (char-after (1- (point))) ? ))
773 (delete-char -1)
774 (insert (car gnus-tree-parent-child-edges))
775 (forward-char -1))
776 (goto-char beg)
777 (gnus-tree-forward-line 1)))
778 (setq dummyp nil)
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))
783 (if (null thread)
784 ;; End of the thread, so we go to the next line.
785 (progn
786 (goto-char (point-min))
787 (end-of-line)
788 (incf gnus-tmp-indent))
789 ;; Recurse downwards in all children of this article.
790 (while thread
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
800 (and gnus-use-trees
801 gnus-show-threads
802 (vectorp (gnus-summary-article-header article))))
803 (save-excursion
804 (let ((top (with-current-buffer gnus-summary-buffer
805 (gnus-cut-thread
806 (gnus-remove-thread
807 (mail-header-id
808 (gnus-summary-article-header article))
809 t))))
810 (gnus-tmp-limit gnus-newsgroup-limit)
811 (gnus-tmp-sparse gnus-newsgroup-sparse))
812 (when (or force
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 (when (buffer-live-p gnus-tree-buffer)
832 (let ((buf (current-buffer))
833 region)
834 (set-buffer gnus-tree-buffer)
835 (when (setq region (gnus-tree-article-region article))
836 (when (or (not gnus-selected-tree-overlay)
837 (gnus-extent-detached-p gnus-selected-tree-overlay))
838 ;; Create a new overlay.
839 (gnus-overlay-put
840 (setq gnus-selected-tree-overlay
841 (gnus-make-overlay (point-min) (1+ (point-min))))
842 'face gnus-selected-tree-face))
843 ;; Move the overlay to the article.
844 (gnus-move-overlay
845 gnus-selected-tree-overlay (goto-char (car region)) (cdr region))
846 (gnus-tree-minimize)
847 (gnus-tree-recenter)
848 (let ((selected (selected-window)))
849 (when (gnus-get-buffer-window (set-buffer gnus-tree-buffer) t)
850 (select-window
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))
857 (set-buffer buf))))
859 (defun gnus-tree-highlight-article (article face)
860 (with-current-buffer (gnus-get-tree-buffer)
861 (let (region)
862 (when (setq region (gnus-tree-article-region article))
863 (gnus-put-text-property (car region) (cdr region) 'face face)
864 (set-window-point
865 (gnus-get-buffer-window (current-buffer) t) (cdr region))))))
867 ;;; Allow redefinition of functions.
868 (gnus-ems-redefine)
870 (provide 'gnus-salt)
872 ;;; gnus-salt.el ends here