1 ;;; gnus-srvr.el --- virtual server support for Gnus
3 ;; Copyright (C) 1995-2015 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}"
247 ;; FIXME: Use define-derived-mode.
249 (when (gnus-visual-p 'server-menu
'menu
)
250 (gnus-server-make-menu-bar))
251 (kill-all-local-variables)
252 (gnus-simplify-mode-line)
253 (setq major-mode
'gnus-server-mode
)
254 (setq mode-name
"Server")
255 (gnus-set-default-directory)
256 (setq mode-line-process nil
)
257 (use-local-map gnus-server-mode-map
)
258 (buffer-disable-undo)
259 (setq truncate-lines t
)
260 (setq buffer-read-only t
)
261 (if (featurep 'xemacs
)
262 (put 'gnus-server-mode
'font-lock-defaults
'(gnus-server-font-lock-keywords t
))
263 (set (make-local-variable 'font-lock-defaults
)
264 '(gnus-server-font-lock-keywords t
)))
265 (gnus-run-mode-hooks 'gnus-server-mode-hook
))
267 (defun gnus-server-insert-server-line (gnus-tmp-name method
)
268 (let* ((gnus-tmp-how (car method
))
269 (gnus-tmp-where (nth 1 method
))
270 (elem (assoc method gnus-opened-servers
))
273 ((eq (nth 1 elem
) 'denied
) "(denied)")
274 ((eq (nth 1 elem
) 'offline
) "(offline)")
277 (if (or (gnus-server-opened method
)
278 (eq (nth 1 elem
) 'ok
))
281 ((error) "(error)")))))
282 (gnus-tmp-agent (if (and gnus-agent
283 (gnus-agent-method-p method
))
287 (gnus-add-text-properties
291 (eval gnus-server-line-format-spec
))
292 (list 'gnus-server
(intern gnus-tmp-name
)
293 'gnus-named-server
(intern (gnus-method-to-server method t
))))))
295 (defun gnus-enter-server-buffer ()
296 "Set up the server buffer."
297 (gnus-server-setup-buffer)
298 (gnus-configure-windows 'server
)
299 ;; Usually `gnus-configure-windows' will finish with the
300 ;; `gnus-server-buffer' selected as the current buffer, but not always (I
301 ;; bumped into it when starting from a dedicated *Group* frame, and
302 ;; gnus-configure-windows opened *Server* into its own dedicated frame).
303 (with-current-buffer (get-buffer gnus-server-buffer
)
304 (gnus-server-prepare)))
306 (defun gnus-server-setup-buffer ()
307 "Initialize the server buffer."
308 (unless (get-buffer gnus-server-buffer
)
309 (with-current-buffer (gnus-get-buffer-create gnus-server-buffer
)
310 (gnus-server-mode))))
312 (defun gnus-server-prepare ()
313 (gnus-set-format 'server-mode
)
314 (gnus-set-format 'server t
)
315 (let ((alist gnus-server-alist
)
316 (buffer-read-only nil
)
319 (setq gnus-inserted-opened-servers nil
)
320 ;; First we do the real list of servers.
322 (unless (member (cdar alist
) done
)
323 (push (cdar alist
) done
)
324 (setq server
(pop alist
))
325 (when (and server
(car server
) (cdr server
))
326 (gnus-server-insert-server-line (car server
) (cdr server
))))
327 (when (member (cdar alist
) done
)
329 ;; Then we insert the list of servers that have been opened in
331 (dolist (open gnus-opened-servers
)
332 (when (and (not (member (car open
) done
))
333 ;; Just ignore ephemeral servers.
334 (not (gnus-method-ephemeral-p (car open
))))
335 (push (car open
) done
)
336 (gnus-server-insert-server-line
337 (setq op-ser
(format "%s:%s" (caar open
) (nth 1 (car open
))))
339 (push (list op-ser
(car open
)) gnus-inserted-opened-servers
))))
340 (goto-char (point-min))
341 (gnus-server-position-point))
343 (defun gnus-server-server-name ()
344 (let ((server (get-text-property (point-at-bol) 'gnus-server
)))
345 (and server
(symbol-name server
))))
347 (defun gnus-server-named-server ()
348 "Return a server name that matches one of the names returned by
349 `gnus-method-to-server'."
350 (let ((server (get-text-property (point-at-bol) 'gnus-named-server
)))
351 (and server
(symbol-name server
))))
353 (defalias 'gnus-server-position-point
'gnus-goto-colon
)
355 (defconst gnus-server-edit-buffer
"*Gnus edit server*")
357 (defun gnus-server-update-server (server)
358 (with-current-buffer gnus-server-buffer
359 (let* ((buffer-read-only nil
)
360 (entry (assoc server gnus-server-alist
))
361 (oentry (assoc (gnus-server-to-method server
)
362 gnus-opened-servers
)))
365 (concat "(gnus-server-set-info \"" server
"\" '"
366 (gnus-prin1-to-string (cdr entry
)) ")\n")
367 (concat "^(gnus-server-set-info \"" (regexp-quote server
) "\"")))
368 (when (or entry oentry
)
369 ;; Buffer may be narrowed.
372 (when (gnus-server-goto-server server
)
375 (gnus-server-insert-server-line (car entry
) (cdr entry
))
376 (gnus-server-insert-server-line
377 (format "%s:%s" (caar oentry
) (nth 1 (car oentry
)))
379 (gnus-server-position-point))))))
381 (defun gnus-server-set-info (server info
)
382 ;; Enter a select method into the virtual server alist.
383 (when (and server info
)
385 (concat "(gnus-server-set-info \"" server
"\" '"
386 (gnus-prin1-to-string info
) ")")
387 (concat "^(gnus-server-set-info \"" (regexp-quote server
) "\""))
388 (let* ((server (nth 1 info
))
389 (entry (assoc server gnus-server-alist
))
390 (cached (assoc server gnus-server-method-cache
)))
392 (setq gnus-server-method-cache
393 (delq cached gnus-server-method-cache
)))
396 ;; Remove the server from `gnus-opened-servers' since
397 ;; it has never been opened with the new `info' yet.
398 (gnus-opened-servers-remove (cdr entry
))
399 ;; Don't make a new Lisp object.
400 (setcar (cdr entry
) (car info
))
401 (setcdr (cdr entry
) (cdr info
)))
402 (setq gnus-server-alist
403 (nconc gnus-server-alist
(list (cons server info
))))))))
405 ;;; Interactive server functions.
407 (defun gnus-server-kill-server (server)
408 "Kill the server on the current line."
409 (interactive (list (gnus-server-server-name)))
410 (unless (gnus-server-goto-server server
)
411 (if server
(error "No such server: %s" server
)
412 (error "No server on the current line")))
413 (unless (assoc server gnus-server-alist
)
414 (error "Read-only server %s" server
))
416 (let ((buffer-read-only nil
))
418 (push (assoc server gnus-server-alist
) gnus-server-killed-servers
)
419 (setq gnus-server-alist
(delq (car gnus-server-killed-servers
)
421 (let ((groups (gnus-groups-from-server server
)))
424 (format "Kill all %s groups from this server? "
426 (dolist (group groups
)
427 (setq gnus-newsrc-alist
428 (delq (assoc group gnus-newsrc-alist
)
430 (when gnus-group-change-level-function
431 (funcall gnus-group-change-level-function
432 group gnus-level-killed
3)))))
433 (gnus-server-position-point))
435 (defun gnus-server-yank-server ()
436 "Yank the previously killed server."
438 (unless gnus-server-killed-servers
439 (error "No killed servers to be yanked"))
440 (let ((alist gnus-server-alist
)
441 (server (gnus-server-server-name))
442 (killed (car gnus-server-killed-servers
)))
444 (setq gnus-server-alist
(nconc gnus-server-alist
(list killed
)))
445 (if (string= server
(caar gnus-server-alist
))
446 (push killed gnus-server-alist
)
447 (while (and (cdr alist
)
448 (not (string= server
(caadr alist
))))
449 (setq alist
(cdr alist
)))
451 (setcdr alist
(cons killed
(cdr alist
)))
452 (setq gnus-server-alist
(list killed
)))))
453 (gnus-server-update-server (car killed
))
454 (setq gnus-server-killed-servers
(cdr gnus-server-killed-servers
))
455 (gnus-server-position-point)))
457 (defun gnus-server-exit ()
458 "Return to the group buffer."
460 (gnus-run-hooks 'gnus-server-exit-hook
)
461 (gnus-kill-buffer (current-buffer))
462 (gnus-configure-windows 'group t
))
464 (defun gnus-server-list-servers ()
465 "List all available servers."
467 (let ((cur (gnus-server-server-name)))
468 (gnus-server-prepare)
469 (if cur
(gnus-server-goto-server cur
)
470 (goto-char (point-max))
472 (gnus-server-position-point)))
474 (defun gnus-server-set-status (method status
)
475 "Make METHOD have STATUS."
476 (let ((entry (assoc method gnus-opened-servers
)))
478 (setcar (cdr entry
) status
)
479 (push (list method status
) gnus-opened-servers
))))
481 (defun gnus-opened-servers-remove (method)
482 "Remove METHOD from the list of opened servers."
483 (setq gnus-opened-servers
(delq (assoc method gnus-opened-servers
)
484 gnus-opened-servers
)))
486 (defun gnus-server-open-server (server)
487 "Force an open of SERVER."
488 (interactive (list (gnus-server-server-name)))
489 (let ((method (gnus-server-to-method server
)))
491 (error "No such server: %s" server
))
492 (gnus-server-set-status method
'ok
)
494 (gnus-open-server method
)
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 definition 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 [delete] gnus-browse-delete-group
718 "\C-c\C-c" gnus-browse-exit
719 "?" gnus-browse-describe-briefly
721 "\C-c\C-i" gnus-info-find-node
722 "\C-c\C-b" gnus-bug
))
724 (defun gnus-browse-make-menu-bar ()
725 (gnus-turn-off-edit-menu 'browse
)
726 (unless (boundp 'gnus-browse-menu
)
728 gnus-browse-menu gnus-browse-mode-map
""
730 ["Subscribe" gnus-browse-unsubscribe-current-group t
]
731 ["Read" gnus-browse-read-group t
]
732 ["Select" gnus-browse-select-group t
]
733 ["Describe" gnus-browse-describe-group t
]
734 ["Next" gnus-browse-next-group t
]
735 ["Prev" gnus-browse-prev-group t
]
736 ["Exit" gnus-browse-exit t
]))
737 (gnus-run-hooks 'gnus-browse-menu-hook
)))
739 (defvar gnus-browse-current-method nil
)
740 (defvar gnus-browse-return-buffer nil
)
742 (defvar gnus-browse-buffer
"*Gnus Browse Server*")
744 (defun gnus-browse-foreign-server (server &optional return-buffer
)
745 "Browse the server SERVER."
746 (setq gnus-browse-current-method
(gnus-server-to-method server
))
747 (setq gnus-browse-return-buffer return-buffer
)
748 (let* ((method gnus-browse-current-method
)
749 (orig-select-method gnus-select-method
)
750 (gnus-select-method method
)
752 (gnus-message 5 "Connecting to %s..." (nth 1 method
))
754 ((not (gnus-check-server method
))
756 1 "Unable to contact server %s: %s" (nth 1 method
)
757 (gnus-status-message method
))
761 (gnus-message 6 "Reading active file...")
762 (gnus-request-list method
)
763 (gnus-message 6 "Reading active file...done")))
765 1 "Couldn't request list: %s" (gnus-status-message method
))
768 (with-current-buffer nntp-server-buffer
769 (let ((cur (current-buffer)))
770 (goto-char (point-min))
771 (unless (or (null gnus-ignored-newsgroups
)
772 (string= gnus-ignored-newsgroups
""))
773 (delete-matching-lines gnus-ignored-newsgroups
))
774 ;; We treat NNTP as a special case to avoid problems with
775 ;; garbage group names like `"foo' that appear in some badly
776 ;; managed active files. -jh.
777 (if (eq (car method
) 'nntp
)
781 (mm-string-as-unibyte
785 (skip-chars-forward "^ \t")
787 (let ((last (read cur
)))
788 (cons (read cur
) last
)))
794 (mm-string-as-unibyte
795 (if (eq (char-after) ?
\")
797 (let ((p (point)) (name ""))
798 (skip-chars-forward "^ \t\\\\")
799 (setq name
(buffer-substring p
(point)))
800 (while (eq (char-after) ?
\\)
801 (setq p
(1+ (point)))
803 (skip-chars-forward "^ \t\\\\")
804 (setq name
(concat name
(buffer-substring
807 (let ((last (read cur
)))
808 (cons (read cur
) last
)))
811 (setq groups
(sort groups
813 (string< (car l1
) (car l2
)))))
814 (if gnus-server-browse-in-group-buffer
815 (let* ((gnus-select-method orig-select-method
)
816 (gnus-group-listed-groups
817 (mapcar (lambda (group)
819 (gnus-group-prefixed-name
820 (car group
) method
)))
821 (gnus-set-active name
(cdr group
))
824 (gnus-configure-windows 'group
)
825 (funcall gnus-group-prepare-function
826 gnus-level-killed
'ignore
1 'ignore
))
827 (gnus-get-buffer-create gnus-browse-buffer
)
828 (gnus-configure-windows 'browse
)
829 (buffer-disable-undo)
830 (let ((buffer-read-only nil
))
833 (setq mode-line-buffer-identification
836 "Gnus: %%b {%s:%s}" (car method
) (cadr method
))))
837 (let ((buffer-read-only nil
)
839 (prefix (let ((gnus-select-method orig-select-method
))
840 (gnus-group-prefixed-name "" method
))))
841 (while (setq group
(pop groups
))
842 (gnus-add-text-properties
846 (format "%c%7d: %s\n"
848 (if (string= prefix
"")
849 (gnus-group-level (setq name
(car group
)))
851 (concat prefix
(setq name
(car group
)))))))
853 ((<= level gnus-level-subscribed
) ?
)
854 ((<= level gnus-level-unsubscribed
) ?U
)
855 ((= level gnus-level-zombie
) ?Z
)
857 (max 0 (- (1+ (cddr group
)) (cadr group
)))
858 ;; Don't decode if name is ASCII
859 (if (and (fboundp 'detect-coding-string
)
860 (eq (detect-coding-string name t
) 'undecided
))
862 (mm-decode-coding-string
864 (inline (gnus-group-name-charset method name
)))))))
865 (list 'gnus-group name
)
867 (switch-to-buffer (current-buffer)))
868 (goto-char (point-min))
869 (gnus-group-position-point)
870 (gnus-message 5 "Connecting to %s...done" (nth 1 method
))
873 (define-derived-mode gnus-browse-mode fundamental-mode
"Browse Server"
874 "Major mode for browsing a foreign server.
876 All normal editing commands are switched off.
878 \\<gnus-browse-mode-map>
879 The only things you can do in this buffer is
881 1) `\\[gnus-browse-unsubscribe-current-group]' to subscribe to a group.
882 The group will be inserted into the group buffer upon exit from this
885 2) `\\[gnus-browse-read-group]' to read a group ephemerally.
887 3) `\\[gnus-browse-exit]' to return to the group buffer."
888 (when (gnus-visual-p 'browse-menu
'menu
)
889 (gnus-browse-make-menu-bar))
890 (gnus-simplify-mode-line)
891 (setq mode-line-process nil
)
892 (buffer-disable-undo)
893 (setq truncate-lines t
)
894 (gnus-set-default-directory)
895 (setq buffer-read-only t
))
897 (defun gnus-browse-read-group (&optional no-article number
)
898 "Enter the group at the current line.
899 If NUMBER, fetch this number of articles."
901 (let ((group (gnus-browse-group-name)))
902 (if (or (not (gnus-get-info group
))
903 (gnus-ephemeral-group-p group
))
904 (unless (gnus-group-read-ephemeral-group
905 group gnus-browse-current-method nil
906 (cons (current-buffer) 'browse
)
908 (error "Couldn't enter %s" group
))
909 (unless (gnus-group-read-group nil no-article group
)
910 (error "Couldn't enter %s" group
)))))
912 (defun gnus-browse-select-group (&optional number
)
913 "Select the current group.
914 If NUMBER, fetch this number of articles."
916 (gnus-browse-read-group 'no number
))
918 (defun gnus-browse-next-group (n)
919 "Go to the next group."
923 (gnus-group-position-point)))
925 (defun gnus-browse-prev-group (n)
926 "Go to the next group."
928 (gnus-browse-next-group (- n
)))
930 (defun gnus-browse-unsubscribe-current-group (arg)
931 "(Un)subscribe to the next ARG groups.
932 The variable `gnus-browse-subscribe-newsgroup-method' determines
933 how new groups will be entered into the group buffer."
936 (error "No group at current line"))
937 (let ((ward (if (< arg
0) -
1 1))
939 (while (and (> arg
0)
941 (gnus-browse-unsubscribe-group)
942 (zerop (gnus-browse-next-group ward
)))
944 (gnus-group-position-point)
946 (gnus-message 7 "No more newsgroups"))
949 (defun gnus-browse-group-name ()
952 (let ((name (get-text-property (point) 'gnus-group
)))
953 (when (re-search-forward ": \\(.*\\)$" (point-at-eol) t
)
954 (concat (gnus-method-to-server-name gnus-browse-current-method
) ":"
956 (match-string-no-properties 1)))))))
958 (defun gnus-browse-describe-group (group)
959 "Describe the current group."
960 (interactive (list (gnus-browse-group-name)))
961 (gnus-group-describe-group nil group
))
963 (defun gnus-browse-delete-group (group force
)
964 "Delete the current group. Only meaningful with editable groups.
965 If FORCE (the prefix) is non-nil, all the articles in the group will
966 be deleted. This is \"deleted\" as in \"removed forever from the face
967 of the Earth\". There is no undo. The user will be prompted before
969 (interactive (list (gnus-browse-group-name)
971 (gnus-group-delete-group group force
))
973 (defun gnus-browse-unsubscribe-group ()
974 "Toggle subscription of the current group in the browse buffer."
976 (buffer-read-only nil
)
980 ;; If this group it killed, then we want to subscribe it.
981 (unless (eq (char-after) ?
)
983 (setq group
(gnus-browse-group-name))
984 (when (gnus-server-equal gnus-browse-current-method
"native")
985 (setq group
(gnus-group-real-name group
)))
988 ;; Make sure the group has been properly removed before we
990 (if (gnus-ephemeral-group-p group
)
991 (gnus-kill-ephemeral-group group
))
992 (let ((entry (gnus-group-entry group
)))
994 ;; Just change the subscription level if it is an
995 ;; unsubscribed group.
996 (gnus-group-change-level entry
997 gnus-level-default-subscribed
)
998 ;; If it is a killed group or a zombie, feed it to the
999 ;; mechanism for new group subscription.
1000 (gnus-call-subscribe-functions
1001 gnus-browse-subscribe-newsgroup-method
1003 (gnus-request-update-group-status group
'subscribe
)))
1005 (insert (let ((lvl (gnus-group-level group
)))
1007 ((< lvl gnus-level-unsubscribed
) ?
)
1008 ((< lvl gnus-level-zombie
) ?U
)
1009 ((< lvl gnus-level-killed
) ?Z
)
1011 (gnus-group-change-level
1012 group gnus-level-unsubscribed gnus-level-default-subscribed
)
1017 (defun gnus-browse-exit ()
1018 "Quit browsing and return to the group buffer."
1020 (when (derived-mode-p 'gnus-browse-mode
)
1021 (gnus-kill-buffer (current-buffer)))
1022 ;; Insert the newly subscribed groups in the group buffer.
1023 (with-current-buffer gnus-group-buffer
1024 (gnus-group-list-groups nil
))
1025 (if gnus-browse-return-buffer
1026 (gnus-configure-windows 'server
'force
)
1027 (gnus-configure-windows 'group
'force
)))
1029 (defun gnus-browse-describe-briefly ()
1030 "Give a one line description of the group mode commands."
1032 (gnus-message 6 "%s"
1033 (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")))
1035 (defun gnus-server-regenerate-server ()
1036 "Issue a command to the server to regenerate all its data structures."
1038 (let ((server (gnus-server-server-name)))
1040 (error "No server on the current line"))
1042 (gnus-get-function (gnus-server-to-method server
)
1043 'request-regenerate
)
1045 (error "This back end doesn't support regeneration")))
1046 (gnus-message 5 "Requesting regeneration of %s..." server
)
1047 (unless (gnus-open-server server
)
1048 (error "Couldn't open server"))
1049 (if (gnus-request-regenerate server
)
1050 (gnus-message 5 "Requesting regeneration of %s...done" server
)
1051 (gnus-message 5 "Couldn't regenerate %s" server
))))
1055 ;;; Server compaction. -- dvl
1058 ;; #### FIXME: this function currently fails to update the Group buffer's
1060 (defun gnus-server-compact-server ()
1061 "Issue a command to the server to compact all its groups.
1063 Note: currently only implemented in nnml."
1065 (let ((server (gnus-server-server-name)))
1067 (error "No server on the current line"))
1069 (gnus-get-function (gnus-server-to-method server
)
1072 (error "This back end doesn't support compaction")))
1074 Requesting compaction of %s... (this may take a long time)"
1076 (unless (gnus-open-server server
)
1077 (error "Couldn't open server"))
1078 (if (not (gnus-request-compact server
))
1079 (gnus-message 5 "Couldn't compact %s" server
)
1080 (gnus-message 5 "Requesting compaction of %s...done" server
)
1081 ;; Invalidate the original article buffer which might be out of date.
1082 ;; #### NOTE: Yes, this might be a bit rude, but since compaction
1083 ;; #### will not happen very often, I think this is acceptable.
1084 (let ((original (get-buffer gnus-original-article-buffer
)))
1085 (and original
(gnus-kill-buffer original
))))))
1087 (provide 'gnus-srvr
)
1089 ;;; gnus-srvr.el ends here