branch: externals/calibre
commit ecf03e1842c7c1a17852d543c1cf3df6495e87d6
Author: Kjartan Óli Ágústsson <[email protected]>
Commit: Kjartan Óli Ágústsson <[email protected]>
Fix circular dependencies and byte compiler warnings
* calibre-book.el: Require parse-time.
Don't require calibre-util and calibre.
(calibre-parse-timestamp, calibre-format-preferences): Move into
calibre-book.el.
(calibre-book--print-info, calibre-book--file): Move into calibre-util.el.
* calibre-library.el: Don't require calibre-book.
Require calibre-util.
(calibre-library-buffer, calibre-library--refresh): Move into
calibre-util.el.
(calibre-remove-books, calibre-library-remove-books): Rename
calibre-remove-books to calibre-library-remove-books.
(calibre-library-execute): Call calibre-library-remove-books instead
of calibre-remove-books.
* calibre-util.el: Change short description.
Add Commentary section.
Don't require parse-time.
Require calibre.
(calibre--books, calibre-select-library, calibre--library,
calibre-library-buffer, calibre-library--refresh,
calibre-book--print-info, calibre-parse-timestamp,
calibre-book--file): Move into calibre-util.el.
* calibre.el: (calibre-library--refresh): Don't declare
calibre-library--refresh.
(calibre-book): Require calibre-book.
(calibre--books, calibre--library, calibre-select-library): Move into
calibre-util.el.
---
calibre-book.el | 39 ++++++++-------------------
calibre-library.el | 18 +++----------
calibre-util.el | 79 +++++++++++++++++++++++++++++++++++++++++++++++++-----
calibre.el | 32 +---------------------
4 files changed, 88 insertions(+), 80 deletions(-)
diff --git a/calibre-book.el b/calibre-book.el
index fd973f8856..718661c9eb 100644
--- a/calibre-book.el
+++ b/calibre-book.el
@@ -26,10 +26,14 @@
;;; Code:
(require 'eieio)
+(require 'parse-time)
-(require 'calibre-util)
(require 'calibre-db)
-(require 'calibre)
+
+(defun calibre-parse-timestamp (timestamp)
+ "Return a Lisp timestamp from TIMESTAMP.
+TIMESTAMP is a string of the form YYYY-MM-DD HH:MM:SS.xxxxxx+00:00."
+ (parse-iso8601-time-string (string-replace " " "T" timestamp)))
(defclass calibre-book ()
((id :initarg :id
@@ -109,32 +113,11 @@ ENTRY is a list of the form:
:path path
:file-name (calibre-db--get-book-file-name id))))
-(defun calibre-book--print-info (book)
- "Return list suitable as a value of `tabulated-list-entries'.
-BOOK is a `calibre-book'."
- (list book
- (with-slots (id title authors publishers series series-index tags
formats) book
- (vconcat (mapcar (lambda (x)
- (let ((column (car x))
- (width (cdr x)))
- (cl-case column
- (id (format (format "%%%ds" width) id))
- (title title)
- (authors (string-join authors ", "))
- (publishers (string-join publishers ", "))
- (series (if (not series) "" series))
- (series-index (if series (format "%.1f"
series-index) ""))
- (tags (string-join tags ", "))
- (formats (string-join (mapcar (lambda (f)
(upcase (symbol-name f))) formats) ", ")))))
- calibre-library-columns)))))
-
-(defun calibre-book--file (book format)
- "Return the path to BOOK in FORMAT."
- (with-slots (path file-name) book
- (message "%S" file-name)
- (file-name-concat (calibre--library)
- path
- (message "%s.%s" file-name format))))
+(defcustom calibre-format-preferences '(pdf epub)
+ "The preference order of file formats."
+ :type '(repeat symbol :tag "Format")
+ :package-version '("calibre" . "0.1.0")
+ :group 'calibre)
(defun calibre-book--pick-format (book)
"Return the preferred format for BOOK."
diff --git a/calibre-library.el b/calibre-library.el
index 66fbba24e5..da4dc7d194 100644
--- a/calibre-library.el
+++ b/calibre-library.el
@@ -24,19 +24,7 @@
;;; Code:
(require 'dired)
-(require 'calibre-book)
-
-(defconst calibre-library-buffer "*Library*")
-
-(defun calibre-library--refresh (&optional force)
- "Refresh the contents of the library buffer.
-If FORCE is non-nil fetch book data from the database."
- (let* ((buffer (get-buffer calibre-library-buffer)))
- (with-current-buffer buffer
- (setf tabulated-list-entries
- (mapcar #'calibre-book--print-info
- (calibre--books force)))
- (tabulated-list-print))))
+(require 'calibre-util)
;;;###autoload
(defun calibre-library-add-book (file)
@@ -55,7 +43,7 @@ If FORCE is non-nil fetch book data from the database."
(if (derived-mode-p 'dired-mode)
(calibre-library-add-books (dired-get-marked-files))))
-(defun calibre-remove-books (books)
+(defun calibre-library-remove-books (books)
"Remove BOOKS from the Calibre library."
(let ((ids (mapcar #'int-to-string (mapcar #'calibre-book-id books))))
(calibre-library--execute `("remove" ,(string-join ids ",")))))
@@ -100,7 +88,7 @@ ARGS should be a list of strings. SENTINEL is a process
sentinel to install."
(cl-case mark
(?\D (push (tabulated-list-get-id) remove-list)))
(forward-line)))
- (when remove-list (calibre-remove-books remove-list)))
+ (when remove-list (calibre-library-remove-books remove-list)))
(calibre--books t)
(calibre-library--refresh))
diff --git a/calibre-util.el b/calibre-util.el
index 7dfa77f1a7..59ed2c1604 100644
--- a/calibre-util.el
+++ b/calibre-util.el
@@ -1,4 +1,4 @@
-;;; calibre-util.el --- Small utilities that have no better place -*-
lexical-binding:t -*-
+;;; calibre-util.el --- Break circular dependencies in other parts -*-
lexical-binding:t -*-
;; Copyright (C) 2023 Kjartan Oli Agustsson
@@ -20,13 +20,80 @@
;; You should have received a copy of the GNU General Public License
;; along with calibre.el. If not, see <http://www.gnu.org/licenses/>.
+;;; Commentary:
+;; This file contains functions and variables that might conceptually
+;; belong in other files, whose presence in those files would create a
+;; circular dependency.
+
;;; Code:
-(require 'parse-time)
+(require 'calibre)
+
+(defvar calibre--books nil)
+(defun calibre--books (&optional force)
+ "Return the in memory list of books.
+If FORCE is non-nil the list is refreshed from the database."
+ (when (or force (not calibre--books))
+ (setf calibre--books (calibre-db--get-books)))
+ calibre--books)
+
+(defun calibre-select-library (&optional library)
+ "Prompt the user to select a library from `calibre-libraries'.
+If LIBRARY is non-nil, select that instead."
+ (interactive)
+ (setf calibre--library (if library
+ library
+ (completing-read "Library: "
(calibre--library-names) nil t))
+ calibre--db nil
+ calibre--books nil)
+ (calibre-library--refresh t))
+
+(defvar calibre--library nil
+ "The active library.")
+
+(defun calibre--library ()
+ "Return the active library.
+If no library is active, prompt the user to select one."
+ (unless calibre--library
+ (calibre-select-library))
+ (alist-get calibre--library calibre-libraries nil nil #'string=))
+
+(defconst calibre-library-buffer "*Library*")
+(defun calibre-library--refresh (&optional force)
+ "Refresh the contents of the library buffer.
+If FORCE is non-nil fetch book data from the database."
+ (let* ((buffer (get-buffer calibre-library-buffer)))
+ (with-current-buffer buffer
+ (setf tabulated-list-entries
+ (mapcar #'calibre-book--print-info
+ (calibre--books force)))
+ (tabulated-list-print))))
+
+(defun calibre-book--print-info (book)
+ "Return list suitable as a value of `tabulated-list-entries'.
+BOOK is a `calibre-book'."
+ (list book
+ (with-slots (id title authors publishers series series-index tags
formats) book
+ (vconcat (mapcar (lambda (x)
+ (let ((column (car x))
+ (width (cdr x)))
+ (cl-case column
+ (id (format (format "%%%ds" width) id))
+ (title title)
+ (authors (string-join authors ", "))
+ (publishers (string-join publishers ", "))
+ (series (if (not series) "" series))
+ (series-index (if series (format "%.1f"
series-index) ""))
+ (tags (string-join tags ", "))
+ (formats (string-join (mapcar (lambda (f)
(upcase (symbol-name f))) formats) ", ")))))
+ calibre-library-columns)))))
-(defun calibre-parse-timestamp (timestamp)
- "Return a Lisp timestamp from TIMESTAMP.
-TIMESTAMP is a string of the form YYYY-MM-DD HH:MM:SS.xxxxxx+00:00."
- (parse-iso8601-time-string (string-replace " " "T" timestamp)))
+(defun calibre-book--file (book format)
+ "Return the path to BOOK in FORMAT."
+ (with-slots (path file-name) book
+ (message "%S" file-name)
+ (file-name-concat (calibre--library)
+ path
+ (message "%s.%s" file-name format))))
(provide 'calibre-util)
;;; calibre-util.el ends here
diff --git a/calibre.el b/calibre.el
index 381f60738f..c338f1a732 100644
--- a/calibre.el
+++ b/calibre.el
@@ -27,8 +27,7 @@
;;; Code:
(require 'calibre-db)
-
-(declare-function calibre-library--refresh "calibre-library.el")
+(require 'calibre-book)
(defgroup calibre nil
"Interact with a Calibre library."
@@ -72,39 +71,10 @@ column should have."
(directory :tag "Location")))
:package-version '("calibre" . "0.1.0"))
-(defvar calibre--books nil)
-(defun calibre--books (&optional force)
- "Return the in memory list of books.
-If FORCE is non-nil the list is refreshed from the database."
- (when (or force (not calibre--books))
- (setf calibre--books (calibre-db--get-books)))
- calibre--books)
-
(defun calibre--library-names ()
"Return a list of the names of defined libraries."
(mapcar #'car calibre-libraries))
-(defvar calibre--library nil
- "The active library.")
-
-(defun calibre-select-library (&optional library)
- "Prompt the user to select a library from `calibre-libraries'.
-If LIBRARY is non-nil, select that instead."
- (interactive)
- (setf calibre--library (if library
- library
- (completing-read "Library: "
(calibre--library-names) nil t))
- calibre--db nil
- calibre--books nil)
- (calibre-library--refresh t))
-
-(defun calibre--library ()
- "Return the active library.
-If no library is active, prompt the user to select one."
- (unless calibre--library
- (calibre-select-library))
- (alist-get calibre--library calibre-libraries nil nil #'string=))
-
(defcustom calibre-format-preferences '(pdf epub)
"The preference order of file formats."
:type '(repeat symbol :tag "Format")