Configure Symbola font only for symbols and punctuation
[emacs.git] / lisp / gnus / gnus-srvr.el
blobd32f7cad3db53740317cde7c7e9e2dafd6851542
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>
6 ;; Keywords: news
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/>.
23 ;;; Commentary:
25 ;;; Code:
27 (eval-when-compile (require 'cl))
29 (require 'gnus)
30 (require 'gnus-start)
31 (require 'gnus-spec)
32 (require 'gnus-group)
33 (require 'gnus-int)
34 (require 'gnus-range)
36 (autoload 'gnus-group-make-nnir-group "nnir")
38 (defcustom gnus-server-mode-hook nil
39 "Hook run in `gnus-server-mode' buffers."
40 :group 'gnus-server
41 :type 'hook)
43 (defcustom gnus-server-exit-hook nil
44 "Hook run when exiting the server buffer."
45 :group 'gnus-server
46 :type 'hook)
48 (defcustom gnus-server-line-format " {%(%h:%w%)} %s%a%c\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:
55 %h back end
56 %n name
57 %w address
58 %s status
59 %a agent covered
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
65 :type 'string)
67 (defcustom gnus-server-mode-line-format "Gnus: %%b"
68 "The format specification for the server mode line."
69 :group 'gnus-server-visual
70 :type 'string)
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."
75 :version "22.1"
76 :group 'gnus-server-visual
77 :type 'boolean)
79 ;;; Internal variables.
81 (defvar gnus-tmp-how)
82 (defvar gnus-tmp-name)
83 (defvar gnus-tmp-where)
84 (defvar gnus-tmp-status)
85 (defvar gnus-tmp-agent)
86 (defvar gnus-tmp-cloud)
87 (defvar gnus-tmp-news-server)
88 (defvar gnus-tmp-news-method)
89 (defvar gnus-tmp-user-defined)
91 (defvar gnus-inserted-opened-servers nil)
93 (defvar gnus-server-line-format-alist
94 `((?h gnus-tmp-how ?s)
95 (?n gnus-tmp-name ?s)
96 (?w gnus-tmp-where ?s)
97 (?s gnus-tmp-status ?s)
98 (?a gnus-tmp-agent ?s)
99 (?c gnus-tmp-cloud ?s)))
101 (defvar gnus-server-mode-line-format-alist
102 `((?S gnus-tmp-news-server ?s)
103 (?M gnus-tmp-news-method ?s)
104 (?u gnus-tmp-user-defined ?s)))
106 (defvar gnus-server-line-format-spec nil)
107 (defvar gnus-server-mode-line-format-spec nil)
108 (defvar gnus-server-killed-servers nil)
110 (defvar gnus-server-mode-map)
112 (defvar gnus-server-menu-hook nil
113 "*Hook run after the creation of the server mode menu.")
115 (defun gnus-server-make-menu-bar ()
116 (gnus-turn-off-edit-menu 'server)
117 (unless (boundp 'gnus-server-server-menu)
118 (easy-menu-define
119 gnus-server-server-menu gnus-server-mode-map ""
120 '("Server"
121 ["Add..." gnus-server-add-server t]
122 ["Browse" gnus-server-read-server t]
123 ["Scan" gnus-server-scan-server t]
124 ["List" gnus-server-list-servers t]
125 ["Kill" gnus-server-kill-server t]
126 ["Yank" gnus-server-yank-server t]
127 ["Copy" gnus-server-copy-server t]
128 ["Show" gnus-server-show-server t]
129 ["Edit" gnus-server-edit-server t]
130 ["Regenerate" gnus-server-regenerate-server t]
131 ["Compact" gnus-server-compact-server t]
132 ["Exit" gnus-server-exit t]))
134 (easy-menu-define
135 gnus-server-connections-menu gnus-server-mode-map ""
136 '("Connections"
137 ["Open" gnus-server-open-server t]
138 ["Close" gnus-server-close-server t]
139 ["Offline" gnus-server-offline-server t]
140 ["Deny" gnus-server-deny-server t]
141 ["Toggle Cloud" gnus-server-toggle-cloud-server t]
142 "---"
143 ["Open All" gnus-server-open-all-servers t]
144 ["Close All" gnus-server-close-all-servers t]
145 ["Reset All" gnus-server-remove-denials t]))
147 (gnus-run-hooks 'gnus-server-menu-hook)))
149 (defvar gnus-server-mode-map nil)
150 (put 'gnus-server-mode 'mode-class 'special)
152 (unless gnus-server-mode-map
153 (setq gnus-server-mode-map (make-sparse-keymap))
154 (suppress-keymap gnus-server-mode-map)
156 (gnus-define-keys gnus-server-mode-map
157 " " gnus-server-read-server-in-server-buffer
158 "\r" gnus-server-read-server
159 gnus-mouse-2 gnus-server-pick-server
160 "q" gnus-server-exit
161 "l" gnus-server-list-servers
162 "k" gnus-server-kill-server
163 "y" gnus-server-yank-server
164 "c" gnus-server-copy-server
165 "a" gnus-server-add-server
166 "e" gnus-server-edit-server
167 "S" gnus-server-show-server
168 "s" gnus-server-scan-server
170 "O" gnus-server-open-server
171 "\M-o" gnus-server-open-all-servers
172 "C" gnus-server-close-server
173 "\M-c" gnus-server-close-all-servers
174 "D" gnus-server-deny-server
175 "L" gnus-server-offline-server
176 "R" gnus-server-remove-denials
178 "n" next-line
179 "p" previous-line
181 "g" gnus-server-regenerate-server
183 "G" gnus-group-make-nnir-group
185 "z" gnus-server-compact-server
187 "i" gnus-server-toggle-cloud-server
189 "\C-c\C-i" gnus-info-find-node
190 "\C-c\C-b" gnus-bug))
192 (defface gnus-server-agent
193 '((((class color) (background light)) (:foreground "PaleTurquoise" :bold t))
194 (((class color) (background dark)) (:foreground "PaleTurquoise" :bold t))
195 (t (:bold t)))
196 "Face used for displaying AGENTIZED servers"
197 :group 'gnus-server-visual)
198 ;; backward-compatibility alias
199 (put 'gnus-server-agent-face 'face-alias 'gnus-server-agent)
200 (put 'gnus-server-agent-face 'obsolete-face "22.1")
202 (defface gnus-server-cloud
203 '((((class color) (background light)) (:foreground "ForestGreen" :bold t))
204 (((class color) (background dark)) (:foreground "PaleGreen" :bold t))
205 (t (:bold t)))
206 "Face used for displaying AGENTIZED servers"
207 :group 'gnus-server-visual)
209 (defface gnus-server-opened
210 '((((class color) (background light)) (:foreground "Green3" :bold t))
211 (((class color) (background dark)) (:foreground "Green1" :bold t))
212 (t (:bold t)))
213 "Face used for displaying OPENED servers"
214 :group 'gnus-server-visual)
215 ;; backward-compatibility alias
216 (put 'gnus-server-opened-face 'face-alias 'gnus-server-opened)
217 (put 'gnus-server-opened-face 'obsolete-face "22.1")
219 (defface gnus-server-closed
220 '((((class color) (background light)) (:foreground "Steel Blue" :italic t))
221 (((class color) (background dark))
222 (:foreground "LightBlue" :italic t))
223 (t (:italic t)))
224 "Face used for displaying CLOSED servers"
225 :group 'gnus-server-visual)
226 ;; backward-compatibility alias
227 (put 'gnus-server-closed-face 'face-alias 'gnus-server-closed)
228 (put 'gnus-server-closed-face 'obsolete-face "22.1")
230 (defface gnus-server-denied
231 '((((class color) (background light)) (:foreground "Red" :bold t))
232 (((class color) (background dark)) (:foreground "Pink" :bold t))
233 (t (:inverse-video t :bold t)))
234 "Face used for displaying DENIED servers"
235 :group 'gnus-server-visual)
236 ;; backward-compatibility alias
237 (put 'gnus-server-denied-face 'face-alias 'gnus-server-denied)
238 (put 'gnus-server-denied-face 'obsolete-face "22.1")
240 (defface gnus-server-offline
241 '((((class color) (background light)) (:foreground "Orange" :bold t))
242 (((class color) (background dark)) (:foreground "Yellow" :bold t))
243 (t (:inverse-video t :bold t)))
244 "Face used for displaying OFFLINE servers"
245 :group 'gnus-server-visual)
246 ;; backward-compatibility alias
247 (put 'gnus-server-offline-face 'face-alias 'gnus-server-offline)
248 (put 'gnus-server-offline-face 'obsolete-face "22.1")
250 (defvar gnus-server-font-lock-keywords
251 '(("(\\(agent\\))" 1 'gnus-server-agent)
252 ("(\\(cloud\\))" 1 'gnus-server-cloud)
253 ("(\\(opened\\))" 1 'gnus-server-opened)
254 ("(\\(closed\\))" 1 'gnus-server-closed)
255 ("(\\(offline\\))" 1 'gnus-server-offline)
256 ("(\\(denied\\))" 1 'gnus-server-denied)))
258 (defun gnus-server-mode ()
259 "Major mode for listing and editing servers.
261 All normal editing commands are switched off.
262 \\<gnus-server-mode-map>
263 For more in-depth information on this mode, read the manual
264 \(`\\[gnus-info-find-node]').
266 The following commands are available:
268 \\{gnus-server-mode-map}"
269 ;; FIXME: Use define-derived-mode.
270 (interactive)
271 (when (gnus-visual-p 'server-menu 'menu)
272 (gnus-server-make-menu-bar))
273 (kill-all-local-variables)
274 (gnus-simplify-mode-line)
275 (setq major-mode 'gnus-server-mode)
276 (setq mode-name "Server")
277 (gnus-set-default-directory)
278 (setq mode-line-process nil)
279 (use-local-map gnus-server-mode-map)
280 (buffer-disable-undo)
281 (setq truncate-lines t)
282 (setq buffer-read-only t)
283 (if (featurep 'xemacs)
284 (put 'gnus-server-mode 'font-lock-defaults '(gnus-server-font-lock-keywords t))
285 (set (make-local-variable 'font-lock-defaults)
286 '(gnus-server-font-lock-keywords t)))
287 (gnus-run-mode-hooks 'gnus-server-mode-hook))
289 (defun gnus-server-insert-server-line (name method)
290 (let* ((gnus-tmp-name name)
291 (gnus-tmp-how (car method))
292 (gnus-tmp-where (nth 1 method))
293 (elem (assoc method gnus-opened-servers))
294 (gnus-tmp-status
295 (cond
296 ((eq (nth 1 elem) 'denied) "(denied)")
297 ((eq (nth 1 elem) 'offline) "(offline)")
299 (condition-case nil
300 (if (or (gnus-server-opened method)
301 (eq (nth 1 elem) 'ok))
302 "(opened)"
303 "(closed)")
304 ((error) "(error)")))))
305 (gnus-tmp-agent (if (and gnus-agent
306 (gnus-agent-method-p method))
307 " (agent)"
308 ""))
309 (gnus-tmp-cloud (if (gnus-cloud-server-p gnus-tmp-name)
310 " (cloud)"
311 "")))
312 (beginning-of-line)
313 (gnus-add-text-properties
314 (point)
315 (prog1 (1+ (point))
316 ;; Insert the text.
317 (eval gnus-server-line-format-spec))
318 (list 'gnus-server (intern gnus-tmp-name)
319 'gnus-named-server (intern (gnus-method-to-server method t))))))
321 (defun gnus-enter-server-buffer ()
322 "Set up the server buffer."
323 (gnus-server-setup-buffer)
324 (gnus-configure-windows 'server)
325 ;; Usually `gnus-configure-windows' will finish with the
326 ;; `gnus-server-buffer' selected as the current buffer, but not always (I
327 ;; bumped into it when starting from a dedicated *Group* frame, and
328 ;; gnus-configure-windows opened *Server* into its own dedicated frame).
329 (with-current-buffer (get-buffer gnus-server-buffer)
330 (gnus-server-prepare)))
332 (defun gnus-server-setup-buffer ()
333 "Initialize the server buffer."
334 (unless (get-buffer gnus-server-buffer)
335 (with-current-buffer (gnus-get-buffer-create gnus-server-buffer)
336 (gnus-server-mode))))
338 (defun gnus-server-prepare ()
339 (gnus-set-format 'server-mode)
340 (gnus-set-format 'server t)
341 (let ((alist gnus-server-alist)
342 (buffer-read-only nil)
343 done server op-ser)
344 (erase-buffer)
345 (setq gnus-inserted-opened-servers nil)
346 ;; First we do the real list of servers.
347 (while alist
348 (unless (member (cdar alist) done)
349 (push (cdar alist) done)
350 (setq server (pop alist))
351 (when (and server (car server) (cdr server))
352 (gnus-server-insert-server-line (car server) (cdr server))))
353 (when (member (cdar alist) done)
354 (pop alist)))
355 ;; Then we insert the list of servers that have been opened in
356 ;; this session.
357 (dolist (open gnus-opened-servers)
358 (when (and (not (member (car open) done))
359 ;; Just ignore ephemeral servers.
360 (not (gnus-method-ephemeral-p (car open))))
361 (push (car open) done)
362 (gnus-server-insert-server-line
363 (setq op-ser (format "%s:%s" (caar open) (nth 1 (car open))))
364 (car open))
365 (push (list op-ser (car open)) gnus-inserted-opened-servers))))
366 (goto-char (point-min))
367 (gnus-server-position-point))
369 (defun gnus-server-server-name ()
370 (let ((server (get-text-property (point-at-bol) 'gnus-server)))
371 (and server (symbol-name server))))
373 (defun gnus-server-named-server ()
374 "Return a server name that matches one of the names returned by
375 `gnus-method-to-server'."
376 (let ((server (get-text-property (point-at-bol) 'gnus-named-server)))
377 (and server (symbol-name server))))
379 (defalias 'gnus-server-position-point 'gnus-goto-colon)
381 (defconst gnus-server-edit-buffer "*Gnus edit server*")
383 (defun gnus-server-update-server (server)
384 (with-current-buffer gnus-server-buffer
385 (let* ((buffer-read-only nil)
386 (entry (assoc server gnus-server-alist))
387 (oentry (assoc (gnus-server-to-method server)
388 gnus-opened-servers)))
389 (when entry
390 (gnus-dribble-enter
391 (concat "(gnus-server-set-info \"" server "\" '"
392 (gnus-prin1-to-string (cdr entry)) ")\n")
393 (concat "^(gnus-server-set-info \"" (regexp-quote server) "\"")))
394 (when (or entry oentry)
395 ;; Buffer may be narrowed.
396 (save-restriction
397 (widen)
398 (when (gnus-server-goto-server server)
399 (gnus-delete-line))
400 (if entry
401 (gnus-server-insert-server-line (car entry) (cdr entry))
402 (gnus-server-insert-server-line
403 (format "%s:%s" (caar oentry) (nth 1 (car oentry)))
404 (car oentry)))
405 (gnus-server-position-point))))))
407 (defun gnus-server-set-info (server info)
408 ;; Enter a select method into the virtual server alist.
409 (when (and server info)
410 (gnus-dribble-enter
411 (concat "(gnus-server-set-info \"" server "\" '"
412 (gnus-prin1-to-string info) ")")
413 (concat "^(gnus-server-set-info \"" (regexp-quote server) "\""))
414 (let* ((server (nth 1 info))
415 (entry (assoc server gnus-server-alist))
416 (cached (assoc server gnus-server-method-cache)))
417 (if cached
418 (setq gnus-server-method-cache
419 (delq cached gnus-server-method-cache)))
420 (if entry
421 (progn
422 ;; Remove the server from `gnus-opened-servers' since
423 ;; it has never been opened with the new `info' yet.
424 (gnus-opened-servers-remove (cdr entry))
425 ;; Don't make a new Lisp object.
426 (setcar (cdr entry) (car info))
427 (setcdr (cdr entry) (cdr info)))
428 (setq gnus-server-alist
429 (nconc gnus-server-alist (list (cons server info))))))))
431 ;;; Interactive server functions.
433 (defun gnus-server-kill-server (server)
434 "Kill the server on the current line."
435 (interactive (list (gnus-server-server-name)))
436 (unless (gnus-server-goto-server server)
437 (if server (error "No such server: %s" server)
438 (error "No server on the current line")))
439 (unless (assoc server gnus-server-alist)
440 (error "Read-only server %s" server))
441 (gnus-dribble-touch)
442 (let ((buffer-read-only nil))
443 (gnus-delete-line))
444 (push (assoc server gnus-server-alist) gnus-server-killed-servers)
445 (setq gnus-server-alist (delq (car gnus-server-killed-servers)
446 gnus-server-alist))
447 (let ((groups (gnus-groups-from-server server)))
448 (when (and groups
449 (gnus-yes-or-no-p
450 (format "Kill all %s groups from this server? "
451 (length groups))))
452 (dolist (group groups)
453 (setq gnus-newsrc-alist
454 (delq (assoc group gnus-newsrc-alist)
455 gnus-newsrc-alist))
456 (when gnus-group-change-level-function
457 (funcall gnus-group-change-level-function
458 group gnus-level-killed 3)))))
459 (gnus-server-position-point))
461 (defun gnus-server-yank-server ()
462 "Yank the previously killed server."
463 (interactive)
464 (unless gnus-server-killed-servers
465 (error "No killed servers to be yanked"))
466 (let ((alist gnus-server-alist)
467 (server (gnus-server-server-name))
468 (killed (car gnus-server-killed-servers)))
469 (if (not server)
470 (setq gnus-server-alist (nconc gnus-server-alist (list killed)))
471 (if (string= server (caar gnus-server-alist))
472 (push killed gnus-server-alist)
473 (while (and (cdr alist)
474 (not (string= server (caadr alist))))
475 (setq alist (cdr alist)))
476 (if alist
477 (setcdr alist (cons killed (cdr alist)))
478 (setq gnus-server-alist (list killed)))))
479 (gnus-server-update-server (car killed))
480 (setq gnus-server-killed-servers (cdr gnus-server-killed-servers))
481 (gnus-server-position-point)))
483 (defun gnus-server-exit ()
484 "Return to the group buffer."
485 (interactive)
486 (gnus-run-hooks 'gnus-server-exit-hook)
487 (gnus-kill-buffer (current-buffer))
488 (gnus-configure-windows 'group t))
490 (defun gnus-server-list-servers ()
491 "List all available servers."
492 (interactive)
493 (let ((cur (gnus-server-server-name)))
494 (gnus-server-prepare)
495 (if cur (gnus-server-goto-server cur)
496 (goto-char (point-max))
497 (forward-line -1))
498 (gnus-server-position-point)))
500 (defun gnus-server-set-status (method status)
501 "Make METHOD have STATUS."
502 (let ((entry (assoc method gnus-opened-servers)))
503 (if entry
504 (setcar (cdr entry) status)
505 (push (list method status) gnus-opened-servers))))
507 (defun gnus-opened-servers-remove (method)
508 "Remove METHOD from the list of opened servers."
509 (setq gnus-opened-servers (delq (assoc method gnus-opened-servers)
510 gnus-opened-servers)))
512 (defun gnus-server-open-server (server)
513 "Force an open of SERVER."
514 (interactive (list (gnus-server-server-name)))
515 (let ((method (gnus-server-to-method server)))
516 (unless method
517 (error "No such server: %s" server))
518 (gnus-server-set-status method 'ok)
519 (prog1
520 (gnus-open-server method)
521 (gnus-server-update-server server)
522 (gnus-server-position-point))))
524 (defun gnus-server-open-all-servers ()
525 "Open all servers."
526 (interactive)
527 (dolist (server gnus-inserted-opened-servers)
528 (gnus-server-open-server (car server))))
530 (defun gnus-server-close-server (server)
531 "Close SERVER."
532 (interactive (list (gnus-server-server-name)))
533 (let ((method (gnus-server-to-method server)))
534 (unless method
535 (error "No such server: %s" server))
536 (gnus-server-set-status method 'closed)
537 (prog1
538 (gnus-close-server method)
539 (gnus-server-update-server server)
540 (gnus-server-position-point))))
542 (defun gnus-server-offline-server (server)
543 "Set SERVER to offline."
544 (interactive (list (gnus-server-server-name)))
545 (let ((method (gnus-server-to-method server)))
546 (unless method
547 (error "No such server: %s" server))
548 (prog1
549 (gnus-close-server method)
550 (gnus-server-set-status method 'offline)
551 (gnus-server-update-server server)
552 (gnus-server-position-point))))
554 (defun gnus-server-close-all-servers ()
555 "Close all servers."
556 (interactive)
557 (dolist (server gnus-inserted-opened-servers)
558 (gnus-server-close-server (car server)))
559 (dolist (server gnus-server-alist)
560 (gnus-server-close-server (car server))))
562 (defun gnus-server-deny-server (server)
563 "Make sure SERVER will never be attempted opened."
564 (interactive (list (gnus-server-server-name)))
565 (let ((method (gnus-server-to-method server)))
566 (unless method
567 (error "No such server: %s" server))
568 (gnus-server-set-status method 'denied))
569 (gnus-server-update-server server)
570 (gnus-server-position-point)
573 (defun gnus-server-remove-denials ()
574 "Make all denied servers into closed servers."
575 (interactive)
576 (dolist (server gnus-opened-servers)
577 (when (eq (nth 1 server) 'denied)
578 (setcar (nthcdr 1 server) 'closed)))
579 (gnus-server-list-servers))
581 (defun gnus-server-copy-server (from to)
582 "Copy a server definition to a new name."
583 (interactive
584 (list
585 (or (gnus-server-server-name)
586 (error "No server on the current line"))
587 (read-string "Copy to: ")))
588 (unless from
589 (error "No server on current line"))
590 (unless (and to (not (string= to "")))
591 (error "No name to copy to"))
592 (when (assoc to gnus-server-alist)
593 (error "%s already exists" to))
594 (unless (gnus-server-to-method from)
595 (error "%s: no such server" from))
596 (let ((to-entry (cons from (gnus-copy-sequence
597 (gnus-server-to-method from)))))
598 (setcar to-entry to)
599 (setcar (nthcdr 2 to-entry) to)
600 (push to-entry gnus-server-killed-servers)
601 (gnus-server-yank-server)))
603 (defun gnus-server-add-server (how where)
604 (interactive
605 (list (intern (gnus-completing-read "Server method"
606 (mapcar 'car gnus-valid-select-methods)
608 (read-string "Server name: ")))
609 (when (assq where gnus-server-alist)
610 (error "Server with that name already defined"))
611 (push (list where how where) gnus-server-killed-servers)
612 (gnus-server-yank-server))
614 (defun gnus-server-goto-server (server)
615 "Jump to a server line."
616 (interactive
617 (list (gnus-completing-read "Goto server" (mapcar 'car gnus-server-alist) t)))
618 (let ((to (text-property-any (point-min) (point-max)
619 'gnus-server (intern server))))
620 (when to
621 (goto-char to)
622 (gnus-server-position-point))))
624 (defun gnus-server-edit-server (server)
625 "Edit the server on the current line."
626 (interactive (list (gnus-server-server-name)))
627 (unless server
628 (error "No server on current line"))
629 (unless (assoc server gnus-server-alist)
630 (error "This server can't be edited"))
631 (let ((info (cdr (assoc server gnus-server-alist))))
632 (gnus-close-server info)
633 (gnus-edit-form
634 info "Editing the server."
635 `(lambda (form)
636 (gnus-server-set-info ,server form)
637 (gnus-server-list-servers)
638 (gnus-server-position-point))
639 'edit-server)))
641 (defun gnus-server-show-server (server)
642 "Show the definition of the server on the current line."
643 (interactive (list (gnus-server-server-name)))
644 (unless server
645 (error "No server on current line"))
646 (let ((info (gnus-server-to-method server)))
647 (gnus-edit-form
648 info "Showing the server."
649 `(lambda (form)
650 (gnus-server-position-point))
651 'edit-server)))
653 (defun gnus-server-scan-server (server)
654 "Request a scan from the current server."
655 (interactive (list (gnus-server-server-name)))
656 (let ((method (gnus-server-to-method server)))
657 (if (not (gnus-get-function method 'request-scan))
658 (error "Server %s can't scan" (car method))
659 (gnus-message 3 "Scanning %s..." server)
660 (gnus-request-scan nil method)
661 (gnus-message 3 "Scanning %s...done" server))))
663 (defun gnus-server-read-server-in-server-buffer (server)
664 "Browse a server in server buffer."
665 (interactive (list (gnus-server-server-name)))
666 (let (gnus-server-browse-in-group-buffer)
667 (gnus-server-read-server server)))
669 (defun gnus-server-read-server (server)
670 "Browse a server."
671 (interactive (list (gnus-server-server-name)))
672 (let ((buf (current-buffer)))
673 (prog1
674 (gnus-browse-foreign-server server buf)
675 (with-current-buffer buf
676 (gnus-server-update-server (gnus-server-server-name))
677 (gnus-server-position-point)))))
679 (defun gnus-server-pick-server (e)
680 (interactive "e")
681 (mouse-set-point e)
682 (gnus-server-read-server (gnus-server-server-name)))
686 ;;; Browse Server Mode
689 (defvar gnus-browse-menu-hook nil
690 "*Hook run after the creation of the browse mode menu.")
692 (defcustom gnus-browse-subscribe-newsgroup-method
693 'gnus-subscribe-alphabetically
694 "Function(s) called when subscribing groups in the Browse Server Buffer
695 A few pre-made functions are supplied: `gnus-subscribe-randomly'
696 inserts new groups at the beginning of the list of groups;
697 `gnus-subscribe-alphabetically' inserts new groups in strict
698 alphabetic order; `gnus-subscribe-hierarchically' inserts new groups
699 in hierarchical newsgroup order; `gnus-subscribe-interactively' asks
700 for your decision; `gnus-subscribe-killed' kills all new groups;
701 `gnus-subscribe-zombies' will make all new groups into zombies;
702 `gnus-subscribe-topics' will enter groups into the topics that
703 claim them."
704 :version "24.1"
705 :group 'gnus-server
706 :type '(radio (function-item gnus-subscribe-randomly)
707 (function-item gnus-subscribe-alphabetically)
708 (function-item gnus-subscribe-hierarchically)
709 (function-item gnus-subscribe-interactively)
710 (function-item gnus-subscribe-killed)
711 (function-item gnus-subscribe-zombies)
712 (function-item gnus-subscribe-topics)
713 function
714 (repeat function)))
716 (defvar gnus-browse-mode-hook nil)
717 (defvar gnus-browse-mode-map nil)
718 (put 'gnus-browse-mode 'mode-class 'special)
720 (unless gnus-browse-mode-map
721 (setq gnus-browse-mode-map (make-keymap))
722 (suppress-keymap gnus-browse-mode-map)
724 (gnus-define-keys
725 gnus-browse-mode-map
726 " " gnus-browse-read-group
727 "=" gnus-browse-select-group
728 "n" gnus-browse-next-group
729 "p" gnus-browse-prev-group
730 "\177" gnus-browse-prev-group
731 [delete] gnus-browse-prev-group
732 "N" gnus-browse-next-group
733 "P" gnus-browse-prev-group
734 "\M-n" gnus-browse-next-group
735 "\M-p" gnus-browse-prev-group
736 "\r" gnus-browse-select-group
737 "u" gnus-browse-unsubscribe-current-group
738 "l" gnus-browse-exit
739 "L" gnus-browse-exit
740 "q" gnus-browse-exit
741 "Q" gnus-browse-exit
742 "d" gnus-browse-describe-group
743 [delete] gnus-browse-delete-group
744 "\C-c\C-c" gnus-browse-exit
745 "?" gnus-browse-describe-briefly
747 "\C-c\C-i" gnus-info-find-node
748 "\C-c\C-b" gnus-bug))
750 (defun gnus-browse-make-menu-bar ()
751 (gnus-turn-off-edit-menu 'browse)
752 (unless (boundp 'gnus-browse-menu)
753 (easy-menu-define
754 gnus-browse-menu gnus-browse-mode-map ""
755 '("Browse"
756 ["Subscribe" gnus-browse-unsubscribe-current-group t]
757 ["Read" gnus-browse-read-group t]
758 ["Select" gnus-browse-select-group t]
759 ["Describe" gnus-browse-describe-group t]
760 ["Next" gnus-browse-next-group t]
761 ["Prev" gnus-browse-prev-group t]
762 ["Exit" gnus-browse-exit t]))
763 (gnus-run-hooks 'gnus-browse-menu-hook)))
765 (defvar gnus-browse-current-method nil)
766 (defvar gnus-browse-return-buffer nil)
768 (defvar gnus-browse-buffer "*Gnus Browse Server*")
770 (defun gnus-browse-foreign-server (server &optional return-buffer)
771 "Browse the server SERVER."
772 (setq gnus-browse-current-method (gnus-server-to-method server))
773 (setq gnus-browse-return-buffer return-buffer)
774 (let* ((method gnus-browse-current-method)
775 (orig-select-method gnus-select-method)
776 (gnus-select-method method)
777 groups group)
778 (gnus-message 5 "Connecting to %s..." (nth 1 method))
779 (cond
780 ((not (gnus-check-server method))
781 (gnus-message
782 1 "Unable to contact server %s: %s" (nth 1 method)
783 (gnus-status-message method))
784 nil)
785 ((not
786 (prog2
787 (gnus-message 6 "Reading active file...")
788 (gnus-request-list method)
789 (gnus-message 6 "Reading active file...done")))
790 (gnus-message
791 1 "Couldn't request list: %s" (gnus-status-message method))
792 nil)
794 (with-current-buffer nntp-server-buffer
795 (let ((cur (current-buffer)))
796 (goto-char (point-min))
797 (unless (or (null gnus-ignored-newsgroups)
798 (string= gnus-ignored-newsgroups ""))
799 (delete-matching-lines gnus-ignored-newsgroups))
800 ;; We treat NNTP as a special case to avoid problems with
801 ;; garbage group names like `"foo' that appear in some badly
802 ;; managed active files. -jh.
803 (if (eq (car method) 'nntp)
804 (while (not (eobp))
805 (ignore-errors
806 (push (cons
807 (mm-string-as-unibyte
808 (buffer-substring
809 (point)
810 (progn
811 (skip-chars-forward "^ \t")
812 (point))))
813 (let ((last (read cur)))
814 (cons (read cur) last)))
815 groups))
816 (forward-line))
817 (while (not (eobp))
818 (ignore-errors
819 (push (cons
820 (mm-string-as-unibyte
821 (if (eq (char-after) ?\")
822 (read cur)
823 (let ((p (point)) (name ""))
824 (skip-chars-forward "^ \t\\\\")
825 (setq name (buffer-substring p (point)))
826 (while (eq (char-after) ?\\)
827 (setq p (1+ (point)))
828 (forward-char 2)
829 (skip-chars-forward "^ \t\\\\")
830 (setq name (concat name (buffer-substring
831 p (point)))))
832 name)))
833 (let ((last (read cur)))
834 (cons (read cur) last)))
835 groups))
836 (forward-line)))))
837 (setq groups (sort groups
838 (lambda (l1 l2)
839 (string< (car l1) (car l2)))))
840 (if gnus-server-browse-in-group-buffer
841 (let* ((gnus-select-method orig-select-method)
842 (gnus-group-listed-groups
843 (mapcar (lambda (group)
844 (let ((name
845 (gnus-group-prefixed-name
846 (car group) method)))
847 (gnus-set-active name (cdr group))
848 name))
849 groups)))
850 (gnus-configure-windows 'group)
851 (funcall gnus-group-prepare-function
852 gnus-level-killed 'ignore 1 'ignore))
853 (gnus-get-buffer-create gnus-browse-buffer)
854 (gnus-configure-windows 'browse)
855 (buffer-disable-undo)
856 (let ((buffer-read-only nil))
857 (erase-buffer))
858 (gnus-browse-mode)
859 (setq mode-line-buffer-identification
860 (list
861 (format
862 "Gnus: %%b {%s:%s}" (car method) (cadr method))))
863 (let ((buffer-read-only nil)
864 name
865 (prefix (let ((gnus-select-method orig-select-method))
866 (gnus-group-prefixed-name "" method))))
867 (while (setq group (pop groups))
868 (gnus-add-text-properties
869 (point)
870 (prog1 (1+ (point))
871 (insert
872 (format "%c%7d: %s\n"
873 (let ((level
874 (if (string= prefix "")
875 (gnus-group-level (setq name (car group)))
876 (gnus-group-level
877 (concat prefix (setq name (car group)))))))
878 (cond
879 ((<= level gnus-level-subscribed) ? )
880 ((<= level gnus-level-unsubscribed) ?U)
881 ((= level gnus-level-zombie) ?Z)
882 (t ?K)))
883 (max 0 (- (1+ (cddr group)) (cadr group)))
884 ;; Don't decode if name is ASCII
885 (if (and (fboundp 'detect-coding-string)
886 (eq (detect-coding-string name t) 'undecided))
887 name
888 (mm-decode-coding-string
889 name
890 (inline (gnus-group-name-charset method name)))))))
891 (list 'gnus-group name)
893 (switch-to-buffer (current-buffer)))
894 (goto-char (point-min))
895 (gnus-group-position-point)
896 (gnus-message 5 "Connecting to %s...done" (nth 1 method))
897 t))))
899 (define-derived-mode gnus-browse-mode fundamental-mode "Browse Server"
900 "Major mode for browsing a foreign server.
902 All normal editing commands are switched off.
904 \\<gnus-browse-mode-map>
905 The only things you can do in this buffer is
907 1) `\\[gnus-browse-unsubscribe-current-group]' to subscribe to a group.
908 The group will be inserted into the group buffer upon exit from this
909 buffer.
911 2) `\\[gnus-browse-read-group]' to read a group ephemerally.
913 3) `\\[gnus-browse-exit]' to return to the group buffer."
914 (when (gnus-visual-p 'browse-menu 'menu)
915 (gnus-browse-make-menu-bar))
916 (gnus-simplify-mode-line)
917 (setq mode-line-process nil)
918 (buffer-disable-undo)
919 (setq truncate-lines t)
920 (gnus-set-default-directory)
921 (setq buffer-read-only t))
923 (defun gnus-browse-read-group (&optional no-article number)
924 "Enter the group at the current line.
925 If NUMBER, fetch this number of articles."
926 (interactive "P")
927 (let ((group (gnus-browse-group-name)))
928 (if (or (not (gnus-get-info group))
929 (gnus-ephemeral-group-p group))
930 (unless (gnus-group-read-ephemeral-group
931 group gnus-browse-current-method nil
932 (cons (current-buffer) 'browse)
933 nil nil nil number)
934 (error "Couldn't enter %s" group))
935 (unless (gnus-group-read-group nil no-article group)
936 (error "Couldn't enter %s" group)))))
938 (defun gnus-browse-select-group (&optional number)
939 "Select the current group.
940 If NUMBER, fetch this number of articles."
941 (interactive "P")
942 (gnus-browse-read-group 'no number))
944 (defun gnus-browse-next-group (n)
945 "Go to the next group."
946 (interactive "p")
947 (prog1
948 (forward-line n)
949 (gnus-group-position-point)))
951 (defun gnus-browse-prev-group (n)
952 "Go to the next group."
953 (interactive "p")
954 (gnus-browse-next-group (- n)))
956 (defun gnus-browse-unsubscribe-current-group (arg)
957 "(Un)subscribe to the next ARG groups.
958 The variable `gnus-browse-subscribe-newsgroup-method' determines
959 how new groups will be entered into the group buffer."
960 (interactive "p")
961 (when (eobp)
962 (error "No group at current line"))
963 (let ((ward (if (< arg 0) -1 1))
964 (arg (abs arg)))
965 (while (and (> arg 0)
966 (not (eobp))
967 (gnus-browse-unsubscribe-group)
968 (zerop (gnus-browse-next-group ward)))
969 (decf arg))
970 (gnus-group-position-point)
971 (when (/= 0 arg)
972 (gnus-message 7 "No more newsgroups"))
973 arg))
975 (defun gnus-browse-group-name ()
976 (save-excursion
977 (beginning-of-line)
978 (let ((name (get-text-property (point) 'gnus-group)))
979 (when (re-search-forward ": \\(.*\\)$" (point-at-eol) t)
980 (concat (gnus-method-to-server-name gnus-browse-current-method) ":"
981 (or name
982 (match-string-no-properties 1)))))))
984 (defun gnus-browse-describe-group (group)
985 "Describe the current group."
986 (interactive (list (gnus-browse-group-name)))
987 (gnus-group-describe-group nil group))
989 (defun gnus-browse-delete-group (group force)
990 "Delete the current group. Only meaningful with editable groups.
991 If FORCE (the prefix) is non-nil, all the articles in the group will
992 be deleted. This is \"deleted\" as in \"removed forever from the face
993 of the Earth\". There is no undo. The user will be prompted before
994 doing the deletion."
995 (interactive (list (gnus-browse-group-name)
996 current-prefix-arg))
997 (gnus-group-delete-group group force))
999 (defun gnus-browse-unsubscribe-group ()
1000 "Toggle subscription of the current group in the browse buffer."
1001 (let ((sub nil)
1002 (buffer-read-only nil)
1003 group)
1004 (save-excursion
1005 (beginning-of-line)
1006 ;; If this group it killed, then we want to subscribe it.
1007 (unless (eq (char-after) ? )
1008 (setq sub t))
1009 (setq group (gnus-browse-group-name))
1010 (when (gnus-server-equal gnus-browse-current-method "native")
1011 (setq group (gnus-group-real-name group)))
1012 (if sub
1013 (progn
1014 ;; Make sure the group has been properly removed before we
1015 ;; subscribe to it.
1016 (if (gnus-ephemeral-group-p group)
1017 (gnus-kill-ephemeral-group group))
1018 (let ((entry (gnus-group-entry group)))
1019 (if entry
1020 ;; Just change the subscription level if it is an
1021 ;; unsubscribed group.
1022 (gnus-group-change-level entry
1023 gnus-level-default-subscribed)
1024 ;; If it is a killed group or a zombie, feed it to the
1025 ;; mechanism for new group subscription.
1026 (gnus-call-subscribe-functions
1027 gnus-browse-subscribe-newsgroup-method
1028 group)
1029 (gnus-request-update-group-status group 'subscribe)))
1030 (delete-char 1)
1031 (insert (let ((lvl (gnus-group-level group)))
1032 (cond
1033 ((< lvl gnus-level-unsubscribed) ? )
1034 ((< lvl gnus-level-zombie) ?U)
1035 ((< lvl gnus-level-killed) ?Z)
1036 (t ?K)))))
1037 (gnus-group-change-level
1038 group gnus-level-unsubscribed gnus-level-default-subscribed)
1039 (delete-char 1)
1040 (insert ?U)))
1043 (defun gnus-browse-exit ()
1044 "Quit browsing and return to the group buffer."
1045 (interactive)
1046 (when (derived-mode-p 'gnus-browse-mode)
1047 (gnus-kill-buffer (current-buffer)))
1048 ;; Insert the newly subscribed groups in the group buffer.
1049 (with-current-buffer gnus-group-buffer
1050 (gnus-group-list-groups nil))
1051 (if gnus-browse-return-buffer
1052 (gnus-configure-windows 'server 'force)
1053 (gnus-configure-windows 'group 'force)))
1055 (defun gnus-browse-describe-briefly ()
1056 "Give a one line description of the group mode commands."
1057 (interactive)
1058 (gnus-message 6 "%s"
1059 (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")))
1061 (defun gnus-server-regenerate-server ()
1062 "Issue a command to the server to regenerate all its data structures."
1063 (interactive)
1064 (let ((server (gnus-server-server-name)))
1065 (unless server
1066 (error "No server on the current line"))
1067 (condition-case ()
1068 (gnus-get-function (gnus-server-to-method server)
1069 'request-regenerate)
1070 (error
1071 (error "This back end doesn't support regeneration")))
1072 (gnus-message 5 "Requesting regeneration of %s..." server)
1073 (unless (gnus-open-server server)
1074 (error "Couldn't open server"))
1075 (if (gnus-request-regenerate server)
1076 (gnus-message 5 "Requesting regeneration of %s...done" server)
1077 (gnus-message 5 "Couldn't regenerate %s" server))))
1081 ;;; Server compaction. -- dvl
1084 ;; #### FIXME: this function currently fails to update the Group buffer's
1085 ;; #### appearance.
1086 (defun gnus-server-compact-server ()
1087 "Issue a command to the server to compact all its groups.
1089 Note: currently only implemented in nnml."
1090 (interactive)
1091 (let ((server (gnus-server-server-name)))
1092 (unless server
1093 (error "No server on the current line"))
1094 (condition-case ()
1095 (gnus-get-function (gnus-server-to-method server)
1096 'request-compact)
1097 (error
1098 (error "This back end doesn't support compaction")))
1099 (gnus-message 5 "\
1100 Requesting compaction of %s... (this may take a long time)"
1101 server)
1102 (unless (gnus-open-server server)
1103 (error "Couldn't open server"))
1104 (if (not (gnus-request-compact server))
1105 (gnus-message 5 "Couldn't compact %s" server)
1106 (gnus-message 5 "Requesting compaction of %s...done" server)
1107 ;; Invalidate the original article buffer which might be out of date.
1108 ;; #### NOTE: Yes, this might be a bit rude, but since compaction
1109 ;; #### will not happen very often, I think this is acceptable.
1110 (let ((original (get-buffer gnus-original-article-buffer)))
1111 (and original (gnus-kill-buffer original))))))
1113 (defun gnus-server-toggle-cloud-server ()
1114 "Make the server under point be replicated in the Emacs Cloud."
1115 (interactive)
1116 (let ((server (gnus-server-server-name)))
1117 (unless server
1118 (error "No server on the current line"))
1120 (unless (gnus-method-option-p server 'cloud)
1121 (error "The server under point doesn't support cloudiness"))
1123 (if (gnus-cloud-server-p server)
1124 (setq gnus-cloud-covered-servers
1125 (delete server gnus-cloud-covered-servers))
1126 (push server gnus-cloud-covered-servers))
1128 (gnus-server-update-server server)
1129 (gnus-message 1 (if (gnus-cloud-server-p server)
1130 "Replication of %s in the cloud will start"
1131 "Replication of %s in the cloud will stop")
1132 server)))
1134 (provide 'gnus-srvr)
1136 ;;; gnus-srvr.el ends here