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)

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.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.

Source Code

;; Defined in /usr/src/emacs/lisp/net/eudc.el.gz
;;;###autoload
(defun eudc-query-with-words (query-words)
  "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.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'."
  (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
	 (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
	(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))))
	  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)))))