* gnus-cache.el (gnus-cache-save-buffers): Use
[gnus] / lisp / 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       (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