1 ;;; gnus-salt.el --- alternate summary mode interfaces for Gnus
2 ;; Copyright (C) 1996 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
6 ;; This file is part of GNU Emacs.
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to
20 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
32 (defvar gnus-pick-mode nil
33 "Minor mode for providing a pick-and-read interface in Gnus summary buffers.")
35 (defvar gnus-pick-display-summary nil
36 "*Display summary while reading.")
38 (defvar gnus-pick-mode-hook nil
39 "Hook run in summary pick mode buffers.")
41 ;;; Internal variables.
43 (defvar gnus-pick-mode-map nil)
45 (unless gnus-pick-mode-map
46 (setq gnus-pick-mode-map (make-sparse-keymap))
50 "t" gnus-uu-mark-thread
51 "T" gnus-uu-unmark-thread
52 " " gnus-summary-mark-as-processable
53 "u" gnus-summary-unmark-as-processable
54 "U" gnus-summary-unmark-all-processable
55 "r" gnus-uu-mark-region
56 "R" gnus-uu-unmark-region
57 "e" gnus-uu-mark-by-regexp
58 "E" gnus-uu-mark-by-regexp
59 "b" gnus-uu-mark-buffer
60 "B" gnus-uu-unmark-buffer
61 "\r" gnus-pick-start-reading))
63 (defun gnus-pick-make-menu-bar ()
64 (unless (boundp 'gnus-pick-menu)
66 gnus-pick-menu gnus-pick-mode-map ""
69 ["Article" gnus-summary-mark-as-processable t]
70 ["Thread" gnus-uu-mark-thread t]
71 ["Region" gnus-uu-mark-region t]
72 ["Regexp" gnus-uu-mark-regexp t]
73 ["Buffer" gnus-uu-mark-buffer t])
75 ["Article" gnus-summary-unmark-as-processable t]
76 ["Thread" gnus-uu-unmark-thread t]
77 ["Region" gnus-uu-unmark-region t]
78 ["Regexp" gnus-uu-unmark-regexp t]
79 ["Buffer" gnus-uu-unmark-buffer t])
80 ["Start reading" gnus-pick-start-reading t]
81 ["Switch pick mode off" gnus-pick-mode gnus-pick-mode]))))
83 (defun gnus-pick-mode (&optional arg)
84 "Minor mode for provind a pick-and-read interface in Gnus summary buffers."
86 (when (eq major-mode 'gnus-summary-mode)
87 (make-local-variable 'gnus-pick-mode)
89 (if (null arg) (not gnus-pick-mode)
90 (> (prefix-numeric-value arg) 0)))
92 ;; Make sure that we don't select any articles upon group entry.
93 (make-local-variable 'gnus-auto-select-first)
94 (setq gnus-auto-select-first nil)
96 (when (and menu-bar-mode
97 (gnus-visual-p 'pick-menu 'menu))
98 (gnus-pick-make-menu-bar))
99 (unless (assq 'gnus-pick-mode minor-mode-alist)
100 (push '(gnus-pick-mode " Pick") minor-mode-alist))
101 (unless (assq 'gnus-topic-mode minor-mode-map-alist)
102 (push (cons 'gnus-topic-mode gnus-pick-mode-map)
103 minor-mode-map-alist))
104 (run-hooks 'gnus-pick-mode-hook))))
106 (defun gnus-pick-start-reading (&optional catch-up)
107 "Start reading the picked articles.
108 If given a prefix, mark all unpicked articles as read."
110 (unless gnus-newsgroup-processable
111 (error "No articles have been picked"))
112 (gnus-summary-limit-to-articles nil)
114 (gnus-summary-limit-mark-excluded-as-read))
115 (gnus-configure-windows (if gnus-pick-display-summary 'summary 'pick) t))
122 (defvar gnus-binary-mode nil
123 "Minor mode for provind a binary group interface in Gnus summary buffers.")
125 (defvar gnus-binary-mode-hook nil
126 "Hook run in summary binary mode buffers.")
128 (defvar gnus-binary-mode-map nil)
130 (unless gnus-binary-mode-map
131 (setq gnus-binary-mode-map (make-sparse-keymap))
135 "g" gnus-binary-show-article))
137 (defun gnus-binary-make-menu-bar ()
138 (unless (boundp 'gnus-binary-menu)
140 gnus-binary-menu gnus-binary-mode-map ""
142 ["Switch binary mode off" gnus-binary-mode t]))))
144 (defun gnus-binary-mode (&optional arg)
145 "Minor mode for providing a binary group interface in Gnus summary buffers."
147 (when (eq major-mode 'gnus-summary-mode)
148 (make-local-variable 'gnus-binary-mode)
149 (setq gnus-binary-mode
150 (if (null arg) (not gnus-binary-mode)
151 (> (prefix-numeric-value arg) 0)))
152 (when gnus-binary-mode
153 ;; Make sure that we don't select any articles upon group entry.
154 (make-local-variable 'gnus-auto-select-first)
155 (setq gnus-auto-select-first nil)
156 (make-local-variable 'gnus-summary-display-article-function)
157 (setq gnus-summary-display-article-function 'gnus-binary-display-article)
159 (when (and menu-bar-mode
160 (gnus-visual-p 'binary-menu 'menu))
161 (gnus-binary-make-menu-bar))
162 (unless (assq 'gnus-binary-mode minor-mode-alist)
163 (push '(gnus-binary-mode " Binary") minor-mode-alist))
164 (unless (assq 'gnus-topic-mode minor-mode-map-alist)
165 (push (cons 'gnus-topic-mode gnus-binary-mode-map)
166 minor-mode-map-alist))
167 (run-hooks 'gnus-binary-mode-hook))))
169 (defun gnus-binary-display-article (article &optional all-header)
170 "Run ARTICLE through the binary decode functions."
171 (when (gnus-summary-goto-subject article)
172 (let ((gnus-view-pseudos 'automatic))
173 (gnus-uu-decode-uu))))
175 (defun gnus-binary-show-article (&optional arg)
176 "Bypass the binary functions and show the article."
178 (let (gnus-summary-display-article-function)
179 (gnus-summary-show-article arg)))
185 (defvar gnus-tree-line-format "%(%[%3,3n%]%)"
186 "Format of tree elements.")
188 (defvar gnus-tree-minimize-window t
189 "If non-nil, minimize the tree buffer window.
190 If a number, never let the tree buffer grow taller than that number of
193 (defvar gnus-selected-tree-face 'modeline
194 "*Face used for highlighting selected articles in the thread tree.")
196 (defvar gnus-tree-brackets '((?\[ . ?\]) (?\( . ?\)) (?\{ . ?\}))
197 "Brackets used in tree nodes.")
199 (defvar gnus-tree-parent-child-edges '(?- ?\\ ?|)
200 "Charaters used to connect parents with children.")
202 (defvar gnus-tree-mode-line-format "Gnus: %%b %S %Z"
203 "*The format specification for the tree mode line.")
205 (defvar gnus-generate-tree-function 'gnus-generate-vertical-tree
206 "*Function for generating a thread tree.
207 Two predefined functions are available:
208 `gnus-generate-horizontal-tree' and `gnus-generate-vertical-tree'.")
210 (defvar gnus-tree-mode-hook nil
211 "*Hook run in tree mode buffers.")
213 (defvar gnus-tree-buffer "*Tree*"
214 "Buffer where Gnus thread trees are displayed.")
216 ;;; Internal variables.
218 (defvar gnus-tree-line-format-alist
219 `((?n gnus-tmp-name ?s)
220 (?f gnus-tmp-from ?s)
221 (?N gnus-tmp-number ?d)
222 (?\[ gnus-tmp-open-bracket ?c)
223 (?\] gnus-tmp-close-bracket ?c)
224 (?s gnus-tmp-subject ?s)))
226 (defvar gnus-tree-mode-line-format-alist gnus-summary-mode-line-format-alist)
228 (defvar gnus-tree-mode-line-format-spec nil)
229 (defvar gnus-tree-line-format-spec nil)
231 (defvar gnus-tree-node-length nil)
232 (defvar gnus-selected-tree-overlay nil)
234 (defvar gnus-tree-displayed-thread nil)
236 (defvar gnus-tree-mode-map nil)
237 (put 'gnus-tree-mode 'mode-class 'special)
239 (unless gnus-tree-mode-map
240 (setq gnus-tree-mode-map (make-keymap))
241 (suppress-keymap gnus-tree-mode-map)
244 "\r" gnus-tree-select-article
245 gnus-mouse-2 gnus-tree-pick-article
246 "\C-?" gnus-tree-read-summary-keys)
248 (substitute-key-definition
249 'undefined 'gnus-tree-read-summary-keys gnus-tree-mode-map))
251 (defun gnus-tree-make-menu-bar ()
254 (defun gnus-tree-mode ()
255 "Major mode for displaying thread trees."
257 (setq gnus-tree-mode-line-format-spec
258 (gnus-parse-format gnus-tree-mode-line-format
259 gnus-summary-mode-line-format-alist))
260 (setq gnus-tree-line-format-spec
261 (gnus-parse-format gnus-tree-line-format
262 gnus-tree-line-format-alist t))
263 (when (and menu-bar-mode
264 (gnus-visual-p 'tree-menu 'menu))
265 (gnus-tree-make-menu-bar))
266 (kill-all-local-variables)
267 (gnus-simplify-mode-line)
268 (setq mode-name "Tree")
269 (setq major-mode 'gnus-tree-mode)
270 (use-local-map gnus-tree-mode-map)
271 (buffer-disable-undo (current-buffer))
272 (setq buffer-read-only t)
273 (setq truncate-lines t)
275 (gnus-set-work-buffer)
276 (gnus-tree-node-insert (make-mail-header "") nil)
277 (setq gnus-tree-node-length (1- (point))))
278 (run-hooks 'gnus-tree-mode-hook))
280 (defun gnus-tree-read-summary-keys (&optional arg)
281 "Read a summary buffer key sequence and execute it."
283 (let ((buf (current-buffer))
285 (gnus-article-read-summary-keys arg nil t)
286 (when (setq win (get-buffer-window buf))
288 (when gnus-selected-tree-overlay
289 (goto-char (overlay-end gnus-selected-tree-overlay)))
290 (gnus-tree-minimize))))
292 (defun gnus-tree-select-article (article)
293 "Select the article under point, if any."
294 (interactive (list (gnus-tree-article-number)))
295 (let ((buf (current-buffer)))
298 (set-buffer gnus-summary-buffer)
299 (gnus-summary-goto-article article))
300 (select-window (get-buffer-window buf)))))
302 (defun gnus-tree-pick-article (e)
303 "Select the article under the mouse pointer."
306 (gnus-tree-select-article (gnus-tree-article-number)))
308 (defun gnus-tree-article-number ()
309 (get-text-property (point) 'gnus-number))
311 (defun gnus-tree-article-region (article)
312 "Return a cons with BEG and END of the article region."
313 (let ((pos (text-property-any (point-min) (point-max) 'gnus-number article)))
315 (cons pos (next-single-property-change pos 'gnus-number)))))
317 (defun gnus-tree-goto-article (article)
318 (let ((pos (text-property-any (point-min) (point-max) 'gnus-number article)))
322 (defun gnus-tree-recenter ()
323 "Center point in the tree window."
324 (when (get-buffer-window (current-buffer))
325 (save-selected-window
326 (select-window (get-buffer-window (current-buffer)))
327 (let* ((top (cond ((< (window-height) 4) 0)
328 ((< (window-height) 7) 1)
330 (height (1- (window-height)))
331 (bottom (save-excursion (goto-char (point-max))
332 (forward-line (- height))
334 (window (get-buffer-window (current-buffer))))
335 ;; Set the window start to either `bottom', which is the biggest
336 ;; possible valid number, or the second line from the top,
337 ;; whichever is the least.
339 window (min bottom (save-excursion
340 (forward-line (- top)) (point))))))))
342 (defun gnus-get-tree-buffer ()
343 "Return the tree buffer properly initialized."
345 (set-buffer (get-buffer-create gnus-tree-buffer))
346 (unless (eq major-mode 'gnus-tree-mode)
347 (gnus-add-current-to-buffer-list)
351 (defun gnus-tree-minimize ()
352 (when (and gnus-tree-minimize-window
353 (not (one-window-p)))
354 (let* ((window-min-height 2)
355 (height (count-lines (point-min) (point-max)))
356 (min (max (1- window-min-height) height))
357 (tot (if (numberp gnus-tree-minimize-window)
358 (min gnus-tree-minimize-window min)
360 (win (get-buffer-window (current-buffer)))
361 (wh (and win (1- (window-height win)))))
364 (save-selected-window
366 (enlarge-window (- tot wh)))))))
368 ;;; Generating the tree.
370 (defun gnus-tree-node-insert (header sparse)
371 (let* ((dummy (stringp header))
372 (header (if (vectorp header) header
374 (setq header (make-mail-header "*****"))
375 (mail-header-set-number header 0)
376 (mail-header-set-lines header 0)
377 (mail-header-set-chars header 0)
379 (gnus-tmp-from (mail-header-from header))
380 (gnus-tmp-subject (mail-header-subject header))
381 (gnus-tmp-number (mail-header-number header))
384 ((string-match "(.+)" gnus-tmp-from)
385 (substring gnus-tmp-from
386 (1+ (match-beginning 0)) (1- (match-end 0))))
387 ((string-match "<[^>]+> *$" gnus-tmp-from)
388 (let ((beg (match-beginning 0)))
389 (or (and (string-match "^\"[^\"]*\"" gnus-tmp-from)
390 (substring gnus-tmp-from (1+ (match-beginning 0))
392 (substring gnus-tmp-from 0 beg))))
393 ((memq gnus-tmp-number sparse)
396 (gnus-tmp-open-bracket
397 (cond ((memq gnus-tmp-number sparse)
398 (caadr gnus-tree-brackets))
399 (dummy (caaddr gnus-tree-brackets))
400 (t (caar gnus-tree-brackets))))
401 (gnus-tmp-close-bracket
402 (cond ((memq gnus-tmp-number sparse)
403 (cdadr gnus-tree-brackets))
405 (cdaddr gnus-tree-brackets))
406 (t (cdar gnus-tree-brackets))))
407 (buffer-read-only nil)
411 (setq end (progn (eval gnus-tree-line-format-spec) (point)))
412 (list 'gnus-number gnus-tmp-number))
413 (when (or t (gnus-visual-p 'tree-highlight 'highlight))
414 (gnus-tree-highlight-node gnus-tmp-number beg end))))
416 (defun gnus-tree-highlight-node (article beg end)
417 "Highlight current line according to `gnus-summary-highlight'."
418 (let ((list gnus-summary-highlight)
421 (set-buffer gnus-summary-buffer)
422 (let* ((score (or (cdr (assq article gnus-newsgroup-scored))
423 gnus-summary-default-score 0))
424 (default gnus-summary-default-score)
425 (mark (or (gnus-summary-article-mark article) gnus-unread-mark)))
426 ;; Eval the cars of the lists until we find a match.
428 (not (eval (caar list))))
429 (setq list (cdr list)))))
430 (unless (eq (setq face (cdar list)) (get-text-property beg 'face))
433 (if (boundp face) (symbol-value face) face)))))
435 (defun gnus-tree-indent (level)
436 (insert (make-string (1- (* (1+ gnus-tree-node-length) level)) ? )))
438 (defvar gnus-tmp-limit)
439 (defvar gnus-tmp-sparse)
440 (defvar gnus-tmp-indent)
442 (defun gnus-generate-tree (thread)
443 "Generate a thread tree for THREAD."
445 (set-buffer (gnus-get-tree-buffer))
446 (let ((buffer-read-only nil)
449 (funcall gnus-generate-tree-function thread 0)
450 (gnus-set-mode-line 'tree)
451 (goto-char (point-min))
454 (gnus-horizontal-recenter))))
456 (defun gnus-generate-horizontal-tree (thread level &optional dummyp)
457 "Generate a horizontal tree."
458 (let* ((dummy (stringp (car thread)))
460 (memq (mail-header-number (car thread)) gnus-tmp-limit)))
463 ;; We don't want this article.
464 (setq thread (cdr thread))
466 ;; Not the first article on the line, so we insert a "-".
467 (insert (car gnus-tree-parent-child-edges))
468 ;; If the level isn't zero, then we insert some indentation.
469 (unless (zerop level)
470 (gnus-tree-indent level)
471 (insert (cadr gnus-tree-parent-child-edges))
472 (setq col (- (setq beg (point)) (gnus-point-at-bol) 1))
473 ;; Draw "|" lines upwards.
477 (= (following-char) ? ))
479 (insert (caddr gnus-tree-parent-child-edges)))
482 ;; Insert the article node.
483 (gnus-tree-node-insert (pop thread) gnus-tmp-sparse))
485 ;; End of the thread, so we go to the next line.
488 ;; Recurse downwards in all children of this article.
490 (gnus-generate-horizontal-tree
491 (pop thread) (if do (1+ level) level)
492 (or dummyp dummy))))))
494 (defsubst gnus-tree-indent-vertical ()
495 (let ((len (- (* (1+ gnus-tree-node-length) gnus-tmp-indent)
496 (- (point) (gnus-point-at-bol)))))
498 (insert (make-string len ? )))))
500 (defsubst gnus-tree-forward-line (n)
501 (while (>= (decf n) 0)
502 (unless (zerop (forward-line 1))
507 (defun gnus-generate-vertical-tree (thread level &optional dummyp)
508 "Generate a vertical tree."
509 (let* ((dummy (stringp (car thread)))
511 (memq (mail-header-number (car thread)) gnus-tmp-limit)))
514 ;; We don't want this article.
515 (setq thread (cdr thread))
516 (if (not (save-excursion (beginning-of-line) (bobp)))
517 ;; Not the first article on the line, so we insert a "-".
519 (gnus-tree-indent-vertical)
520 (insert (make-string (/ gnus-tree-node-length 2) ? ))
521 (insert (caddr gnus-tree-parent-child-edges))
522 (gnus-tree-forward-line 1))
523 ;; If the level isn't zero, then we insert some indentation.
524 (unless (zerop gnus-tmp-indent)
525 (gnus-tree-forward-line (1- (* 2 level)))
526 (gnus-tree-indent-vertical)
528 (insert (cadr gnus-tree-parent-child-edges))
530 ;; Draw "-" lines leftwards.
533 (= (following-char) ? ))
535 (insert (car gnus-tree-parent-child-edges)))
537 (gnus-tree-forward-line 1)))
539 ;; Insert the article node.
540 (gnus-tree-indent-vertical)
541 (gnus-tree-node-insert (pop thread) gnus-tmp-sparse)
542 (gnus-tree-forward-line 1))
544 ;; End of the thread, so we go to the next line.
546 (goto-char (point-min))
548 (incf gnus-tmp-indent))
549 ;; Recurse downwards in all children of this article.
551 (gnus-generate-vertical-tree
552 (pop thread) (if do (1+ level) level)
553 (or dummyp dummy))))))
555 ;;; Interface functions.
557 (defun gnus-possibly-generate-tree (article &optional force)
558 "Generate the thread tree for ARTICLE if it isn't displayed already."
560 (let ((top (save-excursion
561 (set-buffer gnus-summary-buffer)
564 (mail-header-id (gnus-summary-article-header article)) t))))
565 (gnus-tmp-limit gnus-newsgroup-limit)
566 (gnus-tmp-sparse gnus-newsgroup-sparse))
568 (not (eq top gnus-tree-displayed-thread)))
569 (gnus-generate-tree top)
570 (setq gnus-tree-displayed-thread top)))))
572 (defun gnus-tree-open (group)
573 (gnus-get-tree-buffer))
575 (defun gnus-tree-close (group)
576 (gnus-kill-buffer gnus-tree-buffer))
578 (defun gnus-highlight-selected-tree (article)
579 "Highlight the selected article in the tree."
580 (let ((buf (current-buffer))
582 (set-buffer gnus-tree-buffer)
583 (when (setq region (gnus-tree-article-region article))
584 (unless gnus-selected-tree-overlay
585 ;; Create a new overlay.
587 (setq gnus-selected-tree-overlay (gnus-make-overlay 1 1))
588 'face gnus-selected-tree-face))
589 ;; Move the overlay to the article.
591 gnus-selected-tree-overlay (goto-char (car region)) (cdr region))
594 (gnus-horizontal-recenter))
595 ;; If we remove this save-excursion, it updates the wrong mode lines?!?
597 (set-buffer gnus-tree-buffer)
598 (gnus-set-mode-line 'tree))
601 (defun gnus-tree-highlight-article (article face)
603 (set-buffer (gnus-get-tree-buffer))
605 (when (setq region (gnus-tree-article-region article))
606 (put-text-property (car region) (cdr region) 'face face)))))
608 ;;; gnus-salt.el ends here