Function: erc--auth-source-search
erc--auth-source-search is a byte-compiled function defined in
erc.el.gz.
Signature
(erc--auth-source-search &rest DEFAULTS)
Documentation
Ask auth-source for a secret and return it if found.
Use DEFAULTS as keyword arguments for querying auth-source and as a guide for narrowing results. Return a string if found or nil otherwise. The ordering of DEFAULTS influences how results are filtered, as does the ordering of the members of any individual composite values. If necessary, the former takes priority. For example, if DEFAULTS were to contain
:host ("foo" "bar") :port ("123" "456")
the secret from an auth-source entry of host foo and port 456 would be chosen over another of host bar and port 123. However, if DEFAULTS looked like
:port ("123" "456") :host ("foo" "bar")
the opposite would be true. In both cases, two entries with the same host but different ports would result in the one with port 123 getting the nod. Much the same would happen for entries sharing only a port: the one with host foo would win.
Source Code
;; Defined in /usr/src/emacs/lisp/erc/erc.el.gz
(defun erc--auth-source-search (&rest defaults)
"Ask auth-source for a secret and return it if found.
Use DEFAULTS as keyword arguments for querying auth-source and as a
guide for narrowing results. Return a string if found or nil otherwise.
The ordering of DEFAULTS influences how results are filtered, as does
the ordering of the members of any individual composite values. If
necessary, the former takes priority. For example, if DEFAULTS were to
contain
:host (\"foo\" \"bar\") :port (\"123\" \"456\")
the secret from an auth-source entry of host foo and port 456 would be
chosen over another of host bar and port 123. However, if DEFAULTS
looked like
:port (\"123\" \"456\") :host (\"foo\" \"bar\")
the opposite would be true. In both cases, two entries with the same
host but different ports would result in the one with port 123 getting
the nod. Much the same would happen for entries sharing only a port:
the one with host foo would win."
(when-let*
((auth-source-backend-parser-functions
(erc-compat--auth-source-backend-parser-functions))
(priority (map-keys defaults))
(test (lambda (a b)
(catch 'done
(dolist (key priority)
(let* ((d (plist-get defaults key))
(defval (if (listp d) d (list d)))
;; featurep 'seq via auth-source > json > map
(p (seq-position defval (plist-get a key)))
(q (seq-position defval (plist-get b key))))
(unless (eql p q)
(throw 'done (when p (or (not q) (< p q))))))))))
(plist (copy-sequence defaults)))
(unless (plist-get plist :max)
(setq plist (plist-put plist :max 5000))) ; `auth-source-netrc-parse'
(unless (plist-get defaults :require)
(setq plist (plist-put plist :require '(:secret))))
(when-let* ((sorted (sort (apply #'auth-source-search plist) test)))
(plist-get (car sorted) :secret))))