@lisp
(with-eval-after-load "message"
- (define-key message-mode-map [(control ?c) (tab)] 'eudc-expand-inline))
+ (define-key message-mode-map [(control ?c) (tab)] 'eudc-expand-try-all))
(with-eval-after-load "sendmail"
- (define-key mail-mode-map [(control ?c) (tab)] 'eudc-expand-inline))
+ (define-key mail-mode-map [(control ?c) (tab)] 'eudc-expand-try-all))
@end lisp
@menu
@vindex message-mode-map
@findex eudc-expand-inline
+@findex eudc-expand-try-all
@vindex eudc-server-hotlist
@vindex ldap-host-parameters-alist
@lisp
(with-eval-after-load "message"
- (define-key message-mode-map (kbd "TAB") 'eudc-expand-inline))
+ (define-key message-mode-map (kbd "TAB") 'eudc-expand-try-all))
(setopt eudc-server-hotlist
'(("" . bbdb)
("ldaps://ldap.gnu.org" . ldap)))
@vindex message-mode-map
@findex eudc-expand-inline
+@findex eudc-expand-try-all
@vindex eudc-server-hotlist
@vindex ldap-host-parameters-alist
@lisp
(with-eval-after-load "message"
- (define-key message-mode-map (kbd "TAB") 'eudc-expand-inline))
+ (define-key message-mode-map (kbd "TAB") 'eudc-expand-try-all))
(setopt 'eudc-server-hotlist
'(("" . bbdb)
("ldaps://ldap.gnu.org" . ldap)))
@vindex message-mode-map
@findex eudc-expand-inline
+@findex eudc-expand-try-all
@vindex eudc-server-hotlist
@vindex ldap-host-parameters-alist
@lisp
(with-eval-after-load "message"
- (define-key message-mode-map (kbd "TAB") 'eudc-expand-inline))
+ (define-key message-mode-map (kbd "TAB") 'eudc-expand-try-all))
(setopt 'eudc-server-hotlist
'(("" . bbdb) ("" . ldap)))
(setopt 'ldap-host-parameters-alist
@node Inline Query Expansion
@section Inline Query Expansion
-Inline query expansion is a powerful method to get completion from your
-directory server. The most common usage is for expanding names to email
-addresses in mail message buffers. The expansion is performed by the
-command @kbd{M-x eudc-expand-inline} which is available from the
-@samp{Expand Inline Query} menu item but can also be conveniently
-bound to a key shortcut (@pxref{Installation}). The operation is
-controlled by the variables @code{eudc-inline-expansion-format},
-@code{eudc-inline-query-format},
+Inline query expansion is a powerful method to get completion from
+your directory servers. The most common usage is for expanding names
+to email addresses in mail message buffers. The expansion is
+performed by the command @kbd{M-x eudc-expand-try-all} which is
+available from the @samp{Expand Inline Query Trying All Servers} menu
+item but can also be conveniently bound to a key shortcut
+(@pxref{Installation}). The operation is controlled by the variables
+@code{eudc-inline-expansion-format}, @code{eudc-inline-query-format},
@code{eudc-expanding-overwrites-query} and
@code{eudc-multiple-match-handling-method}.
-If the query fails for a server, other servers may be tried successively
-until one of them finds a match (@pxref{Multi-server Queries}).
+If the query fails for a server, other servers may be tried
+successively until one of them finds a match (@pxref{Multi-server
+Queries}), or all servers can be tried and all matches returned.
+
+@deffn Command eudc-expand-try-all try-all-servers-p
+Query some or all servers and expand the query string before point.
+The query string consists of the buffer substring from the point back
+to the preceding comma, colon or beginning of line.
+@code{eudc-inline-query-format} controls how individual words are
+mapped onto directory attribute names. After querying the server or
+servers for the given string, the expansion specified by
+@code{eudc-inline-expansion-format} is inserted in the buffer at
+point. If multiple matches are available, a selection window is
+displayed. If @var{try-all-servers-p} is non-@code{nil} then all
+servers are queried.
+@end deffn
@deffn Command eudc-expand-inline save-query-as-kill-p
Query the server and expand the query string before point. The query
(setq n (1- n)))
formats))
+;;;###autoload
+(defun eudc-expand-try-all (&optional try-all-servers)
+ "Wrap `eudc-expand-inline' with a prefix argument.
+If TRY-ALL-SERVERS -- the prefix argument when called
+interactively -- is non-nil, collect results from all servers.
+If TRY-ALL-SERVERS is nil, do not try subsequent servers after
+one server returns any match."
+ (interactive "P")
+ (eudc-expand-inline (not eudc-expansion-save-query-as-kill) try-all-servers))
;;;###autoload
-(defun eudc-expand-inline (&optional save-query-as-kill)
+(defun eudc-expand-inline (&optional save-query-as-kill try-all-servers)
"Query the directory server, and expand the query string before point.
The query string consists of the buffer substring from the point back to
the preceding comma, colon or beginning of line.
(point)))
(query-words (split-string (buffer-substring-no-properties beg end)
"[ \t]+"))
- (response-strings (eudc-query-with-words query-words)))
+ (response-strings (eudc-query-with-words query-words try-all-servers)))
(if (null response-strings)
(error "No match")
(error "There is more than one match for the query"))))))
;;;###autoload
-(defun eudc-query-with-words (query-words)
+(defun eudc-query-with-words (query-words &optional try-all-servers)
"Query the directory server, and return the matching responses.
The variable `eudc-inline-query-format' controls how to associate the
individual QUERY-WORDS with directory attribute names.
specified by `eudc-inline-expansion-format' is applied to the
matches before returning them.inserted in the buffer at point.
Multiple servers can be tried with the same query until one finds a match,
-see `eudc-inline-expansion-servers'."
+see `eudc-inline-expansion-servers'. When TRY-ALL-SERVERS is non-nil,
+keep collecting results from subsequent servers after the first match."
(cond
((eq eudc-inline-expansion-servers 'current-server)
(or eudc-server
(error "Wrong value for `eudc-inline-expansion-servers': %S"
eudc-inline-expansion-servers)))
(let* (query-formats
+ response-strings
(eudc-former-server eudc-server)
(eudc-former-protocol eudc-protocol)
;; Prepare the list of servers to query
(if eudc-server
(cons (cons eudc-server eudc-protocol)
(delete (cons eudc-server eudc-protocol)
- (copy-sequence eudc-server-hotlist)))
+ (copy-sequence eudc-server-hotlist)))
eudc-server-hotlist))
((eq eudc-inline-expansion-servers 'current-server)
(list (cons eudc-server eudc-protocol))))))
(setcdr (nthcdr (1- eudc-max-servers-to-query) servers) nil))
(unwind-protect
- (let ((response
- (catch 'found
- ;; Loop on the servers
- (dolist (server servers)
- (eudc-set-server (car server) (cdr server) t)
-
- ;; Determine which formats apply in the query-format list
- (setq query-formats
- (or
- (eudc-extract-n-word-formats eudc-inline-query-format
- (length query-words))
- (if (null eudc-protocol-has-default-query-attributes)
- '(name))))
-
- ;; Loop on query-formats
- (while query-formats
- (let ((response
- (eudc-query
- (eudc-format-query query-words (car query-formats))
- (eudc-translate-attribute-list
- (cdr eudc-inline-expansion-format)))))
- (if response
- (throw 'found response)))
- (setq query-formats (cdr query-formats))))
- ;; No more servers to try... no match found
- nil))
- (response-strings '()))
-
- ;; Process response through eudc-inline-expansion-format
- (dolist (r response)
- (let ((response-string
- (apply #'format
- (car eudc-inline-expansion-format)
- (mapcar (lambda (field)
- (or (cdr (assq field r))
- ""))
- (eudc-translate-attribute-list
- (cdr eudc-inline-expansion-format))))))
- (if (> (length response-string) 0)
- (push response-string response-strings))))
+ (cl-flet
+ ((run-query
+ (query-formats)
+ (let ((response
+ (eudc-query
+ (eudc-format-query query-words (car query-formats))
+ (eudc-translate-attribute-list
+ (cdr eudc-inline-expansion-format)))))
+ (if response
+ ;; Process response through eudc-inline-expansion-format.
+ (dolist (r response)
+ (let ((response-string
+ (apply #'format
+ (car eudc-inline-expansion-format)
+ (mapcar
+ (lambda (field)
+ (or (cdr (assq field r))
+ ""))
+ (eudc-translate-attribute-list
+ (cdr eudc-inline-expansion-format))))))
+ (if (> (length response-string) 0)
+ (push response-string response-strings))
+ (when (not try-all-servers)
+ (throw 'found nil))))))))
+ (catch 'found
+ ;; Loop on the servers.
+ (dolist (server servers)
+ (eudc-set-server (car server) (cdr server) t)
+
+ ;; Determine which formats apply in the query-format list.
+ (setq query-formats
+ (or
+ (eudc-extract-n-word-formats eudc-inline-query-format
+ (length query-words))
+ (if (null eudc-protocol-has-default-query-attributes)
+ '(name))))
+
+ ;; Loop on query-formats.
+ (while query-formats
+ (run-query query-formats)
+ (setq query-formats (cdr query-formats))))
+ ;; No more servers to try... no match found.
+ nil)
response-strings)
(or (and (equal eudc-server eudc-former-server)
(equal eudc-protocol eudc-former-protocol))
`(["---" nil nil]
["Query with Form" eudc-query-form
:help "Display a form to query the directory server"]
+ ["Expand Inline Query Trying All Servers" eudc-expand-try-all
+ :help "Query all directory servers and expand the query string before point"]
["Expand Inline Query" eudc-expand-inline
:help "Query the directory server, and expand the query string before point"]
["Insert Record into BBDB" eudc-insert-record-at-point-into-bbdb