(gnus-article-mode): Turn off the "\ " non-break space.
[bpt/emacs.git] / lisp / gnus / gnus-salt.el
CommitLineData
eec82323 1;;; gnus-salt.el --- alternate summary mode interfaces for Gnus
16409b0b 2
23f87bed
MB
3;; Copyright (C) 1996, 1997, 1998, 1999, 2001
4;; Free Software Foundation, Inc.
eec82323 5
6748645f
LMI
6;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7;; Keywords: news
eec82323
LMI
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
5ab7173c
RS
30(eval-when-compile (require 'cl))
31
eec82323
LMI
32(require 'gnus)
33(require 'gnus-sum)
23f87bed 34(require 'gnus-win)
eec82323
LMI
35
36;;;
37;;; gnus-pick-mode
38;;;
39
40(defvar gnus-pick-mode nil
23f87bed
MB
41 "Minor mode for providing a pick-and-read interface in Gnus
42summary buffers.")
eec82323 43
a8151ef7
LMI
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
23f87bed
MB
54(when (featurep 'xemacs)
55 (add-hook 'gnus-pick-mode-hook 'gnus-xmas-pick-menu-add))
56
a8151ef7
LMI
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
23f87bed
MB
63 "If non-nil, `gnus-pick-start-reading' runs
64 `gnus-summary-next-group' when no articles have been picked."
a8151ef7
LMI
65 :type 'boolean
66 :group 'gnus-summary-pick)
67
68(defcustom gnus-summary-pick-line-format
23f87bed 69 "%-5P %U\%R\%z\%I\%(%[%4L: %-23,23n%]%) %s\n"
eec82323 70 "*The format specification of the lines in pick buffers.
a8151ef7
LMI
71It accepts the same format specs that `gnus-summary-line-format' does."
72 :type 'string
73 :group 'gnus-summary-pick)
eec82323
LMI
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
6748645f
LMI
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
16409b0b 87 "\r" gnus-pick-start-reading))
eec82323
LMI
88
89(defun gnus-pick-make-menu-bar ()
90 (unless (boundp 'gnus-pick-menu)
91 (easy-menu-define
23f87bed
MB
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]))))
eec82323
LMI
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))
16409b0b
GM
131 (gnus-add-minor-mode 'gnus-pick-mode " Pick" gnus-pick-mode-map
132 nil 'gnus-pick-mode)
6748645f 133 (gnus-run-hooks 'gnus-pick-mode-hook))))
eec82323
LMI
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
16409b0b
GM
142 '(gnus-configure-windows ,gnus-current-window-configuration t)
143 'send 'exit 'postpone 'kill)))
eec82323
LMI
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.
154If given a prefix, mark all unpicked articles as read."
155 (interactive "P")
156 (if gnus-newsgroup-processable
157 (progn
23f87bed
MB
158 (gnus-summary-limit-to-articles nil)
159 (when (or catch-up gnus-mark-unpicked-articles-as-read)
eec82323 160 (gnus-summary-limit-mark-excluded-as-read))
23f87bed
MB
161 (gnus-summary-first-article)
162 (gnus-configure-windows
eec82323
LMI
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)
a8151ef7 167 (gnus-summary-catchup nil t))
eec82323
LMI
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
6748645f 173(defun gnus-pick-goto-article (arg)
16409b0b
GM
174 "Go to the article number indicated by ARG.
175If ARG is an invalid article number, then stay on current line."
6748645f
LMI
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))))
16409b0b 184
eec82323 185(defun gnus-pick-article (&optional arg)
16409b0b 186 "Pick the article on the current line.
eec82323
LMI
187If ARG, pick the article on that line instead."
188 (interactive "P")
189 (when arg
6748645f 190 (gnus-pick-goto-article arg))
eec82323
LMI
191 (gnus-summary-mark-as-processable 1))
192
6748645f 193(defun gnus-pick-article-or-thread (&optional arg)
16409b0b 194 "If `gnus-thread-hide-subtree' is t, then pick the thread on the current line.
6748645f
LMI
195Otherwise pick the article on the current line.
196If 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
16409b0b
GM
201 (progn
202 (save-excursion
203 (gnus-uu-mark-thread))
204 (forward-line 1))
6748645f 205 (gnus-summary-mark-as-processable 1)))
16409b0b 206
6748645f 207(defun gnus-pick-unmark-article-or-thread (&optional arg)
16409b0b 208 "If `gnus-thread-hide-subtree' is t, then unmark the thread on current line.
6748645f
LMI
209Otherwise unmark the article on current line.
210If 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
16409b0b
GM
215 (save-excursion
216 (gnus-uu-unmark-thread))
6748645f 217 (gnus-summary-unmark-as-processable 1)))
16409b0b 218
eec82323
LMI
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.
227This 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))
9b40100a 233 (start-line (1+ (count-lines (point-min) start-point)))
eec82323 234 (start-window (posn-window start-posn))
6748645f 235 (bounds (gnus-window-edges start-window))
eec82323
LMI
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)
23f87bed 245 ;; In case the down click is in the middle of some intangible text,
eec82323
LMI
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).
6748645f 254 (let (event end end-point (end-of-range (point)))
eec82323 255 (track-mouse
23f87bed
MB
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))
9b40100a 269 ;; Go to START-POINT first, so that when we move to END-POINT,
23f87bed
MB
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
9b40100a
SM
276 ;; articles on the line between this one and the last one.
277 (let* ((this-line (1+ (count-lines (point-min) end-point)))
23f87bed
MB
278 (min-line (min this-line start-line))
279 (max-line (max this-line start-line)))
9b40100a 280 ;; Why not use `forward-line'? --Stef
23f87bed
MB
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)))))))))))
eec82323
LMI
297 (when (consp event)
298 (let ((fun (key-binding (vector (car event)))))
299 ;; Run the binding of the terminating up-event, if possible.
23f87bed 300 ;; In the case of a multiple click, it gives the wrong results,
eec82323
LMI
301 ;; because it would fail to set up a region.
302 (when nil
23f87bed
MB
303 ;; (and (= (mod mouse-selection-click-count 3) 0) (fboundp fun))
304 ;; In this case, we can just let the up-event execute normally.
eec82323
LMI
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,
23f87bed 311 ;; because delete-overlay increases buffer-modified-tick.
eec82323
LMI
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
16409b0b
GM
338 gnus-binary-mode-map
339 "g" gnus-binary-show-article))
eec82323
LMI
340
341(defun gnus-binary-make-menu-bar ()
342 (unless (boundp 'gnus-binary-menu)
343 (easy-menu-define
23f87bed
MB
344 gnus-binary-menu gnus-binary-mode-map ""
345 '("Pick"
346 ["Switch binary mode off" gnus-binary-mode t]))))
eec82323
LMI
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))
16409b0b 365 (gnus-add-minor-mode 'gnus-binary-mode " Binary"
cb9040ed 366 gnus-binary-mode-map nil 'gnus-binary-mode)
6748645f 367 (gnus-run-hooks 'gnus-binary-mode-hook))))
eec82323
LMI
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)
23f87bed 372 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
eec82323
LMI
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
a8151ef7
LMI
385(defcustom gnus-tree-line-format "%(%[%3,3n%]%)"
386 "Format of tree elements."
387 :type 'string
388 :group 'gnus-summary-tree)
eec82323 389
a8151ef7 390(defcustom gnus-tree-minimize-window t
eec82323
LMI
391 "If non-nil, minimize the tree buffer window.
392If a number, never let the tree buffer grow taller than that number of
a8151ef7 393lines."
6748645f
LMI
394 :type '(choice boolean
395 integer)
a8151ef7 396 :group 'gnus-summary-tree)
eec82323 397
a8151ef7
LMI
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)
eec82323
LMI
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
a8151ef7
LMI
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)
eec82323 414
a8151ef7 415(defcustom gnus-generate-tree-function 'gnus-generate-vertical-tree
eec82323
LMI
416 "*Function for generating a thread tree.
417Two predefined functions are available:
a8151ef7
LMI
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)
eec82323 423
a8151ef7
LMI
424(defcustom gnus-tree-mode-hook nil
425 "*Hook run in tree mode buffers."
426 :type 'hook
427 :group 'gnus-summary-tree)
eec82323 428
23f87bed
MB
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
eec82323
LMI
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)
16409b0b 453(defvar gnus-tree-inhibit nil)
eec82323
LMI
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
16409b0b
GM
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
eec82323 467
16409b0b 468 "\C-c\C-i" gnus-info-find-node)
eec82323
LMI
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
23f87bed
MB
476 gnus-tree-menu gnus-tree-mode-map ""
477 '("Tree"
478 ["Select article" gnus-tree-select-article t]))))
eec82323
LMI
479
480(defun gnus-tree-mode ()
481 "Major mode for displaying thread trees."
482 (interactive)
6748645f
LMI
483 (gnus-set-format 'tree-mode)
484 (gnus-set-format 'tree t)
eec82323
LMI
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)
16409b0b 492 (buffer-disable-undo)
eec82323
LMI
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))))
6748645f 499 (gnus-run-hooks 'gnus-tree-mode-hook))
eec82323
LMI
500
501(defun gnus-tree-read-summary-keys (&optional arg)
502 "Read a summary buffer key sequence and execute it."
503 (interactive "P")
16409b0b
GM
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)))))
eec82323 515
a8151ef7
LMI
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
eec82323
LMI
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."
16409b0b
GM
545 (let ((pos (text-property-any
546 (point-min) (point-max) 'gnus-number article)))
eec82323
LMI
547 (when pos
548 (cons pos (next-single-property-change pos 'gnus-number)))))
549
550(defun gnus-tree-goto-article (article)
16409b0b
GM
551 (let ((pos (text-property-any
552 (point-min) (point-max) 'gnus-number article)))
eec82323
LMI
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))
23f87bed 559 (tree-window (gnus-get-buffer-window gnus-tree-buffer t)))
eec82323
LMI
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))))
23f87bed 571 ;; Set the window start to either `bottom', which is the biggest
eec82323
LMI
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
6748645f 582 (set-buffer (gnus-get-buffer-create gnus-tree-buffer))
eec82323 583 (unless (eq major-mode 'gnus-tree-mode)
eec82323
LMI
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)
23f87bed
MB
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))
eec82323
LMI
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))
6748645f 682 (gnus-put-text-property-excluding-characters-with-faces
eec82323
LMI
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)))
23f87bed
MB
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))
eec82323
LMI
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
a8151ef7
LMI
715 (and (car thread)
716 (memq (mail-header-number (car thread))
717 gnus-tmp-limit))))
eec82323
LMI
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)
16409b0b 734 (eq (char-after) ? ))
eec82323
LMI
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))
a8151ef7 789 (forward-char -1)
eec82323 790 ;; Draw "-" lines leftwards.
9b40100a 791 (while (and (not (bobp))
16409b0b 792 (eq (char-after (1- (point))) ? ))
a8151ef7
LMI
793 (delete-char -1)
794 (insert (car gnus-tree-parent-child-edges))
795 (forward-char -1))
eec82323
LMI
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)
6748645f 843 (gnus-kill-buffer gnus-tree-buffer))
eec82323 844
23f87bed
MB
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
eec82323
LMI
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
9b40100a
SM
862 (setq gnus-selected-tree-overlay
863 (gnus-make-overlay (point-min) (1+ (point-min))))
eec82323
LMI
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)))
23f87bed
MB
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))
eec82323
LMI
873 (gnus-horizontal-recenter)
874 (select-window selected))))
23f87bed 875;; If we remove this save-excursion, it updates the wrong mode lines?!?
eec82323
LMI
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
23f87bed 888 (gnus-get-buffer-window (current-buffer) t) (cdr region))))))
eec82323
LMI
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)
23f87bed 914 ("local" . (lambda () (interactive) (gnus-group-news 0)))
eec82323
LMI
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)
23f87bed
MB
945 ("local" . gnus-summary-news-other-window)
946 ("mail" . gnus-summary-mail-other-window)
eec82323
LMI
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
997All normal editing commands are switched off.
998\\<gnus-carpal-mode-map>
999The following commands are available:
1000
1001\\{gnus-carpal-mode-map}"
1002 (interactive)
1003 (kill-all-local-variables)
a8151ef7 1004 (setq mode-line-modified (cdr gnus-mode-line-modified))
eec82323
LMI
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)
16409b0b 1009 (buffer-disable-undo)
eec82323
LMI
1010 (setq buffer-read-only t)
1011 (make-local-variable 'gnus-carpal-attached-buffer)
6748645f 1012 (gnus-run-hooks 'gnus-carpal-mode-hook))
eec82323
LMI
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
6748645f 1019 (set-buffer (gnus-get-buffer-create buffer))
eec82323
LMI
1020 (gnus-carpal-mode)
1021 (setq gnus-carpal-attached-buffer
1022 (intern (format "gnus-%s-buffer" type)))
eec82323
LMI
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
9b40100a 1067;; arch-tag: 35449164-77b3-4398-bcbd-a2e3e998f810
eec82323 1068;;; gnus-salt.el ends here