Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-151
[bpt/emacs.git] / lisp / gnus / gnus-salt.el
1 ;;; gnus-salt.el --- alternate summary mode interfaces for Gnus
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2001
4 ;; Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (eval-when-compile (require 'cl))
31
32 (require 'gnus)
33 (require 'gnus-sum)
34 (require 'gnus-win)
35
36 ;;;
37 ;;; gnus-pick-mode
38 ;;;
39
40 (defvar gnus-pick-mode nil
41 "Minor mode for providing a pick-and-read interface in Gnus
42 summary buffers.")
43
44 (defcustom gnus-pick-display-summary nil
45 "*Display summary while reading."
46 :type 'boolean
47 :group 'gnus-summary-pick)
48
49 (defcustom gnus-pick-mode-hook nil
50 "Hook run in summary pick mode buffers."
51 :type 'hook
52 :group 'gnus-summary-pick)
53
54 (when (featurep 'xemacs)
55 (add-hook 'gnus-pick-mode-hook 'gnus-xmas-pick-menu-add))
56
57 (defcustom gnus-mark-unpicked-articles-as-read nil
58 "*If non-nil, mark all unpicked articles as read."
59 :type 'boolean
60 :group 'gnus-summary-pick)
61
62 (defcustom gnus-pick-elegant-flow t
63 "If non-nil, `gnus-pick-start-reading' runs
64 `gnus-summary-next-group' when no articles have been picked."
65 :type 'boolean
66 :group 'gnus-summary-pick)
67
68 (defcustom gnus-summary-pick-line-format
69 "%-5P %U\%R\%z\%I\%(%[%4L: %-23,23n%]%) %s\n"
70 "*The format specification of the lines in pick buffers.
71 It accepts the same format specs that `gnus-summary-line-format' does."
72 :type 'string
73 :group 'gnus-summary-pick)
74
75 ;;; Internal variables.
76
77 (defvar gnus-pick-mode-map nil)
78
79 (unless gnus-pick-mode-map
80 (setq gnus-pick-mode-map (make-sparse-keymap))
81
82 (gnus-define-keys gnus-pick-mode-map
83 " " gnus-pick-next-page
84 "u" gnus-pick-unmark-article-or-thread
85 "." gnus-pick-article-or-thread
86 gnus-down-mouse-2 gnus-pick-mouse-pick-region
87 "\r" gnus-pick-start-reading))
88
89 (defun gnus-pick-make-menu-bar ()
90 (unless (boundp 'gnus-pick-menu)
91 (easy-menu-define
92 gnus-pick-menu gnus-pick-mode-map ""
93 '("Pick"
94 ("Pick"
95 ["Article" gnus-summary-mark-as-processable t]
96 ["Thread" gnus-uu-mark-thread t]
97 ["Region" gnus-uu-mark-region t]
98 ["Regexp" gnus-uu-mark-by-regexp t]
99 ["Buffer" gnus-uu-mark-buffer t])
100 ("Unpick"
101 ["Article" gnus-summary-unmark-as-processable t]
102 ["Thread" gnus-uu-unmark-thread t]
103 ["Region" gnus-uu-unmark-region t]
104 ["Regexp" gnus-uu-unmark-by-regexp t]
105 ["Buffer" gnus-summary-unmark-all-processable t])
106 ["Start reading" gnus-pick-start-reading t]
107 ["Switch pick mode off" gnus-pick-mode gnus-pick-mode]))))
108
109 (defun gnus-pick-mode (&optional arg)
110 "Minor mode for providing a pick-and-read interface in Gnus summary buffers.
111
112 \\{gnus-pick-mode-map}"
113 (interactive "P")
114 (when (eq major-mode 'gnus-summary-mode)
115 (if (not (set (make-local-variable 'gnus-pick-mode)
116 (if (null arg) (not gnus-pick-mode)
117 (> (prefix-numeric-value arg) 0))))
118 (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 (add-hook 'gnus-message-setup-hook 'gnus-pick-setup-message)
127 (set (make-local-variable 'gnus-summary-goto-unread) 'never)
128 ;; Set up the menu.
129 (when (gnus-visual-p 'pick-menu 'menu)
130 (gnus-pick-make-menu-bar))
131 (gnus-add-minor-mode 'gnus-pick-mode " Pick" gnus-pick-mode-map
132 nil 'gnus-pick-mode)
133 (gnus-run-hooks 'gnus-pick-mode-hook))))
134
135 (defun gnus-pick-setup-message ()
136 "Make Message do the right thing on exit."
137 (when (and (gnus-buffer-live-p gnus-summary-buffer)
138 (save-excursion
139 (set-buffer gnus-summary-buffer)
140 gnus-pick-mode))
141 (message-add-action
142 '(gnus-configure-windows ,gnus-current-window-configuration t)
143 'send 'exit 'postpone 'kill)))
144
145 (defvar gnus-pick-line-number 1)
146 (defun gnus-pick-line-number ()
147 "Return the current line number."
148 (if (bobp)
149 (setq gnus-pick-line-number 1)
150 (incf gnus-pick-line-number)))
151
152 (defun gnus-pick-start-reading (&optional catch-up)
153 "Start reading the picked articles.
154 If given a prefix, mark all unpicked articles as read."
155 (interactive "P")
156 (if gnus-newsgroup-processable
157 (progn
158 (gnus-summary-limit-to-articles nil)
159 (when (or catch-up gnus-mark-unpicked-articles-as-read)
160 (gnus-summary-limit-mark-excluded-as-read))
161 (gnus-summary-first-article)
162 (gnus-configure-windows
163 (if gnus-pick-display-summary 'article 'pick) t))
164 (if gnus-pick-elegant-flow
165 (progn
166 (when (or catch-up gnus-mark-unpicked-articles-as-read)
167 (gnus-summary-catchup nil t))
168 (if (gnus-group-quit-config gnus-newsgroup-name)
169 (gnus-summary-exit)
170 (gnus-summary-next-group)))
171 (error "No articles have been picked"))))
172
173 (defun gnus-pick-goto-article (arg)
174 "Go to the article number indicated by ARG.
175 If ARG is an invalid article number, then stay on current line."
176 (let (pos)
177 (save-excursion
178 (goto-char (point-min))
179 (when (zerop (forward-line (1- (prefix-numeric-value arg))))
180 (setq pos (point))))
181 (if (not pos)
182 (gnus-error 2 "No such line: %s" arg)
183 (goto-char pos))))
184
185 (defun gnus-pick-article (&optional arg)
186 "Pick the article on the current line.
187 If ARG, pick the article on that line instead."
188 (interactive "P")
189 (when arg
190 (gnus-pick-goto-article arg))
191 (gnus-summary-mark-as-processable 1))
192
193 (defun gnus-pick-article-or-thread (&optional arg)
194 "If `gnus-thread-hide-subtree' is t, then pick the thread on the current line.
195 Otherwise pick the article on the current line.
196 If ARG, pick the article/thread on that line instead."
197 (interactive "P")
198 (when arg
199 (gnus-pick-goto-article arg))
200 (if gnus-thread-hide-subtree
201 (progn
202 (save-excursion
203 (gnus-uu-mark-thread))
204 (forward-line 1))
205 (gnus-summary-mark-as-processable 1)))
206
207 (defun gnus-pick-unmark-article-or-thread (&optional arg)
208 "If `gnus-thread-hide-subtree' is t, then unmark the thread on current line.
209 Otherwise unmark the article on current line.
210 If ARG, unmark thread/article on that line instead."
211 (interactive "P")
212 (when arg
213 (gnus-pick-goto-article arg))
214 (if gnus-thread-hide-subtree
215 (save-excursion
216 (gnus-uu-unmark-thread))
217 (gnus-summary-unmark-as-processable 1)))
218
219 (defun gnus-pick-mouse-pick (e)
220 (interactive "e")
221 (mouse-set-point e)
222 (save-excursion
223 (gnus-summary-mark-as-processable 1)))
224
225 (defun gnus-pick-mouse-pick-region (start-event)
226 "Pick articles that the mouse is dragged over.
227 This must be bound to a button-down mouse event."
228 (interactive "e")
229 (mouse-minibuffer-check start-event)
230 (let* ((echo-keystrokes 0)
231 (start-posn (event-start start-event))
232 (start-point (posn-point start-posn))
233 (start-line (1+ (count-lines (point-min) start-point)))
234 (start-window (posn-window start-posn))
235 (bounds (gnus-window-edges start-window))
236 (top (nth 1 bounds))
237 (bottom (if (window-minibuffer-p start-window)
238 (nth 3 bounds)
239 ;; Don't count the mode line.
240 (1- (nth 3 bounds))))
241 (click-count (1- (event-click-count start-event))))
242 (setq mouse-selection-click-count click-count)
243 (setq mouse-selection-click-count-buffer (current-buffer))
244 (mouse-set-point start-event)
245 ;; In case the down click is in the middle of some intangible text,
246 ;; use the end of that text, and put it in START-POINT.
247 (when (< (point) start-point)
248 (goto-char start-point))
249 (gnus-pick-article)
250 (setq start-point (point))
251 ;; end-of-range is used only in the single-click case.
252 ;; It is the place where the drag has reached so far
253 ;; (but not outside the window where the drag started).
254 (let (event end end-point (end-of-range (point)))
255 (track-mouse
256 (while (progn
257 (setq event (cdr (gnus-read-event-char)))
258 (or (mouse-movement-p event)
259 (eq (car-safe event) 'switch-frame)))
260 (if (eq (car-safe event) 'switch-frame)
261 nil
262 (setq end (event-end event)
263 end-point (posn-point end))
264
265 (cond
266 ;; Are we moving within the original window?
267 ((and (eq (posn-window end) start-window)
268 (integer-or-marker-p end-point))
269 ;; Go to START-POINT first, so that when we move to END-POINT,
270 ;; if it's in the middle of intangible text,
271 ;; point jumps in the direction away from START-POINT.
272 (goto-char start-point)
273 (goto-char end-point)
274 (gnus-pick-article)
275 ;; In case the user moved his mouse really fast, pick
276 ;; articles on the line between this one and the last one.
277 (let* ((this-line (1+ (count-lines (point-min) end-point)))
278 (min-line (min this-line start-line))
279 (max-line (max this-line start-line)))
280 ;; Why not use `forward-line'? --Stef
281 (while (< min-line max-line)
282 (goto-line min-line)
283 (gnus-pick-article)
284 (setq min-line (1+ min-line)))
285 (setq start-line this-line))
286 (when (zerop (% click-count 3))
287 (setq end-of-range (point))))
288 (t
289 (let ((mouse-row (cdr (cdr (mouse-position)))))
290 (cond
291 ((null mouse-row))
292 ((< mouse-row top)
293 (mouse-scroll-subr start-window (- mouse-row top)))
294 ((>= mouse-row bottom)
295 (mouse-scroll-subr start-window
296 (1+ (- mouse-row bottom)))))))))))
297 (when (consp event)
298 (let ((fun (key-binding (vector (car event)))))
299 ;; Run the binding of the terminating up-event, if possible.
300 ;; In the case of a multiple click, it gives the wrong results,
301 ;; because it would fail to set up a region.
302 (when nil
303 ;; (and (= (mod mouse-selection-click-count 3) 0) (fboundp fun))
304 ;; In this case, we can just let the up-event execute normally.
305 (let ((end (event-end event)))
306 ;; Set the position in the event before we replay it,
307 ;; because otherwise it may have a position in the wrong
308 ;; buffer.
309 (setcar (cdr end) end-of-range)
310 ;; Delete the overlay before calling the function,
311 ;; because delete-overlay increases buffer-modified-tick.
312 (push event unread-command-events))))))))
313
314 (defun gnus-pick-next-page ()
315 "Go to the next page. If at the end of the buffer, start reading articles."
316 (interactive)
317 (let ((scroll-in-place nil))
318 (condition-case nil
319 (scroll-up)
320 (end-of-buffer (gnus-pick-start-reading)))))
321
322 ;;;
323 ;;; gnus-binary-mode
324 ;;;
325
326 (defvar gnus-binary-mode nil
327 "Minor mode for providing a binary group interface in Gnus summary buffers.")
328
329 (defvar gnus-binary-mode-hook nil
330 "Hook run in summary binary mode buffers.")
331
332 (defvar gnus-binary-mode-map nil)
333
334 (unless gnus-binary-mode-map
335 (setq gnus-binary-mode-map (make-sparse-keymap))
336
337 (gnus-define-keys
338 gnus-binary-mode-map
339 "g" gnus-binary-show-article))
340
341 (defun gnus-binary-make-menu-bar ()
342 (unless (boundp 'gnus-binary-menu)
343 (easy-menu-define
344 gnus-binary-menu gnus-binary-mode-map ""
345 '("Pick"
346 ["Switch binary mode off" gnus-binary-mode t]))))
347
348 (defun gnus-binary-mode (&optional arg)
349 "Minor mode for providing a binary group interface in Gnus summary buffers."
350 (interactive "P")
351 (when (eq major-mode 'gnus-summary-mode)
352 (make-local-variable 'gnus-binary-mode)
353 (setq gnus-binary-mode
354 (if (null arg) (not gnus-binary-mode)
355 (> (prefix-numeric-value arg) 0)))
356 (when gnus-binary-mode
357 ;; Make sure that we don't select any articles upon group entry.
358 (make-local-variable 'gnus-auto-select-first)
359 (setq gnus-auto-select-first nil)
360 (make-local-variable 'gnus-summary-display-article-function)
361 (setq gnus-summary-display-article-function 'gnus-binary-display-article)
362 ;; Set up the menu.
363 (when (gnus-visual-p 'binary-menu 'menu)
364 (gnus-binary-make-menu-bar))
365 (gnus-add-minor-mode 'gnus-binary-mode " Binary"
366 gnus-binary-mode-map nil 'gnus-binary-mode)
367 (gnus-run-hooks 'gnus-binary-mode-hook))))
368
369 (defun gnus-binary-display-article (article &optional all-header)
370 "Run ARTICLE through the binary decode functions."
371 (when (gnus-summary-goto-subject article)
372 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
373 (gnus-uu-decode-uu))))
374
375 (defun gnus-binary-show-article (&optional arg)
376 "Bypass the binary functions and show the article."
377 (interactive "P")
378 (let (gnus-summary-display-article-function)
379 (gnus-summary-show-article arg)))
380
381 ;;;
382 ;;; gnus-tree-mode
383 ;;;
384
385 (defcustom gnus-tree-line-format "%(%[%3,3n%]%)"
386 "Format of tree elements."
387 :type 'string
388 :group 'gnus-summary-tree)
389
390 (defcustom gnus-tree-minimize-window t
391 "If non-nil, minimize the tree buffer window.
392 If a number, never let the tree buffer grow taller than that number of
393 lines."
394 :type '(choice boolean
395 integer)
396 :group 'gnus-summary-tree)
397
398 (defcustom gnus-selected-tree-face 'modeline
399 "*Face used for highlighting selected articles in the thread tree."
400 :type 'face
401 :group 'gnus-summary-tree)
402
403 (defvar gnus-tree-brackets '((?\[ . ?\]) (?\( . ?\))
404 (?\{ . ?\}) (?< . ?>))
405 "Brackets used in tree nodes.")
406
407 (defvar gnus-tree-parent-child-edges '(?- ?\\ ?|)
408 "Characters used to connect parents with children.")
409
410 (defcustom gnus-tree-mode-line-format "Gnus: %%b %S %Z"
411 "*The format specification for the tree mode line."
412 :type 'string
413 :group 'gnus-summary-tree)
414
415 (defcustom gnus-generate-tree-function 'gnus-generate-vertical-tree
416 "*Function for generating a thread tree.
417 Two predefined functions are available:
418 `gnus-generate-horizontal-tree' and `gnus-generate-vertical-tree'."
419 :type '(radio (function-item gnus-generate-vertical-tree)
420 (function-item gnus-generate-horizontal-tree)
421 (function :tag "Other" nil))
422 :group 'gnus-summary-tree)
423
424 (defcustom gnus-tree-mode-hook nil
425 "*Hook run in tree mode buffers."
426 :type 'hook
427 :group 'gnus-summary-tree)
428
429 (when (featurep 'xemacs)
430 (add-hook 'gnus-tree-mode-hook 'gnus-xmas-tree-menu-add)
431 (add-hook 'gnus-tree-mode-hook 'gnus-xmas-switch-horizontal-scrollbar-off))
432
433
434 ;;; Internal variables.
435
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)))
443
444 (defvar gnus-tree-mode-line-format-alist gnus-summary-mode-line-format-alist)
445
446 (defvar gnus-tree-mode-line-format-spec nil)
447 (defvar gnus-tree-line-format-spec nil)
448
449 (defvar gnus-tree-node-length nil)
450 (defvar gnus-selected-tree-overlay nil)
451
452 (defvar gnus-tree-displayed-thread nil)
453 (defvar gnus-tree-inhibit nil)
454
455 (defvar gnus-tree-mode-map nil)
456 (put 'gnus-tree-mode 'mode-class 'special)
457
458 (unless gnus-tree-mode-map
459 (setq gnus-tree-mode-map (make-keymap))
460 (suppress-keymap gnus-tree-mode-map)
461 (gnus-define-keys
462 gnus-tree-mode-map
463 "\r" gnus-tree-select-article
464 gnus-mouse-2 gnus-tree-pick-article
465 "\C-?" gnus-tree-read-summary-keys
466 "h" gnus-tree-show-summary
467
468 "\C-c\C-i" gnus-info-find-node)
469
470 (substitute-key-definition
471 'undefined 'gnus-tree-read-summary-keys gnus-tree-mode-map))
472
473 (defun gnus-tree-make-menu-bar ()
474 (unless (boundp 'gnus-tree-menu)
475 (easy-menu-define
476 gnus-tree-menu gnus-tree-mode-map ""
477 '("Tree"
478 ["Select article" gnus-tree-select-article t]))))
479
480 (defun gnus-tree-mode ()
481 "Major mode for displaying thread trees."
482 (interactive)
483 (gnus-set-format 'tree-mode)
484 (gnus-set-format 'tree t)
485 (when (gnus-visual-p 'tree-menu 'menu)
486 (gnus-tree-make-menu-bar))
487 (kill-all-local-variables)
488 (gnus-simplify-mode-line)
489 (setq mode-name "Tree")
490 (setq major-mode 'gnus-tree-mode)
491 (use-local-map gnus-tree-mode-map)
492 (buffer-disable-undo)
493 (setq buffer-read-only t)
494 (setq truncate-lines t)
495 (save-excursion
496 (gnus-set-work-buffer)
497 (gnus-tree-node-insert (make-mail-header "") nil)
498 (setq gnus-tree-node-length (1- (point))))
499 (gnus-run-hooks 'gnus-tree-mode-hook))
500
501 (defun gnus-tree-read-summary-keys (&optional arg)
502 "Read a summary buffer key sequence and execute it."
503 (interactive "P")
504 (unless gnus-tree-inhibit
505 (let ((buf (current-buffer))
506 (gnus-tree-inhibit t)
507 win)
508 (set-buffer gnus-article-buffer)
509 (gnus-article-read-summary-keys arg nil t)
510 (when (setq win (get-buffer-window buf))
511 (select-window win)
512 (when gnus-selected-tree-overlay
513 (goto-char (or (gnus-overlay-end gnus-selected-tree-overlay) 1)))
514 (gnus-tree-minimize)))))
515
516 (defun gnus-tree-show-summary ()
517 "Reconfigure windows to show summary buffer."
518 (interactive)
519 (if (not (gnus-buffer-live-p gnus-summary-buffer))
520 (error "There is no summary buffer for this tree buffer")
521 (gnus-configure-windows 'article)
522 (gnus-summary-goto-subject gnus-current-article)))
523
524 (defun gnus-tree-select-article (article)
525 "Select the article under point, if any."
526 (interactive (list (gnus-tree-article-number)))
527 (let ((buf (current-buffer)))
528 (when article
529 (save-excursion
530 (set-buffer gnus-summary-buffer)
531 (gnus-summary-goto-article article))
532 (select-window (get-buffer-window buf)))))
533
534 (defun gnus-tree-pick-article (e)
535 "Select the article under the mouse pointer."
536 (interactive "e")
537 (mouse-set-point e)
538 (gnus-tree-select-article (gnus-tree-article-number)))
539
540 (defun gnus-tree-article-number ()
541 (get-text-property (point) 'gnus-number))
542
543 (defun gnus-tree-article-region (article)
544 "Return a cons with BEG and END of the article region."
545 (let ((pos (text-property-any
546 (point-min) (point-max) 'gnus-number article)))
547 (when pos
548 (cons pos (next-single-property-change pos 'gnus-number)))))
549
550 (defun gnus-tree-goto-article (article)
551 (let ((pos (text-property-any
552 (point-min) (point-max) 'gnus-number article)))
553 (when pos
554 (goto-char pos))))
555
556 (defun gnus-tree-recenter ()
557 "Center point in the tree window."
558 (let ((selected (selected-window))
559 (tree-window (gnus-get-buffer-window gnus-tree-buffer t)))
560 (when tree-window
561 (select-window tree-window)
562 (when gnus-selected-tree-overlay
563 (goto-char (or (gnus-overlay-end gnus-selected-tree-overlay) 1)))
564 (let* ((top (cond ((< (window-height) 4) 0)
565 ((< (window-height) 7) 1)
566 (t 2)))
567 (height (1- (window-height)))
568 (bottom (save-excursion (goto-char (point-max))
569 (forward-line (- height))
570 (point))))
571 ;; Set the window start to either `bottom', which is the biggest
572 ;; possible valid number, or the second line from the top,
573 ;; whichever is the least.
574 (set-window-start
575 tree-window (min bottom (save-excursion
576 (forward-line (- top)) (point)))))
577 (select-window selected))))
578
579 (defun gnus-get-tree-buffer ()
580 "Return the tree buffer properly initialized."
581 (save-excursion
582 (set-buffer (gnus-get-buffer-create gnus-tree-buffer))
583 (unless (eq major-mode 'gnus-tree-mode)
584 (gnus-tree-mode))
585 (current-buffer)))
586
587 (defun gnus-tree-minimize ()
588 (when (and gnus-tree-minimize-window
589 (not (one-window-p)))
590 (let ((windows 0)
591 tot-win-height)
592 (walk-windows (lambda (window) (incf windows)))
593 (setq tot-win-height
594 (- (frame-height)
595 (* window-min-height (1- windows))
596 2))
597 (let* ((window-min-height 2)
598 (height (count-lines (point-min) (point-max)))
599 (min (max (1- window-min-height) height))
600 (tot (if (numberp gnus-tree-minimize-window)
601 (min gnus-tree-minimize-window min)
602 min))
603 (win (get-buffer-window (current-buffer)))
604 (wh (and win (1- (window-height win)))))
605 (setq tot (min tot tot-win-height))
606 (when (and win
607 (not (eq tot wh)))
608 (let ((selected (selected-window)))
609 (when (ignore-errors (select-window win))
610 (enlarge-window (- tot wh))
611 (select-window selected))))))))
612
613 ;;; Generating the tree.
614
615 (defun gnus-tree-node-insert (header sparse &optional adopted)
616 (let* ((dummy (stringp header))
617 (header (if (vectorp header) header
618 (progn
619 (setq header (make-mail-header "*****"))
620 (mail-header-set-number header 0)
621 (mail-header-set-lines header 0)
622 (mail-header-set-chars header 0)
623 header)))
624 (gnus-tmp-from (mail-header-from header))
625 (gnus-tmp-subject (mail-header-subject header))
626 (gnus-tmp-number (mail-header-number header))
627 (gnus-tmp-name
628 (cond
629 ((string-match "(.+)" gnus-tmp-from)
630 (substring gnus-tmp-from
631 (1+ (match-beginning 0)) (1- (match-end 0))))
632 ((string-match "<[^>]+> *$" gnus-tmp-from)
633 (let ((beg (match-beginning 0)))
634 (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
635 (substring gnus-tmp-from (1+ (match-beginning 0))
636 (1- (match-end 0))))
637 (substring gnus-tmp-from 0 beg))))
638 ((memq gnus-tmp-number sparse)
639 "***")
640 (t gnus-tmp-from)))
641 (gnus-tmp-open-bracket
642 (cond ((memq gnus-tmp-number sparse)
643 (caadr gnus-tree-brackets))
644 (dummy (caaddr gnus-tree-brackets))
645 (adopted (car (nth 3 gnus-tree-brackets)))
646 (t (caar gnus-tree-brackets))))
647 (gnus-tmp-close-bracket
648 (cond ((memq gnus-tmp-number sparse)
649 (cdadr gnus-tree-brackets))
650 (adopted (cdr (nth 3 gnus-tree-brackets)))
651 (dummy
652 (cdaddr gnus-tree-brackets))
653 (t (cdar gnus-tree-brackets))))
654 (buffer-read-only nil)
655 beg end)
656 (gnus-add-text-properties
657 (setq beg (point))
658 (setq end (progn (eval gnus-tree-line-format-spec) (point)))
659 (list 'gnus-number gnus-tmp-number))
660 (when (or t (gnus-visual-p 'tree-highlight 'highlight))
661 (gnus-tree-highlight-node gnus-tmp-number beg end))))
662
663 (defun gnus-tree-highlight-node (article beg end)
664 "Highlight current line according to `gnus-summary-highlight'."
665 (let ((list gnus-summary-highlight)
666 face)
667 (save-excursion
668 (set-buffer gnus-summary-buffer)
669 (let* ((score (or (cdr (assq article gnus-newsgroup-scored))
670 gnus-summary-default-score 0))
671 (default gnus-summary-default-score)
672 (default-high gnus-summary-default-high-score)
673 (default-low gnus-summary-default-low-score)
674 (uncached (memq article gnus-newsgroup-undownloaded))
675 (downloaded (not uncached))
676 (mark (or (gnus-summary-article-mark article) gnus-unread-mark)))
677 ;; Eval the cars of the lists until we find a match.
678 (while (and list
679 (not (eval (caar list))))
680 (setq list (cdr list)))))
681 (unless (eq (setq face (cdar list)) (get-text-property beg 'face))
682 (gnus-put-text-property-excluding-characters-with-faces
683 beg end 'face
684 (if (boundp face) (symbol-value face) face)))))
685
686 (defun gnus-tree-indent (level)
687 (insert (make-string (1- (* (1+ gnus-tree-node-length) level)) ? )))
688
689 (defvar gnus-tmp-limit)
690 (defvar gnus-tmp-sparse)
691 (defvar gnus-tmp-indent)
692
693 (defun gnus-generate-tree (thread)
694 "Generate a thread tree for THREAD."
695 (save-excursion
696 (set-buffer (gnus-get-tree-buffer))
697 (let ((buffer-read-only nil)
698 (gnus-tmp-indent 0))
699 (erase-buffer)
700 (funcall gnus-generate-tree-function thread 0)
701 (gnus-set-mode-line 'tree)
702 (goto-char (point-min))
703 (gnus-tree-minimize)
704 (gnus-tree-recenter)
705 (let ((selected (selected-window)))
706 (when (gnus-get-buffer-window (set-buffer gnus-tree-buffer) t)
707 (select-window (gnus-get-buffer-window (set-buffer gnus-tree-buffer) t))
708 (gnus-horizontal-recenter)
709 (select-window selected))))))
710
711 (defun gnus-generate-horizontal-tree (thread level &optional dummyp adopted)
712 "Generate a horizontal tree."
713 (let* ((dummy (stringp (car thread)))
714 (do (or dummy
715 (and (car thread)
716 (memq (mail-header-number (car thread))
717 gnus-tmp-limit))))
718 col beg)
719 (if (not do)
720 ;; We don't want this article.
721 (setq thread (cdr thread))
722 (if (not (bolp))
723 ;; Not the first article on the line, so we insert a "-".
724 (insert (car gnus-tree-parent-child-edges))
725 ;; If the level isn't zero, then we insert some indentation.
726 (unless (zerop level)
727 (gnus-tree-indent level)
728 (insert (cadr gnus-tree-parent-child-edges))
729 (setq col (- (setq beg (point)) (gnus-point-at-bol) 1))
730 ;; Draw "|" lines upwards.
731 (while (progn
732 (forward-line -1)
733 (forward-char col)
734 (eq (char-after) ? ))
735 (delete-char 1)
736 (insert (caddr gnus-tree-parent-child-edges)))
737 (goto-char beg)))
738 (setq dummyp nil)
739 ;; Insert the article node.
740 (gnus-tree-node-insert (pop thread) gnus-tmp-sparse adopted))
741 (if (null thread)
742 ;; End of the thread, so we go to the next line.
743 (unless (bolp)
744 (insert "\n"))
745 ;; Recurse downwards in all children of this article.
746 (while thread
747 (gnus-generate-horizontal-tree
748 (pop thread) (if do (1+ level) level)
749 (or dummyp dummy) dummy)))))
750
751 (defsubst gnus-tree-indent-vertical ()
752 (let ((len (- (* (1+ gnus-tree-node-length) gnus-tmp-indent)
753 (- (point) (gnus-point-at-bol)))))
754 (when (> len 0)
755 (insert (make-string len ? )))))
756
757 (defsubst gnus-tree-forward-line (n)
758 (while (>= (decf n) 0)
759 (unless (zerop (forward-line 1))
760 (end-of-line)
761 (insert "\n")))
762 (end-of-line))
763
764 (defun gnus-generate-vertical-tree (thread level &optional dummyp adopted)
765 "Generate a vertical tree."
766 (let* ((dummy (stringp (car thread)))
767 (do (or dummy
768 (and (car thread)
769 (memq (mail-header-number (car thread))
770 gnus-tmp-limit))))
771 beg)
772 (if (not do)
773 ;; We don't want this article.
774 (setq thread (cdr thread))
775 (if (not (save-excursion (beginning-of-line) (bobp)))
776 ;; Not the first article on the line, so we insert a "-".
777 (progn
778 (gnus-tree-indent-vertical)
779 (insert (make-string (/ gnus-tree-node-length 2) ? ))
780 (insert (caddr gnus-tree-parent-child-edges))
781 (gnus-tree-forward-line 1))
782 ;; If the level isn't zero, then we insert some indentation.
783 (unless (zerop gnus-tmp-indent)
784 (gnus-tree-forward-line (1- (* 2 level)))
785 (gnus-tree-indent-vertical)
786 (delete-char -1)
787 (insert (cadr gnus-tree-parent-child-edges))
788 (setq beg (point))
789 (forward-char -1)
790 ;; Draw "-" lines leftwards.
791 (while (and (not (bobp))
792 (eq (char-after (1- (point))) ? ))
793 (delete-char -1)
794 (insert (car gnus-tree-parent-child-edges))
795 (forward-char -1))
796 (goto-char beg)
797 (gnus-tree-forward-line 1)))
798 (setq dummyp nil)
799 ;; Insert the article node.
800 (gnus-tree-indent-vertical)
801 (gnus-tree-node-insert (pop thread) gnus-tmp-sparse adopted)
802 (gnus-tree-forward-line 1))
803 (if (null thread)
804 ;; End of the thread, so we go to the next line.
805 (progn
806 (goto-char (point-min))
807 (end-of-line)
808 (incf gnus-tmp-indent))
809 ;; Recurse downwards in all children of this article.
810 (while thread
811 (gnus-generate-vertical-tree
812 (pop thread) (if do (1+ level) level)
813 (or dummyp dummy) dummy)))))
814
815 ;;; Interface functions.
816
817 (defun gnus-possibly-generate-tree (article &optional force)
818 "Generate the thread tree for ARTICLE if it isn't displayed already."
819 (when (save-excursion
820 (set-buffer gnus-summary-buffer)
821 (and gnus-use-trees
822 gnus-show-threads
823 (vectorp (gnus-summary-article-header article))))
824 (save-excursion
825 (let ((top (save-excursion
826 (set-buffer gnus-summary-buffer)
827 (gnus-cut-thread
828 (gnus-remove-thread
829 (mail-header-id
830 (gnus-summary-article-header article))
831 t))))
832 (gnus-tmp-limit gnus-newsgroup-limit)
833 (gnus-tmp-sparse gnus-newsgroup-sparse))
834 (when (or force
835 (not (eq top gnus-tree-displayed-thread)))
836 (gnus-generate-tree top)
837 (setq gnus-tree-displayed-thread top))))))
838
839 (defun gnus-tree-open (group)
840 (gnus-get-tree-buffer))
841
842 (defun gnus-tree-close (group)
843 (gnus-kill-buffer gnus-tree-buffer))
844
845 (defun gnus-tree-perhaps-minimize ()
846 (when (and gnus-tree-minimize-window
847 (get-buffer gnus-tree-buffer))
848 (save-excursion
849 (set-buffer gnus-tree-buffer)
850 (gnus-tree-minimize))))
851
852 (defun gnus-highlight-selected-tree (article)
853 "Highlight the selected article in the tree."
854 (let ((buf (current-buffer))
855 region)
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.
861 (gnus-overlay-put
862 (setq gnus-selected-tree-overlay
863 (gnus-make-overlay (point-min) (1+ (point-min))))
864 'face gnus-selected-tree-face))
865 ;; Move the overlay to the article.
866 (gnus-move-overlay
867 gnus-selected-tree-overlay (goto-char (car region)) (cdr region))
868 (gnus-tree-minimize)
869 (gnus-tree-recenter)
870 (let ((selected (selected-window)))
871 (when (gnus-get-buffer-window (set-buffer gnus-tree-buffer) t)
872 (select-window (gnus-get-buffer-window (set-buffer gnus-tree-buffer) t))
873 (gnus-horizontal-recenter)
874 (select-window selected))))
875 ;; If we remove this save-excursion, it updates the wrong mode lines?!?
876 (save-excursion
877 (set-buffer gnus-tree-buffer)
878 (gnus-set-mode-line 'tree))
879 (set-buffer buf)))
880
881 (defun gnus-tree-highlight-article (article face)
882 (save-excursion
883 (set-buffer (gnus-get-tree-buffer))
884 (let (region)
885 (when (setq region (gnus-tree-article-region article))
886 (gnus-put-text-property (car region) (cdr region) 'face face)
887 (set-window-point
888 (gnus-get-buffer-window (current-buffer) t) (cdr region))))))
889
890 ;;;
891 ;;; gnus-carpal
892 ;;;
893
894 (defvar gnus-carpal-group-buffer-buttons
895 '(("next" . gnus-group-next-unread-group)
896 ("prev" . gnus-group-prev-unread-group)
897 ("read" . gnus-group-read-group)
898 ("select" . gnus-group-select-group)
899 ("catch-up" . gnus-group-catchup-current)
900 ("new-news" . gnus-group-get-new-news-this-group)
901 ("toggle-sub" . gnus-group-unsubscribe-current-group)
902 ("subscribe" . gnus-group-unsubscribe-group)
903 ("kill" . gnus-group-kill-group)
904 ("yank" . gnus-group-yank-group)
905 ("describe" . gnus-group-describe-group)
906 "list"
907 ("subscribed" . gnus-group-list-groups)
908 ("all" . gnus-group-list-all-groups)
909 ("killed" . gnus-group-list-killed)
910 ("zombies" . gnus-group-list-zombies)
911 ("matching" . gnus-group-list-matching)
912 ("post" . gnus-group-post-news)
913 ("mail" . gnus-group-mail)
914 ("local" . (lambda () (interactive) (gnus-group-news 0)))
915 ("rescan" . gnus-group-get-new-news)
916 ("browse-foreign" . gnus-group-browse-foreign)
917 ("exit" . gnus-group-exit)))
918
919 (defvar gnus-carpal-summary-buffer-buttons
920 '("mark"
921 ("read" . gnus-summary-mark-as-read-forward)
922 ("tick" . gnus-summary-tick-article-forward)
923 ("clear" . gnus-summary-clear-mark-forward)
924 ("expirable" . gnus-summary-mark-as-expirable)
925 "move"
926 ("scroll" . gnus-summary-next-page)
927 ("next-unread" . gnus-summary-next-unread-article)
928 ("prev-unread" . gnus-summary-prev-unread-article)
929 ("first" . gnus-summary-first-unread-article)
930 ("best" . gnus-summary-best-unread-article)
931 "article"
932 ("headers" . gnus-summary-toggle-header)
933 ("uudecode" . gnus-uu-decode-uu)
934 ("enter-digest" . gnus-summary-enter-digest-group)
935 ("fetch-parent" . gnus-summary-refer-parent-article)
936 "mail"
937 ("move" . gnus-summary-move-article)
938 ("copy" . gnus-summary-copy-article)
939 ("respool" . gnus-summary-respool-article)
940 "threads"
941 ("lower" . gnus-summary-lower-thread)
942 ("kill" . gnus-summary-kill-thread)
943 "post"
944 ("post" . gnus-summary-post-news)
945 ("local" . gnus-summary-news-other-window)
946 ("mail" . gnus-summary-mail-other-window)
947 ("followup" . gnus-summary-followup-with-original)
948 ("reply" . gnus-summary-reply-with-original)
949 ("cancel" . gnus-summary-cancel-article)
950 "misc"
951 ("exit" . gnus-summary-exit)
952 ("fed-up" . gnus-summary-catchup-and-goto-next-group)))
953
954 (defvar gnus-carpal-server-buffer-buttons
955 '(("add" . gnus-server-add-server)
956 ("browse" . gnus-server-browse-server)
957 ("list" . gnus-server-list-servers)
958 ("kill" . gnus-server-kill-server)
959 ("yank" . gnus-server-yank-server)
960 ("copy" . gnus-server-copy-server)
961 ("exit" . gnus-server-exit)))
962
963 (defvar gnus-carpal-browse-buffer-buttons
964 '(("subscribe" . gnus-browse-unsubscribe-current-group)
965 ("exit" . gnus-browse-exit)))
966
967 (defvar gnus-carpal-group-buffer "*Carpal Group*")
968 (defvar gnus-carpal-summary-buffer "*Carpal Summary*")
969 (defvar gnus-carpal-server-buffer "*Carpal Server*")
970 (defvar gnus-carpal-browse-buffer "*Carpal Browse*")
971
972 (defvar gnus-carpal-attached-buffer nil)
973
974 (defvar gnus-carpal-mode-hook nil
975 "*Hook run in carpal mode buffers.")
976
977 (defvar gnus-carpal-button-face 'bold
978 "*Face used on carpal buttons.")
979
980 (defvar gnus-carpal-header-face 'bold-italic
981 "*Face used on carpal buffer headers.")
982
983 (defvar gnus-carpal-mode-map nil)
984 (put 'gnus-carpal-mode 'mode-class 'special)
985
986 (if gnus-carpal-mode-map
987 nil
988 (setq gnus-carpal-mode-map (make-keymap))
989 (suppress-keymap gnus-carpal-mode-map)
990 (define-key gnus-carpal-mode-map " " 'gnus-carpal-select)
991 (define-key gnus-carpal-mode-map "\r" 'gnus-carpal-select)
992 (define-key gnus-carpal-mode-map gnus-mouse-2 'gnus-carpal-mouse-select))
993
994 (defun gnus-carpal-mode ()
995 "Major mode for clicking buttons.
996
997 All normal editing commands are switched off.
998 \\<gnus-carpal-mode-map>
999 The following commands are available:
1000
1001 \\{gnus-carpal-mode-map}"
1002 (interactive)
1003 (kill-all-local-variables)
1004 (setq mode-line-modified (cdr gnus-mode-line-modified))
1005 (setq major-mode 'gnus-carpal-mode)
1006 (setq mode-name "Gnus Carpal")
1007 (setq mode-line-process nil)
1008 (use-local-map gnus-carpal-mode-map)
1009 (buffer-disable-undo)
1010 (setq buffer-read-only t)
1011 (make-local-variable 'gnus-carpal-attached-buffer)
1012 (gnus-run-hooks 'gnus-carpal-mode-hook))
1013
1014 (defun gnus-carpal-setup-buffer (type)
1015 (let ((buffer (symbol-value (intern (format "gnus-carpal-%s-buffer" type)))))
1016 (if (get-buffer buffer)
1017 ()
1018 (save-excursion
1019 (set-buffer (gnus-get-buffer-create buffer))
1020 (gnus-carpal-mode)
1021 (setq gnus-carpal-attached-buffer
1022 (intern (format "gnus-%s-buffer" type)))
1023 (let ((buttons (symbol-value
1024 (intern (format "gnus-carpal-%s-buffer-buttons"
1025 type))))
1026 (buffer-read-only nil)
1027 button)
1028 (while buttons
1029 (setq button (car buttons)
1030 buttons (cdr buttons))
1031 (if (stringp button)
1032 (gnus-set-text-properties
1033 (point)
1034 (prog2 (insert button) (point) (insert " "))
1035 (list 'face gnus-carpal-header-face))
1036 (gnus-set-text-properties
1037 (point)
1038 (prog2 (insert (car button)) (point) (insert " "))
1039 (list 'gnus-callback (cdr button)
1040 'face gnus-carpal-button-face
1041 gnus-mouse-face-prop 'highlight))))
1042 (let ((fill-column (- (window-width) 2)))
1043 (fill-region (point-min) (point-max)))
1044 (set-window-point (get-buffer-window (current-buffer))
1045 (point-min)))))))
1046
1047 (defun gnus-carpal-select ()
1048 "Select the button under point."
1049 (interactive)
1050 (let ((func (get-text-property (point) 'gnus-callback)))
1051 (if (null func)
1052 ()
1053 (pop-to-buffer (symbol-value gnus-carpal-attached-buffer))
1054 (call-interactively func))))
1055
1056 (defun gnus-carpal-mouse-select (event)
1057 "Select the button under the mouse pointer."
1058 (interactive "e")
1059 (mouse-set-point event)
1060 (gnus-carpal-select))
1061
1062 ;;; Allow redefinition of functions.
1063 (gnus-ems-redefine)
1064
1065 (provide 'gnus-salt)
1066
1067 ;; arch-tag: 35449164-77b3-4398-bcbd-a2e3e998f810
1068 ;;; gnus-salt.el ends here