Synch to No Gnus 200408041711.
[elisp/gnus.git-] / lisp / password.el
index 4683a9c..e4fb910 100644 (file)
 ;;
 ;; (password-cache-add "test" "foo")
 ;;  => nil
-;;
+
+;; Note the previous two can be replaced with:
+;; (password-read-and-add "Password? " "test")
+;; ;; Minibuffer prompt for password.
+;; => "foo"
+;; ;; "foo" is now cached with key "test"
+
+
 ;; (password-read "Password? " "test")
 ;; ;; No minibuffer prompt
 ;;  => "foo"
@@ -83,6 +90,15 @@ The variable `password-cache' control whether the cache is used."
           (symbol-value (intern-soft key password-data)))
       (read-passwd prompt)))
 
+(defun password-read-and-add (prompt &optional key)
+  "Read password, for use with KEY, from user, or from cache if wanted.
+Then store the password in the cache.  Uses `password-read' and
+`password-cache-add'."
+  (let ((password (password-read prompt key)))
+    (when (and password key)
+      (password-cache-add key password))
+    password))
+
 (defun password-cache-remove (key)
   "Remove password indexed by KEY from password cache.
 This is typically run be a timer setup from `password-cache-add',