Mercurial > hg > xemacs-beta
diff lisp/gnus/gnus-srvr.el @ 70:131b0175ea99 r20-0b30
Import from CVS: tag r20-0b30
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:02:59 +0200 |
parents | 8b8b7f3559a2 |
children | 0d2f883870bc |
line wrap: on
line diff
--- a/lisp/gnus/gnus-srvr.el Mon Aug 13 09:00:04 2007 +0200 +++ b/lisp/gnus/gnus-srvr.el Mon Aug 13 09:02:59 2007 +0200 @@ -1,5 +1,5 @@ ;;; gnus-srvr.el --- virtual server support for Gnus -;; Copyright (C) 1995,96,97 Free Software Foundation, Inc. +;; Copyright (C) 1995,96 Free Software Foundation, Inc. ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no> ;; Keywords: news @@ -26,10 +26,7 @@ ;;; Code: (require 'gnus) -(require 'gnus-spec) -(require 'gnus-group) -(require 'gnus-int) -(require 'gnus-range) +(eval-when-compile (require 'cl)) (defvar gnus-server-mode-hook nil "Hook run in `gnus-server-mode' buffers.") @@ -55,7 +52,7 @@ (?w where ?s) (?s status ?s))) -(defvar gnus-server-mode-line-format-alist +(defvar gnus-server-mode-line-format-alist `((?S news-server ?s) (?M news-method ?s) (?u user-defined ?s))) @@ -70,21 +67,20 @@ "*Hook run after the creation of the server mode menu.") (defun gnus-server-make-menu-bar () - (gnus-turn-off-edit-menu 'server) + (gnus-visual-turn-off-edit-menu 'server) (unless (boundp 'gnus-server-server-menu) (easy-menu-define gnus-server-server-menu gnus-server-mode-map "" '("Server" ["Add" gnus-server-add-server t] ["Browse" gnus-server-read-server t] - ["Scan" gnus-server-scan-server t] ["List" gnus-server-list-servers t] ["Kill" gnus-server-kill-server t] ["Yank" gnus-server-yank-server t] ["Copy" gnus-server-copy-server t] ["Edit" gnus-server-edit-server t] - ["Regenerate" gnus-server-regenerate-server t] - ["Exit" gnus-server-exit t])) + ["Exit" gnus-server-exit t] + )) (easy-menu-define gnus-server-connections-menu gnus-server-mode-map "" @@ -92,10 +88,8 @@ ["Open" gnus-server-open-server t] ["Close" gnus-server-close-server t] ["Deny" gnus-server-deny-server t] - "---" - ["Open All" gnus-server-open-all-servers t] - ["Close All" gnus-server-close-all-servers t] - ["Reset All" gnus-server-remove-denials t])) + ["Reset" gnus-server-remove-denials t] + )) (run-hooks 'gnus-server-menu-hook))) @@ -118,39 +112,34 @@ "c" gnus-server-copy-server "a" gnus-server-add-server "e" gnus-server-edit-server - "s" gnus-server-scan-server "O" gnus-server-open-server - "\M-o" gnus-server-open-all-servers "C" gnus-server-close-server - "\M-c" gnus-server-close-all-servers "D" gnus-server-deny-server "R" gnus-server-remove-denials - "g" gnus-server-regenerate-server - - "\C-c\C-i" gnus-info-find-node - "\C-c\C-b" gnus-bug)) + "\C-c\C-i" gnus-info-find-node)) (defun gnus-server-mode () "Major mode for listing and editing servers. All normal editing commands are switched off. \\<gnus-server-mode-map> -For more in-depth information on this mode, read the manual -(`\\[gnus-info-find-node]'). +For more in-depth information on this mode, read the manual +(`\\[gnus-info-find-node]'). The following commands are available: \\{gnus-server-mode-map}" (interactive) - (when (gnus-visual-p 'server-menu 'menu) + (when (and menu-bar-mode + (gnus-visual-p 'server-menu 'menu)) (gnus-server-make-menu-bar)) (kill-all-local-variables) (gnus-simplify-mode-line) (setq major-mode 'gnus-server-mode) (setq mode-name "Server") - (gnus-set-default-directory) + ; (gnus-group-set-mode-line) (setq mode-line-process nil) (use-local-map gnus-server-mode-map) (buffer-disable-undo (current-buffer)) @@ -189,15 +178,15 @@ (save-excursion (set-buffer (get-buffer-create gnus-server-buffer)) (gnus-server-mode) - (when gnus-carpal + (when gnus-carpal (gnus-carpal-setup-buffer 'server))))) (defun gnus-server-prepare () - (setq gnus-server-mode-line-format-spec - (gnus-parse-format gnus-server-mode-line-format + (setq gnus-server-mode-line-format-spec + (gnus-parse-format gnus-server-mode-line-format gnus-server-mode-line-format-alist)) - (setq gnus-server-line-format-spec - (gnus-parse-format gnus-server-line-format + (setq gnus-server-line-format-spec + (gnus-parse-format gnus-server-line-format gnus-server-line-format-alist t)) (let ((alist gnus-server-alist) (buffer-read-only nil) @@ -207,19 +196,14 @@ (setq gnus-inserted-opened-servers nil) ;; First we do the real list of servers. (while alist - (unless (member (cdar alist) done) - (push (cdar alist) done) - (cdr (setq server (pop alist))) - (when (and server (car server) (cdr server)) - (gnus-server-insert-server-line (car server) (cdr server)))) - (when (member (cdar alist) done) - (pop alist))) + (push (cdr (setq server (pop alist))) done) + (when (and server (car server) (cdr server)) + (gnus-server-insert-server-line (car server) (cdr server)))) ;; Then we insert the list of servers that have been opened in ;; this session. - (while opened + (while opened (unless (member (caar opened) done) - (push (caar opened) done) - (gnus-server-insert-server-line + (gnus-server-insert-server-line (setq op-ser (format "%s:%s" (caaar opened) (nth 1 (caar opened)))) (caar opened)) (push (list op-ser (caar opened)) gnus-inserted-opened-servers)) @@ -243,9 +227,9 @@ (oentry (assoc (gnus-server-to-method server) gnus-opened-servers))) (when entry - (gnus-dribble-enter + (gnus-dribble-enter (concat "(gnus-server-set-info \"" server "\" '" - (prin1-to-string (cdr entry)) ")\n"))) + (prin1-to-string (cdr entry)) ")"))) (when (or entry oentry) ;; Buffer may be narrowed. (save-restriction @@ -254,7 +238,7 @@ (gnus-delete-line)) (if entry (gnus-server-insert-server-line (car entry) (cdr entry)) - (gnus-server-insert-server-line + (gnus-server-insert-server-line (format "%s:%s" (caar oentry) (nth 1 (car oentry))) (car oentry))) (gnus-server-position-point)))))) @@ -262,7 +246,7 @@ (defun gnus-server-set-info (server info) ;; Enter a select method into the virtual server alist. (when (and server info) - (gnus-dribble-enter + (gnus-dribble-enter (concat "(gnus-server-set-info \"" server "\" '" (prin1-to-string info) ")")) (let* ((server (nth 1 info)) @@ -284,7 +268,8 @@ (gnus-dribble-enter "") (let ((buffer-read-only nil)) (gnus-delete-line)) - (push (assoc server gnus-server-alist) gnus-server-killed-servers) + (setq gnus-server-killed-servers + (cons (assoc server gnus-server-alist) gnus-server-killed-servers)) (setq gnus-server-alist (delq (car gnus-server-killed-servers) gnus-server-alist)) (gnus-server-position-point)) @@ -292,15 +277,15 @@ (defun gnus-server-yank-server () "Yank the previously killed server." (interactive) - (unless gnus-server-killed-servers - (error "No killed servers to be yanked")) + (or gnus-server-killed-servers + (error "No killed servers to be yanked")) (let ((alist gnus-server-alist) (server (gnus-server-server-name)) (killed (car gnus-server-killed-servers))) - (if (not server) + (if (not server) (setq gnus-server-alist (nconc gnus-server-alist (list killed))) (if (string= server (caar gnus-server-alist)) - (push killed gnus-server-alist) + (setq gnus-server-alist (cons killed gnus-server-alist)) (while (and (cdr alist) (not (string= server (caadr alist)))) (setq alist (cdr alist))) @@ -344,8 +329,7 @@ "Force an open of SERVER." (interactive (list (gnus-server-server-name))) (let ((method (gnus-server-to-method server))) - (unless method - (error "No such server: %s" server)) + (or method (error "No such server: %s" server)) (gnus-server-set-status method 'ok) (prog1 (or (gnus-open-server method) @@ -353,38 +337,22 @@ (gnus-server-update-server server) (gnus-server-position-point)))) -(defun gnus-server-open-all-servers () - "Open all servers." - (interactive) - (let ((servers gnus-inserted-opened-servers)) - (while servers - (gnus-server-open-server (car (pop servers)))))) - (defun gnus-server-close-server (server) "Close SERVER." (interactive (list (gnus-server-server-name))) (let ((method (gnus-server-to-method server))) - (unless method - (error "No such server: %s" server)) + (or method (error "No such server: %s" server)) (gnus-server-set-status method 'closed) (prog1 (gnus-close-server method) (gnus-server-update-server server) (gnus-server-position-point)))) -(defun gnus-server-close-all-servers () - "Close all servers." - (interactive) - (let ((servers gnus-inserted-opened-servers)) - (while servers - (gnus-server-close-server (car (pop servers)))))) - (defun gnus-server-deny-server (server) "Make sure SERVER will never be attempted opened." (interactive (list (gnus-server-server-name))) (let ((method (gnus-server-to-method server))) - (unless method - (error "No such server: %s" server)) + (or method (error "No such server: %s" server)) (gnus-server-set-status method 'denied)) (gnus-server-update-server server) (gnus-server-position-point) @@ -406,40 +374,37 @@ (or (gnus-server-server-name) (error "No server on the current line")) (read-string "Copy to: "))) - (unless from - (error "No server on current line")) - (unless (and to (not (string= to ""))) - (error "No name to copy to")) - (when (assoc to gnus-server-alist) - (error "%s already exists" to)) - (unless (gnus-server-to-method from) - (error "%s: no such server" from)) - (let ((to-entry (cons from (gnus-copy-sequence - (gnus-server-to-method from))))) + (or from (error "No server on current line")) + (or (and to (not (string= to ""))) (error "No name to copy to")) + (and (assoc to gnus-server-alist) (error "%s already exists" to)) + (or (assoc from gnus-server-alist) + (error "%s: no such server" from)) + (let ((to-entry (gnus-copy-sequence (assoc from gnus-server-alist)))) (setcar to-entry to) (setcar (nthcdr 2 to-entry) to) - (push to-entry gnus-server-killed-servers) + (setq gnus-server-killed-servers + (cons to-entry gnus-server-killed-servers)) (gnus-server-yank-server))) (defun gnus-server-add-server (how where) - (interactive + (interactive (list (intern (completing-read "Server method: " gnus-valid-select-methods nil t)) (read-string "Server name: "))) - (when (assq where gnus-server-alist) - (error "Server with that name already defined")) - (push (list where how where) gnus-server-killed-servers) + (setq gnus-server-killed-servers + (cons (list where how where) gnus-server-killed-servers)) (gnus-server-yank-server)) (defun gnus-server-goto-server (server) "Jump to a server line." (interactive (list (completing-read "Goto server: " gnus-server-alist nil t))) - (let ((to (text-property-any (point-min) (point-max) + (let ((to (text-property-any (point-min) (point-max) 'gnus-server (intern server)))) - (when to - (goto-char to) - (gnus-server-position-point)))) + (and to + (progn + (goto-char to) + (gnus-server-position-point))))) (defun gnus-server-edit-server (server) "Edit the server on the current line." @@ -448,21 +413,39 @@ (error "No server on current line")) (unless (assoc server gnus-server-alist) (error "This server can't be edited")) - (let ((info (cdr (assoc server gnus-server-alist)))) + (let ((winconf (current-window-configuration)) + (info (cdr (assoc server gnus-server-alist)))) (gnus-close-server info) - (gnus-edit-form - info "Editing the server." - `(lambda (form) - (gnus-server-set-info ,server form) - (gnus-server-list-servers) - (gnus-server-position-point))))) + (get-buffer-create gnus-server-edit-buffer) + (gnus-configure-windows 'edit-server) + (gnus-add-current-to-buffer-list) + (emacs-lisp-mode) + (make-local-variable 'gnus-prev-winconf) + (setq gnus-prev-winconf winconf) + (use-local-map (copy-keymap (current-local-map))) + (let ((done-func '(lambda () + "Exit editing mode and update the information." + (interactive) + (gnus-server-edit-server-done 'group)))) + (setcar (cdr (nth 4 done-func)) server) + (local-set-key "\C-c\C-c" done-func)) + (erase-buffer) + (insert ";; Type `C-c C-c' after you have edited the server.\n\n") + (insert (pp-to-string info)))) -(defun gnus-server-scan-server (server) - "Request a scan from the current server." - (interactive (list (gnus-server-server-name))) - (gnus-message 3 "Scanning %s...done" server) - (gnus-request-scan nil (gnus-server-to-method server)) - (gnus-message 3 "Scanning %s...done" server)) +(defun gnus-server-edit-server-done (server) + (interactive) + (set-buffer (get-buffer-create gnus-server-edit-buffer)) + (goto-char (point-min)) + (let ((form (read (current-buffer))) + (winconf gnus-prev-winconf)) + (gnus-server-set-info server form) + (kill-buffer (current-buffer)) + (and winconf (set-window-configuration winconf)) + (set-buffer gnus-server-buffer) + (gnus-server-update-server server) + (gnus-server-list-servers) + (gnus-server-position-point))) (defun gnus-server-read-server (server) "Browse a server." @@ -474,7 +457,7 @@ (set-buffer buf) (gnus-server-update-server (gnus-server-server-name)) (gnus-server-position-point))))) - + (defun gnus-server-pick-server (e) (interactive "e") (mouse-set-point e) @@ -516,22 +499,24 @@ "\C-c\C-c" gnus-browse-exit "?" gnus-browse-describe-briefly - "\C-c\C-i" gnus-info-find-node - "\C-c\C-b" gnus-bug)) + "\C-c\C-i" gnus-info-find-node)) (defun gnus-browse-make-menu-bar () - (gnus-turn-off-edit-menu 'browse) - (unless (boundp 'gnus-browse-menu) - (easy-menu-define - gnus-browse-menu gnus-browse-mode-map "" - '("Browse" - ["Subscribe" gnus-browse-unsubscribe-current-group t] - ["Read" gnus-browse-read-group t] - ["Select" gnus-browse-read-group t] - ["Next" gnus-browse-next-group t] - ["Prev" gnus-browse-next-group t] - ["Exit" gnus-browse-exit t])) - (run-hooks 'gnus-browse-menu-hook))) + (gnus-visual-turn-off-edit-menu 'browse) + (or + (boundp 'gnus-browse-menu) + (progn + (easy-menu-define + gnus-browse-menu gnus-browse-mode-map "" + '("Browse" + ["Subscribe" gnus-browse-unsubscribe-current-group t] + ["Read" gnus-browse-read-group t] + ["Select" gnus-browse-read-group t] + ["Next" gnus-browse-next-group t] + ["Prev" gnus-browse-next-group t] + ["Exit" gnus-browse-exit t] + )) + (run-hooks 'gnus-browse-menu-hook)))) (defvar gnus-browse-current-method nil) (defvar gnus-browse-return-buffer nil) @@ -542,8 +527,6 @@ "Browse the server METHOD." (setq gnus-browse-current-method method) (setq gnus-browse-return-buffer return-buffer) - (when (stringp method) - (setq method (gnus-server-to-method method))) (let ((gnus-select-method method) groups group) (gnus-message 5 "Connecting to %s..." (nth 1 method)) @@ -552,19 +535,14 @@ (gnus-message 1 "Unable to contact server: %s" (gnus-status-message method)) nil) - ((not - (prog2 - (gnus-message 6 "Reading active file...") - (gnus-request-list method) - (gnus-message 6 "Reading active file...done"))) + ((not (gnus-request-list method)) (gnus-message 1 "Couldn't request list: %s" (gnus-status-message method)) nil) (t (get-buffer-create gnus-browse-buffer) (gnus-add-current-to-buffer-list) - (when gnus-carpal - (gnus-carpal-setup-buffer 'browse)) + (and gnus-carpal (gnus-carpal-setup-buffer 'browse)) (gnus-configure-windows 'browse) (buffer-disable-undo (current-buffer)) (let ((buffer-read-only nil)) @@ -578,14 +556,14 @@ (set-buffer nntp-server-buffer) (let ((cur (current-buffer))) (goto-char (point-min)) - (unless (string= gnus-ignored-newsgroups "") - (delete-matching-lines gnus-ignored-newsgroups)) + (or (string= gnus-ignored-newsgroups "") + (delete-matching-lines gnus-ignored-newsgroups)) (while (re-search-forward "\\(^[^ \t]+\\)[ \t]+[0-9]+[ \t]+[0-9]+" nil t) (goto-char (match-end 1)) - (push (cons (match-string 1) - (max 0 (- (1+ (read cur)) (read cur)))) - groups)))) + (setq groups (cons (cons (match-string 1) + (max 0 (- (1+ (read cur)) (read cur)))) + groups))))) (setq groups (sort groups (lambda (l1 l2) (string< (car l1) (car l2))))) @@ -618,7 +596,8 @@ 3) `\\[gnus-browse-exit]' to return to the group buffer." (interactive) (kill-all-local-variables) - (when (gnus-visual-p 'browse-menu 'menu) + (when (and menu-bar-mode + (gnus-visual-p 'browse-menu 'menu)) (gnus-browse-make-menu-bar)) (gnus-simplify-mode-line) (setq major-mode 'gnus-browse-mode) @@ -627,18 +606,17 @@ (use-local-map gnus-browse-mode-map) (buffer-disable-undo (current-buffer)) (setq truncate-lines t) - (gnus-set-default-directory) (setq buffer-read-only t) (run-hooks 'gnus-browse-mode-hook)) (defun gnus-browse-read-group (&optional no-article) "Enter the group at the current line." (interactive) - (let ((group (gnus-group-real-name (gnus-browse-group-name)))) - (unless (gnus-group-read-ephemeral-group - group gnus-browse-current-method nil - (cons (current-buffer) 'browse)) - (error "Couldn't enter %s" group)))) + (let ((group (gnus-browse-group-name))) + (or (gnus-group-read-ephemeral-group + group gnus-browse-current-method nil + (cons (current-buffer) 'browse)) + (error "Couldn't enter %s" group)))) (defun gnus-browse-select-group () "Select the current group." @@ -670,8 +648,7 @@ (zerop (gnus-browse-next-group ward))) (decf arg)) (gnus-group-position-point) - (when (/= 0 arg) - (gnus-message 7 "No more newsgroups")) + (if (/= 0 arg) (gnus-message 7 "No more newsgroups")) arg)) (defun gnus-browse-group-name () @@ -688,12 +665,8 @@ (save-excursion (beginning-of-line) ;; If this group it killed, then we want to subscribe it. - (when (= (following-char) ?K) - (setq sub t)) + (if (= (following-char) ?K) (setq sub t)) (setq group (gnus-browse-group-name)) - ;; Make sure the group has been properly removed before we - ;; subscribe to it. - (gnus-kill-ephemeral-group group) (delete-char 1) (if sub (progn @@ -730,20 +703,6 @@ (gnus-message 6 (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"))) -(defun gnus-server-regenerate-server () - "Issue a command to the server to regenerate all its data structures." - (interactive) - (let ((server (gnus-server-server-name))) - (unless server - (error "No server on the current line")) - (if (not (gnus-check-backend-function - 'request-regenerate (car (gnus-server-to-method server)))) - (error "This backend doesn't support regeneration") - (gnus-message 5 "Requesting regeneration of %s..." server) - (if (gnus-request-regenerate server) - (gnus-message 5 "Requesting regeneration of %s...done" server) - (gnus-message 5 "Couldn't regenerate %s" server))))) - (provide 'gnus-srvr) ;;; gnus-srvr.el ends here.