Function: eudc-format-inline-expansion-result

eudc-format-inline-expansion-result is an autoloaded and byte-compiled function defined in eudc.el.gz.

Signature

(eudc-format-inline-expansion-result RES QUERY-ATTRS)

Documentation

Format a query result RES according to eudc-inline-expansion-format.

QUERY-ATTRS is a list of attributes to include in the expansion.

Source Code

;; Defined in /usr/src/emacs/lisp/net/eudc.el.gz
;;;###autoload
(defun eudc-format-inline-expansion-result (res query-attrs)
  "Format a query result RES according to `eudc-inline-expansion-format'.
QUERY-ATTRS is a list of attributes to include in the expansion."
  (cond
   ;; format string
   ((consp eudc-inline-expansion-format)
    (string-trim (apply #'format
                        (car eudc-inline-expansion-format)
                        (mapcar
                         (lambda (field)
                           (or (cdr (assq field res))
                               ""))
                         (eudc-translate-attribute-list
                          (cdr eudc-inline-expansion-format))))))

   ;; formatting function
   ((functionp eudc-inline-expansion-format)
    (let ((addr (cdr (assq (nth 2 query-attrs) res)))
          (ucontent (funcall eudc-inline-expansion-format res)))
      (if (and ucontent
               (listp ucontent))
          (let* ((phrase (car ucontent))
                 (comment (cadr ucontent))
                 (phrase-given
                  (and phrase
                       (stringp phrase)
                       (not (string-blank-p phrase))))
                 (valid-comment-given
                  (and comment
                       (stringp comment)
                       (not (string-blank-p comment))
                       (eudc-rfc5322-valid-comment-p
                        comment))))
            (eudc-rfc5322-make-address
             addr nil
             (if phrase-given phrase nil)
             (if valid-comment-given comment nil)))
        (progn
          (error "Error: the function referenced by \
`eudc-inline-expansion-format' is expected to return a list")
          nil))))

   ;; fallback behavior (nil function, or non-matching type)
   (t
    (let ((fname (cdr (assq (nth 0 query-attrs) res)))
          (lname (cdr (assq (nth 1 query-attrs) res)))
          (addr (cdr (assq (nth 2 query-attrs) res))))
      (eudc-rfc5322-make-address addr fname lname)))))