1 ;;; gnus-salt.el --- alternate summary mode interfaces for Gnus
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
9 ;; This file is part of GNU Emacs.
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 3, or (at your option)
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.
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., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
30 (eval-when-compile (require 'cl
))
40 (defvar gnus-pick-mode nil
41 "Minor mode for providing a pick-and-read interface in Gnus
44 (defcustom gnus-pick-display-summary nil
45 "*Display summary while reading."
47 :group
'gnus-summary-pick
)
49 (defcustom gnus-pick-mode-hook nil
50 "Hook run in summary pick mode buffers."
52 :group
'gnus-summary-pick
)
54 (when (featurep 'xemacs
)
55 (add-hook 'gnus-pick-mode-hook
'gnus-xmas-pick-menu-add
))
57 (defcustom gnus-mark-unpicked-articles-as-read nil
58 "*If non-nil, mark all unpicked articles as read."
60 :group
'gnus-summary-pick
)
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."
66 :group
'gnus-summary-pick
)
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."
73 :group
'gnus-summary-pick
)
75 ;;; Internal variables.
77 (defvar gnus-pick-mode-map nil
)
79 (unless gnus-pick-mode-map
80 (setq gnus-pick-mode-map
(make-sparse-keymap))
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
))
89 (defun gnus-pick-make-menu-bar ()
90 (unless (boundp 'gnus-pick-menu
)
92 gnus-pick-menu gnus-pick-mode-map
""
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
])
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
]))))
109 (defun gnus-pick-mode (&optional arg
)
110 "Minor mode for providing a pick-and-read interface in Gnus summary buffers.
112 \\{gnus-pick-mode-map}"
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
)
129 (when (gnus-visual-p 'pick-menu
'menu
)
130 (gnus-pick-make-menu-bar))
131 (add-minor-mode 'gnus-pick-mode
" Pick" gnus-pick-mode-map
)
132 (gnus-run-hooks 'gnus-pick-mode-hook
))))
134 (defun gnus-pick-setup-message ()
135 "Make Message do the right thing on exit."
136 (when (and (gnus-buffer-live-p gnus-summary-buffer
)
137 (with-current-buffer gnus-summary-buffer
140 `(gnus-configure-windows ,gnus-current-window-configuration t
)
141 'send
'exit
'postpone
'kill
)))
143 (defvar gnus-pick-line-number
1)
144 (defun gnus-pick-line-number ()
145 "Return the current line number."
147 (setq gnus-pick-line-number
1)
148 (incf gnus-pick-line-number
)))
150 (defun gnus-pick-start-reading (&optional catch-up
)
151 "Start reading the picked articles.
152 If given a prefix, mark all unpicked articles as read."
154 (if gnus-newsgroup-processable
156 (gnus-summary-limit-to-articles nil
)
157 (when (or catch-up gnus-mark-unpicked-articles-as-read
)
158 (gnus-summary-limit-mark-excluded-as-read))
159 (gnus-summary-first-article)
160 (gnus-configure-windows
161 (if gnus-pick-display-summary
'article
'pick
) t
))
162 (if gnus-pick-elegant-flow
164 (when (or catch-up gnus-mark-unpicked-articles-as-read
)
165 (gnus-summary-catchup nil t
))
166 (if (gnus-group-quit-config gnus-newsgroup-name
)
168 (gnus-summary-next-group)))
169 (error "No articles have been picked"))))
171 (defun gnus-pick-goto-article (arg)
172 "Go to the article number indicated by ARG.
173 If ARG is an invalid article number, then stay on current line."
176 (goto-char (point-min))
177 (when (zerop (forward-line (1- (prefix-numeric-value arg
))))
180 (gnus-error 2 "No such line: %s" arg
)
183 (defun gnus-pick-article (&optional arg
)
184 "Pick the article on the current line.
185 If ARG, pick the article on that line instead."
188 (gnus-pick-goto-article arg
))
189 (gnus-summary-mark-as-processable 1))
191 (defun gnus-pick-article-or-thread (&optional arg
)
192 "If `gnus-thread-hide-subtree' is t, then pick the thread on the current line.
193 Otherwise pick the article on the current line.
194 If ARG, pick the article/thread on that line instead."
197 (gnus-pick-goto-article arg
))
198 (if gnus-thread-hide-subtree
201 (gnus-uu-mark-thread))
203 (gnus-summary-mark-as-processable 1)))
205 (defun gnus-pick-unmark-article-or-thread (&optional arg
)
206 "If `gnus-thread-hide-subtree' is t, then unmark the thread on current line.
207 Otherwise unmark the article on current line.
208 If ARG, unmark thread/article on that line instead."
211 (gnus-pick-goto-article arg
))
212 (if gnus-thread-hide-subtree
214 (gnus-uu-unmark-thread))
215 (gnus-summary-unmark-as-processable 1)))
217 (defun gnus-pick-mouse-pick (e)
221 (gnus-summary-mark-as-processable 1)))
223 (defun gnus-pick-mouse-pick-region (start-event)
224 "Pick articles that the mouse is dragged over.
225 This must be bound to a button-down mouse event."
227 (mouse-minibuffer-check start-event
)
228 (let* ((echo-keystrokes 0)
229 (start-posn (event-start start-event
))
230 (start-point (posn-point start-posn
))
231 (start-line (1+ (count-lines (point-min) start-point
)))
232 (start-window (posn-window start-posn
))
233 (bounds (gnus-window-edges start-window
))
235 (bottom (if (window-minibuffer-p start-window
)
237 ;; Don't count the mode line.
238 (1- (nth 3 bounds
))))
239 (click-count (1- (event-click-count start-event
))))
240 (setq mouse-selection-click-count click-count
)
241 (setq mouse-selection-click-count-buffer
(current-buffer))
242 (mouse-set-point start-event
)
243 ;; In case the down click is in the middle of some intangible text,
244 ;; use the end of that text, and put it in START-POINT.
245 (when (< (point) start-point
)
246 (goto-char start-point
))
248 (setq start-point
(point))
249 ;; end-of-range is used only in the single-click case.
250 ;; It is the place where the drag has reached so far
251 ;; (but not outside the window where the drag started).
252 (let (event end end-point
(end-of-range (point)))
255 (setq event
(cdr (gnus-read-event-char)))
256 (or (mouse-movement-p event
)
257 (eq (car-safe event
) 'switch-frame
)))
258 (if (eq (car-safe event
) 'switch-frame
)
260 (setq end
(event-end event
)
261 end-point
(posn-point end
))
264 ;; Are we moving within the original window?
265 ((and (eq (posn-window end
) start-window
)
266 (integer-or-marker-p end-point
))
267 ;; Go to START-POINT first, so that when we move to END-POINT,
268 ;; if it's in the middle of intangible text,
269 ;; point jumps in the direction away from START-POINT.
270 (goto-char start-point
)
271 (goto-char end-point
)
273 ;; In case the user moved his mouse really fast, pick
274 ;; articles on the line between this one and the last one.
275 (let* ((this-line (1+ (count-lines (point-min) end-point
)))
276 (min-line (min this-line start-line
))
277 (max-line (max this-line start-line
)))
278 ;; Why not use `forward-line'? --Stef
279 (while (< min-line max-line
)
282 (setq min-line
(1+ min-line
)))
283 (setq start-line this-line
))
284 (when (zerop (% click-count
3))
285 (setq end-of-range
(point))))
287 (let ((mouse-row (cdr (cdr (mouse-position)))))
291 (mouse-scroll-subr start-window
(- mouse-row top
)))
292 ((>= mouse-row bottom
)
293 (mouse-scroll-subr start-window
294 (1+ (- mouse-row bottom
)))))))))))
296 (let ((fun (key-binding (vector (car event
)))))
297 ;; Run the binding of the terminating up-event, if possible.
298 ;; In the case of a multiple click, it gives the wrong results,
299 ;; because it would fail to set up a region.
301 ;; (and (= (mod mouse-selection-click-count 3) 0) (fboundp fun))
302 ;; In this case, we can just let the up-event execute normally.
303 (let ((end (event-end event
)))
304 ;; Set the position in the event before we replay it,
305 ;; because otherwise it may have a position in the wrong
307 (setcar (cdr end
) end-of-range
)
308 ;; Delete the overlay before calling the function,
309 ;; because delete-overlay increases buffer-modified-tick.
310 (push event unread-command-events
))))))))
312 (defun gnus-pick-next-page ()
313 "Go to the next page. If at the end of the buffer, start reading articles."
315 (let ((scroll-in-place nil
))
318 (end-of-buffer (gnus-pick-start-reading)))))
324 (defvar gnus-binary-mode nil
325 "Minor mode for providing a binary group interface in Gnus summary buffers.")
327 (defvar gnus-binary-mode-hook nil
328 "Hook run in summary binary mode buffers.")
330 (defvar gnus-binary-mode-map nil
)
332 (unless gnus-binary-mode-map
333 (setq gnus-binary-mode-map
(make-sparse-keymap))
337 "g" gnus-binary-show-article
))
339 (defun gnus-binary-make-menu-bar ()
340 (unless (boundp 'gnus-binary-menu
)
342 gnus-binary-menu gnus-binary-mode-map
""
344 ["Switch binary mode off" gnus-binary-mode t
]))))
346 (defun gnus-binary-mode (&optional arg
)
347 "Minor mode for providing a binary group interface in Gnus summary buffers."
349 (when (eq major-mode
'gnus-summary-mode
)
350 (make-local-variable 'gnus-binary-mode
)
351 (setq gnus-binary-mode
352 (if (null arg
) (not gnus-binary-mode
)
353 (> (prefix-numeric-value arg
) 0)))
354 (when gnus-binary-mode
355 ;; Make sure that we don't select any articles upon group entry.
356 (make-local-variable 'gnus-auto-select-first
)
357 (setq gnus-auto-select-first nil
)
358 (make-local-variable 'gnus-summary-display-article-function
)
359 (setq gnus-summary-display-article-function
'gnus-binary-display-article
)
361 (when (gnus-visual-p 'binary-menu
'menu
)
362 (gnus-binary-make-menu-bar))
363 (add-minor-mode 'gnus-binary-mode
" Binary" gnus-binary-mode-map
)
364 (gnus-run-hooks 'gnus-binary-mode-hook
))))
366 (defun gnus-binary-display-article (article &optional all-header
)
367 "Run ARTICLE through the binary decode functions."
368 (when (gnus-summary-goto-subject article
)
369 (let ((gnus-view-pseudos (or gnus-view-pseudos
'automatic
)))
370 (gnus-uu-decode-uu))))
372 (defun gnus-binary-show-article (&optional arg
)
373 "Bypass the binary functions and show the article."
375 (let (gnus-summary-display-article-function)
376 (gnus-summary-show-article arg
)))
382 (defcustom gnus-tree-line-format
"%(%[%3,3n%]%)"
383 "Format of tree elements."
385 :group
'gnus-summary-tree
)
387 (defcustom gnus-tree-minimize-window t
388 "If non-nil, minimize the tree buffer window.
389 If a number, never let the tree buffer grow taller than that number of
391 :type
'(choice boolean
393 :group
'gnus-summary-tree
)
395 (defcustom gnus-selected-tree-face
'modeline
396 "*Face used for highlighting selected articles in the thread tree."
398 :group
'gnus-summary-tree
)
400 (defvar gnus-tree-brackets
'((?\
[ . ?\
]) (?\
( . ?\
))
401 (?\
{ . ?\
}) (?
< . ?
>))
402 "Brackets used in tree nodes.")
404 (defvar gnus-tree-parent-child-edges
'(?- ?
\\ ?|
)
405 "Characters used to connect parents with children.")
407 (defcustom gnus-tree-mode-line-format
"Gnus: %%b %S %Z"
408 "*The format specification for the tree mode line."
410 :group
'gnus-summary-tree
)
412 (defcustom gnus-generate-tree-function
'gnus-generate-vertical-tree
413 "*Function for generating a thread tree.
414 Two predefined functions are available:
415 `gnus-generate-horizontal-tree' and `gnus-generate-vertical-tree'."
416 :type
'(radio (function-item gnus-generate-vertical-tree
)
417 (function-item gnus-generate-horizontal-tree
)
418 (function :tag
"Other" nil
))
419 :group
'gnus-summary-tree
)
421 (defcustom gnus-tree-mode-hook nil
422 "*Hook run in tree mode buffers."
424 :group
'gnus-summary-tree
)
426 (when (featurep 'xemacs
)
427 (add-hook 'gnus-tree-mode-hook
'gnus-xmas-tree-menu-add
)
428 (add-hook 'gnus-tree-mode-hook
'gnus-xmas-switch-horizontal-scrollbar-off
))
431 ;;; Internal variables.
433 (defvar gnus-tree-line-format-alist
434 `((?n gnus-tmp-name ?s
)
435 (?f gnus-tmp-from ?s
)
436 (?N gnus-tmp-number ?d
)
437 (?\
[ gnus-tmp-open-bracket ?c
)
438 (?\
] gnus-tmp-close-bracket ?c
)
439 (?s gnus-tmp-subject ?s
)))
441 (defvar gnus-tree-mode-line-format-alist gnus-summary-mode-line-format-alist
)
443 (defvar gnus-tree-mode-line-format-spec nil
)
444 (defvar gnus-tree-line-format-spec nil
)
446 (defvar gnus-tree-node-length nil
)
447 (defvar gnus-selected-tree-overlay nil
)
449 (defvar gnus-tree-displayed-thread nil
)
450 (defvar gnus-tree-inhibit nil
)
452 (defvar gnus-tree-mode-map nil
)
453 (put 'gnus-tree-mode
'mode-class
'special
)
455 (unless gnus-tree-mode-map
456 (setq gnus-tree-mode-map
(make-keymap))
457 (suppress-keymap gnus-tree-mode-map
)
460 "\r" gnus-tree-select-article
461 gnus-mouse-2 gnus-tree-pick-article
462 "\C-?" gnus-tree-read-summary-keys
463 "h" gnus-tree-show-summary
465 "\C-c\C-i" gnus-info-find-node
)
467 (substitute-key-definition
468 'undefined
'gnus-tree-read-summary-keys gnus-tree-mode-map
))
470 (defun gnus-tree-make-menu-bar ()
471 (unless (boundp 'gnus-tree-menu
)
473 gnus-tree-menu gnus-tree-mode-map
""
475 ["Select article" gnus-tree-select-article t
]))))
477 (defun gnus-tree-mode ()
478 "Major mode for displaying thread trees."
480 (gnus-set-format 'tree-mode
)
481 (gnus-set-format 'tree t
)
482 (when (gnus-visual-p 'tree-menu
'menu
)
483 (gnus-tree-make-menu-bar))
484 (kill-all-local-variables)
485 (gnus-simplify-mode-line)
486 (setq mode-name
"Tree")
487 (setq major-mode
'gnus-tree-mode
)
488 (use-local-map gnus-tree-mode-map
)
489 (buffer-disable-undo)
490 (setq buffer-read-only t
)
491 (setq truncate-lines t
)
493 (gnus-set-work-buffer)
494 (gnus-tree-node-insert (make-mail-header "") nil
)
495 (setq gnus-tree-node-length
(1- (point))))
496 (gnus-run-mode-hooks 'gnus-tree-mode-hook
))
498 (defun gnus-tree-read-summary-keys (&optional arg
)
499 "Read a summary buffer key sequence and execute it."
501 (unless gnus-tree-inhibit
502 (let ((buf (current-buffer))
503 (gnus-tree-inhibit t
)
505 (set-buffer gnus-article-buffer
)
506 (gnus-article-read-summary-keys arg nil t
)
507 (when (setq win
(get-buffer-window buf
))
509 (when gnus-selected-tree-overlay
510 (goto-char (or (gnus-overlay-end gnus-selected-tree-overlay
) 1)))
511 (gnus-tree-minimize)))))
513 (defun gnus-tree-show-summary ()
514 "Reconfigure windows to show summary buffer."
516 (if (not (gnus-buffer-live-p gnus-summary-buffer
))
517 (error "There is no summary buffer for this tree buffer")
518 (gnus-configure-windows 'article
)
519 (gnus-summary-goto-subject gnus-current-article
)))
521 (defun gnus-tree-select-article (article)
522 "Select the article under point, if any."
523 (interactive (list (gnus-tree-article-number)))
524 (let ((buf (current-buffer)))
526 (with-current-buffer gnus-summary-buffer
527 (gnus-summary-goto-article article
))
528 (select-window (get-buffer-window buf
)))))
530 (defun gnus-tree-pick-article (e)
531 "Select the article under the mouse pointer."
534 (gnus-tree-select-article (gnus-tree-article-number)))
536 (defun gnus-tree-article-number ()
537 (get-text-property (point) 'gnus-number
))
539 (defun gnus-tree-article-region (article)
540 "Return a cons with BEG and END of the article region."
541 (let ((pos (text-property-any
542 (point-min) (point-max) 'gnus-number article
)))
544 (cons pos
(next-single-property-change pos
'gnus-number
)))))
546 (defun gnus-tree-goto-article (article)
547 (let ((pos (text-property-any
548 (point-min) (point-max) 'gnus-number article
)))
552 (defun gnus-tree-recenter ()
553 "Center point in the tree window."
554 (let ((selected (selected-window))
555 (tree-window (gnus-get-buffer-window gnus-tree-buffer t
)))
557 (select-window tree-window
)
558 (when gnus-selected-tree-overlay
559 (goto-char (or (gnus-overlay-end gnus-selected-tree-overlay
) 1)))
560 (let* ((top (cond ((< (window-height) 4) 0)
561 ((< (window-height) 7) 1)
563 (height (1- (window-height)))
564 (bottom (save-excursion (goto-char (point-max))
565 (forward-line (- height
))
567 ;; Set the window start to either `bottom', which is the biggest
568 ;; possible valid number, or the second line from the top,
569 ;; whichever is the least.
571 tree-window
(min bottom
(save-excursion
572 (forward-line (- top
)) (point)))))
573 (select-window selected
))))
575 (defun gnus-get-tree-buffer ()
576 "Return the tree buffer properly initialized."
577 (with-current-buffer (gnus-get-buffer-create gnus-tree-buffer
)
578 (unless (eq major-mode
'gnus-tree-mode
)
582 (defun gnus-tree-minimize ()
583 (when (and gnus-tree-minimize-window
584 (not (one-window-p)))
587 (walk-windows (lambda (window) (incf windows
)))
590 (* window-min-height
(1- windows
))
592 (let* ((window-min-height 2)
593 (height (count-lines (point-min) (point-max)))
594 (min (max (1- window-min-height
) height
))
595 (tot (if (numberp gnus-tree-minimize-window
)
596 (min gnus-tree-minimize-window min
)
598 (win (get-buffer-window (current-buffer)))
599 (wh (and win
(1- (window-height win
)))))
600 (setq tot
(min tot tot-win-height
))
603 (let ((selected (selected-window)))
604 (when (ignore-errors (select-window win
))
605 (enlarge-window (- tot wh
))
606 (select-window selected
))))))))
608 ;;; Generating the tree.
610 (defun gnus-tree-node-insert (header sparse
&optional adopted
)
611 (let* ((dummy (stringp header
))
612 (header (if (vectorp header
) header
614 (setq header
(make-mail-header "*****"))
615 (mail-header-set-number header
0)
616 (mail-header-set-lines header
0)
617 (mail-header-set-chars header
0)
619 (gnus-tmp-from (mail-header-from header
))
620 (gnus-tmp-subject (mail-header-subject header
))
621 (gnus-tmp-number (mail-header-number header
))
624 ((string-match "(.+)" gnus-tmp-from
)
625 (substring gnus-tmp-from
626 (1+ (match-beginning 0)) (1- (match-end 0))))
627 ((string-match "<[^>]+> *$" gnus-tmp-from
)
628 (let ((beg (match-beginning 0)))
629 (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from
)
630 (substring gnus-tmp-from
(1+ (match-beginning 0))
632 (substring gnus-tmp-from
0 beg
))))
633 ((memq gnus-tmp-number sparse
)
636 (gnus-tmp-open-bracket
637 (cond ((memq gnus-tmp-number sparse
)
638 (caadr gnus-tree-brackets
))
639 (dummy (caaddr gnus-tree-brackets
))
640 (adopted (car (nth 3 gnus-tree-brackets
)))
641 (t (caar gnus-tree-brackets
))))
642 (gnus-tmp-close-bracket
643 (cond ((memq gnus-tmp-number sparse
)
644 (cdadr gnus-tree-brackets
))
645 (adopted (cdr (nth 3 gnus-tree-brackets
)))
647 (cdaddr gnus-tree-brackets
))
648 (t (cdar gnus-tree-brackets
))))
649 (buffer-read-only nil
)
651 (gnus-add-text-properties
653 (setq end
(progn (eval gnus-tree-line-format-spec
) (point)))
654 (list 'gnus-number gnus-tmp-number
))
655 (when (or t
(gnus-visual-p 'tree-highlight
'highlight
))
656 (gnus-tree-highlight-node gnus-tmp-number beg end
))))
658 (defun gnus-tree-highlight-node (article beg end
)
659 "Highlight current line according to `gnus-summary-highlight'."
660 (let ((list gnus-summary-highlight
)
662 (with-current-buffer gnus-summary-buffer
663 (let* ((score (or (cdr (assq article gnus-newsgroup-scored
))
664 gnus-summary-default-score
0))
665 (default gnus-summary-default-score
)
666 (default-high gnus-summary-default-high-score
)
667 (default-low gnus-summary-default-low-score
)
668 (uncached (memq article gnus-newsgroup-undownloaded
))
669 (downloaded (not uncached
))
670 (mark (or (gnus-summary-article-mark article
) gnus-unread-mark
)))
671 ;; Eval the cars of the lists until we find a match.
673 (not (eval (caar list
))))
674 (setq list
(cdr list
)))))
675 (unless (eq (setq face
(cdar list
)) (get-text-property beg
'face
))
676 (gnus-put-text-property-excluding-characters-with-faces
678 (if (boundp face
) (symbol-value face
) face
)))))
680 (defun gnus-tree-indent (level)
681 (insert (make-string (1- (* (1+ gnus-tree-node-length
) level
)) ?
)))
683 (defvar gnus-tmp-limit
)
684 (defvar gnus-tmp-sparse
)
685 (defvar gnus-tmp-indent
)
687 (defun gnus-generate-tree (thread)
688 "Generate a thread tree for THREAD."
689 (with-current-buffer (gnus-get-tree-buffer)
690 (let ((buffer-read-only nil
)
693 (funcall gnus-generate-tree-function thread
0)
694 (gnus-set-mode-line 'tree
)
695 (goto-char (point-min))
698 (let ((selected (selected-window)))
699 (when (gnus-get-buffer-window (set-buffer gnus-tree-buffer
) t
)
700 (select-window (gnus-get-buffer-window (set-buffer gnus-tree-buffer
) t
))
701 (gnus-horizontal-recenter)
702 (select-window selected
))))))
704 (defun gnus-generate-horizontal-tree (thread level
&optional dummyp adopted
)
705 "Generate a horizontal tree."
706 (let* ((dummy (stringp (car thread
)))
709 (memq (mail-header-number (car thread
))
713 ;; We don't want this article.
714 (setq thread
(cdr thread
))
716 ;; Not the first article on the line, so we insert a "-".
717 (insert (car gnus-tree-parent-child-edges
))
718 ;; If the level isn't zero, then we insert some indentation.
719 (unless (zerop level
)
720 (gnus-tree-indent level
)
721 (insert (cadr gnus-tree-parent-child-edges
))
722 (setq col
(- (setq beg
(point)) (point-at-bol) 1))
723 ;; Draw "|" lines upwards.
727 (eq (char-after) ?
))
729 (insert (caddr gnus-tree-parent-child-edges
)))
732 ;; Insert the article node.
733 (gnus-tree-node-insert (pop thread
) gnus-tmp-sparse adopted
))
735 ;; End of the thread, so we go to the next line.
738 ;; Recurse downwards in all children of this article.
740 (gnus-generate-horizontal-tree
741 (pop thread
) (if do
(1+ level
) level
)
742 (or dummyp dummy
) dummy
)))))
744 (defsubst gnus-tree-indent-vertical
()
745 (let ((len (- (* (1+ gnus-tree-node-length
) gnus-tmp-indent
)
746 (- (point) (point-at-bol)))))
748 (insert (make-string len ?
)))))
750 (defsubst gnus-tree-forward-line
(n)
751 (while (>= (decf n
) 0)
752 (unless (zerop (forward-line 1))
757 (defun gnus-generate-vertical-tree (thread level
&optional dummyp adopted
)
758 "Generate a vertical tree."
759 (let* ((dummy (stringp (car thread
)))
762 (memq (mail-header-number (car thread
))
766 ;; We don't want this article.
767 (setq thread
(cdr thread
))
768 (if (not (save-excursion (beginning-of-line) (bobp)))
769 ;; Not the first article on the line, so we insert a "-".
771 (gnus-tree-indent-vertical)
772 (insert (make-string (/ gnus-tree-node-length
2) ?
))
773 (insert (caddr gnus-tree-parent-child-edges
))
774 (gnus-tree-forward-line 1))
775 ;; If the level isn't zero, then we insert some indentation.
776 (unless (zerop gnus-tmp-indent
)
777 (gnus-tree-forward-line (1- (* 2 level
)))
778 (gnus-tree-indent-vertical)
780 (insert (cadr gnus-tree-parent-child-edges
))
783 ;; Draw "-" lines leftwards.
784 (while (and (not (bobp))
785 (eq (char-after (1- (point))) ?
))
787 (insert (car gnus-tree-parent-child-edges
))
790 (gnus-tree-forward-line 1)))
792 ;; Insert the article node.
793 (gnus-tree-indent-vertical)
794 (gnus-tree-node-insert (pop thread
) gnus-tmp-sparse adopted
)
795 (gnus-tree-forward-line 1))
797 ;; End of the thread, so we go to the next line.
799 (goto-char (point-min))
801 (incf gnus-tmp-indent
))
802 ;; Recurse downwards in all children of this article.
804 (gnus-generate-vertical-tree
805 (pop thread
) (if do
(1+ level
) level
)
806 (or dummyp dummy
) dummy
)))))
808 ;;; Interface functions.
810 (defun gnus-possibly-generate-tree (article &optional force
)
811 "Generate the thread tree for ARTICLE if it isn't displayed already."
812 (when (with-current-buffer gnus-summary-buffer
815 (vectorp (gnus-summary-article-header article
))))
817 (let ((top (with-current-buffer gnus-summary-buffer
821 (gnus-summary-article-header article
))
823 (gnus-tmp-limit gnus-newsgroup-limit
)
824 (gnus-tmp-sparse gnus-newsgroup-sparse
))
826 (not (eq top gnus-tree-displayed-thread
)))
827 (gnus-generate-tree top
)
828 (setq gnus-tree-displayed-thread top
))))))
830 (defun gnus-tree-open (group)
831 (gnus-get-tree-buffer))
833 (defun gnus-tree-close (group)
834 (gnus-kill-buffer gnus-tree-buffer
))
836 (defun gnus-tree-perhaps-minimize ()
837 (when (and gnus-tree-minimize-window
838 (get-buffer gnus-tree-buffer
))
839 (with-current-buffer gnus-tree-buffer
840 (gnus-tree-minimize))))
842 (defun gnus-highlight-selected-tree (article)
843 "Highlight the selected article in the tree."
844 (let ((buf (current-buffer))
846 (set-buffer gnus-tree-buffer
)
847 (when (setq region
(gnus-tree-article-region article
))
848 (when (or (not gnus-selected-tree-overlay
)
849 (gnus-extent-detached-p gnus-selected-tree-overlay
))
850 ;; Create a new overlay.
852 (setq gnus-selected-tree-overlay
853 (gnus-make-overlay (point-min) (1+ (point-min))))
854 'face gnus-selected-tree-face
))
855 ;; Move the overlay to the article.
857 gnus-selected-tree-overlay
(goto-char (car region
)) (cdr region
))
860 (let ((selected (selected-window)))
861 (when (gnus-get-buffer-window (set-buffer gnus-tree-buffer
) t
)
862 (select-window (gnus-get-buffer-window (set-buffer gnus-tree-buffer
) t
))
863 (gnus-horizontal-recenter)
864 (select-window selected
))))
865 ;; If we remove this save-excursion, it updates the wrong mode lines?!?
866 (with-current-buffer gnus-tree-buffer
867 (gnus-set-mode-line 'tree
))
870 (defun gnus-tree-highlight-article (article face
)
871 (with-current-buffer (gnus-get-tree-buffer)
873 (when (setq region
(gnus-tree-article-region article
))
874 (gnus-put-text-property (car region
) (cdr region
) 'face face
)
876 (gnus-get-buffer-window (current-buffer) t
) (cdr region
))))))
882 (defvar gnus-carpal-group-buffer-buttons
883 '(("next" . gnus-group-next-unread-group
)
884 ("prev" . gnus-group-prev-unread-group
)
885 ("read" . gnus-group-read-group
)
886 ("select" . gnus-group-select-group
)
887 ("catch-up" . gnus-group-catchup-current
)
888 ("new-news" . gnus-group-get-new-news-this-group
)
889 ("toggle-sub" . gnus-group-unsubscribe-current-group
)
890 ("subscribe" . gnus-group-unsubscribe-group
)
891 ("kill" . gnus-group-kill-group
)
892 ("yank" . gnus-group-yank-group
)
893 ("describe" . gnus-group-describe-group
)
895 ("subscribed" . gnus-group-list-groups
)
896 ("all" . gnus-group-list-all-groups
)
897 ("killed" . gnus-group-list-killed
)
898 ("zombies" . gnus-group-list-zombies
)
899 ("matching" . gnus-group-list-matching
)
900 ("post" . gnus-group-post-news
)
901 ("mail" . gnus-group-mail
)
902 ("local" .
(lambda () (interactive) (gnus-group-news 0)))
903 ("rescan" . gnus-group-get-new-news
)
904 ("browse-foreign" . gnus-group-browse-foreign
)
905 ("exit" . gnus-group-exit
)))
907 (defvar gnus-carpal-summary-buffer-buttons
909 ("read" . gnus-summary-mark-as-read-forward
)
910 ("tick" . gnus-summary-tick-article-forward
)
911 ("clear" . gnus-summary-clear-mark-forward
)
912 ("expirable" . gnus-summary-mark-as-expirable
)
914 ("scroll" . gnus-summary-next-page
)
915 ("next-unread" . gnus-summary-next-unread-article
)
916 ("prev-unread" . gnus-summary-prev-unread-article
)
917 ("first" . gnus-summary-first-unread-article
)
918 ("best" . gnus-summary-best-unread-article
)
920 ("headers" . gnus-summary-toggle-header
)
921 ("uudecode" . gnus-uu-decode-uu
)
922 ("enter-digest" . gnus-summary-enter-digest-group
)
923 ("fetch-parent" . gnus-summary-refer-parent-article
)
925 ("move" . gnus-summary-move-article
)
926 ("copy" . gnus-summary-copy-article
)
927 ("respool" . gnus-summary-respool-article
)
929 ("lower" . gnus-summary-lower-thread
)
930 ("kill" . gnus-summary-kill-thread
)
932 ("post" . gnus-summary-post-news
)
933 ("local" . gnus-summary-news-other-window
)
934 ("mail" . gnus-summary-mail-other-window
)
935 ("followup" . gnus-summary-followup-with-original
)
936 ("reply" . gnus-summary-reply-with-original
)
937 ("cancel" . gnus-summary-cancel-article
)
939 ("exit" . gnus-summary-exit
)
940 ("fed-up" . gnus-summary-catchup-and-goto-next-group
)))
942 (defvar gnus-carpal-server-buffer-buttons
943 '(("add" . gnus-server-add-server
)
944 ("browse" . gnus-server-browse-server
)
945 ("list" . gnus-server-list-servers
)
946 ("kill" . gnus-server-kill-server
)
947 ("yank" . gnus-server-yank-server
)
948 ("copy" . gnus-server-copy-server
)
949 ("exit" . gnus-server-exit
)))
951 (defvar gnus-carpal-browse-buffer-buttons
952 '(("subscribe" . gnus-browse-unsubscribe-current-group
)
953 ("exit" . gnus-browse-exit
)))
955 (defvar gnus-carpal-group-buffer
"*Carpal Group*")
956 (defvar gnus-carpal-summary-buffer
"*Carpal Summary*")
957 (defvar gnus-carpal-server-buffer
"*Carpal Server*")
958 (defvar gnus-carpal-browse-buffer
"*Carpal Browse*")
960 (defvar gnus-carpal-attached-buffer nil
)
962 (defvar gnus-carpal-mode-hook nil
963 "*Hook run in carpal mode buffers.")
965 (defvar gnus-carpal-button-face
'bold
966 "*Face used on carpal buttons.")
968 (defvar gnus-carpal-header-face
'bold-italic
969 "*Face used on carpal buffer headers.")
971 (defvar gnus-carpal-mode-map nil
)
972 (put 'gnus-carpal-mode
'mode-class
'special
)
974 (if gnus-carpal-mode-map
976 (setq gnus-carpal-mode-map
(make-keymap))
977 (suppress-keymap gnus-carpal-mode-map
)
978 (define-key gnus-carpal-mode-map
" " 'gnus-carpal-select
)
979 (define-key gnus-carpal-mode-map
"\r" 'gnus-carpal-select
)
980 (define-key gnus-carpal-mode-map gnus-mouse-2
'gnus-carpal-mouse-select
))
982 (defun gnus-carpal-mode ()
983 "Major mode for clicking buttons.
985 All normal editing commands are switched off.
986 \\<gnus-carpal-mode-map>
987 The following commands are available:
989 \\{gnus-carpal-mode-map}"
991 (kill-all-local-variables)
992 (setq mode-line-modified
(cdr gnus-mode-line-modified
))
993 (setq major-mode
'gnus-carpal-mode
)
994 (setq mode-name
"Gnus Carpal")
995 (setq mode-line-process nil
)
996 (use-local-map gnus-carpal-mode-map
)
997 (buffer-disable-undo)
998 (setq buffer-read-only t
)
999 (make-local-variable 'gnus-carpal-attached-buffer
)
1000 (gnus-run-mode-hooks 'gnus-carpal-mode-hook
))
1002 (defun gnus-carpal-setup-buffer (type)
1003 (let ((buffer (symbol-value (intern (format "gnus-carpal-%s-buffer" type
)))))
1004 (if (get-buffer buffer
)
1006 (with-current-buffer (gnus-get-buffer-create buffer
)
1008 (setq gnus-carpal-attached-buffer
1009 (intern (format "gnus-%s-buffer" type
)))
1010 (let ((buttons (symbol-value
1011 (intern (format "gnus-carpal-%s-buffer-buttons"
1013 (buffer-read-only nil
)
1016 (setq button
(car buttons
)
1017 buttons
(cdr buttons
))
1018 (if (stringp button
)
1019 (set-text-properties
1021 (prog2 (insert button
) (point) (insert " "))
1022 (list 'face gnus-carpal-header-face
))
1023 (set-text-properties
1025 (prog2 (insert (car button
)) (point) (insert " "))
1026 (list 'gnus-callback
(cdr button
)
1027 'face gnus-carpal-button-face
1028 gnus-mouse-face-prop
'highlight
))))
1029 (let ((fill-column (- (window-width) 2)))
1030 (fill-region (point-min) (point-max)))
1031 (set-window-point (get-buffer-window (current-buffer))
1034 (defun gnus-carpal-select ()
1035 "Select the button under point."
1037 (let ((func (get-text-property (point) 'gnus-callback
)))
1040 (pop-to-buffer (symbol-value gnus-carpal-attached-buffer
))
1041 (call-interactively func
))))
1043 (defun gnus-carpal-mouse-select (event)
1044 "Select the button under the mouse pointer."
1046 (mouse-set-point event
)
1047 (gnus-carpal-select))
1049 ;;; Allow redefinition of functions.
1052 (provide 'gnus-salt
)
1054 ;; arch-tag: 35449164-77b3-4398-bcbd-a2e3e998f810
1055 ;;; gnus-salt.el ends here