branch: externals/calibre
commit 5ddbea80a7a14ef3b4f9f43d41d0b4583daa65a5
Author: Kjartan Oli Agustsson <[email protected]>
Commit: Kjartan Oli Agustsson <[email protected]>

    Add ability to specify tags when adding books
    
    * calibre-library.el (calibre--read-tags): New function.
      (calibre-library-add-book): New optional argument 'tags'.
      Add mode specification to (interactive) declaration.
      (calibre-library-add-books): New optional argument 'tags'.
      (calibre-dired-add): New optional argument 'tags'.
      Add mode specification to (interactive) declaration.
      (calibre-library-add-tags): Factor out calibre--read-tags.
      Add mode specification to (interactive) declaration.
      (calibre-library-remove-tags): Factor out calibre--read-tags.
      Add mode specification to (interactive) declaration.
    * doc/calibre.texi (Tagging added books): New paragraph mentioning the
      new prefix argument behaviour of calibre-library-add-book and
      calibre-dired-add.
    * etc/NEWS: New section mentioning the new prefix argument behaviourof
      calibre-library-add-book and calibre-dired-add.
---
 calibre-library.el | 47 +++++++++++++++++++++++++++++++----------------
 doc/calibre.texi   |  5 +++++
 etc/NEWS           |  5 +++++
 3 files changed, 41 insertions(+), 16 deletions(-)

diff --git a/calibre-library.el b/calibre-library.el
index d5afffafb2..66db3151a4 100644
--- a/calibre-library.el
+++ b/calibre-library.el
@@ -42,33 +42,47 @@ opening books in that format."
   :group 'calibre
   :package-version '("calibre" . "1.4.0"))
 
+(defun calibre--read-tags ()
+  "Prompt the user for a list of tags."
+  (completing-read-multiple "Tag: " calibre-tags-completion-table))
+
 ;;;###autoload
-(defun calibre-library-add-book (file)
-  "Add FILE to the Calibre library."
-  (interactive "f")
-  (calibre-library-add-books (list file)))
+(defun calibre-library-add-book (file &optional tags)
+  "Add FILE to the Calibre library.
+
+TAGS should be a list of strings to add to FILE."
+  (interactive (list (read-file-name "File: " nil nil t)
+                     (if current-prefix-arg (calibre--read-tags) nil))
+               calibre-library-mode)
+  (calibre-library-add-books (list file) tags))
+
+(defun calibre-library-add-books (files &optional tags)
+  "Add FILES to the Calibre library.
 
-(defun calibre-library-add-books (files)
-  "Add FILES to the Calibre library."
+TAGS should be a list of strings to add to FILE."
   (calibre-exec--queue-command
    `("add" "-r"
      ,@(mapcar #'expand-file-name files)
-     ,@(if calibre-default-tags
-           (list "--tags" (string-join calibre-default-tags ","))
+     ,@(if (or tags calibre-default-tags)
+           (list "--tags" (string-join (append tags calibre-default-tags) ","))
          nil)))
   (calibre-exec--start-execution))
 
 ;;;###autoload
-(defun calibre-dired-add ()
-  "Add marked files to the Calibre library."
-    (interactive)
+(defun calibre-dired-add (&optional tags)
+  "Add marked files to the Calibre library.
+
+TAGS should be a list of strings to add to FILE."
+  (interactive (list (if current-prefix-arg (calibre--read-tags) nil))
+               dired-mode)
     (if (derived-mode-p 'dired-mode)
-        (calibre-library-add-books (dired-get-marked-files))))
+        (calibre-library-add-books (dired-get-marked-files) tags)))
 
 (defun calibre-library-add-tags (tags books)
   "Add TAGS to BOOKS if not already present."
-  (interactive (list (completing-read-multiple "Tag: " 
calibre-tags-completion-table)
-                     (or (calibre-library-get-marked) (list 
(tabulated-list-get-id)))))
+  (interactive (list (calibre--read-tags)
+                     (or (calibre-library-get-marked) (list 
(tabulated-list-get-id))))
+               calibre-library-mode)
   (dolist (tag tags)
     (dolist (book books)
       (calibre-edit-add-tag tag book)))
@@ -76,8 +90,9 @@ opening books in that format."
 
 (defun calibre-library-remove-tags (tags books)
   "Remove TAGS from BOOKS if present."
-  (interactive (list (completing-read-multiple "Tag: " 
calibre-tags-completion-table)
-                     (or (calibre-library-get-marked) (list 
(tabulated-list-get-id)))))
+  (interactive (list (calibre--read-tags)
+                     (or (calibre-library-get-marked) (list 
(tabulated-list-get-id))))
+               calibre-library-mode)
   (dolist (tag tags)
     (dolist (book books)
       (calibre-edit-remove-tag tag book)))
diff --git a/doc/calibre.texi b/doc/calibre.texi
index af1fb2aa67..d053d826cb 100644
--- a/doc/calibre.texi
+++ b/doc/calibre.texi
@@ -319,6 +319,11 @@ for example to tag all books as ``unread'', you can 
customise
 @code{calibre-default-tags}.  Any tag present in this list will be
 automatically added to the book.
 
+For more specific control over tags both @code{calibre-library-add-book}
+and @code{calibre-dired-add} can be called with a prefix argument.  When
+called with a prefix argument they will prompt for a list of tags to
+apply to the books being added.
+
 @node Modifying books
 @section Modifying books
 calibre.el provides two methods of modifying book metadata.  A dedicated
diff --git a/etc/NEWS b/etc/NEWS
index 49e8bc4a18..09e0fd5eb6 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -20,6 +20,11 @@ operate on all of the marked books.
 The new defcustom calibre-default-tags allows specifying a list of
 tags which should be applied to all books added to the library.
 
+** Add ability to specify tags to apply when adding books.
+calibre-library-add-book and calibre-dired-add now accept a prefix
+argument.  When called with a prefix argument they will prompt for
+tags which should be applied to the books being added.
+
 
 * Changes in calibre.el 1.4.1
 ** Fix sorting by series

Reply via email to