Mercurial > emacs
annotate lisp/net/eudcb-bbdb.el @ 112453:06719a229a46 default tip
* calc/calc.el (calc-default-power-reference-level)
(calc-default-field-reference-level): New variables.
* calc/calc-units.el (math-standard-units): Add dB and Np.
(math-logunits): New variable.
(math-extract-logunits, math-logcombine, calcFunc-luplus)
(calcFunc-luminus, calc-luplus, calc-luminus, math-logunit-level)
(calcFunc-fieldlevel, calcFunc-powerlevel, calc-level): New
functions.
(math-find-base-units-rec): Add entry for ln(10).
* calc/calc-help.el (calc-u-prefix-help): Add logarithmic help.
(calc-ul-prefix-help): New function.
* calc/calc-ext.el (calc-init-extensions): Autoload new units
functions. Add keybindings for new units functions.
author | Jay Belanger <jay.p.belanger@gmail.com> |
---|---|
date | Sun, 23 Jan 2011 23:08:04 -0600 |
parents | ef719132ddfa |
children |
rev | line source |
---|---|
27313 | 1 ;;; eudcb-bbdb.el --- Emacs Unified Directory Client - BBDB Backend |
2 | |
74509 | 3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
112218
376148b31b5e
Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents:
106815
diff
changeset
|
4 ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
27313 | 5 |
42778
6d743d659035
New maintainer. Change author's address.
Pavel Janík <Pavel@Janik.cz>
parents:
42574
diff
changeset
|
6 ;; Author: Oscar Figueiredo <oscar@cpe.fr> |
6d743d659035
New maintainer. Change author's address.
Pavel Janík <Pavel@Janik.cz>
parents:
42574
diff
changeset
|
7 ;; Maintainer: Pavel Janík <Pavel@Janik.cz> |
42574 | 8 ;; Keywords: comm |
110015
280c8ae2476d
Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents:
106815
diff
changeset
|
9 ;; Package: eudc |
27313 | 10 |
11 ;; This file is part of GNU Emacs. | |
12 | |
94677
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; GNU Emacs is free software: you can redistribute it and/or modify |
27313 | 14 ;; it under the terms of the GNU General Public License as published by |
94677
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
15 ;; the Free Software Foundation, either version 3 of the License, or |
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
16 ;; (at your option) any later version. |
27313 | 17 |
18 ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 ;; GNU General Public License for more details. | |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
94677
91e5880a36c1
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
27313 | 25 |
26 ;;; Commentary: | |
42570
78a4068d960a
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
27313
diff
changeset
|
27 ;; This library provides an interface to use BBDB as a backend of |
27313 | 28 ;; the Emacs Unified Directory Client. |
29 | |
30 ;;; Code: | |
31 | |
32 (require 'eudc) | |
33 (if (not (featurep 'bbdb)) | |
34 (load-library "bbdb")) | |
35 (if (not (featurep 'bbdb-com)) | |
36 (load-library "bbdb-com")) | |
37 | |
38 ;;{{{ Internal cooking | |
39 | |
40 ;; I don't like this but mapcar does not accept a parameter to the function and | |
41 ;; I don't want to use mapcar* | |
42 (defvar eudc-bbdb-current-query nil) | |
43 (defvar eudc-bbdb-current-return-attributes nil) | |
44 | |
45 (defvar eudc-bbdb-attributes-translation-alist | |
46 '((name . lastname) | |
47 (email . net) | |
48 (phone . phones)) | |
49 "Alist mapping EUDC attribute names to BBDB names.") | |
50 | |
51 (eudc-protocol-set 'eudc-query-function 'eudc-bbdb-query-internal 'bbdb) | |
52 (eudc-protocol-set 'eudc-list-attributes-function nil 'bbdb) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42778
diff
changeset
|
53 (eudc-protocol-set 'eudc-protocol-attributes-translation-alist |
27313 | 54 'eudc-bbdb-attributes-translation-alist 'bbdb) |
55 (eudc-protocol-set 'eudc-bbdb-conversion-alist nil 'bbdb) | |
56 (eudc-protocol-set 'eudc-protocol-has-default-query-attributes nil 'bbdb) | |
57 | |
58 (defun eudc-bbdb-format-query (query) | |
59 "Format a EUDC query alist into a list suitable to `bbdb-search'." | |
60 (let* ((firstname (cdr (assq 'firstname query))) | |
61 (lastname (cdr (assq 'lastname query))) | |
62 (name (or (and firstname lastname | |
63 (concat firstname " " lastname)) | |
64 firstname | |
65 lastname)) | |
66 (company (cdr (assq 'company query))) | |
67 (net (cdr (assq 'net query))) | |
68 (notes (cdr (assq 'notes query))) | |
69 (phone (cdr (assq 'phone query)))) | |
70 (list name company net notes phone))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42778
diff
changeset
|
71 |
27313 | 72 |
73 (defun eudc-bbdb-filter-non-matching-record (record) | |
74 "Return RECORD if it matches `eudc-bbdb-current-query', nil otherwise." | |
75 (catch 'unmatch | |
76 (progn | |
85228
631c2c083474
(eudc-bbdb-filter-non-matching-record)
Glenn Morris <rgm@gnu.org>
parents:
78230
diff
changeset
|
77 (mapc |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42778
diff
changeset
|
78 (function |
27313 | 79 (lambda (condition) |
80 (let ((attr (car condition)) | |
81 (val (cdr condition)) | |
82 (case-fold-search t) | |
83 bbdb-val) | |
84 (or (and (memq attr '(firstname lastname aka company phones addresses net)) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42778
diff
changeset
|
85 (progn |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42778
diff
changeset
|
86 (setq bbdb-val |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42778
diff
changeset
|
87 (eval (list (intern (concat "bbdb-record-" |
27313 | 88 (symbol-name attr))) |
89 'record))) | |
90 (if (listp bbdb-val) | |
91 (if eudc-bbdb-enable-substring-matches | |
92 (eval `(or ,@(mapcar '(lambda (subval) | |
93 (string-match val | |
94 subval)) | |
95 bbdb-val))) | |
96 (member (downcase val) | |
97 (mapcar 'downcase bbdb-val))) | |
98 (if eudc-bbdb-enable-substring-matches | |
99 (string-match val bbdb-val) | |
100 (string-equal (downcase val) (downcase bbdb-val)))))) | |
101 (throw 'unmatch nil))))) | |
102 eudc-bbdb-current-query) | |
103 record))) | |
104 | |
86816
4a5a63e12e5a
(bbdb-phone-location, bbdb-phone-string)
Glenn Morris <rgm@gnu.org>
parents:
85228
diff
changeset
|
105 ;; External. |
86843
9e7d6c65162b
(bbdb-phone-location, bbdb-record-phones)
Glenn Morris <rgm@gnu.org>
parents:
86816
diff
changeset
|
106 (declare-function bbdb-phone-location "ext:bbdb" t) ; via bbdb-defstruct |
86816
4a5a63e12e5a
(bbdb-phone-location, bbdb-phone-string)
Glenn Morris <rgm@gnu.org>
parents:
85228
diff
changeset
|
107 (declare-function bbdb-phone-string "ext:bbdb" (phone)) |
86843
9e7d6c65162b
(bbdb-phone-location, bbdb-record-phones)
Glenn Morris <rgm@gnu.org>
parents:
86816
diff
changeset
|
108 (declare-function bbdb-record-phones "ext:bbdb" t) ; via bbdb-defstruct |
87024
d63d925838d5
(bbdb-address-streets): Declare as a function.
Glenn Morris <rgm@gnu.org>
parents:
86843
diff
changeset
|
109 (declare-function bbdb-address-streets "ext:bbdb" t) ; via bbdb-defstruct |
86843
9e7d6c65162b
(bbdb-phone-location, bbdb-record-phones)
Glenn Morris <rgm@gnu.org>
parents:
86816
diff
changeset
|
110 (declare-function bbdb-address-city "ext:bbdb" t) ; via bbdb-defstruct |
9e7d6c65162b
(bbdb-phone-location, bbdb-record-phones)
Glenn Morris <rgm@gnu.org>
parents:
86816
diff
changeset
|
111 (declare-function bbdb-address-state "ext:bbdb" t) ; via bbdb-defstruct |
9e7d6c65162b
(bbdb-phone-location, bbdb-record-phones)
Glenn Morris <rgm@gnu.org>
parents:
86816
diff
changeset
|
112 (declare-function bbdb-address-zip "ext:bbdb" t) ; via bbdb-defstruct |
9e7d6c65162b
(bbdb-phone-location, bbdb-record-phones)
Glenn Morris <rgm@gnu.org>
parents:
86816
diff
changeset
|
113 (declare-function bbdb-address-location "ext:bbdb" t) ; via bbdb-defstruct |
9e7d6c65162b
(bbdb-phone-location, bbdb-record-phones)
Glenn Morris <rgm@gnu.org>
parents:
86816
diff
changeset
|
114 (declare-function bbdb-record-addresses "ext:bbdb" t) ; via bbdb-defstruct |
86816
4a5a63e12e5a
(bbdb-phone-location, bbdb-phone-string)
Glenn Morris <rgm@gnu.org>
parents:
85228
diff
changeset
|
115 (declare-function bbdb-records "ext:bbdb" |
4a5a63e12e5a
(bbdb-phone-location, bbdb-phone-string)
Glenn Morris <rgm@gnu.org>
parents:
85228
diff
changeset
|
116 (&optional dont-check-disk already-in-db-buffer)) |
4a5a63e12e5a
(bbdb-phone-location, bbdb-phone-string)
Glenn Morris <rgm@gnu.org>
parents:
85228
diff
changeset
|
117 |
27313 | 118 (defun eudc-bbdb-extract-phones (record) |
119 (mapcar (function | |
120 (lambda (phone) | |
121 (if eudc-bbdb-use-locations-as-attribute-names | |
122 (cons (intern (bbdb-phone-location phone)) | |
123 (bbdb-phone-string phone)) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42778
diff
changeset
|
124 (cons 'phones (format "%s: %s" |
27313 | 125 (bbdb-phone-location phone) |
126 (bbdb-phone-string phone)))))) | |
127 (bbdb-record-phones record))) | |
128 | |
129 (defun eudc-bbdb-extract-addresses (record) | |
130 (let (s c val) | |
87024
d63d925838d5
(bbdb-address-streets): Declare as a function.
Glenn Morris <rgm@gnu.org>
parents:
86843
diff
changeset
|
131 (mapcar (lambda (address) |
d63d925838d5
(bbdb-address-streets): Declare as a function.
Glenn Morris <rgm@gnu.org>
parents:
86843
diff
changeset
|
132 (setq c (bbdb-address-streets address)) |
d63d925838d5
(bbdb-address-streets): Declare as a function.
Glenn Morris <rgm@gnu.org>
parents:
86843
diff
changeset
|
133 (dotimes (n 3) |
d63d925838d5
(bbdb-address-streets): Declare as a function.
Glenn Morris <rgm@gnu.org>
parents:
86843
diff
changeset
|
134 (unless (zerop (length (setq s (nth n c)))) |
d63d925838d5
(bbdb-address-streets): Declare as a function.
Glenn Morris <rgm@gnu.org>
parents:
86843
diff
changeset
|
135 (setq val (concat val s "\n")))) |
d63d925838d5
(bbdb-address-streets): Declare as a function.
Glenn Morris <rgm@gnu.org>
parents:
86843
diff
changeset
|
136 (setq c (bbdb-address-city address) |
d63d925838d5
(bbdb-address-streets): Declare as a function.
Glenn Morris <rgm@gnu.org>
parents:
86843
diff
changeset
|
137 s (bbdb-address-state address)) |
d63d925838d5
(bbdb-address-streets): Declare as a function.
Glenn Morris <rgm@gnu.org>
parents:
86843
diff
changeset
|
138 (setq val (concat val |
d63d925838d5
(bbdb-address-streets): Declare as a function.
Glenn Morris <rgm@gnu.org>
parents:
86843
diff
changeset
|
139 (if (and (> (length c) 0) (> (length s) 0)) |
d63d925838d5
(bbdb-address-streets): Declare as a function.
Glenn Morris <rgm@gnu.org>
parents:
86843
diff
changeset
|
140 (concat c ", " s) |
d63d925838d5
(bbdb-address-streets): Declare as a function.
Glenn Morris <rgm@gnu.org>
parents:
86843
diff
changeset
|
141 c) |
d63d925838d5
(bbdb-address-streets): Declare as a function.
Glenn Morris <rgm@gnu.org>
parents:
86843
diff
changeset
|
142 " " |
d63d925838d5
(bbdb-address-streets): Declare as a function.
Glenn Morris <rgm@gnu.org>
parents:
86843
diff
changeset
|
143 (bbdb-address-zip address))) |
d63d925838d5
(bbdb-address-streets): Declare as a function.
Glenn Morris <rgm@gnu.org>
parents:
86843
diff
changeset
|
144 (if eudc-bbdb-use-locations-as-attribute-names |
d63d925838d5
(bbdb-address-streets): Declare as a function.
Glenn Morris <rgm@gnu.org>
parents:
86843
diff
changeset
|
145 (cons (intern (bbdb-address-location address)) val) |
d63d925838d5
(bbdb-address-streets): Declare as a function.
Glenn Morris <rgm@gnu.org>
parents:
86843
diff
changeset
|
146 (cons 'addresses (concat (bbdb-address-location address) |
d63d925838d5
(bbdb-address-streets): Declare as a function.
Glenn Morris <rgm@gnu.org>
parents:
86843
diff
changeset
|
147 "\n" val)))) |
d63d925838d5
(bbdb-address-streets): Declare as a function.
Glenn Morris <rgm@gnu.org>
parents:
86843
diff
changeset
|
148 (bbdb-record-addresses record)))) |
27313 | 149 |
150 (defun eudc-bbdb-format-record-as-result (record) | |
151 "Format the BBDB RECORD as a EUDC query result record. | |
152 The record is filtered according to `eudc-bbdb-current-return-attributes'" | |
153 (let ((attrs (or eudc-bbdb-current-return-attributes | |
154 '(firstname lastname aka company phones addresses net notes))) | |
155 attr | |
156 eudc-rec | |
157 val) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42778
diff
changeset
|
158 (while (prog1 |
27313 | 159 (setq attr (car attrs)) |
160 (setq attrs (cdr attrs))) | |
161 (cond | |
162 ((eq attr 'phones) | |
163 (setq val (eudc-bbdb-extract-phones record))) | |
164 ((eq attr 'addresses) | |
165 (setq val (eudc-bbdb-extract-addresses record))) | |
166 ((memq attr '(firstname lastname aka company net notes)) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42778
diff
changeset
|
167 (setq val (eval |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42778
diff
changeset
|
168 (list (intern |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42778
diff
changeset
|
169 (concat "bbdb-record-" |
27313 | 170 (symbol-name attr))) |
171 'record)))) | |
172 (t | |
173 (setq val "Unknown BBDB attribute"))) | |
174 (if val | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42778
diff
changeset
|
175 (cond |
27313 | 176 ((memq attr '(phones addresses)) |
177 (setq eudc-rec (append val eudc-rec))) | |
178 ((and (listp val) | |
179 (= 1 (length val))) | |
180 (setq eudc-rec (cons (cons attr (car val)) eudc-rec))) | |
181 ((> (length val) 0) | |
182 (setq eudc-rec (cons (cons attr val) eudc-rec))) | |
183 (t | |
184 (error "Unexpected attribute value"))))) | |
185 (nreverse eudc-rec))) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42778
diff
changeset
|
186 |
27313 | 187 |
188 | |
189 (defun eudc-bbdb-query-internal (query &optional return-attrs) | |
190 "Query BBDB with QUERY. | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42778
diff
changeset
|
191 QUERY is a list of cons cells (ATTR . VALUE) where ATTRs should be valid |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42778
diff
changeset
|
192 BBDB attribute names. |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42778
diff
changeset
|
193 RETURN-ATTRS is a list of attributes to return, defaulting to |
27313 | 194 `eudc-default-return-attributes'." |
195 | |
196 (let ((eudc-bbdb-current-query query) | |
197 (eudc-bbdb-current-return-attributes return-attrs) | |
198 (query-attrs (eudc-bbdb-format-query query)) | |
199 bbdb-attrs | |
200 (records (bbdb-records)) | |
201 result | |
202 filtered) | |
203 ;; BBDB ORs its query attributes while EUDC ANDs them, hence we need to | |
204 ;; call bbdb-search iteratively on the returned records for each of the | |
205 ;; requested attributes | |
206 (while (and records (> (length query-attrs) 0)) | |
207 (setq bbdb-attrs (append bbdb-attrs (list (car query-attrs)))) | |
208 (if (car query-attrs) | |
209 (setq records (eval `(bbdb-search ,(quote records) ,@bbdb-attrs)))) | |
210 (setq query-attrs (cdr query-attrs))) | |
85228
631c2c083474
(eudc-bbdb-filter-non-matching-record)
Glenn Morris <rgm@gnu.org>
parents:
78230
diff
changeset
|
211 (mapc (function |
631c2c083474
(eudc-bbdb-filter-non-matching-record)
Glenn Morris <rgm@gnu.org>
parents:
78230
diff
changeset
|
212 (lambda (record) |
631c2c083474
(eudc-bbdb-filter-non-matching-record)
Glenn Morris <rgm@gnu.org>
parents:
78230
diff
changeset
|
213 (setq filtered (eudc-filter-duplicate-attributes record)) |
631c2c083474
(eudc-bbdb-filter-non-matching-record)
Glenn Morris <rgm@gnu.org>
parents:
78230
diff
changeset
|
214 ;; If there were duplicate attributes reverse the order of the |
631c2c083474
(eudc-bbdb-filter-non-matching-record)
Glenn Morris <rgm@gnu.org>
parents:
78230
diff
changeset
|
215 ;; record so the unique attributes appear first |
631c2c083474
(eudc-bbdb-filter-non-matching-record)
Glenn Morris <rgm@gnu.org>
parents:
78230
diff
changeset
|
216 (if (> (length filtered) 1) |
631c2c083474
(eudc-bbdb-filter-non-matching-record)
Glenn Morris <rgm@gnu.org>
parents:
78230
diff
changeset
|
217 (setq filtered (mapcar (function |
631c2c083474
(eudc-bbdb-filter-non-matching-record)
Glenn Morris <rgm@gnu.org>
parents:
78230
diff
changeset
|
218 (lambda (rec) |
631c2c083474
(eudc-bbdb-filter-non-matching-record)
Glenn Morris <rgm@gnu.org>
parents:
78230
diff
changeset
|
219 (reverse rec))) |
631c2c083474
(eudc-bbdb-filter-non-matching-record)
Glenn Morris <rgm@gnu.org>
parents:
78230
diff
changeset
|
220 filtered))) |
631c2c083474
(eudc-bbdb-filter-non-matching-record)
Glenn Morris <rgm@gnu.org>
parents:
78230
diff
changeset
|
221 (setq result (append result filtered)))) |
631c2c083474
(eudc-bbdb-filter-non-matching-record)
Glenn Morris <rgm@gnu.org>
parents:
78230
diff
changeset
|
222 (delq nil |
631c2c083474
(eudc-bbdb-filter-non-matching-record)
Glenn Morris <rgm@gnu.org>
parents:
78230
diff
changeset
|
223 (mapcar 'eudc-bbdb-format-record-as-result |
631c2c083474
(eudc-bbdb-filter-non-matching-record)
Glenn Morris <rgm@gnu.org>
parents:
78230
diff
changeset
|
224 (delq nil |
631c2c083474
(eudc-bbdb-filter-non-matching-record)
Glenn Morris <rgm@gnu.org>
parents:
78230
diff
changeset
|
225 (mapcar 'eudc-bbdb-filter-non-matching-record |
631c2c083474
(eudc-bbdb-filter-non-matching-record)
Glenn Morris <rgm@gnu.org>
parents:
78230
diff
changeset
|
226 records))))) |
27313 | 227 result)) |
228 | |
42570
78a4068d960a
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
27313
diff
changeset
|
229 ;;}}} |
27313 | 230 |
231 ;;{{{ High-level interfaces (interactive functions) | |
232 | |
233 (defun eudc-bbdb-set-server (dummy) | |
234 "Set the EUDC server to BBDB." | |
235 (interactive) | |
236 (eudc-set-server dummy 'bbdb) | |
237 (message "BBDB server selected")) | |
238 | |
42570
78a4068d960a
Remove unnecessary whitespaces.
Pavel Janík <Pavel@Janik.cz>
parents:
27313
diff
changeset
|
239 ;;}}} |
27313 | 240 |
241 | |
242 (eudc-register-protocol 'bbdb) | |
243 | |
244 (provide 'eudcb-bbdb) | |
245 | |
246 ;;; eudcb-bbdb.el ends here |