* auth-source.el (auth-source-user-and-password): Add convenience wrapper to search...
authorTed Zlatanov <tzz@lifelogs.com>
Tue, 10 Jan 2012 14:45:05 +0000 (09:45 -0500)
committerTed Zlatanov <tzz@lifelogs.com>
Tue, 10 Jan 2012 14:45:05 +0000 (09:45 -0500)
lisp/ChangeLog
lisp/auth-source.el

index 5799dcb..3148fb2 100644 (file)
@@ -1,3 +1,8 @@
+2012-01-10  Teodor Zlatanov  <tzz@lifelogs.com>
+
+       * 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  <larsi@gnus.org>
 
        * shr.el (shr-visit-file): Move point to the beginning of the buffer
index 978682f..de2fecf 100644 (file)
@@ -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