Mercurial > emacs
annotate lisp/gnus/nnoo.el @ 44598:0384805eb2d3
.
author | Andreas Schwab <schwab@suse.de> |
---|---|
date | Mon, 15 Apr 2002 13:13:44 +0000 |
parents | a26d9b55abb6 |
children | 695cf19ef79e d7ddb3e565de |
rev | line source |
---|---|
17493 | 1 ;;; nnoo.el --- OO Gnus Backends |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
2 |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000 |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
4 ;; Free Software Foundation, Inc. |
17493 | 5 |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> |
17493 | 7 ;; Keywords: news |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
13 ;; the Free Software Foundation; either version 2, or (at your option) | |
14 ;; any later version. | |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
25 | |
26 ;;; Commentary: | |
27 | |
28 ;;; Code: | |
29 | |
30 (require 'nnheader) | |
19494
4280cff25537
Require cl only at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
31 (eval-when-compile (require 'cl)) |
17493 | 32 |
33 (defvar nnoo-definition-alist nil) | |
34 (defvar nnoo-state-alist nil) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
35 (defvar nnoo-parent-backend nil) |
17493 | 36 |
37 (defmacro defvoo (var init &optional doc &rest map) | |
38 "The same as `defvar', only takes list of variables to MAP to." | |
39 `(prog1 | |
40 ,(if doc | |
41 `(defvar ,var ,init ,doc) | |
42 `(defvar ,var ,init)) | |
43 (nnoo-define ',var ',map))) | |
44 (put 'defvoo 'lisp-indent-function 2) | |
45 (put 'defvoo 'edebug-form-spec '(var init &optional doc &rest map)) | |
46 | |
47 (defmacro deffoo (func args &rest forms) | |
48 "The same as `defun', only register FUNC." | |
49 `(prog1 | |
50 (defun ,func ,args ,@forms) | |
51 (nnoo-register-function ',func))) | |
52 (put 'deffoo 'lisp-indent-function 2) | |
53 (put 'deffoo 'edebug-form-spec '(&define name lambda-list def-body)) | |
54 | |
55 (defun nnoo-register-function (func) | |
56 (let ((funcs (nthcdr 3 (assoc (nnoo-backend func) | |
57 nnoo-definition-alist)))) | |
58 (unless funcs | |
59 (error "%s belongs to a backend that hasn't been declared" func)) | |
60 (setcar funcs (cons func (car funcs))))) | |
61 | |
62 (defmacro nnoo-declare (backend &rest parents) | |
63 `(eval-and-compile | |
64 (push (list ',backend | |
65 (mapcar (lambda (p) (list p)) ',parents) | |
66 nil nil) | |
67 nnoo-definition-alist) | |
68 (push (list ',backend "*internal-non-initialized-backend*") | |
69 nnoo-state-alist))) | |
70 (put 'nnoo-declare 'lisp-indent-function 1) | |
71 | |
72 (defun nnoo-parents (backend) | |
73 (nth 1 (assoc backend nnoo-definition-alist))) | |
74 | |
75 (defun nnoo-variables (backend) | |
76 (nth 2 (assoc backend nnoo-definition-alist))) | |
77 | |
78 (defun nnoo-functions (backend) | |
79 (nth 3 (assoc backend nnoo-definition-alist))) | |
80 | |
81 (defmacro nnoo-import (backend &rest imports) | |
82 `(nnoo-import-1 ',backend ',imports)) | |
83 (put 'nnoo-import 'lisp-indent-function 1) | |
84 | |
85 (defun nnoo-import-1 (backend imports) | |
86 (let ((call-function | |
87 (if (symbolp (car imports)) (pop imports) 'nnoo-parent-function)) | |
88 imp functions function) | |
89 (while (setq imp (pop imports)) | |
90 (setq functions | |
91 (or (cdr imp) | |
92 (nnoo-functions (car imp)))) | |
93 (while functions | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
94 (unless (fboundp |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
95 (setq function |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
96 (nnoo-symbol backend |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
97 (nnoo-rest-symbol (car functions))))) |
17493 | 98 (eval `(deffoo ,function (&rest args) |
99 (,call-function ',backend ',(car functions) args)))) | |
100 (pop functions))))) | |
101 | |
102 (defun nnoo-parent-function (backend function args) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
103 (let ((pbackend (nnoo-backend function)) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
104 (nnoo-parent-backend backend)) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
105 (nnoo-change-server pbackend |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
106 (nnoo-current-server backend) |
17493 | 107 (cdr (assq pbackend (nnoo-parents backend)))) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
108 (prog1 |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
109 (apply function args) |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
110 ;; Copy the changed variables back into the child. |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
111 (let ((vars (cdr (assq pbackend (nnoo-parents backend))))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
112 (while vars |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
113 (set (cadar vars) (symbol-value (caar vars))) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
114 (setq vars (cdr vars))))))) |
17493 | 115 |
116 (defun nnoo-execute (backend function &rest args) | |
117 "Execute FUNCTION on behalf of BACKEND." | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
118 (let ((pbackend (nnoo-backend function)) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
119 (nnoo-parent-backend backend)) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
120 (nnoo-change-server pbackend |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
121 (nnoo-current-server backend) |
17493 | 122 (cdr (assq pbackend (nnoo-parents backend)))) |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
123 (prog1 |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
124 (apply function args) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
125 ;; Copy the changed variables back into the child. |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
126 (let ((vars (cdr (assq pbackend (nnoo-parents backend))))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
127 (while vars |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
128 (set (cadar vars) (symbol-value (caar vars))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
129 (setq vars (cdr vars))))))) |
17493 | 130 |
131 (defmacro nnoo-map-functions (backend &rest maps) | |
132 `(nnoo-map-functions-1 ',backend ',maps)) | |
133 (put 'nnoo-map-functions 'lisp-indent-function 1) | |
134 | |
135 (defun nnoo-map-functions-1 (backend maps) | |
136 (let (m margs i) | |
137 (while (setq m (pop maps)) | |
138 (setq i 0 | |
139 margs nil) | |
140 (while (< i (length (cdr m))) | |
141 (if (numberp (nth i (cdr m))) | |
142 (push `(nth ,i args) margs) | |
143 (push (nth i (cdr m)) margs)) | |
144 (incf i)) | |
145 (eval `(deffoo ,(nnoo-symbol backend (nnoo-rest-symbol (car m))) | |
146 (&rest args) | |
147 (nnoo-parent-function ',backend ',(car m) | |
148 ,(cons 'list (nreverse margs)))))))) | |
149 | |
150 (defun nnoo-backend (symbol) | |
151 (string-match "^[^-]+-" (symbol-name symbol)) | |
152 (intern (substring (symbol-name symbol) 0 (1- (match-end 0))))) | |
153 | |
154 (defun nnoo-rest-symbol (symbol) | |
155 (string-match "^[^-]+-" (symbol-name symbol)) | |
156 (intern (substring (symbol-name symbol) (match-end 0)))) | |
157 | |
158 (defun nnoo-symbol (backend symbol) | |
159 (intern (format "%s-%s" backend symbol))) | |
160 | |
161 (defun nnoo-define (var map) | |
162 (let* ((backend (nnoo-backend var)) | |
163 (def (assq backend nnoo-definition-alist)) | |
164 (parents (nth 1 def))) | |
165 (unless def | |
19969
5f1ab3dd344d
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19494
diff
changeset
|
166 (error "%s belongs to a backend that hasn't been declared" var)) |
17493 | 167 (setcar (nthcdr 2 def) |
168 (delq (assq var (nth 2 def)) (nth 2 def))) | |
169 (setcar (nthcdr 2 def) | |
170 (cons (cons var (symbol-value var)) | |
171 (nth 2 def))) | |
172 (while map | |
173 (nconc (assq (nnoo-backend (car map)) parents) | |
174 (list (list (pop map) var)))))) | |
175 | |
176 (defun nnoo-change-server (backend server defs) | |
177 (let* ((bstate (cdr (assq backend nnoo-state-alist))) | |
178 (current (car bstate)) | |
179 (parents (nnoo-parents backend)) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
180 (server (if nnoo-parent-backend |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
181 (format "%s+%s" nnoo-parent-backend server) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
182 server)) |
17493 | 183 (bvariables (nnoo-variables backend)) |
184 state def) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
185 ;; If we don't have a current state, we push an empty state |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
186 ;; onto the alist. |
17493 | 187 (unless bstate |
188 (push (setq bstate (list backend nil)) | |
189 nnoo-state-alist) | |
190 (pop bstate)) | |
191 (if (equal server current) | |
192 t | |
193 (nnoo-push-server backend current) | |
194 (setq state (or (cdr (assoc server (cddr bstate))) | |
195 (nnoo-variables backend))) | |
196 (while state | |
197 (set (caar state) (cdar state)) | |
198 (pop state)) | |
199 (setcar bstate server) | |
200 (unless (cdr (assoc server (cddr bstate))) | |
201 (while (setq def (pop defs)) | |
202 (unless (assq (car def) bvariables) | |
203 (nconc bvariables | |
204 (list (cons (car def) (and (boundp (car def)) | |
205 (symbol-value (car def))))))) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
206 (if (equal server "*internal-non-initialized-backend*") |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
207 (set (car def) (symbol-value (cadr def))) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
208 (set (car def) (cadr def))))) |
17493 | 209 (while parents |
210 (nnoo-change-server | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
211 (caar parents) (format "%s+%s" backend server) |
17493 | 212 (mapcar (lambda (def) (list (car def) (symbol-value (cadr def)))) |
213 (cdar parents))) | |
214 (pop parents)))) | |
215 t) | |
216 | |
217 (defun nnoo-push-server (backend current) | |
218 (let ((bstate (assq backend nnoo-state-alist)) | |
219 (defs (nnoo-variables backend))) | |
220 ;; Remove the old definition. | |
221 (setcdr (cdr bstate) (delq (assoc current (cddr bstate)) (cddr bstate))) | |
222 ;; If this is the first time we push the server (i. e., this is | |
223 ;; the nil server), then we update the default values of | |
224 ;; all the variables to reflect the current values. | |
225 (when (equal current "*internal-non-initialized-backend*") | |
226 (let ((defaults (nnoo-variables backend)) | |
227 def) | |
228 (while (setq def (pop defaults)) | |
229 (setcdr def (symbol-value (car def)))))) | |
230 (let (state) | |
231 (while defs | |
232 (push (cons (caar defs) (symbol-value (caar defs))) | |
233 state) | |
234 (pop defs)) | |
235 (nconc bstate (list (cons current state)))))) | |
236 | |
237 (defsubst nnoo-current-server-p (backend server) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
238 (equal (nnoo-current-server backend) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
239 (if nnoo-parent-backend |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
240 (format "%s+%s" nnoo-parent-backend server) |
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19969
diff
changeset
|
241 server))) |
17493 | 242 |
243 (defun nnoo-current-server (backend) | |
244 (nth 1 (assq backend nnoo-state-alist))) | |
245 | |
246 (defun nnoo-close-server (backend &optional server) | |
247 (unless server | |
248 (setq server (nnoo-current-server backend))) | |
249 (when server | |
250 (let* ((bstate (cdr (assq backend nnoo-state-alist))) | |
251 (defs (assoc server (cdr bstate)))) | |
252 (when bstate | |
253 (setcar bstate nil) | |
254 (setcdr bstate (delq defs (cdr bstate))) | |
255 (pop defs) | |
256 (while defs | |
257 (set (car (pop defs)) nil))))) | |
258 t) | |
259 | |
260 (defun nnoo-close (backend) | |
261 (setq nnoo-state-alist | |
262 (delq (assq backend nnoo-state-alist) | |
263 nnoo-state-alist)) | |
264 t) | |
265 | |
266 (defun nnoo-status-message (backend server) | |
267 (nnheader-get-report backend)) | |
268 | |
269 (defun nnoo-server-opened (backend server) | |
270 (and (nnoo-current-server-p backend server) | |
271 nntp-server-buffer | |
272 (buffer-name nntp-server-buffer))) | |
273 | |
274 (defmacro nnoo-define-basics (backend) | |
275 "Define `close-server', `server-opened' and `status-message'." | |
276 `(eval-and-compile | |
277 (nnoo-define-basics-1 ',backend))) | |
278 | |
279 (defun nnoo-define-basics-1 (backend) | |
280 (let ((functions '(close-server server-opened status-message))) | |
281 (while functions | |
282 (eval `(deffoo ,(nnoo-symbol backend (car functions)) | |
283 (&optional server) | |
284 (,(nnoo-symbol 'nnoo (pop functions)) ',backend server))))) | |
285 (eval `(deffoo ,(nnoo-symbol backend 'open-server) | |
286 (server &optional defs) | |
287 (nnoo-change-server ',backend server defs)))) | |
288 | |
289 (defmacro nnoo-define-skeleton (backend) | |
290 "Define all required backend functions for BACKEND. | |
291 All functions will return nil and report an error." | |
292 `(eval-and-compile | |
293 (nnoo-define-skeleton-1 ',backend))) | |
294 | |
295 (defun nnoo-define-skeleton-1 (backend) | |
296 (let ((functions '(retrieve-headers | |
297 request-close request-article | |
298 request-group close-group | |
299 request-list request-post request-list-newsgroups)) | |
300 function fun) | |
301 (while (setq function (pop functions)) | |
302 (when (not (fboundp (setq fun (nnoo-symbol backend function)))) | |
303 (eval `(deffoo ,fun | |
304 (&rest args) | |
305 (nnheader-report ',backend ,(format "%s-%s not implemented" | |
306 backend function)))))))) | |
307 (provide 'nnoo) | |
308 | |
38413
a26d9b55abb6
Some fixes to follow coding conventions in files from Gnus.
Pavel Janík <Pavel@Janik.cz>
parents:
31716
diff
changeset
|
309 ;;; nnoo.el ends here |