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