branch: externals/calibre
commit 76427bf5be3a96985d7f45d07b06d3316f81ab1b
Author: Kjartan Óli Ágústsson <[email protected]>
Commit: Kjartan Óli Ágústsson <[email protected]>
Allow customisation of the columns of the library buffer
* calibre-book.el (calibre-book--print-info): Generate the info vector
based on the contents of calibre-library-columns
* calibre-library.el (calibre-library--header-format): Created
(calibre-library-mode): Use the new calibre-library--header-format
function instead of a hard coded vector of headers.
* calibre.el (calibre-library-columns): Created
---
calibre-book.el | 22 ++++++++++++++--------
calibre-library.el | 30 ++++++++++++++++++++----------
calibre.el | 26 ++++++++++++++++++++++++++
3 files changed, 60 insertions(+), 18 deletions(-)
diff --git a/calibre-book.el b/calibre-book.el
index c421b0133b..18ff8ef813 100644
--- a/calibre-book.el
+++ b/calibre-book.el
@@ -109,14 +109,20 @@ ENTRY is a list of the form:
"Return list suitable as a value of `tabulated-list-entries'.
BOOK is a `calibre-book'."
(list book
- (with-slots (id title authors series series-index tags formats) book
- `[,(int-to-string id)
- ,title
- ,(string-join authors ", ")
- ,(if (not series) "" series)
- ,(if series (format "%.1f" series-index) "")
- ,(string-join tags ", ")
- ,(string-join (mapcar (lambda (f) (upcase (symbol-name f)))
formats) ", ")])))
+ (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."
diff --git a/calibre-library.el b/calibre-library.el
index f74d94e4dc..70df68488a 100644
--- a/calibre-library.el
+++ b/calibre-library.el
@@ -97,6 +97,25 @@ ARGS should be a list of strings. SENTINEL is a process
sentinel to install."
(interactive (list (tabulated-list-get-id)) calibre-library-mode)
(find-file (calibre-book--file book (calibre-book--pick-format book))))
+(defun calibre-library--header-format ()
+ (vconcat
+ (mapcar (lambda (x)
+ (let ((column (car x))
+ (width (cdr x)))
+ (cl-case column
+ (id `("ID" ,width (lambda (a b)
+ (< (calibre-book-id (car a))
+ (calibre-book-id (car b))))))
+ (title `("Title" ,width))
+ (authors `("Author(s)" ,width))
+ (publishers `("Publisher(s)" ,width))
+ (series `("Series" ,width (lambda (a b)
+ (calibre-book-sort-by-series (car
a) (car b)))))
+ (series-index `("#" ,width))
+ (tags `("Tags" ,width))
+ (formats `("Formats" ,width)))))
+ calibre-library-columns)))
+
(defvar-keymap calibre-library-mode-map
:doc "Local keymap for Calibre Library buffers."
:parent tabulated-list-mode-map
@@ -110,16 +129,7 @@ ARGS should be a list of strings. SENTINEL is a process
sentinel to install."
(define-derived-mode calibre-library-mode tabulated-list-mode
(setf tabulated-list-padding 2
- tabulated-list-format
- [("ID" 4 (lambda (a b)
- (< (calibre-book-id (car a)) (calibre-book-id (car b)))))
- ("Title" 35 t)
- ("Author(s)" 20 t)
- ("Series" 15 (lambda (a b)
- (calibre-book-sort-by-series (car a) (car b))))
- ("#" 3 nil)
- ("Tags" 10 nil)
- ("Formats" 10 nil)])
+ tabulated-list-format (calibre-library--header-format))
(tabulated-list-init-header))
;;;###autoload
diff --git a/calibre.el b/calibre.el
index 921ad8f3fd..6b1b43decc 100644
--- a/calibre.el
+++ b/calibre.el
@@ -38,6 +38,32 @@
:type 'string
:package-version '("calibre" . "0.1.0"))
+(defcustom calibre-library-columns '((id . 4)
+ (title . 35)
+ (authors . 20)
+ (publishers . 10)
+ (series . 15)
+ (series-index . 3)
+ (tags . 10)
+ (formats . 10))
+ "The metadata fields to display in the library buffer.
+Each entry is a key identifying a metadata field and the width that
+column should have."
+ :type '(repeat (cons
+ :tag "Column"
+ (choice
+ :tag "Attribute"
+ (const :tag "ID" id)
+ (const :tag "Title" title)
+ (const :tag "Author(s)" authors)
+ (const :tag "Publisher(s)" publishers)
+ (const :tag "Series" series)
+ (const :tag "Series Index" series-index)
+ (const :tag "Tags" tags)
+ (const :tag "Formats" formats))
+ (integer :tag "Width")))
+ :package-version '("calibre" . "0.1.0"))
+
(defcustom calibre-library-dir "~/Documents/Calibre"
"The root directory of the Calibre library."
:type 'directory