Mercurial > emacs
annotate lisp/net/eudc.el @ 42597:255b72a74a90
*** empty log message ***
author | Jaeyoun Chung <jay@kldp.org> |
---|---|
date | Mon, 07 Jan 2002 07:36:15 +0000 |
parents | 24c994803548 |
children | cd8db5bd4819 |
rev | line source |
---|---|
27313 | 1 ;;; eudc.el --- Emacs Unified Directory Client |
2 | |
3 ;; Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. | |
4 | |
5 ;; Author: Oscar Figueiredo <oscar@xemacs.org> | |
6 ;; Maintainer: Oscar Figueiredo <oscar@xemacs.org> | |
42575
24c994803548
(top-level): Revert previous change.
Pavel Janík <Pavel@Janik.cz>
parents:
42569
diff
changeset
|
7 ;; Keywords: comm |
27313 | 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 ;; This package provides a common interface to query directory servers using | |
28 ;; different protocols such as LDAP, CCSO PH/QI or BBDB. Queries can be | |
29 ;; made through an interactive form or inline. Inline query strings in | |
30 ;; buffers are expanded with appropriately formatted query results | |
31 ;; (especially used to expand email addresses in message buffers). EUDC | |
32 ;; also interfaces with the BBDB package to let you register query results | |
33 ;; into your own BBDB database. | |
34 | |
35 ;;; Usage: | |
36 ;; EUDC comes with an extensive documentation, please refer to it. | |
37 ;; | |
38 ;; The main entry points of EUDC are: | |
39 ;; `eudc-query-form': Query a directory server from a query form | |
40 ;; `eudc-expand-inline': Query a directory server for the e-mail address | |
41 ;; of the name before cursor and insert it in the | |
42 ;; buffer | |
43 ;; `eudc-get-phone': Get a phone number from a directory server | |
44 ;; `eudc-get-email': Get an e-mail address from a directory server | |
45 ;; `eudc-customize': Customize various aspects of EUDC | |
46 | |
47 ;;; Code: | |
48 | |
49 (require 'wid-edit) | |
50 | |
51 (eval-and-compile | |
52 (if (not (fboundp 'make-overlay)) | |
53 (require 'overlay)) | |
54 (if (not (fboundp 'unless)) | |
55 (require 'cl))) | |
56 | |
57 (unless (fboundp 'custom-menu-create) | |
58 (autoload 'custom-menu-create "cus-edit")) | |
59 | |
60 (require 'eudc-vars) | |
61 | |
62 | |
63 | |
64 ;;{{{ Internal cooking | |
65 | |
66 ;;{{{ Internal variables and compatibility tricks | |
67 | |
68 (defconst eudc-xemacs-p (string-match "XEmacs" emacs-version)) | |
69 (defconst eudc-emacs-p (not eudc-xemacs-p)) | |
70 (defconst eudc-xemacs-mule-p (and eudc-xemacs-p | |
71 (featurep 'mule))) | |
72 (defconst eudc-emacs-mule-p (and eudc-emacs-p | |
73 (featurep 'mule))) | |
74 | |
75 (defvar eudc-form-widget-list nil) | |
76 (defvar eudc-mode-map nil) | |
77 ;; Used by the selection insertion mechanism | |
78 (defvar eudc-pre-select-window-configuration nil) | |
79 (defvar eudc-insertion-marker nil) | |
80 | |
81 ;; List of known servers | |
82 ;; Alist of (SERVER . PROTOCOL) | |
83 (defvar eudc-server-hotlist nil) | |
84 | |
85 ;; List of variables that have server- or protocol-local bindings | |
86 (defvar eudc-local-vars nil) | |
87 | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
88 ;; Protocol local. Query function |
27313 | 89 (defvar eudc-query-function nil) |
90 | |
91 ;; Protocol local. A function that retrieves a list of valid attribute names | |
92 (defvar eudc-list-attributes-function nil) | |
93 | |
94 ;; Protocol local. A mapping between EUDC attribute names and corresponding | |
95 ;; protocol specific names. The following names are defined by EUDC and may be | |
96 ;; included in that list: `name' , `firstname', `email', `phone' | |
97 (defvar eudc-protocol-attributes-translation-alist nil) | |
98 | |
99 ;; Protocol local. Mapping between protocol attribute names and BBDB field | |
100 ;; names | |
101 (defvar eudc-bbdb-conversion-alist nil) | |
102 | |
103 ;; Protocol/Server local. Hook called upon switching to that server | |
104 (defvar eudc-switch-to-server-hook nil) | |
105 | |
106 ;; Protocol/Server local. Hook called upon switching from that server | |
107 (defvar eudc-switch-from-server-hook nil) | |
108 | |
109 ;; Protocol local. Whether the protocol supports queries with no specified | |
110 ;; attribute name | |
111 (defvar eudc-protocol-has-default-query-attributes nil) | |
112 | |
113 (defun eudc-cadr (obj) | |
114 (car (cdr obj))) | |
115 | |
116 (defun eudc-cdar (obj) | |
117 (cdr (car obj))) | |
118 | |
119 (defun eudc-caar (obj) | |
120 (car (car obj))) | |
121 | |
122 (defun eudc-cdaar (obj) | |
123 (cdr (car (car obj)))) | |
124 | |
125 (defun eudc-plist-member (plist prop) | |
126 "Return t if PROP has a value specified in PLIST." | |
127 (if (not (= 0 (% (length plist) 2))) | |
128 (error "Malformed plist")) | |
129 (catch 'found | |
130 (while plist | |
131 (if (eq prop (car plist)) | |
132 (throw 'found t)) | |
133 (setq plist (cdr (cdr plist)))) | |
134 nil)) | |
135 | |
136 ;; Emacs' plist-get lacks third parameter | |
137 (defun eudc-plist-get (plist prop &optional default) | |
138 "Extract a value from a property list. | |
139 PLIST is a property list, which is a list of the form | |
140 (PROP1 VALUE1 PROP2 VALUE2...). This function returns the value | |
141 corresponding to the given PROP, or DEFAULT if PROP is not | |
142 one of the properties on the list." | |
143 (if (eudc-plist-member plist prop) | |
144 (plist-get plist prop) | |
145 default)) | |
146 | |
147 (defun eudc-lax-plist-get (plist prop &optional default) | |
148 "Extract a value from a lax property list. | |
149 | |
150 PLIST is a lax property list, which is a list of the form (PROP1 | |
151 VALUE1 PROP2 VALUE2...), where comparisons between properties are done | |
152 using `equal' instead of `eq'. This function returns the value | |
153 corresponding to PROP, or DEFAULT if PROP is not one of the | |
154 properties on the list." | |
155 (if (not (= 0 (% (length plist) 2))) | |
156 (error "Malformed plist")) | |
157 (catch 'found | |
158 (while plist | |
159 (if (equal prop (car plist)) | |
160 (throw 'found (car (cdr plist)))) | |
161 (setq plist (cdr (cdr plist)))) | |
162 default)) | |
163 | |
164 (if (not (fboundp 'split-string)) | |
165 (defun split-string (string &optional pattern) | |
166 "Return a list of substrings of STRING which are separated by PATTERN. | |
167 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"." | |
168 (or pattern | |
169 (setq pattern "[ \f\t\n\r\v]+")) | |
170 (let (parts (start 0)) | |
171 (when (string-match pattern string 0) | |
172 (if (> (match-beginning 0) 0) | |
173 (setq parts (cons (substring string 0 (match-beginning 0)) nil))) | |
174 (setq start (match-end 0)) | |
175 (while (and (string-match pattern string start) | |
176 (> (match-end 0) start)) | |
177 (setq parts (cons (substring string start (match-beginning 0)) parts) | |
178 start (match-end 0)))) | |
179 (nreverse (if (< start (length string)) | |
180 (cons (substring string start) parts) | |
181 parts))))) | |
182 | |
183 (defun eudc-replace-in-string (str regexp newtext) | |
184 "Replace all matches in STR for REGEXP with NEWTEXT. | |
185 Value is the new string." | |
186 (let ((rtn-str "") | |
187 (start 0) | |
188 match prev-start) | |
189 (while (setq match (string-match regexp str start)) | |
190 (setq prev-start start | |
191 start (match-end 0) | |
192 rtn-str | |
193 (concat rtn-str | |
194 (substring str prev-start match) | |
195 newtext))) | |
196 (concat rtn-str (substring str start)))) | |
197 | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
198 ;;}}} |
27313 | 199 |
200 ;;{{{ Server and Protocol Variable Routines | |
201 | |
202 (defun eudc-server-local-variable-p (var) | |
203 "Return non-nil if VAR has server-local bindings." | |
204 (eudc-plist-member (get var 'eudc-locals) 'server)) | |
205 | |
206 (defun eudc-protocol-local-variable-p (var) | |
207 "Return non-nil if VAR has protocol-local bindings." | |
208 (eudc-plist-member (get var 'eudc-locals) 'protocol)) | |
209 | |
210 (defun eudc-default-set (var val) | |
211 "Set the EUDC default value of VAR to VAL. | |
212 The current binding of VAR is not changed." | |
213 (put var 'eudc-locals | |
214 (plist-put (get var 'eudc-locals) 'default val)) | |
215 (add-to-list 'eudc-local-vars var)) | |
216 | |
217 (defun eudc-protocol-set (var val &optional protocol) | |
218 "Set the PROTOCOL-local binding of VAR to VAL. | |
219 If omitted PROTOCOL defaults to the current value of `eudc-protocol'. | |
220 The current binding of VAR is changed only if PROTOCOL is omitted." | |
221 (if (eq 'unbound (eudc-variable-default-value var)) | |
222 (eudc-default-set var (symbol-value var))) | |
223 (let* ((eudc-locals (get var 'eudc-locals)) | |
224 (protocol-locals (eudc-plist-get eudc-locals 'protocol))) | |
225 (setq protocol-locals (plist-put protocol-locals (or protocol | |
226 eudc-protocol) val)) | |
227 (setq eudc-locals | |
228 (plist-put eudc-locals 'protocol protocol-locals)) | |
229 (put var 'eudc-locals eudc-locals) | |
230 (add-to-list 'eudc-local-vars var) | |
231 (unless protocol | |
232 (eudc-update-variable var)))) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
233 |
27313 | 234 (defun eudc-server-set (var val &optional server) |
235 "Set the SERVER-local binding of VAR to VAL. | |
236 If omitted SERVER defaults to the current value of `eudc-server'. | |
237 The current binding of VAR is changed only if SERVER is omitted." | |
238 (if (eq 'unbound (eudc-variable-default-value var)) | |
239 (eudc-default-set var (symbol-value var))) | |
240 (let* ((eudc-locals (get var 'eudc-locals)) | |
241 (server-locals (eudc-plist-get eudc-locals 'server))) | |
242 (setq server-locals (plist-put server-locals (or server | |
243 eudc-server) val)) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
244 (setq eudc-locals |
27313 | 245 (plist-put eudc-locals 'server server-locals)) |
246 (put var 'eudc-locals eudc-locals) | |
247 (add-to-list 'eudc-local-vars var) | |
248 (unless server | |
249 (eudc-update-variable var)))) | |
250 | |
251 | |
252 (defun eudc-set (var val) | |
253 "Set the most local (server, protocol or default) binding of VAR to VAL. | |
254 The current binding of VAR is also set to VAL" | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
255 (cond |
27313 | 256 ((not (eq 'unbound (eudc-variable-server-value var))) |
257 (eudc-server-set var val)) | |
258 ((not (eq 'unbound (eudc-variable-protocol-value var))) | |
259 (eudc-protocol-set var val)) | |
260 (t | |
261 (eudc-default-set var val))) | |
262 (set var val)) | |
263 | |
264 (defun eudc-variable-default-value (var) | |
265 "Return the default binding of VAR. | |
266 Return `unbound' if VAR has no EUDC default value." | |
267 (let ((eudc-locals (get var 'eudc-locals))) | |
268 (if (and (boundp var) | |
269 eudc-locals) | |
270 (eudc-plist-get eudc-locals 'default 'unbound) | |
271 'unbound))) | |
272 | |
273 (defun eudc-variable-protocol-value (var &optional protocol) | |
274 "Return the value of VAR local to PROTOCOL. | |
275 Return `unbound' if VAR has no value local to PROTOCOL. | |
276 PROTOCOL defaults to `eudc-protocol'" | |
277 (let* ((eudc-locals (get var 'eudc-locals)) | |
278 protocol-locals) | |
279 (if (not (and (boundp var) | |
280 eudc-locals | |
281 (eudc-plist-member eudc-locals 'protocol))) | |
282 'unbound | |
283 (setq protocol-locals (eudc-plist-get eudc-locals 'protocol)) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
284 (eudc-lax-plist-get protocol-locals |
27313 | 285 (or protocol |
286 eudc-protocol) 'unbound)))) | |
287 | |
288 (defun eudc-variable-server-value (var &optional server) | |
289 "Return the value of VAR local to SERVER. | |
290 Return `unbound' if VAR has no value local to SERVER. | |
291 SERVER defaults to `eudc-server'" | |
292 (let* ((eudc-locals (get var 'eudc-locals)) | |
293 server-locals) | |
294 (if (not (and (boundp var) | |
295 eudc-locals | |
296 (eudc-plist-member eudc-locals 'server))) | |
297 'unbound | |
298 (setq server-locals (eudc-plist-get eudc-locals 'server)) | |
299 (eudc-lax-plist-get server-locals | |
300 (or server | |
301 eudc-server) 'unbound)))) | |
302 | |
303 (defun eudc-update-variable (var) | |
304 "Set the value of VAR according to its locals. | |
305 If the VAR has a server- or protocol-local value corresponding | |
306 to the current `eudc-server' and `eudc-protocol' then it is set | |
307 accordingly. Otherwise it is set to its EUDC default binding" | |
308 (let (val) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
309 (cond |
27313 | 310 ((not (eq 'unbound (setq val (eudc-variable-server-value var)))) |
311 (set var val)) | |
312 ((not (eq 'unbound (setq val (eudc-variable-protocol-value var)))) | |
313 (set var val)) | |
314 ((not (eq 'unbound (setq val (eudc-variable-default-value var)))) | |
315 (set var val))))) | |
316 | |
317 (defun eudc-update-local-variables () | |
318 "Update all EUDC variables according to their local settings." | |
319 (interactive) | |
320 (mapcar 'eudc-update-variable eudc-local-vars)) | |
321 | |
322 (eudc-default-set 'eudc-query-function nil) | |
323 (eudc-default-set 'eudc-list-attributes-function nil) | |
324 (eudc-default-set 'eudc-protocol-attributes-translation-alist nil) | |
325 (eudc-default-set 'eudc-bbdb-conversion-alist nil) | |
326 (eudc-default-set 'eudc-switch-to-server-hook nil) | |
327 (eudc-default-set 'eudc-switch-from-server-hook nil) | |
328 (eudc-default-set 'eudc-protocol-has-default-query-attributes nil) | |
329 (eudc-default-set 'eudc-attribute-display-method-alist nil) | |
330 | |
331 ;;}}} | |
332 | |
333 | |
334 ;; Add PROTOCOL to the list of supported protocols | |
335 (defun eudc-register-protocol (protocol) | |
336 (unless (memq protocol eudc-supported-protocols) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
337 (setq eudc-supported-protocols |
27313 | 338 (cons protocol eudc-supported-protocols)) |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
339 (put 'eudc-protocol 'custom-type |
27313 | 340 `(choice :menu-tag "Protocol" |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
341 ,@(mapcar (lambda (s) |
27313 | 342 (list 'string ':tag (symbol-name s))) |
343 eudc-supported-protocols)))) | |
344 (or (memq protocol eudc-known-protocols) | |
345 (setq eudc-known-protocols | |
346 (cons protocol eudc-known-protocols)))) | |
347 | |
348 | |
349 (defun eudc-translate-query (query) | |
350 "Translate attribute names of QUERY. | |
351 The translation is done according to | |
352 `eudc-protocol-attributes-translation-alist'." | |
353 (if eudc-protocol-attributes-translation-alist | |
354 (mapcar '(lambda (attribute) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
355 (let ((trans (assq (car attribute) |
27313 | 356 (symbol-value eudc-protocol-attributes-translation-alist)))) |
357 (if trans | |
358 (cons (cdr trans) (cdr attribute)) | |
359 attribute))) | |
360 query) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
361 query)) |
27313 | 362 |
363 (defun eudc-translate-attribute-list (list) | |
364 "Translate a list of attribute names LIST. | |
365 The translation is done according to | |
366 `eudc-protocol-attributes-translation-alist'." | |
367 (if eudc-protocol-attributes-translation-alist | |
368 (let (trans) | |
369 (mapcar '(lambda (attribute) | |
370 (setq trans (assq attribute | |
371 (symbol-value eudc-protocol-attributes-translation-alist))) | |
372 (if trans | |
373 (cdr trans) | |
374 attribute)) | |
375 list)) | |
376 list)) | |
377 | |
378 (defun eudc-select (choices) | |
379 "Choose one from CHOICES using a completion buffer." | |
380 (setq eudc-pre-select-window-configuration (current-window-configuration)) | |
381 (setq eudc-insertion-marker (point-marker)) | |
382 (with-output-to-temp-buffer "*EUDC Completions*" | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
383 (apply 'display-completion-list |
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
384 choices |
27313 | 385 (if eudc-xemacs-p |
386 '(:activate-callback eudc-insert-selected))))) | |
387 | |
388 (defun eudc-insert-selected (event extent user) | |
389 "Insert a completion at the appropriate point." | |
390 (when eudc-insertion-marker | |
391 (set-buffer (marker-buffer eudc-insertion-marker)) | |
392 (goto-char eudc-insertion-marker) | |
393 (insert (extent-string extent))) | |
394 (if eudc-pre-select-window-configuration | |
395 (set-window-configuration eudc-pre-select-window-configuration)) | |
396 (setq eudc-pre-select-window-configuration nil | |
397 eudc-insertion-marker nil)) | |
398 | |
399 (defun eudc-query (query &optional return-attributes no-translation) | |
400 "Query the current directory server with QUERY. | |
401 QUERY is a list of cons cells (ATTR . VALUE) where ATTR is an attribute | |
402 name and VALUE the corresponding value. | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
403 If NO-TRANSLATION is non-nil, ATTR is translated according to |
27313 | 404 `eudc-protocol-attributes-translation-alist'. |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
405 RETURN-ATTRIBUTES is a list of attributes to return defaulting to |
27313 | 406 `eudc-default-return-attributes'." |
407 (unless eudc-query-function | |
408 (error "Don't know how to perform the query")) | |
409 (if no-translation | |
410 (funcall eudc-query-function query (or return-attributes | |
411 eudc-default-return-attributes)) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
412 |
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
413 (funcall eudc-query-function |
27313 | 414 (eudc-translate-query query) |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
415 (cond |
27313 | 416 (return-attributes |
417 (eudc-translate-attribute-list return-attributes)) | |
418 ((listp eudc-default-return-attributes) | |
419 (eudc-translate-attribute-list eudc-default-return-attributes)) | |
420 (t | |
421 eudc-default-return-attributes))))) | |
422 | |
423 (defun eudc-format-attribute-name-for-display (attribute) | |
424 "Format a directory attribute name for display. | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
425 ATTRIBUTE is looked up in `eudc-user-attribute-names-alist' and replaced |
27313 | 426 by the corresponding user name if any. Otherwise it is capitalized and |
427 underscore characters are replaced by spaces." | |
428 (let ((match (assq attribute eudc-user-attribute-names-alist))) | |
429 (if match | |
430 (cdr match) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
431 (capitalize |
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
432 (mapconcat 'identity |
27313 | 433 (split-string (symbol-name attribute) "_") |
434 " "))))) | |
435 | |
436 (defun eudc-print-attribute-value (field) | |
437 "Insert the value of the directory FIELD at point. | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
438 The directory attribute name in car of FIELD is looked up in |
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
439 `eudc-attribute-display-method-alist' and the corresponding method, |
27313 | 440 if any, is called to print the value in cdr of FIELD." |
441 (let ((match (assoc (downcase (car field)) | |
442 eudc-attribute-display-method-alist)) | |
443 (col (current-column)) | |
444 (val (cdr field))) | |
445 (if match | |
446 (progn | |
447 (eval (list (cdr match) val)) | |
448 (insert "\n")) | |
449 (mapcar | |
450 (function | |
451 (lambda (val-elem) | |
452 (indent-to col) | |
453 (insert val-elem "\n"))) | |
454 (cond | |
455 ((listp val) val) | |
456 ((stringp val) (split-string val "\n")) | |
457 ((null val) '("")) | |
458 (t (list val))))))) | |
459 | |
460 (defun eudc-print-record-field (field column-width) | |
461 "Print the record field FIELD. | |
462 FIELD is a list (ATTR VALUE1 VALUE2 ...) or cons-cell (ATTR . VAL) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
463 COLUMN-WIDTH is the width of the first display column containing the |
27313 | 464 attribute name ATTR." |
465 (let ((field-beg (point))) | |
466 ;; The record field that is passed to this function has already been processed | |
467 ;; by `eudc-format-attribute-name-for-display' so we don't need to call it | |
468 ;; again to display the attribute name | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
469 (insert (format (concat "%" (int-to-string column-width) "s: ") |
27313 | 470 (car field))) |
471 (put-text-property field-beg (point) 'face 'bold) | |
472 (indent-to (+ 2 column-width)) | |
473 (eudc-print-attribute-value field))) | |
474 | |
475 (defun eudc-display-records (records &optional raw-attr-names) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
476 "Display the record list RECORDS in a formatted buffer. |
27313 | 477 If RAW-ATTR-NAMES is non-nil, the raw attribute names are displayed |
478 otherwise they are formatted according to `eudc-user-attribute-names-alist'." | |
479 (let ((buffer (get-buffer-create "*Directory Query Results*")) | |
480 inhibit-read-only | |
481 precords | |
482 (width 0) | |
483 beg | |
484 first-record | |
485 attribute-name) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
486 (switch-to-buffer buffer) |
27313 | 487 (setq buffer-read-only t) |
488 (setq inhibit-read-only t) | |
489 (erase-buffer) | |
490 (insert "Directory Query Result\n") | |
491 (insert "======================\n\n\n") | |
492 (if (null records) | |
493 (insert "No match found.\n" | |
494 (if eudc-strict-return-matches | |
495 "Try setting `eudc-strict-return-matches' to nil or change `eudc-default-return-attributes'.\n" | |
496 "")) | |
497 ;; Replace field names with user names, compute max width | |
498 (setq precords | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
499 (mapcar |
27313 | 500 (function |
501 (lambda (record) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
502 (mapcar |
27313 | 503 (function |
504 (lambda (field) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
505 (setq attribute-name |
27313 | 506 (if raw-attr-names |
507 (symbol-name (car field)) | |
508 (eudc-format-attribute-name-for-display (car field)))) | |
509 (if (> (length attribute-name) width) | |
510 (setq width (length attribute-name))) | |
511 (cons attribute-name (cdr field)))) | |
512 record))) | |
513 records)) | |
514 ;; Display the records | |
515 (setq first-record (point)) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
516 (mapcar |
27313 | 517 (function |
518 (lambda (record) | |
519 (setq beg (point)) | |
520 ;; Map over the record fields to print the attribute/value pairs | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
521 (mapcar (function |
27313 | 522 (lambda (field) |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
523 (eudc-print-record-field field width))) |
27313 | 524 record) |
525 ;; Store the record internal format in some convenient place | |
526 (overlay-put (make-overlay beg (point)) | |
527 'eudc-record | |
528 (car records)) | |
529 (setq records (cdr records)) | |
530 (insert "\n"))) | |
531 precords)) | |
532 (insert "\n") | |
533 (widget-create 'push-button | |
534 :notify (lambda (&rest ignore) | |
535 (eudc-query-form)) | |
536 "New query") | |
537 (widget-insert " ") | |
538 (widget-create 'push-button | |
539 :notify (lambda (&rest ignore) | |
540 (kill-this-buffer)) | |
541 "Quit") | |
542 (eudc-mode) | |
543 (widget-setup) | |
544 (if first-record | |
545 (goto-char first-record)))) | |
546 | |
547 (defun eudc-process-form () | |
548 "Process the query form in current buffer and display the results." | |
549 (let (query-alist | |
550 value) | |
551 (if (not (and (boundp 'eudc-form-widget-list) | |
552 eudc-form-widget-list)) | |
553 (error "Not in a directory query form buffer") | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
554 (mapcar (function |
27313 | 555 (lambda (wid-field) |
556 (setq value (widget-value (cdr wid-field))) | |
557 (if (not (string= value "")) | |
558 (setq query-alist (cons (cons (car wid-field) value) | |
559 query-alist))))) | |
560 eudc-form-widget-list) | |
561 (kill-buffer (current-buffer)) | |
562 (eudc-display-records (eudc-query query-alist) eudc-use-raw-directory-names)))) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
563 |
27313 | 564 |
565 (defun eudc-filter-duplicate-attributes (record) | |
566 "Filter RECORD according to `eudc-duplicate-attribute-handling-method'." | |
567 (let ((rec record) | |
568 unique | |
569 duplicates | |
570 result) | |
571 | |
572 ;; Search for multiple records | |
573 (while (and rec | |
574 (not (listp (eudc-cdar rec)))) | |
575 (setq rec (cdr rec))) | |
576 | |
577 (if (null (eudc-cdar rec)) | |
578 (list record) ; No duplicate attrs in this record | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
579 (mapcar (function |
27313 | 580 (lambda (field) |
581 (if (listp (cdr field)) | |
582 (setq duplicates (cons field duplicates)) | |
583 (setq unique (cons field unique))))) | |
584 record) | |
585 (setq result (list unique)) | |
586 ;; Map over the record fields that have multiple values | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
587 (mapcar |
27313 | 588 (function |
589 (lambda (field) | |
590 (let ((method (if (consp eudc-duplicate-attribute-handling-method) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
591 (cdr |
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
592 (assq |
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
593 (or |
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
594 (car |
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
595 (rassq |
27313 | 596 (car field) |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
597 (symbol-value |
27313 | 598 eudc-protocol-attributes-translation-alist))) |
599 (car field)) | |
600 eudc-duplicate-attribute-handling-method)) | |
601 eudc-duplicate-attribute-handling-method))) | |
602 (cond | |
603 ((or (null method) (eq 'list method)) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
604 (setq result |
27313 | 605 (eudc-add-field-to-records field result))) |
606 ((eq 'first method) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
607 (setq result |
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
608 (eudc-add-field-to-records (cons (car field) |
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
609 (eudc-cadr field)) |
27313 | 610 result))) |
611 ((eq 'concat method) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
612 (setq result |
27313 | 613 (eudc-add-field-to-records (cons (car field) |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
614 (mapconcat |
27313 | 615 'identity |
616 (cdr field) | |
617 "\n")) result))) | |
618 ((eq 'duplicate method) | |
619 (setq result | |
620 (eudc-distribute-field-on-records field result))))))) | |
621 duplicates) | |
622 result))) | |
623 | |
624 (defun eudc-filter-partial-records (records attrs) | |
42575
24c994803548
(top-level): Revert previous change.
Pavel Janík <Pavel@Janik.cz>
parents:
42569
diff
changeset
|
625 "Eliminate records that do not contain all ATTRS from RECORDS." |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
626 (delq nil |
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
627 (mapcar |
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
628 (function |
27313 | 629 (lambda (rec) |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
630 (if (eval (cons 'and |
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
631 (mapcar |
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
632 (function |
27313 | 633 (lambda (attr) |
634 (consp (assq attr rec)))) | |
635 attrs))) | |
636 rec))) | |
637 records))) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
638 |
27313 | 639 (defun eudc-add-field-to-records (field records) |
640 "Add FIELD to each individual record in RECORDS and return the resulting list." | |
641 (mapcar (function | |
642 (lambda (r) | |
643 (cons field r))) | |
644 records)) | |
645 | |
646 (defun eudc-distribute-field-on-records (field records) | |
647 "Duplicate each individual record in RECORDS according to value of FIELD. | |
648 Each copy is added a new field containing one of the values of FIELD." | |
649 (let (result | |
650 (values (cdr field))) | |
651 ;; Uniquify values first | |
652 (while values | |
653 (setcdr values (delete (car values) (cdr values))) | |
654 (setq values (cdr values))) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
655 (mapcar |
27313 | 656 (function |
657 (lambda (value) | |
658 (let ((result-list (copy-sequence records))) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
659 (setq result-list (eudc-add-field-to-records |
27313 | 660 (cons (car field) value) |
661 result-list)) | |
662 (setq result (append result-list result)) | |
663 ))) | |
664 (cdr field)) | |
665 result)) | |
666 | |
667 | |
668 (defun eudc-mode () | |
669 "Major mode used in buffers displaying the results of directory queries. | |
670 There is no sense in calling this command from a buffer other than | |
671 one containing the results of a directory query. | |
672 | |
673 These are the special commands of EUDC mode: | |
674 q -- Kill this buffer. | |
675 f -- Display a form to query the current directory server. | |
676 n -- Move to next record. | |
677 p -- Move to previous record. | |
678 b -- Insert record at point into the BBDB database." | |
679 (interactive) | |
680 (kill-all-local-variables) | |
681 (setq major-mode 'eudc-mode) | |
682 (setq mode-name "EUDC") | |
683 (use-local-map eudc-mode-map) | |
684 (if eudc-emacs-p | |
685 (easy-menu-define eudc-emacs-menu eudc-mode-map "" (eudc-menu)) | |
686 (setq mode-popup-menu (eudc-menu))) | |
687 (run-hooks 'eudc-mode-hook) | |
688 ) | |
689 | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
690 ;;}}} |
27313 | 691 |
692 ;;{{{ High-level interfaces (interactive functions) | |
693 | |
694 (defun eudc-customize () | |
695 "Customize the EUDC package." | |
696 (interactive) | |
697 (customize-group 'eudc)) | |
698 | |
699 ;;;###autoload | |
700 (defun eudc-set-server (server protocol &optional no-save) | |
701 "Set the directory server to SERVER using PROTOCOL. | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
702 Unless NO-SAVE is non-nil, the server is saved as the default |
27313 | 703 server for future sessions." |
704 (interactive (list | |
705 (read-from-minibuffer "Directory Server: ") | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
706 (intern (completing-read "Protocol: " |
27313 | 707 (mapcar '(lambda (elt) |
708 (cons (symbol-name elt) | |
709 elt)) | |
710 eudc-known-protocols))))) | |
711 (unless (or (member protocol | |
712 eudc-supported-protocols) | |
713 (load (concat "eudcb-" (symbol-name protocol)) t)) | |
714 (error "Unsupported protocol: %s" protocol)) | |
715 (run-hooks 'eudc-switch-from-server-hook) | |
716 (setq eudc-protocol protocol) | |
717 (setq eudc-server server) | |
718 (eudc-update-local-variables) | |
719 (run-hooks 'eudc-switch-to-server-hook) | |
720 (if (interactive-p) | |
721 (message "Current directory server is now %s (%s)" eudc-server eudc-protocol)) | |
722 (if (null no-save) | |
723 (eudc-save-options))) | |
724 | |
725 ;;;###autoload | |
726 (defun eudc-get-email (name) | |
727 "Get the email field of NAME from the directory server." | |
728 (interactive "sName: ") | |
729 (or eudc-server | |
730 (call-interactively 'eudc-set-server)) | |
731 (let ((result (eudc-query (list (cons 'name name)) '(email))) | |
732 email) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
733 (if (null (cdr result)) |
27313 | 734 (setq email (eudc-cdaar result)) |
735 (error "Multiple match. Use the query form")) | |
736 (if (interactive-p) | |
737 (if email | |
738 (message "%s" email) | |
739 (error "No record matching %s" name))) | |
740 email)) | |
741 | |
742 ;;;###autoload | |
743 (defun eudc-get-phone (name) | |
744 "Get the phone field of NAME from the directory server." | |
745 (interactive "sName: ") | |
746 (or eudc-server | |
747 (call-interactively 'eudc-set-server)) | |
748 (let ((result (eudc-query (list (cons 'name name)) '(phone))) | |
749 phone) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
750 (if (null (cdr result)) |
27313 | 751 (setq phone (eudc-cdaar result)) |
752 (error "Multiple match. Use the query form")) | |
753 (if (interactive-p) | |
754 (if phone | |
755 (message "%s" phone) | |
756 (error "No record matching %s" name))) | |
757 phone)) | |
758 | |
759 (defun eudc-get-attribute-list () | |
760 "Return a list of valid attributes for the current server. | |
761 When called interactively the list is formatted in a dedicated buffer | |
762 otherwise a list of symbols is returned." | |
763 (interactive) | |
764 (if eudc-list-attributes-function | |
765 (let ((entries (funcall eudc-list-attributes-function (interactive-p)))) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
766 (if entries |
27313 | 767 (if (interactive-p) |
768 (eudc-display-records entries t) | |
769 entries))) | |
770 (error "The %s protocol has no support for listing attributes" eudc-protocol))) | |
771 | |
772 (defun eudc-format-query (words format) | |
773 "Use FORMAT to build a EUDC query from WORDS." | |
774 (let (query | |
775 query-alist | |
776 key val cell) | |
777 (if format | |
778 (progn | |
779 (while (and words format) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
780 (setq query-alist (cons (cons (car format) (car words)) |
27313 | 781 query-alist)) |
782 (setq words (cdr words) | |
783 format (cdr format))) | |
784 ;; If the same attribute appears more than once, merge | |
785 ;; the corresponding values | |
786 (setq query-alist (nreverse query-alist)) | |
787 (while query-alist | |
788 (setq key (eudc-caar query-alist) | |
789 val (eudc-cdar query-alist) | |
790 cell (assq key query)) | |
791 (if cell | |
792 (setcdr cell (concat (cdr cell) " " val)) | |
793 (setq query (cons (car query-alist) query))) | |
794 (setq query-alist (cdr query-alist))) | |
795 query) | |
796 (if eudc-protocol-has-default-query-attributes | |
797 (mapconcat 'identity words " ") | |
798 (list (cons 'name (mapconcat 'identity words " "))))))) | |
799 | |
800 (defun eudc-extract-n-word-formats (format-list n) | |
801 "Extract a list of N-long formats from FORMAT-LIST. | |
802 If none try N - 1 and so forth." | |
803 (let (formats) | |
804 (while (and (null formats) | |
805 (> n 0)) | |
806 (setq formats | |
807 (delq nil | |
808 (mapcar '(lambda (format) | |
809 (if (= n | |
810 (length format)) | |
811 format | |
812 nil)) | |
813 format-list))) | |
814 (setq n (1- n))) | |
815 formats)) | |
816 | |
817 | |
818 ;;;###autoload | |
819 (defun eudc-expand-inline (&optional replace) | |
820 "Query the directory server, and expand the query string before point. | |
821 The query string consists of the buffer substring from the point back to | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
822 the preceding comma, colon or beginning of line. |
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
823 The variable `eudc-inline-query-format' controls how to associate the |
27313 | 824 individual inline query words with directory attribute names. |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
825 After querying the server for the given string, the expansion specified by |
27313 | 826 `eudc-inline-expansion-format' is inserted in the buffer at point. |
827 If REPLACE is non nil, then this expansion replaces the name in the buffer. | |
828 `eudc-expansion-overwrites-query' being non nil inverts the meaning of REPLACE. | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
829 Multiple servers can be tried with the same query until one finds a match, |
27313 | 830 see `eudc-inline-expansion-servers'" |
831 (interactive) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
832 (if (memq eudc-inline-expansion-servers |
27313 | 833 '(current-server server-then-hotlist)) |
834 (or eudc-server | |
835 (call-interactively 'eudc-set-server)) | |
836 (or eudc-server-hotlist | |
837 (error "No server in the hotlist"))) | |
838 (let* ((end (point)) | |
839 (beg (save-excursion | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
840 (if (re-search-backward "\\([:,]\\|^\\)[ \t]*" |
27313 | 841 (save-excursion |
842 (beginning-of-line) | |
843 (point)) | |
844 'move) | |
845 (goto-char (match-end 0))) | |
846 (point))) | |
847 (query-words (split-string (buffer-substring beg end) "[ \t]+")) | |
848 query-formats | |
849 response | |
850 response-string | |
851 response-strings | |
852 (eudc-former-server eudc-server) | |
853 (eudc-former-protocol eudc-protocol) | |
854 servers) | |
855 | |
856 ;; Prepare the list of servers to query | |
857 (setq servers (copy-sequence eudc-server-hotlist)) | |
858 (setq servers | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
859 (cond |
27313 | 860 ((eq eudc-inline-expansion-servers 'hotlist) |
861 eudc-server-hotlist) | |
862 ((eq eudc-inline-expansion-servers 'server-then-hotlist) | |
863 (cons (cons eudc-server eudc-protocol) | |
864 (delete (cons eudc-server eudc-protocol) servers))) | |
865 ((eq eudc-inline-expansion-servers 'current-server) | |
866 (list (cons eudc-server eudc-protocol))) | |
867 (t | |
868 (error "Wrong value for `eudc-inline-expansion-servers': %S" | |
869 eudc-inline-expansion-servers)))) | |
870 (if (and eudc-max-servers-to-query | |
871 (> (length servers) eudc-max-servers-to-query)) | |
872 (setcdr (nthcdr (1- eudc-max-servers-to-query) servers) nil)) | |
873 | |
874 (condition-case signal | |
875 (progn | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
876 (setq response |
27313 | 877 (catch 'found |
878 ;; Loop on the servers | |
879 (while servers | |
880 (eudc-set-server (eudc-caar servers) (eudc-cdar servers) t) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
881 |
27313 | 882 ;; Determine which formats apply in the query-format list |
883 (setq query-formats | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
884 (or |
27313 | 885 (eudc-extract-n-word-formats eudc-inline-query-format |
886 (length query-words)) | |
887 (if (null eudc-protocol-has-default-query-attributes) | |
888 '(name)))) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
889 |
27313 | 890 ;; Loop on query-formats |
891 (while query-formats | |
892 (setq response | |
893 (eudc-query | |
894 (eudc-format-query query-words (car query-formats)) | |
895 (eudc-translate-attribute-list | |
896 (cdr eudc-inline-expansion-format)))) | |
897 (if response | |
898 (throw 'found response)) | |
899 (setq query-formats (cdr query-formats))) | |
900 (setq servers (cdr servers))) | |
901 ;; No more servers to try... no match found | |
902 nil)) | |
903 | |
904 | |
905 (if (null response) | |
906 (error "No match") | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
907 |
27313 | 908 ;; Process response through eudc-inline-expansion-format |
909 (while response | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
910 (setq response-string (apply 'format |
27313 | 911 (car eudc-inline-expansion-format) |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
912 (mapcar (function |
27313 | 913 (lambda (field) |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
914 (or (cdr (assq field (car response))) |
27313 | 915 ""))) |
916 (eudc-translate-attribute-list | |
917 (cdr eudc-inline-expansion-format))))) | |
918 (if (> (length response-string) 0) | |
919 (setq response-strings | |
920 (cons response-string response-strings))) | |
921 (setq response (cdr response))) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
922 |
27313 | 923 (if (or |
924 (and replace (not eudc-expansion-overwrites-query)) | |
925 (and (not replace) eudc-expansion-overwrites-query)) | |
926 (delete-region beg end)) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
927 (cond |
27313 | 928 ((or (= (length response-strings) 1) |
929 (null eudc-multiple-match-handling-method) | |
930 (eq eudc-multiple-match-handling-method 'first)) | |
931 (insert (car response-strings))) | |
932 ((eq eudc-multiple-match-handling-method 'select) | |
933 (eudc-select response-strings)) | |
934 ((eq eudc-multiple-match-handling-method 'all) | |
935 (insert (mapconcat 'identity response-strings ", "))) | |
936 ((eq eudc-multiple-match-handling-method 'abort) | |
937 (error "There is more than one match for the query")) | |
938 )) | |
939 (or (and (equal eudc-server eudc-former-server) | |
940 (equal eudc-protocol eudc-former-protocol)) | |
941 (eudc-set-server eudc-former-server eudc-former-protocol t))) | |
942 (t | |
943 (or (and (equal eudc-server eudc-former-server) | |
944 (equal eudc-protocol eudc-former-protocol)) | |
945 (eudc-set-server eudc-former-server eudc-former-protocol t)) | |
946 (signal (car signal) (cdr signal)))))) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
947 |
27313 | 948 ;;;###autoload |
949 (defun eudc-query-form (&optional get-fields-from-server) | |
950 "Display a form to query the directory server. | |
951 If given a non-nil argument GET-FIELDS-FROM-SERVER, the function first | |
952 queries the server for the existing fields and displays a corresponding form." | |
953 (interactive "P") | |
954 (let ((fields (or (and get-fields-from-server | |
955 (eudc-get-attribute-list)) | |
956 eudc-query-form-attributes)) | |
957 (buffer (get-buffer-create "*Directory Query Form*")) | |
958 prompts | |
959 widget | |
960 (width 0) | |
961 inhibit-read-only | |
962 pt) | |
963 (switch-to-buffer buffer) | |
964 (setq inhibit-read-only t) | |
965 (erase-buffer) | |
966 (kill-all-local-variables) | |
967 (make-local-variable 'eudc-form-widget-list) | |
968 (widget-insert "Directory Query Form\n") | |
969 (widget-insert "====================\n\n") | |
970 (widget-insert "Current server is: " (or eudc-server | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
971 (progn |
27313 | 972 (call-interactively 'eudc-set-server) |
973 eudc-server)) | |
974 "\n") | |
975 (widget-insert "Protocol : " (symbol-name eudc-protocol) "\n") | |
976 ;; Build the list of prompts | |
977 (setq prompts (if eudc-use-raw-directory-names | |
978 (mapcar 'symbol-name (eudc-translate-attribute-list fields)) | |
979 (mapcar (function | |
980 (lambda (field) | |
981 (or (and (assq field eudc-user-attribute-names-alist) | |
982 (cdr (assq field eudc-user-attribute-names-alist))) | |
983 (capitalize (symbol-name field))))) | |
984 fields))) | |
985 ;; Loop over prompt strings to find the longest one | |
986 (mapcar (function | |
987 (lambda (prompt) | |
988 (if (> (length prompt) width) | |
989 (setq width (length prompt))))) | |
990 prompts) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
991 ;; Insert the first widget out of the mapcar to leave the cursor |
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
992 ;; in the first field |
27313 | 993 (widget-insert "\n\n" (format (concat "%" (int-to-string width) "s: ") (car prompts))) |
994 (setq pt (point)) | |
995 (setq widget (widget-create 'editable-field :size 15)) | |
996 (setq eudc-form-widget-list (cons (cons (car fields) widget) | |
997 eudc-form-widget-list)) | |
998 (setq fields (cdr fields)) | |
999 (setq prompts (cdr prompts)) | |
1000 (mapcar (function | |
1001 (lambda (field) | |
1002 (widget-insert "\n\n" (format (concat "%" (int-to-string width) "s: ") (car prompts))) | |
1003 (setq widget (widget-create 'editable-field | |
1004 :size 15)) | |
1005 (setq eudc-form-widget-list (cons (cons field widget) | |
1006 eudc-form-widget-list)) | |
1007 (setq prompts (cdr prompts)))) | |
1008 fields) | |
1009 (widget-insert "\n\n") | |
1010 (widget-create 'push-button | |
1011 :notify (lambda (&rest ignore) | |
1012 (eudc-process-form)) | |
1013 "Query Server") | |
1014 (widget-insert " ") | |
1015 (widget-create 'push-button | |
1016 :notify (lambda (&rest ignore) | |
1017 (eudc-query-form)) | |
1018 "Reset Form") | |
1019 (widget-insert " ") | |
1020 (widget-create 'push-button | |
1021 :notify (lambda (&rest ignore) | |
1022 (kill-this-buffer)) | |
1023 "Quit") | |
1024 (goto-char pt) | |
1025 (use-local-map widget-keymap) | |
1026 (widget-setup)) | |
1027 ) | |
1028 | |
1029 (defun eudc-bookmark-server (server protocol) | |
1030 "Add SERVER using PROTOCOL to the EUDC `servers' hotlist." | |
1031 (interactive "sDirectory server: \nsProtocol: ") | |
1032 (if (member (cons server protocol) eudc-server-hotlist) | |
1033 (error "%s:%s is already in the hotlist" protocol server) | |
1034 (setq eudc-server-hotlist (cons (cons server protocol) eudc-server-hotlist)) | |
1035 (eudc-install-menu) | |
1036 (eudc-save-options))) | |
1037 | |
1038 (defun eudc-bookmark-current-server () | |
1039 "Add current server to the EUDC `servers' hotlist." | |
1040 (interactive) | |
1041 (eudc-bookmark-server eudc-server eudc-protocol)) | |
1042 | |
1043 (defun eudc-save-options () | |
1044 "Save options to `eudc-options-file'." | |
1045 (interactive) | |
1046 (save-excursion | |
1047 (set-buffer (find-file-noselect eudc-options-file t)) | |
1048 (goto-char (point-min)) | |
1049 ;; delete the previous setq | |
1050 (let ((standard-output (current-buffer)) | |
1051 provide-p | |
1052 set-hotlist-p | |
1053 set-server-p) | |
1054 (catch 'found | |
1055 (while t | |
1056 (let ((sexp (condition-case nil | |
1057 (read (current-buffer)) | |
1058 (end-of-file (throw 'found nil))))) | |
1059 (if (listp sexp) | |
1060 (cond | |
1061 ((eq (car sexp) 'eudc-set-server) | |
1062 (delete-region (save-excursion | |
1063 (backward-sexp) | |
1064 (point)) | |
1065 (point)) | |
1066 (setq set-server-p t)) | |
1067 ((and (eq (car sexp) 'setq) | |
1068 (eq (eudc-cadr sexp) 'eudc-server-hotlist)) | |
1069 (delete-region (save-excursion | |
1070 (backward-sexp) | |
1071 (point)) | |
1072 (point)) | |
1073 (setq set-hotlist-p t)) | |
1074 ((and (eq (car sexp) 'provide) | |
1075 (equal (eudc-cadr sexp) '(quote eudc-options-file))) | |
1076 (setq provide-p t))) | |
1077 (if (and provide-p | |
1078 set-hotlist-p | |
1079 set-server-p) | |
1080 (throw 'found t)))))) | |
1081 (if (eq (point-min) (point-max)) | |
1082 (princ ";; This file was automatically generated by eudc.el.\n\n")) | |
1083 (or provide-p | |
1084 (princ "(provide 'eudc-options-file)\n")) | |
1085 (or (bolp) | |
1086 (princ "\n")) | |
1087 (delete-blank-lines) | |
1088 (princ "(eudc-set-server ") | |
1089 (prin1 eudc-server) | |
1090 (princ " '") | |
1091 (prin1 eudc-protocol) | |
1092 (princ " t)\n") | |
1093 (princ "(setq eudc-server-hotlist '") | |
1094 (prin1 eudc-server-hotlist) | |
1095 (princ ")\n") | |
1096 (save-buffer)))) | |
1097 | |
1098 (defun eudc-move-to-next-record () | |
1099 "Move to next record, in a buffer displaying directory query results." | |
1100 (interactive) | |
1101 (if (not (eq major-mode 'eudc-mode)) | |
1102 (error "Not in a EUDC buffer") | |
1103 (let ((pt (next-overlay-change (point)))) | |
1104 (if (< pt (point-max)) | |
1105 (goto-char (1+ pt)) | |
1106 (error "No more records after point"))))) | |
1107 | |
1108 (defun eudc-move-to-previous-record () | |
1109 "Move to previous record, in a buffer displaying directory query results." | |
1110 (interactive) | |
1111 (if (not (eq major-mode 'eudc-mode)) | |
1112 (error "Not in a EUDC buffer") | |
1113 (let ((pt (previous-overlay-change (point)))) | |
1114 (if (> pt (point-min)) | |
1115 (goto-char pt) | |
1116 (error "No more records before point"))))) | |
1117 | |
1118 | |
1119 ;;}}} | |
1120 | |
1121 ;;{{{ Menus an keymaps | |
1122 | |
1123 (require 'easymenu) | |
1124 | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1125 (setq eudc-mode-map |
27313 | 1126 (let ((map (make-sparse-keymap))) |
1127 (define-key map "q" 'kill-this-buffer) | |
1128 (define-key map "x" 'kill-this-buffer) | |
1129 (define-key map "f" 'eudc-query-form) | |
1130 (define-key map "b" 'eudc-try-bbdb-insert) | |
1131 (define-key map "n" 'eudc-move-to-next-record) | |
1132 (define-key map "p" 'eudc-move-to-previous-record) | |
1133 map)) | |
1134 (set-keymap-parent eudc-mode-map widget-keymap) | |
1135 | |
1136 (defconst eudc-custom-generated-menu (cdr (custom-menu-create 'eudc))) | |
1137 | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1138 (defconst eudc-tail-menu |
27313 | 1139 `(["---" nil nil] |
1140 ["Query with Form" eudc-query-form t] | |
1141 ["Expand Inline Query" eudc-expand-inline t] | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1142 ["Insert Record into BBDB" eudc-insert-record-at-point-into-bbdb |
27313 | 1143 (and (or (featurep 'bbdb) |
1144 (prog1 (locate-library "bbdb") (message ""))) | |
1145 (overlays-at (point)) | |
1146 (overlay-get (car (overlays-at (point))) 'eudc-record))] | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1147 ["Insert All Records into BBDB" eudc-batch-export-records-to-bbdb |
27313 | 1148 (and (eq major-mode 'eudc-mode) |
1149 (or (featurep 'bbdb) | |
1150 (prog1 (locate-library "bbdb") (message ""))))] | |
1151 ["---" nil nil] | |
1152 ["Get Email" eudc-get-email t] | |
1153 ["Get Phone" eudc-get-phone t] | |
1154 ["List Valid Attribute Names" eudc-get-attribute-list t] | |
1155 ["---" nil nil] | |
1156 ,(cons "Customize" eudc-custom-generated-menu))) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1157 |
27313 | 1158 |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1159 (defconst eudc-server-menu |
27313 | 1160 '(["---" nil nil] |
1161 ["Bookmark Current Server" eudc-bookmark-current-server t] | |
1162 ["Edit Server List" eudc-edit-hotlist t] | |
1163 ["New Server" eudc-set-server t])) | |
1164 | |
1165 (defun eudc-menu () | |
1166 (let (command) | |
1167 (append '("Directory Search") | |
1168 (list | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1169 (append |
27313 | 1170 '("Server") |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1171 (mapcar |
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1172 (function |
27313 | 1173 (lambda (servspec) |
1174 (let* ((server (car servspec)) | |
1175 (protocol (cdr servspec)) | |
1176 (proto-name (symbol-name protocol))) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1177 (setq command (intern (concat "eudc-set-server-" |
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1178 server |
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1179 "-" |
27313 | 1180 proto-name))) |
1181 (if (not (fboundp command)) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1182 (fset command |
27313 | 1183 `(lambda () |
1184 (interactive) | |
1185 (eudc-set-server ,server (quote ,protocol)) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1186 (message "Selected directory server is now %s (%s)" |
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1187 ,server |
27313 | 1188 ,proto-name)))) |
1189 (vector (format "%s (%s)" server proto-name) | |
1190 command | |
1191 :style 'radio | |
1192 :selected `(equal eudc-server ,server))))) | |
1193 eudc-server-hotlist) | |
1194 eudc-server-menu)) | |
1195 eudc-tail-menu))) | |
1196 | |
1197 (defun eudc-install-menu () | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1198 (cond |
27313 | 1199 ((and eudc-xemacs-p (featurep 'menubar)) |
1200 (add-submenu '("Tools") (eudc-menu))) | |
1201 (eudc-emacs-p | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1202 (cond |
27313 | 1203 ((fboundp 'easy-menu-add-item) |
1204 (let ((menu (eudc-menu))) | |
1205 (easy-menu-add-item nil '("tools") (easy-menu-create-menu (car menu) | |
1206 (cdr menu))))) | |
1207 ((fboundp 'easy-menu-create-keymaps) | |
1208 (easy-menu-define eudc-menu-map eudc-mode-map "Directory Client Menu" (eudc-menu)) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1209 (define-key |
27313 | 1210 global-map |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1211 [menu-bar tools eudc] |
27313 | 1212 (cons "Directory Search" |
1213 (easy-menu-create-keymaps "Directory Search" (cdr (eudc-menu)))))) | |
1214 (t | |
1215 (error "Unknown version of easymenu")))) | |
1216 )) | |
1217 | |
1218 | |
1219 ;;; Load time initializations : | |
1220 | |
1221 ;;; Load the options file | |
1222 (if (and (not noninteractive) | |
1223 (and (locate-library eudc-options-file) | |
1224 (message "")) ; Remove modeline message | |
1225 (not (featurep 'eudc-options-file))) | |
1226 (load eudc-options-file)) | |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1227 |
27313 | 1228 ;;; Install the full menu |
1229 (unless (featurep 'infodock) | |
1230 (eudc-install-menu)) | |
1231 | |
1232 | |
1233 ;;; The following installs a short menu for EUDC at XEmacs startup. | |
1234 | |
1235 ;;;###autoload | |
1236 (defun eudc-load-eudc () | |
1237 "Load the Emacs Unified Directory Client. | |
1238 This does nothing except loading eudc by autoload side-effect." | |
1239 (interactive) | |
1240 nil) | |
1241 | |
27324
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1242 ;;;###autoload |
42575
24c994803548
(top-level): Revert previous change.
Pavel Janík <Pavel@Janik.cz>
parents:
42569
diff
changeset
|
1243 (cond ((not (string-match "XEmacs" emacs-version)) |
27324
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1244 (defvar eudc-tools-menu (make-sparse-keymap "Directory Search")) |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1245 (fset 'eudc-tools-menu (symbol-value 'eudc-tools-menu)) |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1246 (define-key eudc-tools-menu [phone] |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1247 '("Get Phone" . eudc-get-phone)) |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1248 (define-key eudc-tools-menu [email] |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1249 '("Get Email" . eudc-get-email)) |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1250 (define-key eudc-tools-menu [separator-eudc-email] |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1251 '("--")) |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1252 (define-key eudc-tools-menu [expand-inline] |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1253 '("Expand Inline Query" . eudc-expand-inline)) |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1254 (define-key eudc-tools-menu [query] |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1255 '("Query with Form" . eudc-query-form)) |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1256 (define-key eudc-tools-menu [separator-eudc-query] |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1257 '("--")) |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1258 (define-key eudc-tools-menu [new] |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1259 '("New Server" . eudc-set-server)) |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1260 (define-key eudc-tools-menu [load] |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1261 '("Load Hotlist of Servers" . eudc-load-eudc))) |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1262 |
27324
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1263 (t |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1264 (let ((menu '("Directory Search" |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1265 ["Load Hotlist of Servers" eudc-load-eudc t] |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1266 ["New Server" eudc-set-server t] |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1267 ["---" nil nil] |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1268 ["Query with Form" eudc-query-form t] |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1269 ["Expand Inline Query" eudc-expand-inline t] |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1270 ["---" nil nil] |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1271 ["Get Email" eudc-get-email t] |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1272 ["Get Phone" eudc-get-phone t]))) |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1273 (if (not (featurep 'eudc-autoloads)) |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1274 (if eudc-xemacs-p |
27324
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1275 (if (and (featurep 'menubar) |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1276 (not (featurep 'infodock))) |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1277 (add-submenu '("Tools") menu)) |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1278 (require 'easymenu) |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1279 (cond |
27324
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1280 ((fboundp 'easy-menu-add-item) |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1281 (easy-menu-add-item nil '("tools") |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1282 (easy-menu-create-menu (car menu) |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1283 (cdr menu)))) |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1284 ((fboundp 'easy-menu-create-keymaps) |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1285 (define-key |
27324
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1286 global-map |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1287 [menu-bar tools eudc] |
27324
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1288 (cons "Directory Search" |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1289 (easy-menu-create-keymaps "Directory Search" |
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1290 (cdr menu))))))))))) |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1291 |
27324
e33d394fe874
(toplevel): Define EUDC menu for Emacs.
Gerd Moellmann <gerd@gnu.org>
parents:
27320
diff
changeset
|
1292 ;;}}} |
42569
df3f717a3933
(top-level): Use eudc-xemacs-p instead of string-match on emacs-version
Pavel Janík <Pavel@Janik.cz>
parents:
27324
diff
changeset
|
1293 |
27313 | 1294 (provide 'eudc) |
1295 | |
1296 ;;; eudc.el ends here |