auth-source.el (auth-source-netrc-create): Use `read-char' with no argument that...
[gnus] / lisp / auth-source.el
index 59b5ebb..467aa10 100644 (file)
@@ -908,6 +908,11 @@ See `auth-source-search' for details on SPEC."
                             (plist-put spec :create nil)))))
     results))
 
+(defun auth-source-netrc-element-or-first (v)
+  (if (listp v)
+      (nth 0 v)
+    v))
+
 ;;; (auth-source-search :host "nonesuch" :type 'netrc :max 1 :create t)
 ;;; (auth-source-search :host "nonesuch" :type 'netrc :max 1 :create t :create-extra-keys '((A "default A") (B)))
 
@@ -953,9 +958,7 @@ See `auth-source-search' for details on SPEC."
     (dolist (r required)
       (let* ((data (aget valist r))
              ;; take the first element if the data is a list
-             (data (if (listp data)
-                       (nth 0 data)
-                     data))
+             (data (auth-source-netrc-element-or-first data))
              ;; this is the default to be offered
              (given-default (aget auth-source-creation-defaults r))
              ;; the default supplementals are simple: for the user,
@@ -971,10 +974,22 @@ See `auth-source-search' for details on SPEC."
                ((and (null data) (eq r 'secret))
                 ;; special case prompt for passwords
                 (read-passwd (format "Password for %s@%s:%s: "
-                                     (or (aget valist 'user) "[any user]")
-                                     (or (aget valist 'host) "[any host]")
-                                     (or (aget valist 'port) "[any port]"))))
-               (t data)))
+                                     (or
+                                      (auth-source-netrc-element-or-first
+                                       (aget valist 'user))
+                                      (plist-get artificial :user)
+                                      "[any user]")
+                                     (or
+                                      (auth-source-netrc-element-or-first
+                                       (aget valist 'host))
+                                      (plist-get artificial :host)
+                                      "[any host]")
+                                     (or
+                                      (auth-source-netrc-element-or-first
+                                       (aget valist 'port))
+                                      (plist-get artificial :port)
+                                      "[any port]"))))
+               (t (or data default))))
 
         (when data
           (setq artificial (plist-put artificial
@@ -1021,13 +1036,13 @@ See `auth-source-search' for details on SPEC."
       (goto-char (point-max))
 
       ;; ask AFTER we've successfully opened the file
-      (let (done k)
+      (let ((prompt (format "Add to file %s? %s: "
+                            file
+                            "(y)es/(n)o but use it/(e)dit line/(s)kip file"))
+            done k)
         (while (not done)
-          (setq k (read-char-choice
-                   (format "Add to file %s? %s: "
-                           file
-                           "(y)es/(n)o but use it/(e)dit line/(s)kip file")
-                   '(?y ?n ?e ?s)))
+         (message "%s" prompt)
+          (setq k (read-char))
           (case k
             (?y (setq done t))
             (?n (setq add ""