Function: eudc-query-with-words

eudc-query-with-words is an autoloaded and byte-compiled function defined in eudc.el.gz.

Signature

(eudc-query-with-words QUERY-WORDS &optional TRY-ALL-SERVERS)

Documentation

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. After querying the server for the given string, the expansion specified by eudc-inline-expansion-format is applied to the matches before returning them. Multiple servers can be tried with the same query until one finds a match,
see eudc-inline-expansion-servers. When TRY-ALL-SERVERS is non-nil,
keep collecting results from subsequent servers after the first match.

Source Code

;; Defined in /usr/src/emacs/lisp/net/eudc.el.gz
;;;###autoload
(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.
After querying the server for the given string, the expansion
specified by `eudc-inline-expansion-format' is applied to the
matches before returning them.
Multiple servers can be tried with the same query until one finds a match,
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
	(call-interactively 'eudc-set-server)))
   ((eq eudc-inline-expansion-servers 'server-then-hotlist)
    (or eudc-server
	;; Allow server to be nil if hotlist is set.
	eudc-server-hotlist
	(call-interactively 'eudc-set-server)))
   ((eq eudc-inline-expansion-servers 'hotlist)
    (or eudc-server-hotlist
	(error "No server in the hotlist")))
   (t
    (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
	 (servers
	  (cond
	   ((eq eudc-inline-expansion-servers 'hotlist)
	    eudc-server-hotlist)
	   ((eq eudc-inline-expansion-servers 'server-then-hotlist)
	    (if eudc-server
		(cons (cons eudc-server eudc-protocol)
		      (delete (cons eudc-server eudc-protocol)
			      (copy-sequence eudc-server-hotlist)))
	      eudc-server-hotlist))
	   ((eq eudc-inline-expansion-servers 'current-server)
	    (list (cons eudc-server eudc-protocol))))))

    (if (and eudc-max-servers-to-query
	     (> (length servers) eudc-max-servers-to-query))
	(setcdr (nthcdr (1- eudc-max-servers-to-query) servers) nil))

    (unwind-protect
	(cl-flet
	    ((run-query
              (query-formats)
              (let* ((query-attrs (eudc-translate-attribute-list
                                        (if (consp eudc-inline-expansion-format)
                                            (cdr eudc-inline-expansion-format)
                                          '(firstname name email))))
                     (response
                      (eudc-query
                       (eudc-format-query query-words (car query-formats))
                       query-attrs)))
                (when response
                  ;; Format response.
                  (dolist (r response)
                    (let ((response-string
                           (eudc-format-inline-expansion-result r query-attrs)))
                      (if response-string
                          (cl-pushnew response-string response-strings
                                      :test #'equal))))
                  (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))
	  (eudc-set-server eudc-former-server eudc-former-protocol t)))))