1 ;;; gnus-srvr.el --- virtual server support for Gnus
3 ;; Copyright (C) 1995-2013 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 [delete] gnus-browse-delete-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-delete-group (group force
)
969 "Delete the current group. Only meaningful with editable groups.
970 If FORCE (the prefix) is non-nil, all the articles in the group will
971 be deleted. This is \"deleted\" as in \"removed forever from the face
972 of the Earth\". There is no undo. The user will be prompted before
974 (interactive (list (gnus-browse-group-name)
976 (gnus-group-delete-group group force
))
978 (defun gnus-browse-unsubscribe-group ()
979 "Toggle subscription of the current group in the browse buffer."
981 (buffer-read-only nil
)
985 ;; If this group it killed, then we want to subscribe it.
986 (unless (eq (char-after) ?
)
988 (setq group
(gnus-browse-group-name))
989 (when (gnus-server-equal gnus-browse-current-method
"native")
990 (setq group
(gnus-group-real-name group
)))
993 ;; Make sure the group has been properly removed before we
995 (if (gnus-ephemeral-group-p group
)
996 (gnus-kill-ephemeral-group group
))
997 (let ((entry (gnus-group-entry group
)))
999 ;; Just change the subscription level if it is an
1000 ;; unsubscribed group.
1001 (gnus-group-change-level entry
1002 gnus-level-default-subscribed
)
1003 ;; If it is a killed group or a zombie, feed it to the
1004 ;; mechanism for new group subscription.
1005 (gnus-call-subscribe-functions
1006 gnus-browse-subscribe-newsgroup-method
1008 (gnus-request-update-group-status group
'subscribe
)))
1010 (insert (let ((lvl (gnus-group-level group
)))
1012 ((< lvl gnus-level-unsubscribed
) ?
)
1013 ((< lvl gnus-level-zombie
) ?U
)
1014 ((< lvl gnus-level-killed
) ?Z
)
1016 (gnus-group-change-level
1017 group gnus-level-unsubscribed gnus-level-default-subscribed
)
1022 (defun gnus-browse-exit ()
1023 "Quit browsing and return to the group buffer."
1025 (when (eq major-mode
'gnus-browse-mode
)
1026 (gnus-kill-buffer (current-buffer)))
1027 ;; Insert the newly subscribed groups in the group buffer.
1028 (with-current-buffer gnus-group-buffer
1029 (gnus-group-list-groups nil
))
1030 (if gnus-browse-return-buffer
1031 (gnus-configure-windows 'server
'force
)
1032 (gnus-configure-windows 'group
'force
)))
1034 (defun gnus-browse-describe-briefly ()
1035 "Give a one line description of the group mode commands."
1037 (gnus-message 6 "%s"
1038 (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")))
1040 (defun gnus-server-regenerate-server ()
1041 "Issue a command to the server to regenerate all its data structures."
1043 (let ((server (gnus-server-server-name)))
1045 (error "No server on the current line"))
1047 (gnus-get-function (gnus-server-to-method server
)
1048 'request-regenerate
)
1050 (error "This back end doesn't support regeneration")))
1051 (gnus-message 5 "Requesting regeneration of %s..." server
)
1052 (unless (gnus-open-server server
)
1053 (error "Couldn't open server"))
1054 (if (gnus-request-regenerate server
)
1055 (gnus-message 5 "Requesting regeneration of %s...done" server
)
1056 (gnus-message 5 "Couldn't regenerate %s" server
))))
1060 ;;; Server compaction. -- dvl
1063 ;; #### FIXME: this function currently fails to update the Group buffer's
1065 (defun gnus-server-compact-server ()
1066 "Issue a command to the server to compact all its groups.
1068 Note: currently only implemented in nnml."
1070 (let ((server (gnus-server-server-name)))
1072 (error "No server on the current line"))
1074 (gnus-get-function (gnus-server-to-method server
)
1077 (error "This back end doesn't support compaction")))
1079 Requesting compaction of %s... (this may take a long time)"
1081 (unless (gnus-open-server server
)
1082 (error "Couldn't open server"))
1083 (if (not (gnus-request-compact server
))
1084 (gnus-message 5 "Couldn't compact %s" server
)
1085 (gnus-message 5 "Requesting compaction of %s...done" server
)
1086 ;; Invalidate the original article buffer which might be out of date.
1087 ;; #### NOTE: Yes, this might be a bit rude, but since compaction
1088 ;; #### will not happen very often, I think this is acceptable.
1089 (let ((original (get-buffer gnus-original-article-buffer
)))
1090 (and original
(gnus-kill-buffer original
))))))
1092 (provide 'gnus-srvr
)
1094 ;;; gnus-srvr.el ends here