emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ebdb fd66ed0 05/11: Add optional "shortcut" arg to ebdb


From: Eric Abrahamsen
Subject: [elpa] externals/ebdb fd66ed0 05/11: Add optional "shortcut" arg to ebdb-prompt-for-db
Date: Sun, 22 Oct 2017 13:17:02 -0400 (EDT)

branch: externals/ebdb
commit fd66ed012e6dd85469e37a33bbadb46b867fdfe1
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>

    Add optional "shortcut" arg to ebdb-prompt-for-db
    
    * ebdb.el (ebdb-prompt-for-db): If non-nil and there's only one
      database, just return it without prompting.
    * ebdb-migrate.el (ebdb-migrate-from-bbdb): Adjust call.
    * ebdb-com.el (ebdb-create-record-extended): Adjust call.
---
 ebdb-com.el     |  5 +----
 ebdb-migrate.el |  4 +---
 ebdb.el         | 29 ++++++++++++++++++-----------
 3 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/ebdb-com.el b/ebdb-com.el
index 4e31108..449049a 100644
--- a/ebdb-com.el
+++ b/ebdb-com.el
@@ -1573,10 +1573,7 @@ in `ebdb-db-list', using its default record class.  Use
 ;;;###autoload
 (defun ebdb-create-record-extended ()
   (interactive)
-  (let ((db
-        (if (= 1 (length ebdb-db-list))
-            (car ebdb-db-list)
-          (ebdb-prompt-for-db)))
+  (let ((db (ebdb-prompt-for-db nil t))
        (record-class
         (eieio-read-subclass "Use which record class? " 'ebdb-record nil t)))
     (ebdb-create-record db record-class)))
diff --git a/ebdb-migrate.el b/ebdb-migrate.el
index f1d1a0b..0375757 100644
--- a/ebdb-migrate.el
+++ b/ebdb-migrate.el
@@ -404,9 +404,7 @@ BBDB sets the default of that option."
     (when (and (/= (point-min) (point-max))
               (yes-or-no-p "Upgrade from previous version of BBDB? "))
       (let ((v-records (ebdb-migrate-parse-records))
-           (target-db (if (= (length ebdb-db-list) 1)
-                          (car ebdb-db-list)
-                        (ebdb-prompt-for-db)))
+           (target-db (ebdb-prompt-for-db nil t))
            (total 0)
            c-records duds)
        (message "Migrating records from BBDB...")
diff --git a/ebdb.el b/ebdb.el
index 65fc15f..f9a12a8 100644
--- a/ebdb.el
+++ b/ebdb.el
@@ -4118,19 +4118,26 @@ Returns a list of (\"label\" slot . field-class)."
     (or (assoc choice field-list)
        (list choice (cons 'fields 'ebdb-field-user-simple)))))
 
-(defun ebdb-prompt-for-db (&optional db-list)
+(defun ebdb-prompt-for-db (&optional db-list shortcut)
+  "Prompt the user to choose a database.
+Possible choices come from `ebdb-db-list', or from DB-LIST, if
+that argument is given.  If SHORTCUT is non-nil, don't bother
+prompting if there's only one database."
   (unless (or db-list ebdb-db-list)
     (ebdb-load))
-  (let* ((collection (or db-list ebdb-db-list))
-        (db-string
-         (ebdb-read-string "Choose a database: "
-                           nil
-                           (mapcar
-                            (lambda (d)
-                              (slot-value d 'object-name))
-                            collection)
-                           t)))
-    (object-assoc db-string 'object-name collection)))
+  (let ((collection (or db-list ebdb-db-list))
+       db-string)
+    (if (and shortcut (= 1 (length collection)))
+       (car collection)
+      (setq db-string
+           (ebdb-read-string "Choose a database: "
+                             nil
+                             (mapcar
+                              (lambda (d)
+                                (slot-value d 'object-name))
+                              collection)
+                             t))
+      (object-assoc db-string 'object-name collection))))
 
 (defun ebdb-prompt-for-mail (record)
   (let ((mail-alist (mapcar



reply via email to

[Prev in Thread] Current Thread [Next in Thread]