1 ;;; gnus-srvr.el --- virtual server support for Gnus
3 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
4 ;; 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
9 ;; This file is part of GNU Emacs.
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 3, or (at your option)
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.
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., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
30 (eval-when-compile (require 'cl
))
38 (defcustom gnus-server-mode-hook nil
39 "Hook run in `gnus-server-mode' buffers."
43 (defcustom gnus-server-exit-hook nil
44 "Hook run when exiting the server buffer."
48 (defcustom gnus-server-line-format
" {%(%h:%w%)} %s%a\n"
49 "Format of server lines.
50 It works along the same lines as a normal formatting string,
51 with some simple extensions.
53 The following specs are understood:
61 General format specifiers can also be used.
62 See Info node `(gnus)Formatting Variables'."
63 :link
'(custom-manual "(gnus)Formatting Variables")
64 :group
'gnus-server-visual
67 (defcustom gnus-server-mode-line-format
"Gnus: %%b"
68 "The format specification for the server mode line."
69 :group
'gnus-server-visual
72 (defcustom gnus-server-browse-in-group-buffer nil
73 "Whether server browsing should take place in the group buffer.
74 If nil, a faster, but more primitive, buffer is used instead."
76 :group
'gnus-server-visual
79 ;;; Internal variables.
81 (defvar gnus-inserted-opened-servers nil
)
83 (defvar gnus-server-line-format-alist
84 `((?h gnus-tmp-how ?s
)
86 (?w gnus-tmp-where ?s
)
87 (?s gnus-tmp-status ?s
)
88 (?a gnus-tmp-agent ?s
)))
90 (defvar gnus-server-mode-line-format-alist
91 `((?S gnus-tmp-news-server ?s
)
92 (?M gnus-tmp-news-method ?s
)
93 (?u gnus-tmp-user-defined ?s
)))
95 (defvar gnus-server-line-format-spec nil
)
96 (defvar gnus-server-mode-line-format-spec nil
)
97 (defvar gnus-server-killed-servers nil
)
99 (defvar gnus-server-mode-map
)
101 (defvar gnus-server-menu-hook nil
102 "*Hook run after the creation of the server mode menu.")
104 (defun gnus-server-make-menu-bar ()
105 (gnus-turn-off-edit-menu 'server
)
106 (unless (boundp 'gnus-server-server-menu
)
108 gnus-server-server-menu gnus-server-mode-map
""
110 ["Add..." gnus-server-add-server t
]
111 ["Browse" gnus-server-read-server t
]
112 ["Scan" gnus-server-scan-server t
]
113 ["List" gnus-server-list-servers t
]
114 ["Kill" gnus-server-kill-server t
]
115 ["Yank" gnus-server-yank-server t
]
116 ["Copy" gnus-server-copy-server t
]
117 ["Edit" gnus-server-edit-server t
]
118 ["Regenerate" gnus-server-regenerate-server t
]
119 ["Compact" gnus-server-compact-server t
]
120 ["Exit" gnus-server-exit t
]))
123 gnus-server-connections-menu gnus-server-mode-map
""
125 ["Open" gnus-server-open-server t
]
126 ["Close" gnus-server-close-server t
]
127 ["Offline" gnus-server-offline-server t
]
128 ["Deny" gnus-server-deny-server t
]
130 ["Open All" gnus-server-open-all-servers t
]
131 ["Close All" gnus-server-close-all-servers t
]
132 ["Reset All" gnus-server-remove-denials t
]))
134 (gnus-run-hooks 'gnus-server-menu-hook
)))
136 (defvar gnus-server-mode-map nil
)
137 (put 'gnus-server-mode
'mode-class
'special
)
139 (unless gnus-server-mode-map
140 (setq gnus-server-mode-map
(make-sparse-keymap))
141 (suppress-keymap gnus-server-mode-map
)
143 (gnus-define-keys gnus-server-mode-map
144 " " gnus-server-read-server-in-server-buffer
145 "\r" gnus-server-read-server
146 gnus-mouse-2 gnus-server-pick-server
148 "l" gnus-server-list-servers
149 "k" gnus-server-kill-server
150 "y" gnus-server-yank-server
151 "c" gnus-server-copy-server
152 "a" gnus-server-add-server
153 "e" gnus-server-edit-server
154 "s" gnus-server-scan-server
156 "O" gnus-server-open-server
157 "\M-o" gnus-server-open-all-servers
158 "C" gnus-server-close-server
159 "\M-c" gnus-server-close-all-servers
160 "D" gnus-server-deny-server
161 "L" gnus-server-offline-server
162 "R" gnus-server-remove-denials
167 "g" gnus-server-regenerate-server
169 "z" gnus-server-compact-server
171 "\C-c\C-i" gnus-info-find-node
172 "\C-c\C-b" gnus-bug
))
174 (defface gnus-server-agent
175 '((((class color
) (background light
)) (:foreground
"PaleTurquoise" :bold t
))
176 (((class color
) (background dark
)) (:foreground
"PaleTurquoise" :bold t
))
178 "Face used for displaying AGENTIZED servers"
179 :group
'gnus-server-visual
)
180 ;; backward-compatibility alias
181 (put 'gnus-server-agent-face
'face-alias
'gnus-server-agent
)
183 (defface gnus-server-opened
184 '((((class color
) (background light
)) (:foreground
"Green3" :bold t
))
185 (((class color
) (background dark
)) (:foreground
"Green1" :bold t
))
187 "Face used for displaying OPENED servers"
188 :group
'gnus-server-visual
)
189 ;; backward-compatibility alias
190 (put 'gnus-server-opened-face
'face-alias
'gnus-server-opened
)
192 (defface gnus-server-closed
193 '((((class color
) (background light
)) (:foreground
"Steel Blue" :italic t
))
194 (((class color
) (background dark
))
195 (:foreground
"LightBlue" :italic t
))
197 "Face used for displaying CLOSED servers"
198 :group
'gnus-server-visual
)
199 ;; backward-compatibility alias
200 (put 'gnus-server-closed-face
'face-alias
'gnus-server-closed
)
202 (defface gnus-server-denied
203 '((((class color
) (background light
)) (:foreground
"Red" :bold t
))
204 (((class color
) (background dark
)) (:foreground
"Pink" :bold t
))
205 (t (:inverse-video t
:bold t
)))
206 "Face used for displaying DENIED servers"
207 :group
'gnus-server-visual
)
208 ;; backward-compatibility alias
209 (put 'gnus-server-denied-face
'face-alias
'gnus-server-denied
)
211 (defface gnus-server-offline
212 '((((class color
) (background light
)) (:foreground
"Orange" :bold t
))
213 (((class color
) (background dark
)) (:foreground
"Yellow" :bold t
))
214 (t (:inverse-video t
:bold t
)))
215 "Face used for displaying OFFLINE servers"
216 :group
'gnus-server-visual
)
217 ;; backward-compatibility alias
218 (put 'gnus-server-offline-face
'face-alias
'gnus-server-offline
)
220 (defvar gnus-server-font-lock-keywords
221 '(("(\\(agent\\))" 1 'gnus-server-agent
)
222 ("(\\(opened\\))" 1 'gnus-server-opened
)
223 ("(\\(closed\\))" 1 'gnus-server-closed
)
224 ("(\\(offline\\))" 1 'gnus-server-offline
)
225 ("(\\(denied\\))" 1 'gnus-server-denied
)))
227 (defun gnus-server-mode ()
228 "Major mode for listing and editing servers.
230 All normal editing commands are switched off.
231 \\<gnus-server-mode-map>
232 For more in-depth information on this mode, read the manual
233 \(`\\[gnus-info-find-node]').
235 The following commands are available:
237 \\{gnus-server-mode-map}"
239 (when (gnus-visual-p 'server-menu
'menu
)
240 (gnus-server-make-menu-bar))
241 (kill-all-local-variables)
242 (gnus-simplify-mode-line)
243 (setq major-mode
'gnus-server-mode
)
244 (setq mode-name
"Server")
245 (gnus-set-default-directory)
246 (setq mode-line-process nil
)
247 (use-local-map gnus-server-mode-map
)
248 (buffer-disable-undo)
249 (setq truncate-lines t
)
250 (setq buffer-read-only t
)
251 (if (featurep 'xemacs
)
252 (put 'gnus-server-mode
'font-lock-defaults
'(gnus-server-font-lock-keywords t
))
253 (set (make-local-variable 'font-lock-defaults
)
254 '(gnus-server-font-lock-keywords t
)))
255 (gnus-run-mode-hooks 'gnus-server-mode-hook
))
257 (defun gnus-server-insert-server-line (gnus-tmp-name method
)
258 (let* ((gnus-tmp-how (car method
))
259 (gnus-tmp-where (nth 1 method
))
260 (elem (assoc method gnus-opened-servers
))
263 ((eq (nth 1 elem
) 'denied
) "(denied)")
264 ((eq (nth 1 elem
) 'offline
) "(offline)")
267 (if (or (gnus-server-opened method
)
268 (eq (nth 1 elem
) 'ok
))
271 ((error) "(error)")))))
272 (gnus-tmp-agent (if (and gnus-agent
273 (gnus-agent-method-p method
))
277 (gnus-add-text-properties
281 (eval gnus-server-line-format-spec
))
282 (list 'gnus-server
(intern gnus-tmp-name
)
283 'gnus-named-server
(intern (gnus-method-to-server method t
))))))
285 (defun gnus-enter-server-buffer ()
286 "Set up the server buffer."
287 (gnus-server-setup-buffer)
288 (gnus-configure-windows 'server
)
289 (gnus-server-prepare))
291 (defun gnus-server-setup-buffer ()
292 "Initialize the server buffer."
293 (unless (get-buffer gnus-server-buffer
)
295 (set-buffer (gnus-get-buffer-create gnus-server-buffer
))
298 (gnus-carpal-setup-buffer 'server
)))))
300 (defun gnus-server-prepare ()
301 (gnus-set-format 'server-mode
)
302 (gnus-set-format 'server t
)
303 (let ((alist gnus-server-alist
)
304 (buffer-read-only nil
)
307 (setq gnus-inserted-opened-servers nil
)
308 ;; First we do the real list of servers.
310 (unless (member (cdar alist
) done
)
311 (push (cdar alist
) done
)
312 (setq server
(pop alist
))
313 (when (and server
(car server
) (cdr server
))
314 (gnus-server-insert-server-line (car server
) (cdr server
))))
315 (when (member (cdar alist
) done
)
317 ;; Then we insert the list of servers that have been opened in
319 (dolist (open gnus-opened-servers
)
320 (when (and (not (member (car open
) done
))
321 ;; Just ignore ephemeral servers.
322 (not (member (car open
) gnus-ephemeral-servers
)))
323 (push (car open
) done
)
324 (gnus-server-insert-server-line
325 (setq op-ser
(format "%s:%s" (caar open
) (nth 1 (car open
))))
327 (push (list op-ser
(car open
)) gnus-inserted-opened-servers
))))
328 (goto-char (point-min))
329 (gnus-server-position-point))
331 (defun gnus-server-server-name ()
332 (let ((server (get-text-property (point-at-bol) 'gnus-server
)))
333 (and server
(symbol-name server
))))
335 (defun gnus-server-named-server ()
336 "Return a server name that matches one of the names returned by
337 `gnus-method-to-server'."
338 (let ((server (get-text-property (point-at-bol) 'gnus-named-server
)))
339 (and server
(symbol-name server
))))
341 (defalias 'gnus-server-position-point
'gnus-goto-colon
)
343 (defconst gnus-server-edit-buffer
"*Gnus edit server*")
345 (defun gnus-server-update-server (server)
347 (set-buffer gnus-server-buffer
)
348 (let* ((buffer-read-only nil
)
349 (entry (assoc server gnus-server-alist
))
350 (oentry (assoc (gnus-server-to-method server
)
351 gnus-opened-servers
)))
354 (concat "(gnus-server-set-info \"" server
"\" '"
355 (gnus-prin1-to-string (cdr entry
)) ")\n")))
356 (when (or entry oentry
)
357 ;; Buffer may be narrowed.
360 (when (gnus-server-goto-server server
)
363 (gnus-server-insert-server-line (car entry
) (cdr entry
))
364 (gnus-server-insert-server-line
365 (format "%s:%s" (caar oentry
) (nth 1 (car oentry
)))
367 (gnus-server-position-point))))))
369 (defun gnus-server-set-info (server info
)
370 ;; Enter a select method into the virtual server alist.
371 (when (and server info
)
373 (concat "(gnus-server-set-info \"" server
"\" '"
374 (gnus-prin1-to-string info
) ")"))
375 (let* ((server (nth 1 info
))
376 (entry (assoc server gnus-server-alist
))
377 (cached (assoc server gnus-server-method-cache
)))
379 (setq gnus-server-method-cache
380 (delq cached gnus-server-method-cache
)))
383 ;; Remove the server from `gnus-opened-servers' since
384 ;; it has never been opened with the new `info' yet.
385 (gnus-opened-servers-remove (cdr entry
))
386 ;; Don't make a new Lisp object.
387 (setcar (cdr entry
) (car info
))
388 (setcdr (cdr entry
) (cdr info
)))
389 (setq gnus-server-alist
390 (nconc gnus-server-alist
(list (cons server info
))))))))
392 ;;; Interactive server functions.
394 (defun gnus-server-kill-server (server)
395 "Kill the server on the current line."
396 (interactive (list (gnus-server-server-name)))
397 (unless (gnus-server-goto-server server
)
398 (if server
(error "No such server: %s" server
)
399 (error "No server on the current line")))
400 (unless (assoc server gnus-server-alist
)
401 (error "Read-only server %s" server
))
403 (let ((buffer-read-only nil
))
405 (push (assoc server gnus-server-alist
) gnus-server-killed-servers
)
406 (setq gnus-server-alist
(delq (car gnus-server-killed-servers
)
408 (let ((groups (gnus-groups-from-server server
)))
411 (format "Kill all %s groups from this server? "
413 (dolist (group groups
)
414 (setq gnus-newsrc-alist
415 (delq (assoc group gnus-newsrc-alist
)
417 (when gnus-group-change-level-function
418 (funcall gnus-group-change-level-function
419 group gnus-level-killed
3)))))
420 (gnus-server-position-point))
422 (defun gnus-server-yank-server ()
423 "Yank the previously killed server."
425 (unless gnus-server-killed-servers
426 (error "No killed servers to be yanked"))
427 (let ((alist gnus-server-alist
)
428 (server (gnus-server-server-name))
429 (killed (car gnus-server-killed-servers
)))
431 (setq gnus-server-alist
(nconc gnus-server-alist
(list killed
)))
432 (if (string= server
(caar gnus-server-alist
))
433 (push killed gnus-server-alist
)
434 (while (and (cdr alist
)
435 (not (string= server
(caadr alist
))))
436 (setq alist
(cdr alist
)))
438 (setcdr alist
(cons killed
(cdr alist
)))
439 (setq gnus-server-alist
(list killed
)))))
440 (gnus-server-update-server (car killed
))
441 (setq gnus-server-killed-servers
(cdr gnus-server-killed-servers
))
442 (gnus-server-position-point)))
444 (defun gnus-server-exit ()
445 "Return to the group buffer."
447 (gnus-run-hooks 'gnus-server-exit-hook
)
448 (gnus-kill-buffer (current-buffer))
449 (gnus-configure-windows 'group t
))
451 (defun gnus-server-list-servers ()
452 "List all available servers."
454 (let ((cur (gnus-server-server-name)))
455 (gnus-server-prepare)
456 (if cur
(gnus-server-goto-server cur
)
457 (goto-char (point-max))
459 (gnus-server-position-point)))
461 (defun gnus-server-set-status (method status
)
462 "Make METHOD have STATUS."
463 (let ((entry (assoc method gnus-opened-servers
)))
465 (setcar (cdr entry
) status
)
466 (push (list method status
) gnus-opened-servers
))))
468 (defun gnus-opened-servers-remove (method)
469 "Remove METHOD from the list of opened servers."
470 (setq gnus-opened-servers
(delq (assoc method gnus-opened-servers
)
471 gnus-opened-servers
)))
473 (defun gnus-server-open-server (server)
474 "Force an open of SERVER."
475 (interactive (list (gnus-server-server-name)))
476 (let ((method (gnus-server-to-method server
)))
478 (error "No such server: %s" server
))
479 (gnus-server-set-status method
'ok
)
481 (or (gnus-open-server method
)
482 (progn (message "Couldn't open %s" server
) nil
))
483 (gnus-server-update-server server
)
484 (gnus-server-position-point))))
486 (defun gnus-server-open-all-servers ()
489 (dolist (server gnus-inserted-opened-servers
)
490 (gnus-server-open-server (car server
))))
492 (defun gnus-server-close-server (server)
494 (interactive (list (gnus-server-server-name)))
495 (let ((method (gnus-server-to-method server
)))
497 (error "No such server: %s" server
))
498 (gnus-server-set-status method
'closed
)
500 (gnus-close-server method
)
501 (gnus-server-update-server server
)
502 (gnus-server-position-point))))
504 (defun gnus-server-offline-server (server)
505 "Set SERVER to offline."
506 (interactive (list (gnus-server-server-name)))
507 (let ((method (gnus-server-to-method server
)))
509 (error "No such server: %s" server
))
511 (gnus-close-server method
)
512 (gnus-server-set-status method
'offline
)
513 (gnus-server-update-server server
)
514 (gnus-server-position-point))))
516 (defun gnus-server-close-all-servers ()
519 (dolist (server gnus-inserted-opened-servers
)
520 (gnus-server-close-server (car server
)))
521 (dolist (server gnus-server-alist
)
522 (gnus-server-close-server (car server
))))
524 (defun gnus-server-deny-server (server)
525 "Make sure SERVER will never be attempted opened."
526 (interactive (list (gnus-server-server-name)))
527 (let ((method (gnus-server-to-method server
)))
529 (error "No such server: %s" server
))
530 (gnus-server-set-status method
'denied
))
531 (gnus-server-update-server server
)
532 (gnus-server-position-point)
535 (defun gnus-server-remove-denials ()
536 "Make all denied servers into closed servers."
538 (dolist (server gnus-opened-servers
)
539 (when (eq (nth 1 server
) 'denied
)
540 (setcar (nthcdr 1 server
) 'closed
)))
541 (gnus-server-list-servers))
543 (defun gnus-server-copy-server (from to
)
546 (or (gnus-server-server-name)
547 (error "No server on the current line"))
548 (read-string "Copy to: ")))
550 (error "No server on current line"))
551 (unless (and to
(not (string= to
"")))
552 (error "No name to copy to"))
553 (when (assoc to gnus-server-alist
)
554 (error "%s already exists" to
))
555 (unless (gnus-server-to-method from
)
556 (error "%s: no such server" from
))
557 (let ((to-entry (cons from
(gnus-copy-sequence
558 (gnus-server-to-method from
)))))
560 (setcar (nthcdr 2 to-entry
) to
)
561 (push to-entry gnus-server-killed-servers
)
562 (gnus-server-yank-server)))
564 (defun gnus-server-add-server (how where
)
566 (list (intern (completing-read "Server method: "
567 gnus-valid-select-methods nil t
))
568 (read-string "Server name: ")))
569 (when (assq where gnus-server-alist
)
570 (error "Server with that name already defined"))
571 (push (list where how where
) gnus-server-killed-servers
)
572 (gnus-server-yank-server))
574 (defun gnus-server-goto-server (server)
575 "Jump to a server line."
577 (list (completing-read "Goto server: " gnus-server-alist nil t
)))
578 (let ((to (text-property-any (point-min) (point-max)
579 'gnus-server
(intern server
))))
582 (gnus-server-position-point))))
584 (defun gnus-server-edit-server (server)
585 "Edit the server on the current line."
586 (interactive (list (gnus-server-server-name)))
588 (error "No server on current line"))
589 (unless (assoc server gnus-server-alist
)
590 (error "This server can't be edited"))
591 (let ((info (cdr (assoc server gnus-server-alist
))))
592 (gnus-close-server info
)
594 info
"Editing the server."
596 (gnus-server-set-info ,server form
)
597 (gnus-server-list-servers)
598 (gnus-server-position-point))
601 (defun gnus-server-scan-server (server)
602 "Request a scan from the current server."
603 (interactive (list (gnus-server-server-name)))
604 (let ((method (gnus-server-to-method server
)))
605 (if (not (gnus-get-function method
'request-scan
))
606 (error "Server %s can't scan" (car method
))
607 (gnus-message 3 "Scanning %s..." server
)
608 (gnus-request-scan nil method
)
609 (gnus-message 3 "Scanning %s...done" server
))))
611 (defun gnus-server-read-server-in-server-buffer (server)
612 "Browse a server in server buffer."
613 (interactive (list (gnus-server-server-name)))
614 (let (gnus-server-browse-in-group-buffer)
615 (gnus-server-read-server server
)))
617 (defun gnus-server-read-server (server)
619 (interactive (list (gnus-server-server-name)))
620 (let ((buf (current-buffer)))
622 (gnus-browse-foreign-server server buf
)
625 (gnus-server-update-server (gnus-server-server-name))
626 (gnus-server-position-point)))))
628 (defun gnus-server-pick-server (e)
631 (gnus-server-read-server (gnus-server-server-name)))
635 ;;; Browse Server Mode
638 (defvar gnus-browse-menu-hook nil
639 "*Hook run after the creation of the browse mode menu.")
641 (defvar gnus-browse-mode-hook nil
)
642 (defvar gnus-browse-mode-map nil
)
643 (put 'gnus-browse-mode
'mode-class
'special
)
645 (unless gnus-browse-mode-map
646 (setq gnus-browse-mode-map
(make-keymap))
647 (suppress-keymap gnus-browse-mode-map
)
651 " " gnus-browse-read-group
652 "=" gnus-browse-select-group
653 "n" gnus-browse-next-group
654 "p" gnus-browse-prev-group
655 "\177" gnus-browse-prev-group
656 [delete] gnus-browse-prev-group
657 "N" gnus-browse-next-group
658 "P" gnus-browse-prev-group
659 "\M-n" gnus-browse-next-group
660 "\M-p" gnus-browse-prev-group
661 "\r" gnus-browse-select-group
662 "u" gnus-browse-unsubscribe-current-group
667 "d" gnus-browse-describe-group
668 "\C-c\C-c" gnus-browse-exit
669 "?" gnus-browse-describe-briefly
671 "\C-c\C-i" gnus-info-find-node
672 "\C-c\C-b" gnus-bug))
674 (defun gnus-browse-make-menu-bar ()
675 (gnus-turn-off-edit-menu 'browse)
676 (unless (boundp 'gnus-browse-menu)
678 gnus-browse-menu gnus-browse-mode-map ""
680 ["Subscribe" gnus-browse-unsubscribe-current-group t]
681 ["Read" gnus-browse-read-group t]
682 ["Select" gnus-browse-select-group t]
683 ["Describe" gnus-browse-describe-group t]
684 ["Next" gnus-browse-next-group t]
685 ["Prev" gnus-browse-prev-group t]
686 ["Exit" gnus-browse-exit t]))
687 (gnus-run-hooks 'gnus-browse-menu-hook)))
689 (defvar gnus-browse-current-method nil)
690 (defvar gnus-browse-return-buffer nil)
692 (defvar gnus-browse-buffer "*Gnus Browse Server*")
694 (defun gnus-browse-foreign-server (server &optional return-buffer)
695 "Browse the server SERVER."
696 (setq gnus-browse-current-method (gnus-server-to-method server))
697 (setq gnus-browse-return-buffer return-buffer)
698 (let* ((method gnus-browse-current-method)
699 (orig-select-method gnus-select-method)
700 (gnus-select-method method)
702 (gnus-message 5 "Connecting to %s..." (nth 1 method))
704 ((not (gnus-check-server method))
706 1 "Unable to contact server %s: %s" (nth 1 method)
707 (gnus-status-message method))
711 (gnus-message 6 "Reading active file...")
712 (gnus-request-list method)
713 (gnus-message 6 "Reading active file...done")))
715 1 "Couldn't request list: %s" (gnus-status-message method))
718 (with-current-buffer nntp-server-buffer
719 (let ((cur (current-buffer)))
720 (goto-char (point-min))
721 (unless (string= gnus-ignored-newsgroups "")
722 (delete-matching-lines gnus-ignored-newsgroups))
723 ;; We treat NNTP as a special case to avoid problems with
724 ;; garbage group names like `"foo' that appear in some badly
725 ;; managed active files. -jh.
726 (if (eq (car method) 'nntp)
730 (mm-string-as-unibyte
734 (skip-chars-forward "^ \t")
736 (let ((last (read cur)))
737 (cons (read cur) last)))
743 (mm-string-as-unibyte
744 (if (eq (char-after) ?\")
746 (let ((p (point)) (name ""))
747 (skip-chars-forward "^ \t\\\\")
748 (setq name (buffer-substring p (point)))
749 (while (eq (char-after) ?\\)
750 (setq p (1+ (point)))
752 (skip-chars-forward "^ \t\\\\")
753 (setq name (concat name (buffer-substring
756 (let ((last (read cur)))
757 (cons (read cur) last)))
760 (setq groups (sort groups
762 (string< (car l1) (car l2)))))
763 (if gnus-server-browse-in-group-buffer
764 (let* ((gnus-select-method orig-select-method)
765 (gnus-group-listed-groups
766 (mapcar (lambda (group)
768 (gnus-group-prefixed-name
769 (car group) method)))
770 (gnus-set-active name (cdr group))
773 (gnus-configure-windows 'group)
774 (funcall gnus-group-prepare-function
775 gnus-level-killed 'ignore 1 'ignore))
776 (gnus-get-buffer-create gnus-browse-buffer)
778 (gnus-carpal-setup-buffer 'browse))
779 (gnus-configure-windows 'browse)
780 (buffer-disable-undo)
781 (let ((buffer-read-only nil))
784 (setq mode-line-buffer-identification
787 "Gnus: %%b {%s:%s}" (car method) (cadr method))))
788 (let ((buffer-read-only nil)
790 (prefix (let ((gnus-select-method orig-select-method))
791 (gnus-group-prefixed-name "" method))))
792 (while (setq group (pop groups))
793 (gnus-add-text-properties
797 (format "%c%7d: %s\n"
799 (if (string= prefix "")
800 (gnus-group-level (setq name (car group)))
802 (concat prefix (setq name (car group)))))))
804 ((<= level gnus-level-subscribed) ? )
805 ((<= level gnus-level-unsubscribed) ?U)
806 ((= level gnus-level-zombie) ?Z)
808 (max 0 (- (1+ (cddr group)) (cadr group)))
809 ;; Don't decode if name is ASCII
810 (if (and (fboundp 'detect-coding-string)
811 (eq (detect-coding-string name t) 'undecided))
813 (mm-decode-coding-string
815 (inline (gnus-group-name-charset method name)))))))
816 (list 'gnus-group name)
818 (switch-to-buffer (current-buffer)))
819 (goto-char (point-min))
820 (gnus-group-position-point)
821 (gnus-message 5 "Connecting to %s...done" (nth 1 method))
824 (defun gnus-browse-mode ()
825 "Major mode for browsing a foreign server.
827 All normal editing commands are switched off.
829 \\<gnus-browse-mode-map>
830 The only things you can do in this buffer is
832 1) `\\[gnus-browse-unsubscribe-current-group]' to subscribe to a group.
833 The group will be inserted into the group buffer upon exit from this
836 2) `\\[gnus-browse-read-group]' to read a group ephemerally.
838 3) `\\[gnus-browse-exit]' to return to the group buffer."
840 (kill-all-local-variables)
841 (when (gnus-visual-p 'browse-menu 'menu)
842 (gnus-browse-make-menu-bar))
843 (gnus-simplify-mode-line)
844 (setq major-mode 'gnus-browse-mode)
845 (setq mode-name "Browse Server")
846 (setq mode-line-process nil)
847 (use-local-map gnus-browse-mode-map)
848 (buffer-disable-undo)
849 (setq truncate-lines t)
850 (gnus-set-default-directory)
851 (setq buffer-read-only t)
852 (gnus-run-mode-hooks 'gnus-browse-mode-hook))
854 (defun gnus-browse-read-group (&optional no-article number)
855 "Enter the group at the current line.
856 If NUMBER, fetch this number of articles."
858 (let ((group (gnus-browse-group-name)))
859 (if (or (not (gnus-get-info group))
860 (gnus-ephemeral-group-p group))
861 (unless (gnus-group-read-ephemeral-group
862 group gnus-browse-current-method nil
863 (cons (current-buffer) 'browse)
865 (error "Couldn't enter %s" group))
866 (unless (gnus-group-read-group nil no-article group)
867 (error "Couldn't enter %s" group)))))
869 (defun gnus-browse-select-group (&optional number)
870 "Select the current group.
871 If NUMBER, fetch this number of articles."
873 (gnus-browse-read-group 'no number))
875 (defun gnus-browse-next-group (n)
876 "Go to the next group."
880 (gnus-group-position-point)))
882 (defun gnus-browse-prev-group (n)
883 "Go to the next group."
885 (gnus-browse-next-group (- n)))
887 (defun gnus-browse-unsubscribe-current-group (arg)
888 "(Un)subscribe to the next ARG groups."
891 (error "No group at current line"))
892 (let ((ward (if (< arg 0) -1 1))
894 (while (and (> arg 0)
896 (gnus-browse-unsubscribe-group)
897 (zerop (gnus-browse-next-group ward)))
899 (gnus-group-position-point)
901 (gnus-message 7 "No more newsgroups"))
904 (defun gnus-browse-group-name ()
907 (let ((name (get-text-property (point) 'gnus-group)))
908 (when (re-search-forward ": \\(.*\\)$" (point-at-eol) t)
909 (concat (gnus-method-to-server-name gnus-browse-current-method) ":"
911 (match-string-no-properties 1)))))))
913 (defun gnus-browse-describe-group (group)
914 "Describe the current group."
915 (interactive (list (gnus-browse-group-name)))
916 (gnus-group-describe-group nil group))
918 (defun gnus-browse-unsubscribe-group ()
919 "Toggle subscription of the current group in the browse buffer."
921 (buffer-read-only nil)
925 ;; If this group it killed, then we want to subscribe it.
926 (unless (eq (char-after) ? )
928 (setq group (gnus-browse-group-name))
929 (when (gnus-server-equal gnus-browse-current-method "native")
930 (setq group (gnus-group-real-name group)))
933 ;; Make sure the group has been properly removed before we
935 (if (gnus-ephemeral-group-p group)
936 (gnus-kill-ephemeral-group group))
937 ;; We need to discern between killed/zombie groups and
938 ;; just unsubscribed ones.
939 (gnus-group-change-level
940 (or (gnus-group-entry group)
941 (list t group gnus-level-default-subscribed
942 nil nil (if (gnus-server-equal
943 gnus-browse-current-method "native")
945 (gnus-method-simplify
946 gnus-browse-current-method))))
947 gnus-level-default-subscribed (gnus-group-level group)
948 (and (car (nth 1 gnus-newsrc-alist))
949 (gnus-group-entry (car (nth 1 gnus-newsrc-alist))))
950 (null (gnus-group-entry group)))
953 (gnus-group-change-level
954 group gnus-level-unsubscribed gnus-level-default-subscribed)
959 (defun gnus-browse-exit ()
960 "Quit browsing and return to the group buffer."
962 (when (eq major-mode 'gnus-browse-mode)
963 (gnus-kill-buffer (current-buffer)))
964 ;; Insert the newly subscribed groups in the group buffer.
966 (set-buffer gnus-group-buffer)
967 (gnus-group-list-groups nil))
968 (if gnus-browse-return-buffer
969 (gnus-configure-windows 'server 'force)
970 (gnus-configure-windows 'group 'force)))
972 (defun gnus-browse-describe-briefly ()
973 "Give a one line description of the group mode commands."
976 (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")))
978 (defun gnus-server-regenerate-server ()
979 "Issue a command to the server to regenerate all its data structures."
981 (let ((server (gnus-server-server-name)))
983 (error "No server on the current line"))
985 (gnus-get-function (gnus-server-to-method server)
988 (error "This back end doesn't support regeneration")))
989 (gnus-message 5 "Requesting regeneration of %s..." server)
990 (unless (gnus-open-server server)
991 (error "Couldn't open server"))
992 (if (gnus-request-regenerate server)
993 (gnus-message 5 "Requesting regeneration of %s...done" server)
994 (gnus-message 5 "Couldn't regenerate %s" server))))
998 ;;; Server compaction. -- dvl
1001 ;; #### FIXME: this function currently fails to update the Group buffer's
1003 (defun gnus-server-compact-server ()
1004 "Issue a command to the server to compact all its groups.
1006 Note: currently only implemented in nnml."
1008 (let ((server (gnus-server-server-name)))
1010 (error "No server on the current line"))
1012 (gnus-get-function (gnus-server-to-method server)
1015 (error "This back end doesn't support compaction")))
1017 Requesting compaction of %s... (this may take a long time)"
1019 (unless (gnus-open-server server)
1020 (error "Couldn't open server"))
1021 (if (not (gnus-request-compact server))
1022 (gnus-message 5 "Couldn't compact %s" server)
1023 (gnus-message 5 "Requesting compaction of %s...done" server)
1024 ;; Invalidate the original article buffer which might be out of date.
1025 ;; #### NOTE: Yes, this might be a bit rude, but since compaction
1026 ;; #### will not happen very often, I think this is acceptable.
1027 (let ((original (get-buffer gnus-original-article-buffer)))
1028 (and original (gnus-kill-buffer original))))))
1030 (provide 'gnus-srvr)
1032 ;; arch-tag: c0117f64-27ca-475d-9406-8da6854c7a25
1033 ;;; gnus-srvr.el ends here