From 59a2d4c2ef7a5878857e2aa786c9ac03bbdfc6ff Mon Sep 17 00:00:00 2001 From: Ted Zlatanov Date: Tue, 10 Jan 2012 09:45:05 -0500 Subject: [PATCH] * auth-source.el (auth-source-user-and-password): Add convenience wrapper to search by just host and optionally user. --- lisp/ChangeLog | 5 +++++ lisp/auth-source.el | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 5799dcb98..3148fb203 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2012-01-10 Teodor Zlatanov + + * auth-source.el (auth-source-user-and-password): Add convenience + wrapper to search by just host and optionally user. + 2012-01-07 Lars Magne Ingebrigtsen * shr.el (shr-visit-file): Move point to the beginning of the buffer diff --git a/lisp/auth-source.el b/lisp/auth-source.el index 978682f26..de2fecf44 100644 --- a/lisp/auth-source.el +++ b/lisp/auth-source.el @@ -1791,6 +1791,26 @@ MODE can be \"login\" or \"password\"." found)) +(defun auth-source-user-and-password (host &optional user) + (let* ((auth-info (car + (if user + (auth-source-search + :host host + :user "yourusername" + :max 1 + :require '(:user :secret) + :create nil) + (auth-source-search + :host host + :max 1 + :require '(:user :secret) + :create nil)))) + (user (plist-get auth-info :user)) + (password (plist-get auth-info :secret))) + (when (functionp password) + (setq password (funcall password))) + (list user password auth-info))) + (provide 'auth-source) ;;; auth-source.el ends here -- 2.34.1