0
|
1 ;;; gnus-srvr.el --- virtual server support for Gnus
|
16
|
2 ;; Copyright (C) 1995,96,97 Free Software Foundation, Inc.
|
0
|
3
|
|
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
|
|
5 ;; Keywords: news
|
|
6
|
|
7 ;; This file is part of GNU Emacs.
|
|
8
|
|
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
10 ;; it under the terms of the GNU General Public License as published by
|
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
|
14 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 ;; GNU General Public License for more details.
|
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
|
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 ;; Boston, MA 02111-1307, USA.
|
|
23
|
|
24 ;;; Commentary:
|
|
25
|
|
26 ;;; Code:
|
|
27
|
|
28 (require 'gnus)
|
16
|
29 (require 'gnus-spec)
|
|
30 (require 'gnus-group)
|
|
31 (require 'gnus-int)
|
|
32 (require 'gnus-range)
|
0
|
33
|
|
34 (defvar gnus-server-mode-hook nil
|
|
35 "Hook run in `gnus-server-mode' buffers.")
|
|
36
|
|
37 (defconst gnus-server-line-format " {%(%h:%w%)} %s\n"
|
|
38 "Format of server lines.
|
|
39 It works along the same lines as a normal formatting string,
|
|
40 with some simple extensions.")
|
|
41
|
|
42 (defvar gnus-server-mode-line-format "Gnus List of servers"
|
|
43 "The format specification for the server mode line.")
|
|
44
|
|
45 (defvar gnus-server-exit-hook nil
|
|
46 "*Hook run when exiting the server buffer.")
|
|
47
|
|
48 ;;; Internal variables.
|
|
49
|
|
50 (defvar gnus-inserted-opened-servers nil)
|
|
51
|
|
52 (defvar gnus-server-line-format-alist
|
|
53 `((?h how ?s)
|
|
54 (?n name ?s)
|
|
55 (?w where ?s)
|
|
56 (?s status ?s)))
|
|
57
|
|
58 (defvar gnus-server-mode-line-format-alist
|
|
59 `((?S news-server ?s)
|
|
60 (?M news-method ?s)
|
|
61 (?u user-defined ?s)))
|
|
62
|
|
63 (defvar gnus-server-line-format-spec nil)
|
|
64 (defvar gnus-server-mode-line-format-spec nil)
|
|
65 (defvar gnus-server-killed-servers nil)
|
|
66
|
|
67 (defvar gnus-server-mode-map)
|
|
68
|
|
69 (defvar gnus-server-menu-hook nil
|
|
70 "*Hook run after the creation of the server mode menu.")
|
|
71
|
|
72 (defun gnus-server-make-menu-bar ()
|
16
|
73 (gnus-turn-off-edit-menu 'server)
|
0
|
74 (unless (boundp 'gnus-server-server-menu)
|
|
75 (easy-menu-define
|
|
76 gnus-server-server-menu gnus-server-mode-map ""
|
|
77 '("Server"
|
|
78 ["Add" gnus-server-add-server t]
|
|
79 ["Browse" gnus-server-read-server t]
|
16
|
80 ["Scan" gnus-server-scan-server t]
|
0
|
81 ["List" gnus-server-list-servers t]
|
|
82 ["Kill" gnus-server-kill-server t]
|
|
83 ["Yank" gnus-server-yank-server t]
|
|
84 ["Copy" gnus-server-copy-server t]
|
|
85 ["Edit" gnus-server-edit-server t]
|
16
|
86 ["Regenerate" gnus-server-regenerate-server t]
|
|
87 ["Exit" gnus-server-exit t]))
|
0
|
88
|
|
89 (easy-menu-define
|
|
90 gnus-server-connections-menu gnus-server-mode-map ""
|
|
91 '("Connections"
|
|
92 ["Open" gnus-server-open-server t]
|
|
93 ["Close" gnus-server-close-server t]
|
|
94 ["Deny" gnus-server-deny-server t]
|
16
|
95 "---"
|
|
96 ["Open All" gnus-server-open-all-servers t]
|
|
97 ["Close All" gnus-server-close-all-servers t]
|
|
98 ["Reset All" gnus-server-remove-denials t]))
|
0
|
99
|
|
100 (run-hooks 'gnus-server-menu-hook)))
|
|
101
|
|
102 (defvar gnus-server-mode-map nil)
|
|
103 (put 'gnus-server-mode 'mode-class 'special)
|
|
104
|
|
105 (unless gnus-server-mode-map
|
|
106 (setq gnus-server-mode-map (make-sparse-keymap))
|
|
107 (suppress-keymap gnus-server-mode-map)
|
|
108
|
|
109 (gnus-define-keys
|
|
110 gnus-server-mode-map
|
|
111 " " gnus-server-read-server
|
|
112 "\r" gnus-server-read-server
|
|
113 gnus-mouse-2 gnus-server-pick-server
|
|
114 "q" gnus-server-exit
|
|
115 "l" gnus-server-list-servers
|
|
116 "k" gnus-server-kill-server
|
|
117 "y" gnus-server-yank-server
|
|
118 "c" gnus-server-copy-server
|
|
119 "a" gnus-server-add-server
|
|
120 "e" gnus-server-edit-server
|
16
|
121 "s" gnus-server-scan-server
|
0
|
122
|
|
123 "O" gnus-server-open-server
|
16
|
124 "\M-o" gnus-server-open-all-servers
|
0
|
125 "C" gnus-server-close-server
|
16
|
126 "\M-c" gnus-server-close-all-servers
|
0
|
127 "D" gnus-server-deny-server
|
|
128 "R" gnus-server-remove-denials
|
|
129
|
16
|
130 "g" gnus-server-regenerate-server
|
|
131
|
22
|
132 "\C-c\C-i" gnus-info-find-node
|
|
133 "\C-c\C-b" gnus-bug))
|
0
|
134
|
|
135 (defun gnus-server-mode ()
|
|
136 "Major mode for listing and editing servers.
|
|
137
|
|
138 All normal editing commands are switched off.
|
|
139 \\<gnus-server-mode-map>
|
|
140 For more in-depth information on this mode, read the manual
|
|
141 (`\\[gnus-info-find-node]').
|
|
142
|
|
143 The following commands are available:
|
|
144
|
|
145 \\{gnus-server-mode-map}"
|
|
146 (interactive)
|
16
|
147 (when (gnus-visual-p 'server-menu 'menu)
|
0
|
148 (gnus-server-make-menu-bar))
|
|
149 (kill-all-local-variables)
|
|
150 (gnus-simplify-mode-line)
|
|
151 (setq major-mode 'gnus-server-mode)
|
|
152 (setq mode-name "Server")
|
16
|
153 (gnus-set-default-directory)
|
0
|
154 (setq mode-line-process nil)
|
|
155 (use-local-map gnus-server-mode-map)
|
|
156 (buffer-disable-undo (current-buffer))
|
|
157 (setq truncate-lines t)
|
|
158 (setq buffer-read-only t)
|
|
159 (run-hooks 'gnus-server-mode-hook))
|
|
160
|
|
161 (defun gnus-server-insert-server-line (name method)
|
|
162 (let* ((how (car method))
|
|
163 (where (nth 1 method))
|
|
164 (elem (assoc method gnus-opened-servers))
|
|
165 (status (cond ((eq (nth 1 elem) 'denied)
|
|
166 "(denied)")
|
|
167 ((or (gnus-server-opened method)
|
|
168 (eq (nth 1 elem) 'ok))
|
|
169 "(opened)")
|
|
170 (t
|
|
171 "(closed)"))))
|
|
172 (beginning-of-line)
|
|
173 (gnus-add-text-properties
|
|
174 (point)
|
|
175 (prog1 (1+ (point))
|
|
176 ;; Insert the text.
|
|
177 (eval gnus-server-line-format-spec))
|
|
178 (list 'gnus-server (intern name)))))
|
|
179
|
|
180 (defun gnus-enter-server-buffer ()
|
|
181 "Set up the server buffer."
|
|
182 (gnus-server-setup-buffer)
|
|
183 (gnus-configure-windows 'server)
|
|
184 (gnus-server-prepare))
|
|
185
|
|
186 (defun gnus-server-setup-buffer ()
|
|
187 "Initialize the server buffer."
|
|
188 (unless (get-buffer gnus-server-buffer)
|
|
189 (save-excursion
|
|
190 (set-buffer (get-buffer-create gnus-server-buffer))
|
|
191 (gnus-server-mode)
|
|
192 (when gnus-carpal
|
|
193 (gnus-carpal-setup-buffer 'server)))))
|
|
194
|
|
195 (defun gnus-server-prepare ()
|
|
196 (setq gnus-server-mode-line-format-spec
|
|
197 (gnus-parse-format gnus-server-mode-line-format
|
|
198 gnus-server-mode-line-format-alist))
|
|
199 (setq gnus-server-line-format-spec
|
|
200 (gnus-parse-format gnus-server-line-format
|
|
201 gnus-server-line-format-alist t))
|
|
202 (let ((alist gnus-server-alist)
|
|
203 (buffer-read-only nil)
|
|
204 (opened gnus-opened-servers)
|
|
205 done server op-ser)
|
|
206 (erase-buffer)
|
|
207 (setq gnus-inserted-opened-servers nil)
|
|
208 ;; First we do the real list of servers.
|
|
209 (while alist
|
26
|
210 (unless (member (caar alist) done)
|
|
211 (push (caar alist) done)
|
|
212 (cdr (setq server (pop alist)))
|
|
213 (when (and server (car server) (cdr server))
|
|
214 (gnus-server-insert-server-line (car server) (cdr server)))))
|
0
|
215 ;; Then we insert the list of servers that have been opened in
|
|
216 ;; this session.
|
|
217 (while opened
|
16
|
218 (unless (member (cadaar opened) done)
|
|
219 (push (cadaar opened) done)
|
0
|
220 (gnus-server-insert-server-line
|
|
221 (setq op-ser (format "%s:%s" (caaar opened) (nth 1 (caar opened))))
|
|
222 (caar opened))
|
|
223 (push (list op-ser (caar opened)) gnus-inserted-opened-servers))
|
|
224 (setq opened (cdr opened))))
|
|
225 (goto-char (point-min))
|
|
226 (gnus-server-position-point))
|
|
227
|
|
228 (defun gnus-server-server-name ()
|
18
|
229 (let ((server (get-text-property (gnus-point-at-bol) 'gnus-server)))
|
0
|
230 (and server (symbol-name server))))
|
|
231
|
|
232 (defalias 'gnus-server-position-point 'gnus-goto-colon)
|
|
233
|
|
234 (defconst gnus-server-edit-buffer "*Gnus edit server*")
|
|
235
|
|
236 (defun gnus-server-update-server (server)
|
|
237 (save-excursion
|
|
238 (set-buffer gnus-server-buffer)
|
|
239 (let* ((buffer-read-only nil)
|
|
240 (entry (assoc server gnus-server-alist))
|
|
241 (oentry (assoc (gnus-server-to-method server)
|
|
242 gnus-opened-servers)))
|
|
243 (when entry
|
|
244 (gnus-dribble-enter
|
|
245 (concat "(gnus-server-set-info \"" server "\" '"
|
24
|
246 (prin1-to-string (cdr entry)) ")\n")))
|
0
|
247 (when (or entry oentry)
|
|
248 ;; Buffer may be narrowed.
|
|
249 (save-restriction
|
|
250 (widen)
|
|
251 (when (gnus-server-goto-server server)
|
|
252 (gnus-delete-line))
|
|
253 (if entry
|
|
254 (gnus-server-insert-server-line (car entry) (cdr entry))
|
|
255 (gnus-server-insert-server-line
|
|
256 (format "%s:%s" (caar oentry) (nth 1 (car oentry)))
|
|
257 (car oentry)))
|
|
258 (gnus-server-position-point))))))
|
|
259
|
|
260 (defun gnus-server-set-info (server info)
|
|
261 ;; Enter a select method into the virtual server alist.
|
|
262 (when (and server info)
|
|
263 (gnus-dribble-enter
|
|
264 (concat "(gnus-server-set-info \"" server "\" '"
|
|
265 (prin1-to-string info) ")"))
|
|
266 (let* ((server (nth 1 info))
|
|
267 (entry (assoc server gnus-server-alist)))
|
|
268 (if entry (setcdr entry info)
|
|
269 (setq gnus-server-alist
|
|
270 (nconc gnus-server-alist (list (cons server info))))))))
|
|
271
|
|
272 ;;; Interactive server functions.
|
|
273
|
|
274 (defun gnus-server-kill-server (server)
|
|
275 "Kill the server on the current line."
|
|
276 (interactive (list (gnus-server-server-name)))
|
|
277 (unless (gnus-server-goto-server server)
|
|
278 (if server (error "No such server: %s" server)
|
|
279 (error "No server on the current line")))
|
|
280 (unless (assoc server gnus-server-alist)
|
|
281 (error "Read-only server %s" server))
|
|
282 (gnus-dribble-enter "")
|
|
283 (let ((buffer-read-only nil))
|
|
284 (gnus-delete-line))
|
16
|
285 (push (assoc server gnus-server-alist) gnus-server-killed-servers)
|
0
|
286 (setq gnus-server-alist (delq (car gnus-server-killed-servers)
|
|
287 gnus-server-alist))
|
|
288 (gnus-server-position-point))
|
|
289
|
|
290 (defun gnus-server-yank-server ()
|
|
291 "Yank the previously killed server."
|
|
292 (interactive)
|
16
|
293 (unless gnus-server-killed-servers
|
|
294 (error "No killed servers to be yanked"))
|
0
|
295 (let ((alist gnus-server-alist)
|
|
296 (server (gnus-server-server-name))
|
|
297 (killed (car gnus-server-killed-servers)))
|
16
|
298 (if (not server)
|
0
|
299 (setq gnus-server-alist (nconc gnus-server-alist (list killed)))
|
|
300 (if (string= server (caar gnus-server-alist))
|
16
|
301 (push killed gnus-server-alist)
|
0
|
302 (while (and (cdr alist)
|
|
303 (not (string= server (caadr alist))))
|
|
304 (setq alist (cdr alist)))
|
|
305 (if alist
|
|
306 (setcdr alist (cons killed (cdr alist)))
|
|
307 (setq gnus-server-alist (list killed)))))
|
|
308 (gnus-server-update-server (car killed))
|
|
309 (setq gnus-server-killed-servers (cdr gnus-server-killed-servers))
|
|
310 (gnus-server-position-point)))
|
|
311
|
|
312 (defun gnus-server-exit ()
|
|
313 "Return to the group buffer."
|
|
314 (interactive)
|
|
315 (kill-buffer (current-buffer))
|
|
316 (switch-to-buffer gnus-group-buffer)
|
|
317 (run-hooks 'gnus-server-exit-hook))
|
|
318
|
|
319 (defun gnus-server-list-servers ()
|
|
320 "List all available servers."
|
|
321 (interactive)
|
|
322 (let ((cur (gnus-server-server-name)))
|
|
323 (gnus-server-prepare)
|
|
324 (if cur (gnus-server-goto-server cur)
|
|
325 (goto-char (point-max))
|
|
326 (forward-line -1))
|
|
327 (gnus-server-position-point)))
|
|
328
|
|
329 (defun gnus-server-set-status (method status)
|
|
330 "Make METHOD have STATUS."
|
|
331 (let ((entry (assoc method gnus-opened-servers)))
|
|
332 (if entry
|
|
333 (setcar (cdr entry) status)
|
|
334 (push (list method status) gnus-opened-servers))))
|
|
335
|
|
336 (defun gnus-opened-servers-remove (method)
|
|
337 "Remove METHOD from the list of opened servers."
|
|
338 (setq gnus-opened-servers (delq (assoc method gnus-opened-servers)
|
|
339 gnus-opened-servers)))
|
|
340
|
|
341 (defun gnus-server-open-server (server)
|
|
342 "Force an open of SERVER."
|
|
343 (interactive (list (gnus-server-server-name)))
|
|
344 (let ((method (gnus-server-to-method server)))
|
16
|
345 (unless method
|
|
346 (error "No such server: %s" server))
|
0
|
347 (gnus-server-set-status method 'ok)
|
|
348 (prog1
|
|
349 (or (gnus-open-server method)
|
|
350 (progn (message "Couldn't open %s" server) nil))
|
|
351 (gnus-server-update-server server)
|
|
352 (gnus-server-position-point))))
|
|
353
|
16
|
354 (defun gnus-server-open-all-servers ()
|
|
355 "Open all servers."
|
|
356 (interactive)
|
|
357 (let ((servers gnus-inserted-opened-servers))
|
|
358 (while servers
|
|
359 (gnus-server-open-server (car (pop servers))))))
|
|
360
|
0
|
361 (defun gnus-server-close-server (server)
|
|
362 "Close SERVER."
|
|
363 (interactive (list (gnus-server-server-name)))
|
|
364 (let ((method (gnus-server-to-method server)))
|
16
|
365 (unless method
|
|
366 (error "No such server: %s" server))
|
0
|
367 (gnus-server-set-status method 'closed)
|
|
368 (prog1
|
|
369 (gnus-close-server method)
|
|
370 (gnus-server-update-server server)
|
|
371 (gnus-server-position-point))))
|
|
372
|
16
|
373 (defun gnus-server-close-all-servers ()
|
|
374 "Close all servers."
|
|
375 (interactive)
|
|
376 (let ((servers gnus-inserted-opened-servers))
|
|
377 (while servers
|
|
378 (gnus-server-close-server (car (pop servers))))))
|
|
379
|
0
|
380 (defun gnus-server-deny-server (server)
|
|
381 "Make sure SERVER will never be attempted opened."
|
|
382 (interactive (list (gnus-server-server-name)))
|
|
383 (let ((method (gnus-server-to-method server)))
|
16
|
384 (unless method
|
|
385 (error "No such server: %s" server))
|
0
|
386 (gnus-server-set-status method 'denied))
|
|
387 (gnus-server-update-server server)
|
|
388 (gnus-server-position-point)
|
|
389 t)
|
|
390
|
|
391 (defun gnus-server-remove-denials ()
|
|
392 "Make all denied servers into closed servers."
|
|
393 (interactive)
|
|
394 (let ((servers gnus-opened-servers))
|
|
395 (while servers
|
|
396 (when (eq (nth 1 (car servers)) 'denied)
|
|
397 (setcar (nthcdr 1 (car servers)) 'closed))
|
|
398 (setq servers (cdr servers))))
|
|
399 (gnus-server-list-servers))
|
|
400
|
|
401 (defun gnus-server-copy-server (from to)
|
|
402 (interactive
|
|
403 (list
|
24
|
404 (or (gnus-server-server-name)
|
|
405 (error "No server on the current line"))
|
0
|
406 (read-string "Copy to: ")))
|
16
|
407 (unless from
|
|
408 (error "No server on current line"))
|
|
409 (unless (and to (not (string= to "")))
|
|
410 (error "No name to copy to"))
|
|
411 (when (assoc to gnus-server-alist)
|
|
412 (error "%s already exists" to))
|
24
|
413 (unless (gnus-server-to-method from)
|
16
|
414 (error "%s: no such server" from))
|
24
|
415 (let ((to-entry (cons from (gnus-copy-sequence
|
|
416 (gnus-server-to-method from)))))
|
0
|
417 (setcar to-entry to)
|
|
418 (setcar (nthcdr 2 to-entry) to)
|
16
|
419 (push to-entry gnus-server-killed-servers)
|
0
|
420 (gnus-server-yank-server)))
|
|
421
|
|
422 (defun gnus-server-add-server (how where)
|
|
423 (interactive
|
|
424 (list (intern (completing-read "Server method: "
|
|
425 gnus-valid-select-methods nil t))
|
|
426 (read-string "Server name: ")))
|
16
|
427 (when (assq where gnus-server-alist)
|
|
428 (error "Server with that name already defined"))
|
|
429 (push (list where how where) gnus-server-killed-servers)
|
0
|
430 (gnus-server-yank-server))
|
|
431
|
|
432 (defun gnus-server-goto-server (server)
|
|
433 "Jump to a server line."
|
|
434 (interactive
|
|
435 (list (completing-read "Goto server: " gnus-server-alist nil t)))
|
16
|
436 (let ((to (text-property-any (point-min) (point-max)
|
0
|
437 'gnus-server (intern server))))
|
16
|
438 (when to
|
|
439 (goto-char to)
|
|
440 (gnus-server-position-point))))
|
0
|
441
|
|
442 (defun gnus-server-edit-server (server)
|
|
443 "Edit the server on the current line."
|
|
444 (interactive (list (gnus-server-server-name)))
|
|
445 (unless server
|
|
446 (error "No server on current line"))
|
|
447 (unless (assoc server gnus-server-alist)
|
|
448 (error "This server can't be edited"))
|
16
|
449 (let ((info (cdr (assoc server gnus-server-alist))))
|
0
|
450 (gnus-close-server info)
|
16
|
451 (gnus-edit-form
|
|
452 info "Editing the server."
|
|
453 `(lambda (form)
|
|
454 (gnus-server-set-info ,server form)
|
|
455 (gnus-server-list-servers)
|
|
456 (gnus-server-position-point)))))
|
0
|
457
|
16
|
458 (defun gnus-server-scan-server (server)
|
|
459 "Request a scan from the current server."
|
|
460 (interactive (list (gnus-server-server-name)))
|
|
461 (gnus-message 3 "Scanning %s...done" server)
|
|
462 (gnus-request-scan nil (gnus-server-to-method server))
|
|
463 (gnus-message 3 "Scanning %s...done" server))
|
0
|
464
|
|
465 (defun gnus-server-read-server (server)
|
|
466 "Browse a server."
|
|
467 (interactive (list (gnus-server-server-name)))
|
|
468 (let ((buf (current-buffer)))
|
|
469 (prog1
|
|
470 (gnus-browse-foreign-server (gnus-server-to-method server) buf)
|
|
471 (save-excursion
|
|
472 (set-buffer buf)
|
|
473 (gnus-server-update-server (gnus-server-server-name))
|
|
474 (gnus-server-position-point)))))
|
|
475
|
|
476 (defun gnus-server-pick-server (e)
|
|
477 (interactive "e")
|
|
478 (mouse-set-point e)
|
|
479 (gnus-server-read-server (gnus-server-server-name)))
|
|
480
|
|
481
|
|
482 ;;;
|
|
483 ;;; Browse Server Mode
|
|
484 ;;;
|
|
485
|
|
486 (defvar gnus-browse-menu-hook nil
|
|
487 "*Hook run after the creation of the browse mode menu.")
|
|
488
|
|
489 (defvar gnus-browse-mode-hook nil)
|
|
490 (defvar gnus-browse-mode-map nil)
|
|
491 (put 'gnus-browse-mode 'mode-class 'special)
|
|
492
|
|
493 (unless gnus-browse-mode-map
|
|
494 (setq gnus-browse-mode-map (make-keymap))
|
|
495 (suppress-keymap gnus-browse-mode-map)
|
|
496
|
|
497 (gnus-define-keys
|
|
498 gnus-browse-mode-map
|
|
499 " " gnus-browse-read-group
|
|
500 "=" gnus-browse-select-group
|
|
501 "n" gnus-browse-next-group
|
|
502 "p" gnus-browse-prev-group
|
|
503 "\177" gnus-browse-prev-group
|
|
504 "N" gnus-browse-next-group
|
|
505 "P" gnus-browse-prev-group
|
|
506 "\M-n" gnus-browse-next-group
|
|
507 "\M-p" gnus-browse-prev-group
|
|
508 "\r" gnus-browse-select-group
|
|
509 "u" gnus-browse-unsubscribe-current-group
|
|
510 "l" gnus-browse-exit
|
|
511 "L" gnus-browse-exit
|
|
512 "q" gnus-browse-exit
|
|
513 "Q" gnus-browse-exit
|
|
514 "\C-c\C-c" gnus-browse-exit
|
|
515 "?" gnus-browse-describe-briefly
|
|
516
|
22
|
517 "\C-c\C-i" gnus-info-find-node
|
|
518 "\C-c\C-b" gnus-bug))
|
0
|
519
|
|
520 (defun gnus-browse-make-menu-bar ()
|
16
|
521 (gnus-turn-off-edit-menu 'browse)
|
|
522 (unless (boundp 'gnus-browse-menu)
|
|
523 (easy-menu-define
|
|
524 gnus-browse-menu gnus-browse-mode-map ""
|
|
525 '("Browse"
|
|
526 ["Subscribe" gnus-browse-unsubscribe-current-group t]
|
|
527 ["Read" gnus-browse-read-group t]
|
|
528 ["Select" gnus-browse-read-group t]
|
|
529 ["Next" gnus-browse-next-group t]
|
|
530 ["Prev" gnus-browse-next-group t]
|
|
531 ["Exit" gnus-browse-exit t]
|
|
532 ))
|
|
533 (run-hooks 'gnus-browse-menu-hook)))
|
0
|
534
|
|
535 (defvar gnus-browse-current-method nil)
|
|
536 (defvar gnus-browse-return-buffer nil)
|
|
537
|
|
538 (defvar gnus-browse-buffer "*Gnus Browse Server*")
|
|
539
|
|
540 (defun gnus-browse-foreign-server (method &optional return-buffer)
|
|
541 "Browse the server METHOD."
|
|
542 (setq gnus-browse-current-method method)
|
|
543 (setq gnus-browse-return-buffer return-buffer)
|
|
544 (let ((gnus-select-method method)
|
|
545 groups group)
|
|
546 (gnus-message 5 "Connecting to %s..." (nth 1 method))
|
|
547 (cond
|
|
548 ((not (gnus-check-server method))
|
|
549 (gnus-message
|
|
550 1 "Unable to contact server: %s" (gnus-status-message method))
|
|
551 nil)
|
16
|
552 ((not
|
|
553 (prog2
|
|
554 (gnus-message 6 "Reading active file...")
|
|
555 (gnus-request-list method)
|
|
556 (gnus-message 6 "Reading active file...done")))
|
0
|
557 (gnus-message
|
|
558 1 "Couldn't request list: %s" (gnus-status-message method))
|
|
559 nil)
|
|
560 (t
|
|
561 (get-buffer-create gnus-browse-buffer)
|
|
562 (gnus-add-current-to-buffer-list)
|
16
|
563 (when gnus-carpal
|
|
564 (gnus-carpal-setup-buffer 'browse))
|
0
|
565 (gnus-configure-windows 'browse)
|
|
566 (buffer-disable-undo (current-buffer))
|
|
567 (let ((buffer-read-only nil))
|
|
568 (erase-buffer))
|
|
569 (gnus-browse-mode)
|
|
570 (setq mode-line-buffer-identification
|
|
571 (list
|
|
572 (format
|
|
573 "Gnus: %%b {%s:%s}" (car method) (cadr method))))
|
|
574 (save-excursion
|
|
575 (set-buffer nntp-server-buffer)
|
|
576 (let ((cur (current-buffer)))
|
|
577 (goto-char (point-min))
|
16
|
578 (unless (string= gnus-ignored-newsgroups "")
|
|
579 (delete-matching-lines gnus-ignored-newsgroups))
|
0
|
580 (while (re-search-forward
|
|
581 "\\(^[^ \t]+\\)[ \t]+[0-9]+[ \t]+[0-9]+" nil t)
|
|
582 (goto-char (match-end 1))
|
16
|
583 (push (cons (match-string 1)
|
|
584 (max 0 (- (1+ (read cur)) (read cur))))
|
|
585 groups))))
|
0
|
586 (setq groups (sort groups
|
|
587 (lambda (l1 l2)
|
|
588 (string< (car l1) (car l2)))))
|
|
589 (let ((buffer-read-only nil))
|
|
590 (while groups
|
|
591 (setq group (car groups))
|
|
592 (insert
|
|
593 (format "K%7d: %s\n" (cdr group) (car group)))
|
|
594 (setq groups (cdr groups))))
|
|
595 (switch-to-buffer (current-buffer))
|
|
596 (goto-char (point-min))
|
|
597 (gnus-group-position-point)
|
|
598 (gnus-message 5 "Connecting to %s...done" (nth 1 method))
|
|
599 t))))
|
|
600
|
|
601 (defun gnus-browse-mode ()
|
|
602 "Major mode for browsing a foreign server.
|
|
603
|
|
604 All normal editing commands are switched off.
|
|
605
|
|
606 \\<gnus-browse-mode-map>
|
|
607 The only things you can do in this buffer is
|
|
608
|
|
609 1) `\\[gnus-browse-unsubscribe-current-group]' to subscribe to a group.
|
|
610 The group will be inserted into the group buffer upon exit from this
|
|
611 buffer.
|
|
612
|
|
613 2) `\\[gnus-browse-read-group]' to read a group ephemerally.
|
|
614
|
|
615 3) `\\[gnus-browse-exit]' to return to the group buffer."
|
|
616 (interactive)
|
|
617 (kill-all-local-variables)
|
16
|
618 (when (gnus-visual-p 'browse-menu 'menu)
|
0
|
619 (gnus-browse-make-menu-bar))
|
|
620 (gnus-simplify-mode-line)
|
|
621 (setq major-mode 'gnus-browse-mode)
|
|
622 (setq mode-name "Browse Server")
|
|
623 (setq mode-line-process nil)
|
|
624 (use-local-map gnus-browse-mode-map)
|
|
625 (buffer-disable-undo (current-buffer))
|
|
626 (setq truncate-lines t)
|
16
|
627 (gnus-set-default-directory)
|
0
|
628 (setq buffer-read-only t)
|
|
629 (run-hooks 'gnus-browse-mode-hook))
|
|
630
|
|
631 (defun gnus-browse-read-group (&optional no-article)
|
|
632 "Enter the group at the current line."
|
|
633 (interactive)
|
16
|
634 (let ((group (gnus-group-real-name (gnus-browse-group-name))))
|
|
635 (unless (gnus-group-read-ephemeral-group
|
|
636 group gnus-browse-current-method nil
|
|
637 (cons (current-buffer) 'browse))
|
|
638 (error "Couldn't enter %s" group))))
|
0
|
639
|
|
640 (defun gnus-browse-select-group ()
|
|
641 "Select the current group."
|
|
642 (interactive)
|
|
643 (gnus-browse-read-group 'no))
|
|
644
|
|
645 (defun gnus-browse-next-group (n)
|
|
646 "Go to the next group."
|
|
647 (interactive "p")
|
|
648 (prog1
|
|
649 (forward-line n)
|
|
650 (gnus-group-position-point)))
|
|
651
|
|
652 (defun gnus-browse-prev-group (n)
|
|
653 "Go to the next group."
|
|
654 (interactive "p")
|
|
655 (gnus-browse-next-group (- n)))
|
|
656
|
|
657 (defun gnus-browse-unsubscribe-current-group (arg)
|
|
658 "(Un)subscribe to the next ARG groups."
|
|
659 (interactive "p")
|
|
660 (when (eobp)
|
|
661 (error "No group at current line."))
|
|
662 (let ((ward (if (< arg 0) -1 1))
|
|
663 (arg (abs arg)))
|
|
664 (while (and (> arg 0)
|
|
665 (not (eobp))
|
|
666 (gnus-browse-unsubscribe-group)
|
|
667 (zerop (gnus-browse-next-group ward)))
|
|
668 (decf arg))
|
|
669 (gnus-group-position-point)
|
16
|
670 (when (/= 0 arg)
|
|
671 (gnus-message 7 "No more newsgroups"))
|
0
|
672 arg))
|
|
673
|
|
674 (defun gnus-browse-group-name ()
|
|
675 (save-excursion
|
|
676 (beginning-of-line)
|
18
|
677 (when (re-search-forward ": \\(.*\\)$" (gnus-point-at-eol) t)
|
0
|
678 (gnus-group-prefixed-name (match-string 1) gnus-browse-current-method))))
|
|
679
|
|
680 (defun gnus-browse-unsubscribe-group ()
|
|
681 "Toggle subscription of the current group in the browse buffer."
|
|
682 (let ((sub nil)
|
|
683 (buffer-read-only nil)
|
|
684 group)
|
|
685 (save-excursion
|
|
686 (beginning-of-line)
|
|
687 ;; If this group it killed, then we want to subscribe it.
|
16
|
688 (when (= (following-char) ?K)
|
|
689 (setq sub t))
|
0
|
690 (setq group (gnus-browse-group-name))
|
16
|
691 ;; Make sure the group has been properly removed before we
|
|
692 ;; subscribe to it.
|
|
693 (gnus-kill-ephemeral-group group)
|
0
|
694 (delete-char 1)
|
|
695 (if sub
|
|
696 (progn
|
|
697 (gnus-group-change-level
|
|
698 (list t group gnus-level-default-subscribed
|
|
699 nil nil gnus-browse-current-method)
|
|
700 gnus-level-default-subscribed gnus-level-killed
|
|
701 (and (car (nth 1 gnus-newsrc-alist))
|
|
702 (gnus-gethash (car (nth 1 gnus-newsrc-alist))
|
|
703 gnus-newsrc-hashtb))
|
|
704 t)
|
|
705 (insert ? ))
|
|
706 (gnus-group-change-level
|
|
707 group gnus-level-killed gnus-level-default-subscribed)
|
|
708 (insert ?K)))
|
|
709 t))
|
|
710
|
|
711 (defun gnus-browse-exit ()
|
|
712 "Quit browsing and return to the group buffer."
|
|
713 (interactive)
|
|
714 (when (eq major-mode 'gnus-browse-mode)
|
|
715 (kill-buffer (current-buffer)))
|
|
716 ;; Insert the newly subscribed groups in the group buffer.
|
|
717 (save-excursion
|
|
718 (set-buffer gnus-group-buffer)
|
|
719 (gnus-group-list-groups nil))
|
|
720 (if gnus-browse-return-buffer
|
|
721 (gnus-configure-windows 'server 'force)
|
|
722 (gnus-configure-windows 'group 'force)))
|
|
723
|
|
724 (defun gnus-browse-describe-briefly ()
|
|
725 "Give a one line description of the group mode commands."
|
|
726 (interactive)
|
|
727 (gnus-message 6
|
|
728 (substitute-command-keys "\\<gnus-browse-mode-map>\\[gnus-group-next-group]:Forward \\[gnus-group-prev-group]:Backward \\[gnus-browse-exit]:Exit \\[gnus-info-find-node]:Run Info \\[gnus-browse-describe-briefly]:This help")))
|
|
729
|
16
|
730 (defun gnus-server-regenerate-server ()
|
|
731 "Issue a command to the server to regenerate all its data structures."
|
|
732 (interactive)
|
|
733 (let ((server (gnus-server-server-name)))
|
|
734 (unless server
|
|
735 (error "No server on the current line"))
|
|
736 (if (not (gnus-check-backend-function
|
|
737 'request-regenerate (car (gnus-server-to-method server))))
|
|
738 (error "This backend doesn't support regeneration")
|
24
|
739 (gnus-message 5 "Requesting regeneration of %s..." server)
|
|
740 (if (gnus-request-regenerate server)
|
|
741 (gnus-message 5 "Requesting regeneration of %s...done" server)
|
|
742 (gnus-message 5 "Couldn't regenerate %s" server)))))
|
16
|
743
|
0
|
744 (provide 'gnus-srvr)
|
|
745
|
|
746 ;;; gnus-srvr.el ends here.
|