1 ;;; gnus-srvr.el --- virtual server support for Gnus
3 ;; Copyright (C) 1995-2011 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
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 3 of the License, or
13 ;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>.
27 (eval-when-compile (require 'cl
))
36 (autoload 'gnus-group-make-nnir-group
"nnir")
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 ["Show" gnus-server-show-server t
]
118 ["Edit" gnus-server-edit-server t
]
119 ["Regenerate" gnus-server-regenerate-server t
]
120 ["Compact" gnus-server-compact-server t
]
121 ["Exit" gnus-server-exit t
]))
124 gnus-server-connections-menu gnus-server-mode-map
""
126 ["Open" gnus-server-open-server t
]
127 ["Close" gnus-server-close-server t
]
128 ["Offline" gnus-server-offline-server t
]
129 ["Deny" gnus-server-deny-server t
]
131 ["Open All" gnus-server-open-all-servers t
]
132 ["Close All" gnus-server-close-all-servers t
]
133 ["Reset All" gnus-server-remove-denials t
]))
135 (gnus-run-hooks 'gnus-server-menu-hook
)))
137 (defvar gnus-server-mode-map nil
)
138 (put 'gnus-server-mode
'mode-class
'special
)
140 (unless gnus-server-mode-map
141 (setq gnus-server-mode-map
(make-sparse-keymap))
142 (suppress-keymap gnus-server-mode-map
)
144 (gnus-define-keys gnus-server-mode-map
145 " " gnus-server-read-server-in-server-buffer
146 "\r" gnus-server-read-server
147 gnus-mouse-2 gnus-server-pick-server
149 "l" gnus-server-list-servers
150 "k" gnus-server-kill-server
151 "y" gnus-server-yank-server
152 "c" gnus-server-copy-server
153 "a" gnus-server-add-server
154 "e" gnus-server-edit-server
155 "S" gnus-server-show-server
156 "s" gnus-server-scan-server
158 "O" gnus-server-open-server
159 "\M-o" gnus-server-open-all-servers
160 "C" gnus-server-close-server
161 "\M-c" gnus-server-close-all-servers
162 "D" gnus-server-deny-server
163 "L" gnus-server-offline-server
164 "R" gnus-server-remove-denials
169 "g" gnus-server-regenerate-server
171 "G" gnus-group-make-nnir-group
173 "z" gnus-server-compact-server
175 "\C-c\C-i" gnus-info-find-node
176 "\C-c\C-b" gnus-bug
))
178 (defface gnus-server-agent
179 '((((class color
) (background light
)) (:foreground
"PaleTurquoise" :bold t
))
180 (((class color
) (background dark
)) (:foreground
"PaleTurquoise" :bold t
))
182 "Face used for displaying AGENTIZED servers"
183 :group
'gnus-server-visual
)
184 ;; backward-compatibility alias
185 (put 'gnus-server-agent-face
'face-alias
'gnus-server-agent
)
186 (put 'gnus-server-agent-face
'obsolete-face
"22.1")
188 (defface gnus-server-opened
189 '((((class color
) (background light
)) (:foreground
"Green3" :bold t
))
190 (((class color
) (background dark
)) (:foreground
"Green1" :bold t
))
192 "Face used for displaying OPENED servers"
193 :group
'gnus-server-visual
)
194 ;; backward-compatibility alias
195 (put 'gnus-server-opened-face
'face-alias
'gnus-server-opened
)
196 (put 'gnus-server-opened-face
'obsolete-face
"22.1")
198 (defface gnus-server-closed
199 '((((class color
) (background light
)) (:foreground
"Steel Blue" :italic t
))
200 (((class color
) (background dark
))
201 (:foreground
"LightBlue" :italic t
))
203 "Face used for displaying CLOSED servers"
204 :group
'gnus-server-visual
)
205 ;; backward-compatibility alias
206 (put 'gnus-server-closed-face
'face-alias
'gnus-server-closed
)
207 (put 'gnus-server-closed-face
'obsolete-face
"22.1")
209 (defface gnus-server-denied
210 '((((class color
) (background light
)) (:foreground
"Red" :bold t
))
211 (((class color
) (background dark
)) (:foreground
"Pink" :bold t
))
212 (t (:inverse-video t
:bold t
)))
213 "Face used for displaying DENIED servers"
214 :group
'gnus-server-visual
)
215 ;; backward-compatibility alias
216 (put 'gnus-server-denied-face
'face-alias
'gnus-server-denied
)
217 (put 'gnus-server-denied-face
'obsolete-face
"22.1")
219 (defface gnus-server-offline
220 '((((class color
) (background light
)) (:foreground
"Orange" :bold t
))
221 (((class color
) (background dark
)) (:foreground
"Yellow" :bold t
))
222 (t (:inverse-video t
:bold t
)))
223 "Face used for displaying OFFLINE servers"
224 :group
'gnus-server-visual
)
225 ;; backward-compatibility alias
226 (put 'gnus-server-offline-face
'face-alias
'gnus-server-offline
)
227 (put 'gnus-server-offline-face
'obsolete-face
"22.1")
229 (defvar gnus-server-font-lock-keywords
230 '(("(\\(agent\\))" 1 'gnus-server-agent
)
231 ("(\\(opened\\))" 1 'gnus-server-opened
)
232 ("(\\(closed\\))" 1 'gnus-server-closed
)
233 ("(\\(offline\\))" 1 'gnus-server-offline
)
234 ("(\\(denied\\))" 1 'gnus-server-denied
)))
236 (defun gnus-server-mode ()
237 "Major mode for listing and editing servers.
239 All normal editing commands are switched off.
240 \\<gnus-server-mode-map>
241 For more in-depth information on this mode, read the manual
242 \(`\\[gnus-info-find-node]').
244 The following commands are available:
246 \\{gnus-server-mode-map}"
248 (when (gnus-visual-p 'server-menu
'menu
)
249 (gnus-server-make-menu-bar))
250 (kill-all-local-variables)
251 (gnus-simplify-mode-line)
252 (setq major-mode
'gnus-server-mode
)
253 (setq mode-name
"Server")
254 (gnus-set-default-directory)
255 (setq mode-line-process nil
)
256 (use-local-map gnus-server-mode-map
)
257 (buffer-disable-undo)
258 (setq truncate-lines t
)
259 (setq buffer-read-only t
)
260 (if (featurep 'xemacs
)
261 (put 'gnus-server-mode
'font-lock-defaults
'(gnus-server-font-lock-keywords t
))
262 (set (make-local-variable 'font-lock-defaults
)
263 '(gnus-server-font-lock-keywords t
)))
264 (gnus-run-mode-hooks 'gnus-server-mode-hook
))
266 (defun gnus-server-insert-server-line (gnus-tmp-name method
)
267 (let* ((gnus-tmp-how (car method
))
268 (gnus-tmp-where (nth 1 method
))
269 (elem (assoc method gnus-opened-servers
))
272 ((eq (nth 1 elem
) 'denied
) "(denied)")
273 ((eq (nth 1 elem
) 'offline
) "(offline)")
276 (if (or (gnus-server-opened method
)
277 (eq (nth 1 elem
) 'ok
))
280 ((error) "(error)")))))
281 (gnus-tmp-agent (if (and gnus-agent
282 (gnus-agent-method-p method
))
286 (gnus-add-text-properties
290 (eval gnus-server-line-format-spec
))
291 (list 'gnus-server
(intern gnus-tmp-name
)
292 'gnus-named-server
(intern (gnus-method-to-server method t
))))))
294 (defun gnus-enter-server-buffer ()
295 "Set up the server buffer."
296 (gnus-server-setup-buffer)
297 (gnus-configure-windows 'server
)
298 ;; Usually `gnus-configure-windows' will finish with the
299 ;; `gnus-server-buffer' selected as the current buffer, but not always (I
300 ;; bumped into it when starting from a dedicated *Group* frame, and
301 ;; gnus-configure-windows opened *Server* into its own dedicated frame).
302 (with-current-buffer (get-buffer gnus-server-buffer
)
303 (gnus-server-prepare)))
305 (defun gnus-server-setup-buffer ()
306 "Initialize the server buffer."
307 (unless (get-buffer gnus-server-buffer
)
308 (with-current-buffer (gnus-get-buffer-create gnus-server-buffer
)
309 (gnus-server-mode))))
311 (defun gnus-server-prepare ()
312 (gnus-set-format 'server-mode
)
313 (gnus-set-format 'server t
)
314 (let ((alist gnus-server-alist
)
315 (buffer-read-only nil
)
318 (setq gnus-inserted-opened-servers nil
)
319 ;; First we do the real list of servers.
321 (unless (member (cdar alist
) done
)
322 (push (cdar alist
) done
)
323 (setq server
(pop alist
))
324 (when (and server
(car server
) (cdr server
))
325 (gnus-server-insert-server-line (car server
) (cdr server
))))
326 (when (member (cdar alist
) done
)
328 ;; Then we insert the list of servers that have been opened in
330 (dolist (open gnus-opened-servers
)
331 (when (and (not (member (car open
) done
))
332 ;; Just ignore ephemeral servers.
333 (not (member (car open
) gnus-ephemeral-servers
)))
334 (push (car open
) done
)
335 (gnus-server-insert-server-line
336 (setq op-ser
(format "%s:%s" (caar open
) (nth 1 (car open
))))
338 (push (list op-ser
(car open
)) gnus-inserted-opened-servers
))))
339 (goto-char (point-min))
340 (gnus-server-position-point))
342 (defun gnus-server-server-name ()
343 (let ((server (get-text-property (point-at-bol) 'gnus-server
)))
344 (and server
(symbol-name server
))))
346 (defun gnus-server-named-server ()
347 "Return a server name that matches one of the names returned by
348 `gnus-method-to-server'."
349 (let ((server (get-text-property (point-at-bol) 'gnus-named-server
)))
350 (and server
(symbol-name server
))))
352 (defalias 'gnus-server-position-point
'gnus-goto-colon
)
354 (defconst gnus-server-edit-buffer
"*Gnus edit server*")
356 (defun gnus-server-update-server (server)
357 (with-current-buffer gnus-server-buffer
358 (let* ((buffer-read-only nil
)
359 (entry (assoc server gnus-server-alist
))
360 (oentry (assoc (gnus-server-to-method server
)
361 gnus-opened-servers
)))
364 (concat "(gnus-server-set-info \"" server
"\" '"
365 (gnus-prin1-to-string (cdr entry
)) ")\n")
366 (concat "^(gnus-server-set-info \"" (regexp-quote server
) "\"")))
367 (when (or entry oentry
)
368 ;; Buffer may be narrowed.
371 (when (gnus-server-goto-server server
)
374 (gnus-server-insert-server-line (car entry
) (cdr entry
))
375 (gnus-server-insert-server-line
376 (format "%s:%s" (caar oentry
) (nth 1 (car oentry
)))
378 (gnus-server-position-point))))))
380 (defun gnus-server-set-info (server info
)
381 ;; Enter a select method into the virtual server alist.
382 (when (and server info
)
384 (concat "(gnus-server-set-info \"" server
"\" '"
385 (gnus-prin1-to-string info
) ")")
386 (concat "^(gnus-server-set-info \"" (regexp-quote server
) "\""))
387 (let* ((server (nth 1 info
))
388 (entry (assoc server gnus-server-alist
))
389 (cached (assoc server gnus-server-method-cache
)))
391 (setq gnus-server-method-cache
392 (delq cached gnus-server-method-cache
)))
395 ;; Remove the server from `gnus-opened-servers' since
396 ;; it has never been opened with the new `info' yet.
397 (gnus-opened-servers-remove (cdr entry
))
398 ;; Don't make a new Lisp object.
399 (setcar (cdr entry
) (car info
))
400 (setcdr (cdr entry
) (cdr info
)))
401 (setq gnus-server-alist
402 (nconc gnus-server-alist
(list (cons server info
))))))))
404 ;;; Interactive server functions.
406 (defun gnus-server-kill-server (server)
407 "Kill the server on the current line."
408 (interactive (list (gnus-server-server-name)))
409 (unless (gnus-server-goto-server server
)
410 (if server
(error "No such server: %s" server
)
411 (error "No server on the current line")))
412 (unless (assoc server gnus-server-alist
)
413 (error "Read-only server %s" server
))
415 (let ((buffer-read-only nil
))
417 (push (assoc server gnus-server-alist
) gnus-server-killed-servers
)
418 (setq gnus-server-alist
(delq (car gnus-server-killed-servers
)
420 (let ((groups (gnus-groups-from-server server
)))
423 (format "Kill all %s groups from this server? "
425 (dolist (group groups
)
426 (setq gnus-newsrc-alist
427 (delq (assoc group gnus-newsrc-alist
)
429 (when gnus-group-change-level-function
430 (funcall gnus-group-change-level-function
431 group gnus-level-killed
3)))))
432 (gnus-server-position-point))
434 (defun gnus-server-yank-server ()
435 "Yank the previously killed server."
437 (unless gnus-server-killed-servers
438 (error "No killed servers to be yanked"))
439 (let ((alist gnus-server-alist
)
440 (server (gnus-server-server-name))
441 (killed (car gnus-server-killed-servers
)))
443 (setq gnus-server-alist
(nconc gnus-server-alist
(list killed
)))
444 (if (string= server
(caar gnus-server-alist
))
445 (push killed gnus-server-alist
)
446 (while (and (cdr alist
)
447 (not (string= server
(caadr alist
))))
448 (setq alist
(cdr alist
)))
450 (setcdr alist
(cons killed
(cdr alist
)))
451 (setq gnus-server-alist
(list killed
)))))
452 (gnus-server-update-server (car killed
))
453 (setq gnus-server-killed-servers
(cdr gnus-server-killed-servers
))
454 (gnus-server-position-point)))
456 (defun gnus-server-exit ()
457 "Return to the group buffer."
459 (gnus-run-hooks 'gnus-server-exit-hook
)
460 (gnus-kill-buffer (current-buffer))
461 (gnus-configure-windows 'group t
))
463 (defun gnus-server-list-servers ()
464 "List all available servers."
466 (let ((cur (gnus-server-server-name)))
467 (gnus-server-prepare)
468 (if cur
(gnus-server-goto-server cur
)
469 (goto-char (point-max))
471 (gnus-server-position-point)))
473 (defun gnus-server-set-status (method status
)
474 "Make METHOD have STATUS."
475 (let ((entry (assoc method gnus-opened-servers
)))
477 (setcar (cdr entry
) status
)
478 (push (list method status
) gnus-opened-servers
))))
480 (defun gnus-opened-servers-remove (method)
481 "Remove METHOD from the list of opened servers."
482 (setq gnus-opened-servers
(delq (assoc method gnus-opened-servers
)
483 gnus-opened-servers
)))
485 (defun gnus-server-open-server (server)
486 "Force an open of SERVER."
487 (interactive (list (gnus-server-server-name)))
488 (let ((method (gnus-server-to-method server
)))
490 (error "No such server: %s" server
))
491 (gnus-server-set-status method
'ok
)
493 (or (gnus-open-server method
)
494 (progn (message "Couldn't open %s" server
) nil
))
495 (gnus-server-update-server server
)
496 (gnus-server-position-point))))
498 (defun gnus-server-open-all-servers ()
501 (dolist (server gnus-inserted-opened-servers
)
502 (gnus-server-open-server (car server
))))
504 (defun gnus-server-close-server (server)
506 (interactive (list (gnus-server-server-name)))
507 (let ((method (gnus-server-to-method server
)))
509 (error "No such server: %s" server
))
510 (gnus-server-set-status method
'closed
)
512 (gnus-close-server method
)
513 (gnus-server-update-server server
)
514 (gnus-server-position-point))))
516 (defun gnus-server-offline-server (server)
517 "Set SERVER to offline."
518 (interactive (list (gnus-server-server-name)))
519 (let ((method (gnus-server-to-method server
)))
521 (error "No such server: %s" server
))
523 (gnus-close-server method
)
524 (gnus-server-set-status method
'offline
)
525 (gnus-server-update-server server
)
526 (gnus-server-position-point))))
528 (defun gnus-server-close-all-servers ()
531 (dolist (server gnus-inserted-opened-servers
)
532 (gnus-server-close-server (car server
)))
533 (dolist (server gnus-server-alist
)
534 (gnus-server-close-server (car server
))))
536 (defun gnus-server-deny-server (server)
537 "Make sure SERVER will never be attempted opened."
538 (interactive (list (gnus-server-server-name)))
539 (let ((method (gnus-server-to-method server
)))
541 (error "No such server: %s" server
))
542 (gnus-server-set-status method
'denied
))
543 (gnus-server-update-server server
)
544 (gnus-server-position-point)
547 (defun gnus-server-remove-denials ()
548 "Make all denied servers into closed servers."
550 (dolist (server gnus-opened-servers
)
551 (when (eq (nth 1 server
) 'denied
)
552 (setcar (nthcdr 1 server
) 'closed
)))
553 (gnus-server-list-servers))
555 (defun gnus-server-copy-server (from to
)
556 "Copy a server definiton to a new name."
559 (or (gnus-server-server-name)
560 (error "No server on the current line"))
561 (read-string "Copy to: ")))
563 (error "No server on current line"))
564 (unless (and to
(not (string= to
"")))
565 (error "No name to copy to"))
566 (when (assoc to gnus-server-alist
)
567 (error "%s already exists" to
))
568 (unless (gnus-server-to-method from
)
569 (error "%s: no such server" from
))
570 (let ((to-entry (cons from
(gnus-copy-sequence
571 (gnus-server-to-method from
)))))
573 (setcar (nthcdr 2 to-entry
) to
)
574 (push to-entry gnus-server-killed-servers
)
575 (gnus-server-yank-server)))
577 (defun gnus-server-add-server (how where
)
579 (list (intern (gnus-completing-read "Server method"
580 (mapcar 'car gnus-valid-select-methods
)
582 (read-string "Server name: ")))
583 (when (assq where gnus-server-alist
)
584 (error "Server with that name already defined"))
585 (push (list where how where
) gnus-server-killed-servers
)
586 (gnus-server-yank-server))
588 (defun gnus-server-goto-server (server)
589 "Jump to a server line."
591 (list (gnus-completing-read "Goto server" (mapcar 'car gnus-server-alist
) t
)))
592 (let ((to (text-property-any (point-min) (point-max)
593 'gnus-server
(intern server
))))
596 (gnus-server-position-point))))
598 (defun gnus-server-edit-server (server)
599 "Edit the server on the current line."
600 (interactive (list (gnus-server-server-name)))
602 (error "No server on current line"))
603 (unless (assoc server gnus-server-alist
)
604 (error "This server can't be edited"))
605 (let ((info (cdr (assoc server gnus-server-alist
))))
606 (gnus-close-server info
)
608 info
"Editing the server."
610 (gnus-server-set-info ,server form
)
611 (gnus-server-list-servers)
612 (gnus-server-position-point))
615 (defun gnus-server-show-server (server)
616 "Show the definition of the server on the current line."
617 (interactive (list (gnus-server-server-name)))
619 (error "No server on current line"))
620 (let ((info (gnus-server-to-method server
)))
622 info
"Showing the server."
624 (gnus-server-position-point))
627 (defun gnus-server-scan-server (server)
628 "Request a scan from the current server."
629 (interactive (list (gnus-server-server-name)))
630 (let ((method (gnus-server-to-method server
)))
631 (if (not (gnus-get-function method
'request-scan
))
632 (error "Server %s can't scan" (car method
))
633 (gnus-message 3 "Scanning %s..." server
)
634 (gnus-request-scan nil method
)
635 (gnus-message 3 "Scanning %s...done" server
))))
637 (defun gnus-server-read-server-in-server-buffer (server)
638 "Browse a server in server buffer."
639 (interactive (list (gnus-server-server-name)))
640 (let (gnus-server-browse-in-group-buffer)
641 (gnus-server-read-server server
)))
643 (defun gnus-server-read-server (server)
645 (interactive (list (gnus-server-server-name)))
646 (let ((buf (current-buffer)))
648 (gnus-browse-foreign-server server buf
)
649 (with-current-buffer buf
650 (gnus-server-update-server (gnus-server-server-name))
651 (gnus-server-position-point)))))
653 (defun gnus-server-pick-server (e)
656 (gnus-server-read-server (gnus-server-server-name)))
660 ;;; Browse Server Mode
663 (defvar gnus-browse-menu-hook nil
664 "*Hook run after the creation of the browse mode menu.")
666 (defcustom gnus-browse-subscribe-newsgroup-method
667 'gnus-subscribe-alphabetically
668 "Function(s) called when subscribing groups in the Browse Server Buffer
669 A few pre-made functions are supplied: `gnus-subscribe-randomly'
670 inserts new groups at the beginning of the list of groups;
671 `gnus-subscribe-alphabetically' inserts new groups in strict
672 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
673 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
674 for your decision; `gnus-subscribe-killed' kills all new groups;
675 `gnus-subscribe-zombies' will make all new groups into zombies;
676 `gnus-subscribe-topics' will enter groups into the topics that
680 :type
'(radio (function-item gnus-subscribe-randomly
)
681 (function-item gnus-subscribe-alphabetically
)
682 (function-item gnus-subscribe-hierarchically
)
683 (function-item gnus-subscribe-interactively
)
684 (function-item gnus-subscribe-killed
)
685 (function-item gnus-subscribe-zombies
)
686 (function-item gnus-subscribe-topics
)
690 (defvar gnus-browse-mode-hook nil
)
691 (defvar gnus-browse-mode-map nil
)
692 (put 'gnus-browse-mode
'mode-class
'special
)
694 (unless gnus-browse-mode-map
695 (setq gnus-browse-mode-map
(make-keymap))
696 (suppress-keymap gnus-browse-mode-map
)
700 " " gnus-browse-read-group
701 "=" gnus-browse-select-group
702 "n" gnus-browse-next-group
703 "p" gnus-browse-prev-group
704 "\177" gnus-browse-prev-group
705 [delete] gnus-browse-prev-group
706 "N" gnus-browse-next-group
707 "P" gnus-browse-prev-group
708 "\M-n" gnus-browse-next-group
709 "\M-p" gnus-browse-prev-group
710 "\r" gnus-browse-select-group
711 "u" gnus-browse-unsubscribe-current-group
716 "d" gnus-browse-describe-group
717 "\C-c\C-c" gnus-browse-exit
718 "?" gnus-browse-describe-briefly
720 "\C-c\C-i" gnus-info-find-node
721 "\C-c\C-b" gnus-bug))
723 (defun gnus-browse-make-menu-bar ()
724 (gnus-turn-off-edit-menu 'browse)
725 (unless (boundp 'gnus-browse-menu)
727 gnus-browse-menu gnus-browse-mode-map ""
729 ["Subscribe" gnus-browse-unsubscribe-current-group t]
730 ["Read" gnus-browse-read-group t]
731 ["Select" gnus-browse-select-group t]
732 ["Describe" gnus-browse-describe-group t]
733 ["Next" gnus-browse-next-group t]
734 ["Prev" gnus-browse-prev-group t]
735 ["Exit" gnus-browse-exit t]))
736 (gnus-run-hooks 'gnus-browse-menu-hook)))
738 (defvar gnus-browse-current-method nil)
739 (defvar gnus-browse-return-buffer nil)
741 (defvar gnus-browse-buffer "*Gnus Browse Server*")
743 (defun gnus-browse-foreign-server (server &optional return-buffer)
744 "Browse the server SERVER."
745 (setq gnus-browse-current-method (gnus-server-to-method server))
746 (setq gnus-browse-return-buffer return-buffer)
747 (let* ((method gnus-browse-current-method)
748 (orig-select-method gnus-select-method)
749 (gnus-select-method method)
751 (gnus-message 5 "Connecting to %s..." (nth 1 method))
753 ((not (gnus-check-server method))
755 1 "Unable to contact server %s: %s" (nth 1 method)
756 (gnus-status-message method))
760 (gnus-message 6 "Reading active file...")
761 (gnus-request-list method)
762 (gnus-message 6 "Reading active file...done")))
764 1 "Couldn't request list: %s" (gnus-status-message method))
767 (with-current-buffer nntp-server-buffer
768 (let ((cur (current-buffer)))
769 (goto-char (point-min))
770 (unless (or (null gnus-ignored-newsgroups)
771 (string= gnus-ignored-newsgroups ""))
772 (delete-matching-lines gnus-ignored-newsgroups))
773 ;; We treat NNTP as a special case to avoid problems with
774 ;; garbage group names like `"foo' that appear in some badly
775 ;; managed active files. -jh.
776 (if (eq (car method) 'nntp)
780 (mm-string-as-unibyte
784 (skip-chars-forward "^ \t")
786 (let ((last (read cur)))
787 (cons (read cur) last)))
793 (mm-string-as-unibyte
794 (if (eq (char-after) ?\")
796 (let ((p (point)) (name ""))
797 (skip-chars-forward "^ \t\\\\")
798 (setq name (buffer-substring p (point)))
799 (while (eq (char-after) ?\\)
800 (setq p (1+ (point)))
802 (skip-chars-forward "^ \t\\\\")
803 (setq name (concat name (buffer-substring
806 (let ((last (read cur)))
807 (cons (read cur) last)))
810 (setq groups (sort groups
812 (string< (car l1) (car l2)))))
813 (if gnus-server-browse-in-group-buffer
814 (let* ((gnus-select-method orig-select-method)
815 (gnus-group-listed-groups
816 (mapcar (lambda (group)
818 (gnus-group-prefixed-name
819 (car group) method)))
820 (gnus-set-active name (cdr group))
823 (gnus-configure-windows 'group)
824 (funcall gnus-group-prepare-function
825 gnus-level-killed 'ignore 1 'ignore))
826 (gnus-get-buffer-create gnus-browse-buffer)
827 (gnus-configure-windows 'browse)
828 (buffer-disable-undo)
829 (let ((buffer-read-only nil))
832 (setq mode-line-buffer-identification
835 "Gnus: %%b {%s:%s}" (car method) (cadr method))))
836 (let ((buffer-read-only nil)
838 (prefix (let ((gnus-select-method orig-select-method))
839 (gnus-group-prefixed-name "" method))))
840 (while (setq group (pop groups))
841 (gnus-add-text-properties
845 (format "%c%7d: %s\n"
847 (if (string= prefix "")
848 (gnus-group-level (setq name (car group)))
850 (concat prefix (setq name (car group)))))))
852 ((<= level gnus-level-subscribed) ? )
853 ((<= level gnus-level-unsubscribed) ?U)
854 ((= level gnus-level-zombie) ?Z)
856 (max 0 (- (1+ (cddr group)) (cadr group)))
857 ;; Don't decode if name is ASCII
858 (if (and (fboundp 'detect-coding-string)
859 (eq (detect-coding-string name t) 'undecided))
861 (mm-decode-coding-string
863 (inline (gnus-group-name-charset method name)))))))
864 (list 'gnus-group name)
866 (switch-to-buffer (current-buffer)))
867 (goto-char (point-min))
868 (gnus-group-position-point)
869 (gnus-message 5 "Connecting to %s...done" (nth 1 method))
872 (defun gnus-browse-mode ()
873 "Major mode for browsing a foreign server.
875 All normal editing commands are switched off.
877 \\<gnus-browse-mode-map>
878 The only things you can do in this buffer is
880 1) `\\[gnus-browse-unsubscribe-current-group]' to subscribe to a group.
881 The group will be inserted into the group buffer upon exit from this
884 2) `\\[gnus-browse-read-group]' to read a group ephemerally.
886 3) `\\[gnus-browse-exit]' to return to the group buffer."
888 (kill-all-local-variables)
889 (when (gnus-visual-p 'browse-menu 'menu)
890 (gnus-browse-make-menu-bar))
891 (gnus-simplify-mode-line)
892 (setq major-mode 'gnus-browse-mode)
893 (setq mode-name "Browse Server")
894 (setq mode-line-process nil)
895 (use-local-map gnus-browse-mode-map)
896 (buffer-disable-undo)
897 (setq truncate-lines t)
898 (gnus-set-default-directory)
899 (setq buffer-read-only t)
900 (gnus-run-mode-hooks 'gnus-browse-mode-hook))
902 (defun gnus-browse-read-group (&optional no-article number)
903 "Enter the group at the current line.
904 If NUMBER, fetch this number of articles."
906 (let ((group (gnus-browse-group-name)))
907 (if (or (not (gnus-get-info group))
908 (gnus-ephemeral-group-p group))
909 (unless (gnus-group-read-ephemeral-group
910 group gnus-browse-current-method nil
911 (cons (current-buffer) 'browse)
913 (error "Couldn't enter %s" group))
914 (unless (gnus-group-read-group nil no-article group)
915 (error "Couldn't enter %s" group)))))
917 (defun gnus-browse-select-group (&optional number)
918 "Select the current group.
919 If NUMBER, fetch this number of articles."
921 (gnus-browse-read-group 'no number))
923 (defun gnus-browse-next-group (n)
924 "Go to the next group."
928 (gnus-group-position-point)))
930 (defun gnus-browse-prev-group (n)
931 "Go to the next group."
933 (gnus-browse-next-group (- n)))
935 (defun gnus-browse-unsubscribe-current-group (arg)
936 "(Un)subscribe to the next ARG groups.
937 The variable `gnus-browse-subscribe-newsgroup-method' determines
938 how new groups will be entered into the group buffer."
941 (error "No group at current line"))
942 (let ((ward (if (< arg 0) -1 1))
944 (while (and (> arg 0)
946 (gnus-browse-unsubscribe-group)
947 (zerop (gnus-browse-next-group ward)))
949 (gnus-group-position-point)
951 (gnus-message 7 "No more newsgroups"))
954 (defun gnus-browse-group-name ()
957 (let ((name (get-text-property (point) 'gnus-group)))
958 (when (re-search-forward ": \\(.*\\)$" (point-at-eol) t)
959 (concat (gnus-method-to-server-name gnus-browse-current-method) ":"
961 (match-string-no-properties 1)))))))
963 (defun gnus-browse-describe-group (group)
964 "Describe the current group."
965 (interactive (list (gnus-browse-group-name)))
966 (gnus-group-describe-group nil group))
968 (defun gnus-browse-unsubscribe-group ()
969 "Toggle subscription of the current group in the browse buffer."
971 (buffer-read-only nil)
975 ;; If this group it killed, then we want to subscribe it.
976 (unless (eq (char-after) ? )
978 (setq group (gnus-browse-group-name))
979 (when (gnus-server-equal gnus-browse-current-method "native")
980 (setq group (gnus-group-real-name group)))
983 ;; Make sure the group has been properly removed before we
985 (if (gnus-ephemeral-group-p group)
986 (gnus-kill-ephemeral-group group))
987 (let ((entry (gnus-group-entry group)))
989 ;; Just change the subscription level if it is an
990 ;; unsubscribed group.
991 (gnus-group-change-level entry
992 gnus-level-default-subscribed)
993 ;; If it is a killed group or a zombie, feed it to the
994 ;; mechanism for new group subscription.
995 (gnus-call-subscribe-functions
996 gnus-browse-subscribe-newsgroup-method
998 (gnus-request-update-group-status group 'subscribe)))
1000 (insert (let ((lvl (gnus-group-level group)))
1002 ((< lvl gnus-level-unsubscribed) ? )
1003 ((< lvl gnus-level-zombie) ?U)
1004 ((< lvl gnus-level-killed) ?Z)
1006 (gnus-group-change-level
1007 group gnus-level-unsubscribed gnus-level-default-subscribed)
1012 (defun gnus-browse-exit ()
1013 "Quit browsing and return to the group buffer."
1015 (when (eq major-mode 'gnus-browse-mode)
1016 (gnus-kill-buffer (current-buffer)))
1017 ;; Insert the newly subscribed groups in the group buffer.
1018 (with-current-buffer gnus-group-buffer
1019 (gnus-group-list-groups nil))
1020 (if gnus-browse-return-buffer
1021 (gnus-configure-windows 'server 'force)
1022 (gnus-configure-windows 'group 'force)))
1024 (defun gnus-browse-describe-briefly ()
1025 "Give a one line description of the group mode commands."
1027 (gnus-message 6 "%s"
1028 (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")))
1030 (defun gnus-server-regenerate-server ()
1031 "Issue a command to the server to regenerate all its data structures."
1033 (let ((server (gnus-server-server-name)))
1035 (error "No server on the current line"))
1037 (gnus-get-function (gnus-server-to-method server)
1038 'request-regenerate)
1040 (error "This back end doesn't support regeneration")))
1041 (gnus-message 5 "Requesting regeneration of %s..." server)
1042 (unless (gnus-open-server server)
1043 (error "Couldn't open server"))
1044 (if (gnus-request-regenerate server)
1045 (gnus-message 5 "Requesting regeneration of %s...done" server)
1046 (gnus-message 5 "Couldn't regenerate %s" server))))
1050 ;;; Server compaction. -- dvl
1053 ;; #### FIXME: this function currently fails to update the Group buffer's
1055 (defun gnus-server-compact-server ()
1056 "Issue a command to the server to compact all its groups.
1058 Note: currently only implemented in nnml."
1060 (let ((server (gnus-server-server-name)))
1062 (error "No server on the current line"))
1064 (gnus-get-function (gnus-server-to-method server)
1067 (error "This back end doesn't support compaction")))
1069 Requesting compaction of %s... (this may take a long time)"
1071 (unless (gnus-open-server server)
1072 (error "Couldn't open server"))
1073 (if (not (gnus-request-compact server))
1074 (gnus-message 5 "Couldn't compact %s" server)
1075 (gnus-message 5 "Requesting compaction of %s...done" server)
1076 ;; Invalidate the original article buffer which might be out of date.
1077 ;; #### NOTE: Yes, this might be a bit rude, but since compaction
1078 ;; #### will not happen very often, I think this is acceptable.
1079 (let ((original (get-buffer gnus-original-article-buffer)))
1080 (and original (gnus-kill-buffer original))))))
1082 (provide 'gnus-srvr)
1084 ;;; gnus-srvr.el ends here