17493
|
1 ;;; gnus-srvr.el --- virtual server support for Gnus
|
|
2 ;; Copyright (C) 1995,96,97 Free Software Foundation, Inc.
|
|
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)
|
|
29 (require 'gnus-spec)
|
|
30 (require 'gnus-group)
|
|
31 (require 'gnus-int)
|
|
32 (require 'gnus-range)
|
|
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 ()
|
|
73 (gnus-turn-off-edit-menu 'server)
|
|
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]
|
|
80 ["Scan" gnus-server-scan-server t]
|
|
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]
|
|
86 ["Regenerate" gnus-server-regenerate-server t]
|
|
87 ["Exit" gnus-server-exit t]))
|
|
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]
|
|
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]))
|
|
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
|
|
121 "s" gnus-server-scan-server
|
|
122
|
|
123 "O" gnus-server-open-server
|
|
124 "\M-o" gnus-server-open-all-servers
|
|
125 "C" gnus-server-close-server
|
|
126 "\M-c" gnus-server-close-all-servers
|
|
127 "D" gnus-server-deny-server
|
|
128 "R" gnus-server-remove-denials
|
|
129
|
|
130 "g" gnus-server-regenerate-server
|
|
131
|
|
132 "\C-c\C-i" gnus-info-find-node
|
|
133 "\C-c\C-b" gnus-bug))
|
|
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)
|
|
147 (when (gnus-visual-p 'server-menu 'menu)
|
|
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")
|
|
153 (gnus-set-default-directory)
|
|
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
|
|
210 (unless (member (cdar alist) done)
|
|
211 (push (cdar 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))))
|
|
215 (when (member (cdar alist) done)
|
|
216 (pop alist)))
|
|
217 ;; Then we insert the list of servers that have been opened in
|
|
218 ;; this session.
|
|
219 (while opened
|
|
220 (unless (member (caar opened) done)
|
|
221 (push (caar opened) done)
|
|
222 (gnus-server-insert-server-line
|
|
223 (setq op-ser (format "%s:%s" (caaar opened) (nth 1 (caar opened))))
|
|
224 (caar opened))
|
|
225 (push (list op-ser (caar opened)) gnus-inserted-opened-servers))
|
|
226 (setq opened (cdr opened))))
|
|
227 (goto-char (point-min))
|
|
228 (gnus-server-position-point))
|
|
229
|
|
230 (defun gnus-server-server-name ()
|
|
231 (let ((server (get-text-property (gnus-point-at-bol) 'gnus-server)))
|
|
232 (and server (symbol-name server))))
|
|
233
|
|
234 (defalias 'gnus-server-position-point 'gnus-goto-colon)
|
|
235
|
|
236 (defconst gnus-server-edit-buffer "*Gnus edit server*")
|
|
237
|
|
238 (defun gnus-server-update-server (server)
|
|
239 (save-excursion
|
|
240 (set-buffer gnus-server-buffer)
|
|
241 (let* ((buffer-read-only nil)
|
|
242 (entry (assoc server gnus-server-alist))
|
|
243 (oentry (assoc (gnus-server-to-method server)
|
|
244 gnus-opened-servers)))
|
|
245 (when entry
|
|
246 (gnus-dribble-enter
|
|
247 (concat "(gnus-server-set-info \"" server "\" '"
|
|
248 (prin1-to-string (cdr entry)) ")\n")))
|
|
249 (when (or entry oentry)
|
|
250 ;; Buffer may be narrowed.
|
|
251 (save-restriction
|
|
252 (widen)
|
|
253 (when (gnus-server-goto-server server)
|
|
254 (gnus-delete-line))
|
|
255 (if entry
|
|
256 (gnus-server-insert-server-line (car entry) (cdr entry))
|
|
257 (gnus-server-insert-server-line
|
|
258 (format "%s:%s" (caar oentry) (nth 1 (car oentry)))
|
|
259 (car oentry)))
|
|
260 (gnus-server-position-point))))))
|
|
261
|
|
262 (defun gnus-server-set-info (server info)
|
|
263 ;; Enter a select method into the virtual server alist.
|
|
264 (when (and server info)
|
|
265 (gnus-dribble-enter
|
|
266 (concat "(gnus-server-set-info \"" server "\" '"
|
|
267 (prin1-to-string info) ")"))
|
|
268 (let* ((server (nth 1 info))
|
|
269 (entry (assoc server gnus-server-alist)))
|
|
270 (if entry (setcdr entry info)
|
|
271 (setq gnus-server-alist
|
|
272 (nconc gnus-server-alist (list (cons server info))))))))
|
|
273
|
|
274 ;;; Interactive server functions.
|
|
275
|
|
276 (defun gnus-server-kill-server (server)
|
|
277 "Kill the server on the current line."
|
|
278 (interactive (list (gnus-server-server-name)))
|
|
279 (unless (gnus-server-goto-server server)
|
|
280 (if server (error "No such server: %s" server)
|
|
281 (error "No server on the current line")))
|
|
282 (unless (assoc server gnus-server-alist)
|
|
283 (error "Read-only server %s" server))
|
|
284 (gnus-dribble-enter "")
|
|
285 (let ((buffer-read-only nil))
|
|
286 (gnus-delete-line))
|
|
287 (push (assoc server gnus-server-alist) gnus-server-killed-servers)
|
|
288 (setq gnus-server-alist (delq (car gnus-server-killed-servers)
|
|
289 gnus-server-alist))
|
|
290 (gnus-server-position-point))
|
|
291
|
|
292 (defun gnus-server-yank-server ()
|
|
293 "Yank the previously killed server."
|
|
294 (interactive)
|
|
295 (unless gnus-server-killed-servers
|
|
296 (error "No killed servers to be yanked"))
|
|
297 (let ((alist gnus-server-alist)
|
|
298 (server (gnus-server-server-name))
|
|
299 (killed (car gnus-server-killed-servers)))
|
|
300 (if (not server)
|
|
301 (setq gnus-server-alist (nconc gnus-server-alist (list killed)))
|
|
302 (if (string= server (caar gnus-server-alist))
|
|
303 (push killed gnus-server-alist)
|
|
304 (while (and (cdr alist)
|
|
305 (not (string= server (caadr alist))))
|
|
306 (setq alist (cdr alist)))
|
|
307 (if alist
|
|
308 (setcdr alist (cons killed (cdr alist)))
|
|
309 (setq gnus-server-alist (list killed)))))
|
|
310 (gnus-server-update-server (car killed))
|
|
311 (setq gnus-server-killed-servers (cdr gnus-server-killed-servers))
|
|
312 (gnus-server-position-point)))
|
|
313
|
|
314 (defun gnus-server-exit ()
|
|
315 "Return to the group buffer."
|
|
316 (interactive)
|
|
317 (run-hooks 'gnus-server-exit-hook)
|
|
318 (kill-buffer (current-buffer))
|
|
319 (gnus-configure-windows 'group t))
|
|
320
|
|
321 (defun gnus-server-list-servers ()
|
|
322 "List all available servers."
|
|
323 (interactive)
|
|
324 (let ((cur (gnus-server-server-name)))
|
|
325 (gnus-server-prepare)
|
|
326 (if cur (gnus-server-goto-server cur)
|
|
327 (goto-char (point-max))
|
|
328 (forward-line -1))
|
|
329 (gnus-server-position-point)))
|
|
330
|
|
331 (defun gnus-server-set-status (method status)
|
|
332 "Make METHOD have STATUS."
|
|
333 (let ((entry (assoc method gnus-opened-servers)))
|
|
334 (if entry
|
|
335 (setcar (cdr entry) status)
|
|
336 (push (list method status) gnus-opened-servers))))
|
|
337
|
|
338 (defun gnus-opened-servers-remove (method)
|
|
339 "Remove METHOD from the list of opened servers."
|
|
340 (setq gnus-opened-servers (delq (assoc method gnus-opened-servers)
|
|
341 gnus-opened-servers)))
|
|
342
|
|
343 (defun gnus-server-open-server (server)
|
|
344 "Force an open of SERVER."
|
|
345 (interactive (list (gnus-server-server-name)))
|
|
346 (let ((method (gnus-server-to-method server)))
|
|
347 (unless method
|
|
348 (error "No such server: %s" server))
|
|
349 (gnus-server-set-status method 'ok)
|
|
350 (prog1
|
|
351 (or (gnus-open-server method)
|
|
352 (progn (message "Couldn't open %s" server) nil))
|
|
353 (gnus-server-update-server server)
|
|
354 (gnus-server-position-point))))
|
|
355
|
|
356 (defun gnus-server-open-all-servers ()
|
|
357 "Open all servers."
|
|
358 (interactive)
|
|
359 (let ((servers gnus-inserted-opened-servers))
|
|
360 (while servers
|
|
361 (gnus-server-open-server (car (pop servers))))))
|
|
362
|
|
363 (defun gnus-server-close-server (server)
|
|
364 "Close SERVER."
|
|
365 (interactive (list (gnus-server-server-name)))
|
|
366 (let ((method (gnus-server-to-method server)))
|
|
367 (unless method
|
|
368 (error "No such server: %s" server))
|
|
369 (gnus-server-set-status method 'closed)
|
|
370 (prog1
|
|
371 (gnus-close-server method)
|
|
372 (gnus-server-update-server server)
|
|
373 (gnus-server-position-point))))
|
|
374
|
|
375 (defun gnus-server-close-all-servers ()
|
|
376 "Close all servers."
|
|
377 (interactive)
|
|
378 (let ((servers gnus-inserted-opened-servers))
|
|
379 (while servers
|
|
380 (gnus-server-close-server (car (pop servers))))))
|
|
381
|
|
382 (defun gnus-server-deny-server (server)
|
|
383 "Make sure SERVER will never be attempted opened."
|
|
384 (interactive (list (gnus-server-server-name)))
|
|
385 (let ((method (gnus-server-to-method server)))
|
|
386 (unless method
|
|
387 (error "No such server: %s" server))
|
|
388 (gnus-server-set-status method 'denied))
|
|
389 (gnus-server-update-server server)
|
|
390 (gnus-server-position-point)
|
|
391 t)
|
|
392
|
|
393 (defun gnus-server-remove-denials ()
|
|
394 "Make all denied servers into closed servers."
|
|
395 (interactive)
|
|
396 (let ((servers gnus-opened-servers))
|
|
397 (while servers
|
|
398 (when (eq (nth 1 (car servers)) 'denied)
|
|
399 (setcar (nthcdr 1 (car servers)) 'closed))
|
|
400 (setq servers (cdr servers))))
|
|
401 (gnus-server-list-servers))
|
|
402
|
|
403 (defun gnus-server-copy-server (from to)
|
|
404 (interactive
|
|
405 (list
|
|
406 (or (gnus-server-server-name)
|
|
407 (error "No server on the current line"))
|
|
408 (read-string "Copy to: ")))
|
|
409 (unless from
|
|
410 (error "No server on current line"))
|
|
411 (unless (and to (not (string= to "")))
|
|
412 (error "No name to copy to"))
|
|
413 (when (assoc to gnus-server-alist)
|
|
414 (error "%s already exists" to))
|
|
415 (unless (gnus-server-to-method from)
|
|
416 (error "%s: no such server" from))
|
|
417 (let ((to-entry (cons from (gnus-copy-sequence
|
|
418 (gnus-server-to-method from)))))
|
|
419 (setcar to-entry to)
|
|
420 (setcar (nthcdr 2 to-entry) to)
|
|
421 (push to-entry gnus-server-killed-servers)
|
|
422 (gnus-server-yank-server)))
|
|
423
|
|
424 (defun gnus-server-add-server (how where)
|
|
425 (interactive
|
|
426 (list (intern (completing-read "Server method: "
|
|
427 gnus-valid-select-methods nil t))
|
|
428 (read-string "Server name: ")))
|
|
429 (when (assq where gnus-server-alist)
|
|
430 (error "Server with that name already defined"))
|
|
431 (push (list where how where) gnus-server-killed-servers)
|
|
432 (gnus-server-yank-server))
|
|
433
|
|
434 (defun gnus-server-goto-server (server)
|
|
435 "Jump to a server line."
|
|
436 (interactive
|
|
437 (list (completing-read "Goto server: " gnus-server-alist nil t)))
|
|
438 (let ((to (text-property-any (point-min) (point-max)
|
|
439 'gnus-server (intern server))))
|
|
440 (when to
|
|
441 (goto-char to)
|
|
442 (gnus-server-position-point))))
|
|
443
|
|
444 (defun gnus-server-edit-server (server)
|
|
445 "Edit the server on the current line."
|
|
446 (interactive (list (gnus-server-server-name)))
|
|
447 (unless server
|
|
448 (error "No server on current line"))
|
|
449 (unless (assoc server gnus-server-alist)
|
|
450 (error "This server can't be edited"))
|
|
451 (let ((info (cdr (assoc server gnus-server-alist))))
|
|
452 (gnus-close-server info)
|
|
453 (gnus-edit-form
|
|
454 info "Editing the server."
|
|
455 `(lambda (form)
|
|
456 (gnus-server-set-info ,server form)
|
|
457 (gnus-server-list-servers)
|
|
458 (gnus-server-position-point)))))
|
|
459
|
|
460 (defun gnus-server-scan-server (server)
|
|
461 "Request a scan from the current server."
|
|
462 (interactive (list (gnus-server-server-name)))
|
|
463 (gnus-message 3 "Scanning %s...done" server)
|
|
464 (gnus-request-scan nil (gnus-server-to-method server))
|
|
465 (gnus-message 3 "Scanning %s...done" server))
|
|
466
|
|
467 (defun gnus-server-read-server (server)
|
|
468 "Browse a server."
|
|
469 (interactive (list (gnus-server-server-name)))
|
|
470 (let ((buf (current-buffer)))
|
|
471 (prog1
|
|
472 (gnus-browse-foreign-server (gnus-server-to-method server) buf)
|
|
473 (save-excursion
|
|
474 (set-buffer buf)
|
|
475 (gnus-server-update-server (gnus-server-server-name))
|
|
476 (gnus-server-position-point)))))
|
|
477
|
|
478 (defun gnus-server-pick-server (e)
|
|
479 (interactive "e")
|
|
480 (mouse-set-point e)
|
|
481 (gnus-server-read-server (gnus-server-server-name)))
|
|
482
|
|
483
|
|
484 ;;;
|
|
485 ;;; Browse Server Mode
|
|
486 ;;;
|
|
487
|
|
488 (defvar gnus-browse-menu-hook nil
|
|
489 "*Hook run after the creation of the browse mode menu.")
|
|
490
|
|
491 (defvar gnus-browse-mode-hook nil)
|
|
492 (defvar gnus-browse-mode-map nil)
|
|
493 (put 'gnus-browse-mode 'mode-class 'special)
|
|
494
|
|
495 (unless gnus-browse-mode-map
|
|
496 (setq gnus-browse-mode-map (make-keymap))
|
|
497 (suppress-keymap gnus-browse-mode-map)
|
|
498
|
|
499 (gnus-define-keys
|
|
500 gnus-browse-mode-map
|
|
501 " " gnus-browse-read-group
|
|
502 "=" gnus-browse-select-group
|
|
503 "n" gnus-browse-next-group
|
|
504 "p" gnus-browse-prev-group
|
|
505 "\177" gnus-browse-prev-group
|
|
506 "N" gnus-browse-next-group
|
|
507 "P" gnus-browse-prev-group
|
|
508 "\M-n" gnus-browse-next-group
|
|
509 "\M-p" gnus-browse-prev-group
|
|
510 "\r" gnus-browse-select-group
|
|
511 "u" gnus-browse-unsubscribe-current-group
|
|
512 "l" gnus-browse-exit
|
|
513 "L" gnus-browse-exit
|
|
514 "q" gnus-browse-exit
|
|
515 "Q" gnus-browse-exit
|
|
516 "\C-c\C-c" gnus-browse-exit
|
|
517 "?" gnus-browse-describe-briefly
|
|
518
|
|
519 "\C-c\C-i" gnus-info-find-node
|
|
520 "\C-c\C-b" gnus-bug))
|
|
521
|
|
522 (defun gnus-browse-make-menu-bar ()
|
|
523 (gnus-turn-off-edit-menu 'browse)
|
|
524 (unless (boundp 'gnus-browse-menu)
|
|
525 (easy-menu-define
|
|
526 gnus-browse-menu gnus-browse-mode-map ""
|
|
527 '("Browse"
|
|
528 ["Subscribe" gnus-browse-unsubscribe-current-group t]
|
|
529 ["Read" gnus-browse-read-group t]
|
|
530 ["Select" gnus-browse-read-group t]
|
|
531 ["Next" gnus-browse-next-group t]
|
|
532 ["Prev" gnus-browse-next-group t]
|
|
533 ["Exit" gnus-browse-exit t]))
|
|
534 (run-hooks 'gnus-browse-menu-hook)))
|
|
535
|
|
536 (defvar gnus-browse-current-method nil)
|
|
537 (defvar gnus-browse-return-buffer nil)
|
|
538
|
|
539 (defvar gnus-browse-buffer "*Gnus Browse Server*")
|
|
540
|
|
541 (defun gnus-browse-foreign-server (method &optional return-buffer)
|
|
542 "Browse the server METHOD."
|
|
543 (setq gnus-browse-current-method method)
|
|
544 (setq gnus-browse-return-buffer return-buffer)
|
|
545 (when (stringp method)
|
|
546 (setq method (gnus-server-to-method method)))
|
|
547 (let ((gnus-select-method method)
|
|
548 groups group)
|
|
549 (gnus-message 5 "Connecting to %s..." (nth 1 method))
|
|
550 (cond
|
|
551 ((not (gnus-check-server method))
|
|
552 (gnus-message
|
|
553 1 "Unable to contact server: %s" (gnus-status-message method))
|
|
554 nil)
|
|
555 ((not
|
|
556 (prog2
|
|
557 (gnus-message 6 "Reading active file...")
|
|
558 (gnus-request-list method)
|
|
559 (gnus-message 6 "Reading active file...done")))
|
|
560 (gnus-message
|
|
561 1 "Couldn't request list: %s" (gnus-status-message method))
|
|
562 nil)
|
|
563 (t
|
|
564 (get-buffer-create gnus-browse-buffer)
|
|
565 (gnus-add-current-to-buffer-list)
|
|
566 (when gnus-carpal
|
|
567 (gnus-carpal-setup-buffer 'browse))
|
|
568 (gnus-configure-windows 'browse)
|
|
569 (buffer-disable-undo (current-buffer))
|
|
570 (let ((buffer-read-only nil))
|
|
571 (erase-buffer))
|
|
572 (gnus-browse-mode)
|
|
573 (setq mode-line-buffer-identification
|
|
574 (list
|
|
575 (format
|
|
576 "Gnus: %%b {%s:%s}" (car method) (cadr method))))
|
|
577 (save-excursion
|
|
578 (set-buffer nntp-server-buffer)
|
|
579 (let ((cur (current-buffer)))
|
|
580 (goto-char (point-min))
|
|
581 (unless (string= gnus-ignored-newsgroups "")
|
|
582 (delete-matching-lines gnus-ignored-newsgroups))
|
|
583 (while (re-search-forward
|
|
584 "\\(^[^ \t]+\\)[ \t]+[0-9]+[ \t]+[0-9]+" nil t)
|
|
585 (goto-char (match-end 1))
|
|
586 (push (cons (match-string 1)
|
|
587 (max 0 (- (1+ (read cur)) (read cur))))
|
|
588 groups))))
|
|
589 (setq groups (sort groups
|
|
590 (lambda (l1 l2)
|
|
591 (string< (car l1) (car l2)))))
|
|
592 (let ((buffer-read-only nil))
|
|
593 (while groups
|
|
594 (setq group (car groups))
|
|
595 (insert
|
|
596 (format "K%7d: %s\n" (cdr group) (car group)))
|
|
597 (setq groups (cdr groups))))
|
|
598 (switch-to-buffer (current-buffer))
|
|
599 (goto-char (point-min))
|
|
600 (gnus-group-position-point)
|
|
601 (gnus-message 5 "Connecting to %s...done" (nth 1 method))
|
|
602 t))))
|
|
603
|
|
604 (defun gnus-browse-mode ()
|
|
605 "Major mode for browsing a foreign server.
|
|
606
|
|
607 All normal editing commands are switched off.
|
|
608
|
|
609 \\<gnus-browse-mode-map>
|
|
610 The only things you can do in this buffer is
|
|
611
|
|
612 1) `\\[gnus-browse-unsubscribe-current-group]' to subscribe to a group.
|
|
613 The group will be inserted into the group buffer upon exit from this
|
|
614 buffer.
|
|
615
|
|
616 2) `\\[gnus-browse-read-group]' to read a group ephemerally.
|
|
617
|
|
618 3) `\\[gnus-browse-exit]' to return to the group buffer."
|
|
619 (interactive)
|
|
620 (kill-all-local-variables)
|
|
621 (when (gnus-visual-p 'browse-menu 'menu)
|
|
622 (gnus-browse-make-menu-bar))
|
|
623 (gnus-simplify-mode-line)
|
|
624 (setq major-mode 'gnus-browse-mode)
|
|
625 (setq mode-name "Browse Server")
|
|
626 (setq mode-line-process nil)
|
|
627 (use-local-map gnus-browse-mode-map)
|
|
628 (buffer-disable-undo (current-buffer))
|
|
629 (setq truncate-lines t)
|
|
630 (gnus-set-default-directory)
|
|
631 (setq buffer-read-only t)
|
|
632 (run-hooks 'gnus-browse-mode-hook))
|
|
633
|
|
634 (defun gnus-browse-read-group (&optional no-article)
|
|
635 "Enter the group at the current line."
|
|
636 (interactive)
|
|
637 (let ((group (gnus-group-real-name (gnus-browse-group-name))))
|
|
638 (unless (gnus-group-read-ephemeral-group
|
|
639 group gnus-browse-current-method nil
|
|
640 (cons (current-buffer) 'browse))
|
|
641 (error "Couldn't enter %s" group))))
|
|
642
|
|
643 (defun gnus-browse-select-group ()
|
|
644 "Select the current group."
|
|
645 (interactive)
|
|
646 (gnus-browse-read-group 'no))
|
|
647
|
|
648 (defun gnus-browse-next-group (n)
|
|
649 "Go to the next group."
|
|
650 (interactive "p")
|
|
651 (prog1
|
|
652 (forward-line n)
|
|
653 (gnus-group-position-point)))
|
|
654
|
|
655 (defun gnus-browse-prev-group (n)
|
|
656 "Go to the next group."
|
|
657 (interactive "p")
|
|
658 (gnus-browse-next-group (- n)))
|
|
659
|
|
660 (defun gnus-browse-unsubscribe-current-group (arg)
|
|
661 "(Un)subscribe to the next ARG groups."
|
|
662 (interactive "p")
|
|
663 (when (eobp)
|
|
664 (error "No group at current line."))
|
|
665 (let ((ward (if (< arg 0) -1 1))
|
|
666 (arg (abs arg)))
|
|
667 (while (and (> arg 0)
|
|
668 (not (eobp))
|
|
669 (gnus-browse-unsubscribe-group)
|
|
670 (zerop (gnus-browse-next-group ward)))
|
|
671 (decf arg))
|
|
672 (gnus-group-position-point)
|
|
673 (when (/= 0 arg)
|
|
674 (gnus-message 7 "No more newsgroups"))
|
|
675 arg))
|
|
676
|
|
677 (defun gnus-browse-group-name ()
|
|
678 (save-excursion
|
|
679 (beginning-of-line)
|
|
680 (when (re-search-forward ": \\(.*\\)$" (gnus-point-at-eol) t)
|
|
681 (gnus-group-prefixed-name
|
|
682 ;; Remove text props.
|
|
683 (format "%s" (match-string 1))
|
|
684 gnus-browse-current-method))))
|
|
685
|
|
686 (defun gnus-browse-unsubscribe-group ()
|
|
687 "Toggle subscription of the current group in the browse buffer."
|
|
688 (let ((sub nil)
|
|
689 (buffer-read-only nil)
|
|
690 group)
|
|
691 (save-excursion
|
|
692 (beginning-of-line)
|
|
693 ;; If this group it killed, then we want to subscribe it.
|
|
694 (when (= (following-char) ?K)
|
|
695 (setq sub t))
|
|
696 (setq group (gnus-browse-group-name))
|
|
697 ;; Make sure the group has been properly removed before we
|
|
698 ;; subscribe to it.
|
|
699 (gnus-kill-ephemeral-group group)
|
|
700 (delete-char 1)
|
|
701 (if sub
|
|
702 (progn
|
|
703 (gnus-group-change-level
|
|
704 (list t group gnus-level-default-subscribed
|
|
705 nil nil gnus-browse-current-method)
|
|
706 gnus-level-default-subscribed gnus-level-killed
|
|
707 (and (car (nth 1 gnus-newsrc-alist))
|
|
708 (gnus-gethash (car (nth 1 gnus-newsrc-alist))
|
|
709 gnus-newsrc-hashtb))
|
|
710 t)
|
|
711 (insert ? ))
|
|
712 (gnus-group-change-level
|
|
713 group gnus-level-killed gnus-level-default-subscribed)
|
|
714 (insert ?K)))
|
|
715 t))
|
|
716
|
|
717 (defun gnus-browse-exit ()
|
|
718 "Quit browsing and return to the group buffer."
|
|
719 (interactive)
|
|
720 (when (eq major-mode 'gnus-browse-mode)
|
|
721 (kill-buffer (current-buffer)))
|
|
722 ;; Insert the newly subscribed groups in the group buffer.
|
|
723 (save-excursion
|
|
724 (set-buffer gnus-group-buffer)
|
|
725 (gnus-group-list-groups nil))
|
|
726 (if gnus-browse-return-buffer
|
|
727 (gnus-configure-windows 'server 'force)
|
|
728 (gnus-configure-windows 'group 'force)))
|
|
729
|
|
730 (defun gnus-browse-describe-briefly ()
|
|
731 "Give a one line description of the group mode commands."
|
|
732 (interactive)
|
|
733 (gnus-message 6
|
|
734 (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")))
|
|
735
|
|
736 (defun gnus-server-regenerate-server ()
|
|
737 "Issue a command to the server to regenerate all its data structures."
|
|
738 (interactive)
|
|
739 (let ((server (gnus-server-server-name)))
|
|
740 (unless server
|
|
741 (error "No server on the current line"))
|
|
742 (if (not (gnus-check-backend-function
|
|
743 'request-regenerate (car (gnus-server-to-method server))))
|
|
744 (error "This backend doesn't support regeneration")
|
|
745 (gnus-message 5 "Requesting regeneration of %s..." server)
|
|
746 (if (gnus-request-regenerate server)
|
|
747 (gnus-message 5 "Requesting regeneration of %s...done" server)
|
|
748 (gnus-message 5 "Couldn't regenerate %s" server)))))
|
|
749
|
|
750 (provide 'gnus-srvr)
|
|
751
|
|
752 ;;; gnus-srvr.el ends here.
|