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