]> code.delx.au - gnu-emacs/blob - lisp/gnus/gnus-salt.el
Remove obsolete leading * from defcustom, defface doc strings.
[gnu-emacs] / lisp / gnus / gnus-salt.el
1 ;;; gnus-salt.el --- alternate summary mode interfaces for Gnus
2
3 ;; Copyright (C) 1996-1999, 2001-2016 Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
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.
14
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.
19
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/>.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 (eval-when-compile (require 'cl))
28
29 (require 'gnus)
30 (require 'gnus-sum)
31 (require 'gnus-win)
32
33 ;;;
34 ;;; gnus-pick-mode
35 ;;;
36
37 (defcustom gnus-pick-display-summary nil
38 "Display summary while reading."
39 :type 'boolean
40 :group 'gnus-summary-pick)
41
42 (defcustom gnus-pick-mode-hook nil
43 "Hook run in summary pick mode buffers."
44 :type 'hook
45 :group 'gnus-summary-pick)
46
47 (defcustom gnus-mark-unpicked-articles-as-read nil
48 "If non-nil, mark all unpicked articles as read."
49 :type 'boolean
50 :group 'gnus-summary-pick)
51
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."
55 :type 'boolean
56 :group 'gnus-summary-pick)
57
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."
62 :type 'string
63 :group 'gnus-summary-pick)
64
65 ;;; Internal variables.
66
67 (defvar gnus-pick-mode-map
68 (let ((map (make-sparse-keymap)))
69 (gnus-define-keys map
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)
75 map))
76
77 (defun gnus-pick-make-menu-bar ()
78 (unless (boundp 'gnus-pick-menu)
79 (easy-menu-define
80 gnus-pick-menu gnus-pick-mode-map ""
81 '("Pick"
82 ("Pick"
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])
88 ("Unpick"
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]))))
96
97 (define-minor-mode gnus-pick-mode
98 "Minor mode for providing a pick-and-read interface in Gnus summary buffers.
99
100 \\{gnus-pick-mode-map}"
101 :lighter " Pick" :keymap gnus-pick-mode-map
102 (cond
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))
107 (t
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)
118 ;; Set up the menu.
119 (when (gnus-visual-p 'pick-menu 'menu)
120 (gnus-pick-make-menu-bar)))))
121
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
126 gnus-pick-mode))
127 (message-add-action
128 `(gnus-configure-windows ,gnus-current-window-configuration t)
129 'send 'exit 'postpone 'kill)))
130
131 (defvar gnus-pick-line-number 1)
132 (defun gnus-pick-line-number ()
133 "Return the current line number."
134 (if (bobp)
135 (setq gnus-pick-line-number 1)
136 (incf gnus-pick-line-number)))
137
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."
141 (interactive "P")
142 (if gnus-newsgroup-processable
143 (progn
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
151 (progn
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)
155 (gnus-summary-exit)
156 (gnus-summary-next-group)))
157 (error "No articles have been picked"))))
158
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."
162 (let (pos)
163 (save-excursion
164 (goto-char (point-min))
165 (when (zerop (forward-line (1- (prefix-numeric-value arg))))
166 (setq pos (point))))
167 (if (not pos)
168 (gnus-error 2 "No such line: %s" arg)
169 (goto-char pos))))
170
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."
174 (interactive "P")
175 (when arg
176 (gnus-pick-goto-article arg))
177 (gnus-summary-mark-as-processable 1))
178
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."
183 (interactive "P")
184 (when arg
185 (gnus-pick-goto-article arg))
186 (if gnus-thread-hide-subtree
187 (progn
188 (save-excursion
189 (gnus-uu-mark-thread))
190 (forward-line 1))
191 (gnus-summary-mark-as-processable 1)))
192
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."
197 (interactive "P")
198 (when arg
199 (gnus-pick-goto-article arg))
200 (if gnus-thread-hide-subtree
201 (save-excursion
202 (gnus-uu-unmark-thread))
203 (gnus-summary-unmark-as-processable 1)))
204
205 (defun gnus-pick-mouse-pick (e)
206 (interactive "e")
207 (mouse-set-point e)
208 (save-excursion
209 (gnus-summary-mark-as-processable 1)))
210
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."
214 (interactive "e")
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))
222 (top (nth 1 bounds))
223 (bottom (if (window-minibuffer-p start-window)
224 (nth 3 bounds)
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))
235 (gnus-pick-article)
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)))
241 (track-mouse
242 (while (progn
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)
247 nil
248 (setq end (event-end event)
249 end-point (posn-point end))
250
251 (cond
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)
260 (gnus-pick-article)
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))
269 (gnus-pick-article)
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))))
274 (t
275 (let ((mouse-row (cdr (cdr (mouse-position)))))
276 (cond
277 ((null mouse-row))
278 ((< mouse-row top)
279 (mouse-scroll-subr start-window (- mouse-row top)))
280 ((>= mouse-row bottom)
281 (mouse-scroll-subr start-window
282 (1+ (- mouse-row bottom)))))))))))
283 (when (consp event)
284 (let (;; (fun (key-binding (vector (car event))))
285 )
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.
289 (when nil
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
295 ;; buffer.
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))))))))
300
301 (defvar scroll-in-place)
302
303 (defun gnus-pick-next-page ()
304 "Go to the next page. If at the end of the buffer, start reading articles."
305 (interactive)
306 (let ((scroll-in-place nil))
307 (condition-case nil
308 (scroll-up)
309 (end-of-buffer (gnus-pick-start-reading)))))
310
311 ;;;
312 ;;; gnus-binary-mode
313 ;;;
314
315 (defvar gnus-binary-mode-hook nil
316 "Hook run in summary binary mode buffers.")
317
318 (defvar gnus-binary-mode-map
319 (let ((map (make-sparse-keymap)))
320 (gnus-define-keys map
321 "g" gnus-binary-show-article)
322 map))
323
324 (defun gnus-binary-make-menu-bar ()
325 (unless (boundp 'gnus-binary-menu)
326 (easy-menu-define
327 gnus-binary-menu gnus-binary-mode-map ""
328 '("Pick"
329 ["Switch binary mode off" gnus-binary-mode t]))))
330
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
334 (cond
335 ((not (derived-mode-p 'gnus-summary-mode)) (setq gnus-binary-mode nil))
336 (gnus-binary-mode
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)
342 ;; Set up the menu.
343 (when (gnus-visual-p 'binary-menu 'menu)
344 (gnus-binary-make-menu-bar)))))
345
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))))
351
352 (defun gnus-binary-show-article (&optional arg)
353 "Bypass the binary functions and show the article."
354 (interactive "P")
355 (let (gnus-summary-display-article-function)
356 (gnus-summary-show-article arg)))
357
358 ;;;
359 ;;; gnus-tree-mode
360 ;;;
361
362 (defcustom gnus-tree-line-format "%(%[%3,3n%]%)"
363 "Format of tree elements."
364 :type 'string
365 :group 'gnus-summary-tree)
366
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
370 lines."
371 :type '(choice boolean
372 integer)
373 :group 'gnus-summary-tree)
374
375 (defcustom gnus-selected-tree-face 'mode-line
376 "Face used for highlighting selected articles in the thread tree."
377 :type 'face
378 :group 'gnus-summary-tree)
379
380 (defvar gnus-tree-brackets '((?\[ . ?\]) (?\( . ?\))
381 (?\{ . ?\}) (?< . ?>))
382 "Brackets used in tree nodes.")
383
384 (defvar gnus-tree-parent-child-edges '(?- ?\\ ?|)
385 "Characters used to connect parents with children.")
386
387 (defcustom gnus-tree-mode-line-format "Gnus: %%b %S %Z"
388 "The format specification for the tree mode line."
389 :type 'string
390 :group 'gnus-summary-tree)
391
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)
400
401 (defcustom gnus-tree-mode-hook nil
402 "Hook run in tree mode buffers."
403 :type 'hook
404 :group 'gnus-summary-tree)
405
406 ;;; Internal variables.
407
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)
414
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)))
422
423 (defvar gnus-tree-mode-line-format-alist gnus-summary-mode-line-format-alist)
424
425 (defvar gnus-tree-mode-line-format-spec nil)
426 (defvar gnus-tree-line-format-spec nil)
427
428 (defvar gnus-tree-node-length nil)
429 (defvar gnus-selected-tree-overlay nil)
430
431 (defvar gnus-tree-displayed-thread nil)
432 (defvar gnus-tree-inhibit nil)
433
434 (defvar gnus-tree-mode-map
435 (let ((map (make-keymap)))
436 (suppress-keymap map)
437 (gnus-define-keys
438 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
443
444 "\C-c\C-i" gnus-info-find-node)
445
446 (substitute-key-definition
447 'undefined 'gnus-tree-read-summary-keys map)
448 map))
449
450 (put 'gnus-tree-mode 'mode-class 'special)
451
452 (defun gnus-tree-make-menu-bar ()
453 (unless (boundp 'gnus-tree-menu)
454 (easy-menu-define
455 gnus-tree-menu gnus-tree-mode-map ""
456 '("Tree"
457 ["Select article" gnus-tree-select-article t]))))
458
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)
469 (save-current-buffer
470 (gnus-set-work-buffer)
471 (gnus-tree-node-insert (make-mail-header "") nil)
472 (setq gnus-tree-node-length (1- (point)))))
473
474 (defun gnus-tree-read-summary-keys (&optional arg)
475 "Read a summary buffer key sequence and execute it."
476 (interactive "P")
477 (unless gnus-tree-inhibit
478 (let ((buf (current-buffer))
479 (gnus-tree-inhibit t)
480 win)
481 (set-buffer gnus-article-buffer)
482 (gnus-article-read-summary-keys arg nil t)
483 (when (setq win (get-buffer-window buf))
484 (select-window win)
485 (when gnus-selected-tree-overlay
486 (goto-char (or (overlay-end gnus-selected-tree-overlay) 1)))
487 (gnus-tree-minimize)))))
488
489 (defun gnus-tree-show-summary ()
490 "Reconfigure windows to show summary buffer."
491 (interactive)
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)))
496
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)))
501 (when article
502 (with-current-buffer gnus-summary-buffer
503 (gnus-summary-goto-article article))
504 (select-window (get-buffer-window buf)))))
505
506 (defun gnus-tree-pick-article (e)
507 "Select the article under the mouse pointer."
508 (interactive "e")
509 (mouse-set-point e)
510 (gnus-tree-select-article (gnus-tree-article-number)))
511
512 (defun gnus-tree-article-number ()
513 (get-text-property (point) 'gnus-number))
514
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)))
519 (when pos
520 (cons pos (next-single-property-change pos 'gnus-number)))))
521
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)))
526 (when tree-window
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)
532 (t 2)))
533 (height (1- (window-height)))
534 (bottom (save-excursion (goto-char (point-max))
535 (forward-line (- height))
536 (point))))
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.
540 (set-window-start
541 tree-window (min bottom (save-excursion
542 (forward-line (- top)) (point)))))
543 (select-window selected))))
544
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)
549 (gnus-tree-mode))
550 (current-buffer)))
551
552 (defun gnus-tree-minimize ()
553 (when (and gnus-tree-minimize-window
554 (not (one-window-p)))
555 (let ((windows 0)
556 tot-win-height)
557 (walk-windows (lambda (_window) (incf windows)))
558 (setq tot-win-height
559 (- (frame-height)
560 (* window-min-height (1- windows))
561 2))
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)
567 min))
568 (win (get-buffer-window (current-buffer)))
569 (wh (and win (1- (window-height win)))))
570 (setq tot (min tot tot-win-height))
571 (when (and win
572 (not (eq tot wh)))
573 (let ((selected (selected-window)))
574 (when (ignore-errors (select-window win))
575 (enlarge-window (- tot wh))
576 (select-window selected))))))))
577
578 ;;; Generating the tree.
579
580 (defun gnus-tree-node-insert (header sparse &optional adopted)
581 (let* ((dummy (stringp header))
582 (header (if (vectorp header) header
583 (progn
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)
588 header)))
589 (gnus-tmp-from (mail-header-from header))
590 (gnus-tmp-subject (mail-header-subject header))
591 (gnus-tmp-number (mail-header-number header))
592 (gnus-tmp-name
593 (cond
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))
601 (1- (match-end 0))))
602 (substring gnus-tmp-from 0 beg))))
603 ((memq gnus-tmp-number sparse)
604 "***")
605 (t gnus-tmp-from)))
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)))
616 (dummy
617 (cdaddr gnus-tree-brackets))
618 (t (cdar gnus-tree-brackets))))
619 (buffer-read-only nil)
620 beg end)
621 (add-text-properties
622 (setq beg (point))
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))))
627
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)))
638 bindings)))
639 (,evalsym (lambda (exp) (eval exp env))))
640 ,@body)
641 `(let (,@bindings (,evalsym #'eval)) ,@body)))
642
643 (defun gnus-tree-highlight-node (article beg end)
644 "Highlight current line according to `gnus-summary-highlight'."
645 (let ((list gnus-summary-highlight)
646 face)
647 (with-current-buffer gnus-summary-buffer
648 (let ((uncached (memq article gnus-newsgroup-undownloaded)))
649 (gnus--let-eval
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)
655 (uncached uncached)
656 (downloaded (not uncached))
657 (mark (or (gnus-summary-article-mark article) gnus-unread-mark)))
658 evalfun
659 ;; Eval the cars of the lists until we find a match.
660 (while (and list
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
665 beg end 'face
666 (if (boundp face) (symbol-value face) face)))))
667
668 (defun gnus-tree-indent (level)
669 (insert (make-string (1- (* (1+ gnus-tree-node-length) level)) ? )))
670
671 (defvar gnus-tmp-limit)
672 (defvar gnus-tmp-sparse)
673 (defvar gnus-tmp-indent)
674
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)
679 (gnus-tmp-indent 0))
680 (erase-buffer)
681 (funcall gnus-generate-tree-function thread 0)
682 (gnus-set-mode-line 'tree)
683 (goto-char (point-min))
684 (gnus-tree-minimize)
685 (gnus-tree-recenter)
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))))))
691
692 (defun gnus-generate-horizontal-tree (thread level &optional dummyp adopted)
693 "Generate a horizontal tree."
694 (let* ((dummy (stringp (car thread)))
695 (do (or dummy
696 (and (car thread)
697 (memq (mail-header-number (car thread))
698 gnus-tmp-limit))))
699 col beg)
700 (if (not do)
701 ;; We don't want this article.
702 (setq thread (cdr thread))
703 (if (not (bolp))
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.
712 (while (progn
713 (forward-line -1)
714 (forward-char col)
715 (eq (char-after) ? ))
716 (delete-char 1)
717 (insert (caddr gnus-tree-parent-child-edges)))
718 (goto-char beg)))
719 (setq dummyp nil)
720 ;; Insert the article node.
721 (gnus-tree-node-insert (pop thread) gnus-tmp-sparse adopted))
722 (if (null thread)
723 ;; End of the thread, so we go to the next line.
724 (unless (bolp)
725 (insert "\n"))
726 ;; Recurse downwards in all children of this article.
727 (while thread
728 (gnus-generate-horizontal-tree
729 (pop thread) (if do (1+ level) level)
730 (or dummyp dummy) dummy)))))
731
732 (defsubst gnus-tree-indent-vertical ()
733 (let ((len (- (* (1+ gnus-tree-node-length) gnus-tmp-indent)
734 (- (point) (point-at-bol)))))
735 (when (> len 0)
736 (insert (make-string len ? )))))
737
738 (defsubst gnus-tree-forward-line (n)
739 (while (>= (decf n) 0)
740 (unless (zerop (forward-line 1))
741 (end-of-line)
742 (insert "\n")))
743 (end-of-line))
744
745 (defun gnus-generate-vertical-tree (thread level &optional dummyp adopted)
746 "Generate a vertical tree."
747 (let* ((dummy (stringp (car thread)))
748 (do (or dummy
749 (and (car thread)
750 (memq (mail-header-number (car thread))
751 gnus-tmp-limit))))
752 beg)
753 (if (not do)
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 "-".
758 (progn
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)
767 (delete-char -1)
768 (insert (cadr gnus-tree-parent-child-edges))
769 (setq beg (point))
770 (forward-char -1)
771 ;; Draw "-" lines leftwards.
772 (while (and (not (bobp))
773 (eq (char-after (1- (point))) ? ))
774 (delete-char -1)
775 (insert (car gnus-tree-parent-child-edges))
776 (forward-char -1))
777 (goto-char beg)
778 (gnus-tree-forward-line 1)))
779 (setq dummyp nil)
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))
784 (if (null thread)
785 ;; End of the thread, so we go to the next line.
786 (progn
787 (goto-char (point-min))
788 (end-of-line)
789 (incf gnus-tmp-indent))
790 ;; Recurse downwards in all children of this article.
791 (while thread
792 (gnus-generate-vertical-tree
793 (pop thread) (if do (1+ level) level)
794 (or dummyp dummy) dummy)))))
795
796 ;;; Interface functions.
797
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
801 (and gnus-use-trees
802 gnus-show-threads
803 (vectorp (gnus-summary-article-header article))))
804 (save-excursion
805 (let ((top (with-current-buffer gnus-summary-buffer
806 (gnus-cut-thread
807 (gnus-remove-thread
808 (mail-header-id
809 (gnus-summary-article-header article))
810 t))))
811 (gnus-tmp-limit gnus-newsgroup-limit)
812 (gnus-tmp-sparse gnus-newsgroup-sparse))
813 (when (or force
814 (not (eq top gnus-tree-displayed-thread)))
815 (gnus-generate-tree top)
816 (setq gnus-tree-displayed-thread top))))))
817
818 (defun gnus-tree-open ()
819 (gnus-get-tree-buffer))
820
821 (defun gnus-tree-close ()
822 (gnus-kill-buffer gnus-tree-buffer))
823
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))))
829
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))
834 region)
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.
839 (overlay-put
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.
844 (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))))
858
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.
862 (save-excursion
863 (with-current-buffer (gnus-get-tree-buffer)
864 (let (region)
865 (when (setq region (gnus-tree-article-region article))
866 (put-text-property (car region) (cdr region) 'face face)
867 (set-window-point
868 (gnus-get-buffer-window (current-buffer) t) (cdr region)))))))
869
870 (provide 'gnus-salt)
871
872 ;;; gnus-salt.el ends here