1 ;;; gnus-srvr.el --- virtual server support for Gnus
3 ;; Copyright (C) 1995-2012 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 (gnus-method-ephemeral-p (car open
))))
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 (gnus-open-server method
)
494 (gnus-server-update-server server
)
495 (gnus-server-position-point))))
497 (defun gnus-server-open-all-servers ()
500 (dolist (server gnus-inserted-opened-servers
)
501 (gnus-server-open-server (car server
))))
503 (defun gnus-server-close-server (server)
505 (interactive (list (gnus-server-server-name)))
506 (let ((method (gnus-server-to-method server
)))
508 (error "No such server: %s" server
))
509 (gnus-server-set-status method
'closed
)
511 (gnus-close-server method
)
512 (gnus-server-update-server server
)
513 (gnus-server-position-point))))
515 (defun gnus-server-offline-server (server)
516 "Set SERVER to offline."
517 (interactive (list (gnus-server-server-name)))
518 (let ((method (gnus-server-to-method server
)))
520 (error "No such server: %s" server
))
522 (gnus-close-server method
)
523 (gnus-server-set-status method
'offline
)
524 (gnus-server-update-server server
)
525 (gnus-server-position-point))))
527 (defun gnus-server-close-all-servers ()
530 (dolist (server gnus-inserted-opened-servers
)
531 (gnus-server-close-server (car server
)))
532 (dolist (server gnus-server-alist
)
533 (gnus-server-close-server (car server
))))
535 (defun gnus-server-deny-server (server)
536 "Make sure SERVER will never be attempted opened."
537 (interactive (list (gnus-server-server-name)))
538 (let ((method (gnus-server-to-method server
)))
540 (error "No such server: %s" server
))
541 (gnus-server-set-status method
'denied
))
542 (gnus-server-update-server server
)
543 (gnus-server-position-point)
546 (defun gnus-server-remove-denials ()
547 "Make all denied servers into closed servers."
549 (dolist (server gnus-opened-servers
)
550 (when (eq (nth 1 server
) 'denied
)
551 (setcar (nthcdr 1 server
) 'closed
)))
552 (gnus-server-list-servers))
554 (defun gnus-server-copy-server (from to
)
555 "Copy a server definition to a new name."
558 (or (gnus-server-server-name)
559 (error "No server on the current line"))
560 (read-string "Copy to: ")))
562 (error "No server on current line"))
563 (unless (and to
(not (string= to
"")))
564 (error "No name to copy to"))
565 (when (assoc to gnus-server-alist
)
566 (error "%s already exists" to
))
567 (unless (gnus-server-to-method from
)
568 (error "%s: no such server" from
))
569 (let ((to-entry (cons from
(gnus-copy-sequence
570 (gnus-server-to-method from
)))))
572 (setcar (nthcdr 2 to-entry
) to
)
573 (push to-entry gnus-server-killed-servers
)
574 (gnus-server-yank-server)))
576 (defun gnus-server-add-server (how where
)
578 (list (intern (gnus-completing-read "Server method"
579 (mapcar 'car gnus-valid-select-methods
)
581 (read-string "Server name: ")))
582 (when (assq where gnus-server-alist
)
583 (error "Server with that name already defined"))
584 (push (list where how where
) gnus-server-killed-servers
)
585 (gnus-server-yank-server))
587 (defun gnus-server-goto-server (server)
588 "Jump to a server line."
590 (list (gnus-completing-read "Goto server" (mapcar 'car gnus-server-alist
) t
)))
591 (let ((to (text-property-any (point-min) (point-max)
592 'gnus-server
(intern server
))))
595 (gnus-server-position-point))))
597 (defun gnus-server-edit-server (server)
598 "Edit the server on the current line."
599 (interactive (list (gnus-server-server-name)))
601 (error "No server on current line"))
602 (unless (assoc server gnus-server-alist
)
603 (error "This server can't be edited"))
604 (let ((info (cdr (assoc server gnus-server-alist
))))
605 (gnus-close-server info
)
607 info
"Editing the server."
609 (gnus-server-set-info ,server form
)
610 (gnus-server-list-servers)
611 (gnus-server-position-point))
614 (defun gnus-server-show-server (server)
615 "Show the definition of the server on the current line."
616 (interactive (list (gnus-server-server-name)))
618 (error "No server on current line"))
619 (let ((info (gnus-server-to-method server
)))
621 info
"Showing the server."
623 (gnus-server-position-point))
626 (defun gnus-server-scan-server (server)
627 "Request a scan from the current server."
628 (interactive (list (gnus-server-server-name)))
629 (let ((method (gnus-server-to-method server
)))
630 (if (not (gnus-get-function method
'request-scan
))
631 (error "Server %s can't scan" (car method
))
632 (gnus-message 3 "Scanning %s..." server
)
633 (gnus-request-scan nil method
)
634 (gnus-message 3 "Scanning %s...done" server
))))
636 (defun gnus-server-read-server-in-server-buffer (server)
637 "Browse a server in server buffer."
638 (interactive (list (gnus-server-server-name)))
639 (let (gnus-server-browse-in-group-buffer)
640 (gnus-server-read-server server
)))
642 (defun gnus-server-read-server (server)
644 (interactive (list (gnus-server-server-name)))
645 (let ((buf (current-buffer)))
647 (gnus-browse-foreign-server server buf
)
648 (with-current-buffer buf
649 (gnus-server-update-server (gnus-server-server-name))
650 (gnus-server-position-point)))))
652 (defun gnus-server-pick-server (e)
655 (gnus-server-read-server (gnus-server-server-name)))
659 ;;; Browse Server Mode
662 (defvar gnus-browse-menu-hook nil
663 "*Hook run after the creation of the browse mode menu.")
665 (defcustom gnus-browse-subscribe-newsgroup-method
666 'gnus-subscribe-alphabetically
667 "Function(s) called when subscribing groups in the Browse Server Buffer
668 A few pre-made functions are supplied: `gnus-subscribe-randomly'
669 inserts new groups at the beginning of the list of groups;
670 `gnus-subscribe-alphabetically' inserts new groups in strict
671 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
672 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
673 for your decision; `gnus-subscribe-killed' kills all new groups;
674 `gnus-subscribe-zombies' will make all new groups into zombies;
675 `gnus-subscribe-topics' will enter groups into the topics that
679 :type
'(radio (function-item gnus-subscribe-randomly
)
680 (function-item gnus-subscribe-alphabetically
)
681 (function-item gnus-subscribe-hierarchically
)
682 (function-item gnus-subscribe-interactively
)
683 (function-item gnus-subscribe-killed
)
684 (function-item gnus-subscribe-zombies
)
685 (function-item gnus-subscribe-topics
)
689 (defvar gnus-browse-mode-hook nil
)
690 (defvar gnus-browse-mode-map nil
)
691 (put 'gnus-browse-mode
'mode-class
'special
)
693 (unless gnus-browse-mode-map
694 (setq gnus-browse-mode-map
(make-keymap))
695 (suppress-keymap gnus-browse-mode-map
)
699 " " gnus-browse-read-group
700 "=" gnus-browse-select-group
701 "n" gnus-browse-next-group
702 "p" gnus-browse-prev-group
703 "\177" gnus-browse-prev-group
704 [delete] gnus-browse-prev-group
705 "N" gnus-browse-next-group
706 "P" gnus-browse-prev-group
707 "\M-n" gnus-browse-next-group
708 "\M-p" gnus-browse-prev-group
709 "\r" gnus-browse-select-group
710 "u" gnus-browse-unsubscribe-current-group
715 "d" gnus-browse-describe-group
716 "\C-c\C-c" gnus-browse-exit
717 "?" gnus-browse-describe-briefly
719 "\C-c\C-i" gnus-info-find-node
720 "\C-c\C-b" gnus-bug))
722 (defun gnus-browse-make-menu-bar ()
723 (gnus-turn-off-edit-menu 'browse)
724 (unless (boundp 'gnus-browse-menu)
726 gnus-browse-menu gnus-browse-mode-map ""
728 ["Subscribe" gnus-browse-unsubscribe-current-group t]
729 ["Read" gnus-browse-read-group t]
730 ["Select" gnus-browse-select-group t]
731 ["Describe" gnus-browse-describe-group t]
732 ["Next" gnus-browse-next-group t]
733 ["Prev" gnus-browse-prev-group t]
734 ["Exit" gnus-browse-exit t]))
735 (gnus-run-hooks 'gnus-browse-menu-hook)))
737 (defvar gnus-browse-current-method nil)
738 (defvar gnus-browse-return-buffer nil)
740 (defvar gnus-browse-buffer "*Gnus Browse Server*")
742 (defun gnus-browse-foreign-server (server &optional return-buffer)
743 "Browse the server SERVER."
744 (setq gnus-browse-current-method (gnus-server-to-method server))
745 (setq gnus-browse-return-buffer return-buffer)
746 (let* ((method gnus-browse-current-method)
747 (orig-select-method gnus-select-method)
748 (gnus-select-method method)
750 (gnus-message 5 "Connecting to %s..." (nth 1 method))
752 ((not (gnus-check-server method))
754 1 "Unable to contact server %s: %s" (nth 1 method)
755 (gnus-status-message method))
759 (gnus-message 6 "Reading active file...")
760 (gnus-request-list method)
761 (gnus-message 6 "Reading active file...done")))
763 1 "Couldn't request list: %s" (gnus-status-message method))
766 (with-current-buffer nntp-server-buffer
767 (let ((cur (current-buffer)))
768 (goto-char (point-min))
769 (unless (or (null gnus-ignored-newsgroups)
770 (string= gnus-ignored-newsgroups ""))
771 (delete-matching-lines gnus-ignored-newsgroups))
772 ;; We treat NNTP as a special case to avoid problems with
773 ;; garbage group names like `"foo' that appear in some badly
774 ;; managed active files. -jh.
775 (if (eq (car method) 'nntp)
779 (mm-string-as-unibyte
783 (skip-chars-forward "^ \t")
785 (let ((last (read cur)))
786 (cons (read cur) last)))
792 (mm-string-as-unibyte
793 (if (eq (char-after) ?\")
795 (let ((p (point)) (name ""))
796 (skip-chars-forward "^ \t\\\\")
797 (setq name (buffer-substring p (point)))
798 (while (eq (char-after) ?\\)
799 (setq p (1+ (point)))
801 (skip-chars-forward "^ \t\\\\")
802 (setq name (concat name (buffer-substring
805 (let ((last (read cur)))
806 (cons (read cur) last)))
809 (setq groups (sort groups
811 (string< (car l1) (car l2)))))
812 (if gnus-server-browse-in-group-buffer
813 (let* ((gnus-select-method orig-select-method)
814 (gnus-group-listed-groups
815 (mapcar (lambda (group)
817 (gnus-group-prefixed-name
818 (car group) method)))
819 (gnus-set-active name (cdr group))
822 (gnus-configure-windows 'group)
823 (funcall gnus-group-prepare-function
824 gnus-level-killed 'ignore 1 'ignore))
825 (gnus-get-buffer-create gnus-browse-buffer)
826 (gnus-configure-windows 'browse)
827 (buffer-disable-undo)
828 (let ((buffer-read-only nil))
831 (setq mode-line-buffer-identification
834 "Gnus: %%b {%s:%s}" (car method) (cadr method))))
835 (let ((buffer-read-only nil)
837 (prefix (let ((gnus-select-method orig-select-method))
838 (gnus-group-prefixed-name "" method))))
839 (while (setq group (pop groups))
840 (gnus-add-text-properties
844 (format "%c%7d: %s\n"
846 (if (string= prefix "")
847 (gnus-group-level (setq name (car group)))
849 (concat prefix (setq name (car group)))))))
851 ((<= level gnus-level-subscribed) ? )
852 ((<= level gnus-level-unsubscribed) ?U)
853 ((= level gnus-level-zombie) ?Z)
855 (max 0 (- (1+ (cddr group)) (cadr group)))
856 ;; Don't decode if name is ASCII
857 (if (and (fboundp 'detect-coding-string)
858 (eq (detect-coding-string name t) 'undecided))
860 (mm-decode-coding-string
862 (inline (gnus-group-name-charset method name)))))))
863 (list 'gnus-group name)
865 (switch-to-buffer (current-buffer)))
866 (goto-char (point-min))
867 (gnus-group-position-point)
868 (gnus-message 5 "Connecting to %s...done" (nth 1 method))
871 (defun gnus-browse-mode ()
872 "Major mode for browsing a foreign server.
874 All normal editing commands are switched off.
876 \\<gnus-browse-mode-map>
877 The only things you can do in this buffer is
879 1) `\\[gnus-browse-unsubscribe-current-group]' to subscribe to a group.
880 The group will be inserted into the group buffer upon exit from this
883 2) `\\[gnus-browse-read-group]' to read a group ephemerally.
885 3) `\\[gnus-browse-exit]' to return to the group buffer."
887 (kill-all-local-variables)
888 (when (gnus-visual-p 'browse-menu 'menu)
889 (gnus-browse-make-menu-bar))
890 (gnus-simplify-mode-line)
891 (setq major-mode 'gnus-browse-mode)
892 (setq mode-name "Browse Server")
893 (setq mode-line-process nil)
894 (use-local-map gnus-browse-mode-map)
895 (buffer-disable-undo)
896 (setq truncate-lines t)
897 (gnus-set-default-directory)
898 (setq buffer-read-only t)
899 (gnus-run-mode-hooks 'gnus-browse-mode-hook))
901 (defun gnus-browse-read-group (&optional no-article number)
902 "Enter the group at the current line.
903 If NUMBER, fetch this number of articles."
905 (let ((group (gnus-browse-group-name)))
906 (if (or (not (gnus-get-info group))
907 (gnus-ephemeral-group-p group))
908 (unless (gnus-group-read-ephemeral-group
909 group gnus-browse-current-method nil
910 (cons (current-buffer) 'browse)
912 (error "Couldn't enter %s" group))
913 (unless (gnus-group-read-group nil no-article group)
914 (error "Couldn't enter %s" group)))))
916 (defun gnus-browse-select-group (&optional number)
917 "Select the current group.
918 If NUMBER, fetch this number of articles."
920 (gnus-browse-read-group 'no number))
922 (defun gnus-browse-next-group (n)
923 "Go to the next group."
927 (gnus-group-position-point)))
929 (defun gnus-browse-prev-group (n)
930 "Go to the next group."
932 (gnus-browse-next-group (- n)))
934 (defun gnus-browse-unsubscribe-current-group (arg)
935 "(Un)subscribe to the next ARG groups.
936 The variable `gnus-browse-subscribe-newsgroup-method' determines
937 how new groups will be entered into the group buffer."
940 (error "No group at current line"))
941 (let ((ward (if (< arg 0) -1 1))
943 (while (and (> arg 0)
945 (gnus-browse-unsubscribe-group)
946 (zerop (gnus-browse-next-group ward)))
948 (gnus-group-position-point)
950 (gnus-message 7 "No more newsgroups"))
953 (defun gnus-browse-group-name ()
956 (let ((name (get-text-property (point) 'gnus-group)))
957 (when (re-search-forward ": \\(.*\\)$" (point-at-eol) t)
958 (concat (gnus-method-to-server-name gnus-browse-current-method) ":"
960 (match-string-no-properties 1)))))))
962 (defun gnus-browse-describe-group (group)
963 "Describe the current group."
964 (interactive (list (gnus-browse-group-name)))
965 (gnus-group-describe-group nil group))
967 (defun gnus-browse-unsubscribe-group ()
968 "Toggle subscription of the current group in the browse buffer."
970 (buffer-read-only nil)
974 ;; If this group it killed, then we want to subscribe it.
975 (unless (eq (char-after) ? )
977 (setq group (gnus-browse-group-name))
978 (when (gnus-server-equal gnus-browse-current-method "native")
979 (setq group (gnus-group-real-name group)))
982 ;; Make sure the group has been properly removed before we
984 (if (gnus-ephemeral-group-p group)
985 (gnus-kill-ephemeral-group group))
986 (let ((entry (gnus-group-entry group)))
988 ;; Just change the subscription level if it is an
989 ;; unsubscribed group.
990 (gnus-group-change-level entry
991 gnus-level-default-subscribed)
992 ;; If it is a killed group or a zombie, feed it to the
993 ;; mechanism for new group subscription.
994 (gnus-call-subscribe-functions
995 gnus-browse-subscribe-newsgroup-method
997 (gnus-request-update-group-status group 'subscribe)))
999 (insert (let ((lvl (gnus-group-level group)))
1001 ((< lvl gnus-level-unsubscribed) ? )
1002 ((< lvl gnus-level-zombie) ?U)
1003 ((< lvl gnus-level-killed) ?Z)
1005 (gnus-group-change-level
1006 group gnus-level-unsubscribed gnus-level-default-subscribed)
1011 (defun gnus-browse-exit ()
1012 "Quit browsing and return to the group buffer."
1014 (when (eq major-mode 'gnus-browse-mode)
1015 (gnus-kill-buffer (current-buffer)))
1016 ;; Insert the newly subscribed groups in the group buffer.
1017 (with-current-buffer gnus-group-buffer
1018 (gnus-group-list-groups nil))
1019 (if gnus-browse-return-buffer
1020 (gnus-configure-windows 'server 'force)
1021 (gnus-configure-windows 'group 'force)))
1023 (defun gnus-browse-describe-briefly ()
1024 "Give a one line description of the group mode commands."
1026 (gnus-message 6 "%s"
1027 (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")))
1029 (defun gnus-server-regenerate-server ()
1030 "Issue a command to the server to regenerate all its data structures."
1032 (let ((server (gnus-server-server-name)))
1034 (error "No server on the current line"))
1036 (gnus-get-function (gnus-server-to-method server)
1037 'request-regenerate)
1039 (error "This back end doesn't support regeneration")))
1040 (gnus-message 5 "Requesting regeneration of %s..." server)
1041 (unless (gnus-open-server server)
1042 (error "Couldn't open server"))
1043 (if (gnus-request-regenerate server)
1044 (gnus-message 5 "Requesting regeneration of %s...done" server)
1045 (gnus-message 5 "Couldn't regenerate %s" server))))
1049 ;;; Server compaction. -- dvl
1052 ;; #### FIXME: this function currently fails to update the Group buffer's
1054 (defun gnus-server-compact-server ()
1055 "Issue a command to the server to compact all its groups.
1057 Note: currently only implemented in nnml."
1059 (let ((server (gnus-server-server-name)))
1061 (error "No server on the current line"))
1063 (gnus-get-function (gnus-server-to-method server)
1066 (error "This back end doesn't support compaction")))
1068 Requesting compaction of %s... (this may take a long time)"
1070 (unless (gnus-open-server server)
1071 (error "Couldn't open server"))
1072 (if (not (gnus-request-compact server))
1073 (gnus-message 5 "Couldn't compact %s" server)
1074 (gnus-message 5 "Requesting compaction of %s...done" server)
1075 ;; Invalidate the original article buffer which might be out of date.
1076 ;; #### NOTE: Yes, this might be a bit rude, but since compaction
1077 ;; #### will not happen very often, I think this is acceptable.
1078 (let ((original (get-buffer gnus-original-article-buffer)))
1079 (and original (gnus-kill-buffer original))))))
1081 (provide 'gnus-srvr)
1083 ;;; gnus-srvr.el ends here