branch: externals/calibre
commit 4a0d5b9606455c50dc5ea69d93fcf09bb0c755d3
Author: Kjartan Óli Ágústsson <[email protected]>
Commit: Kjartan Óli Ágústsson <[email protected]>

    Factor the setting of the Library header into a function
    
    * calibre-db.el (calibre-library--set-header): Create
    (calibre-library--header-format): Move from calibre-library.el.
    * calibre-library.el (calibre-library--header-format): Move to calibre-db.el
    (calibre-library-mode): Call calibre-library--set-header instead of
    using setf.
---
 calibre-db.el      | 29 +++++++++++++++++++++++++++++
 calibre-library.el | 31 +++----------------------------
 2 files changed, 32 insertions(+), 28 deletions(-)

diff --git a/calibre-db.el b/calibre-db.el
index 9f865a269d..60cd02163e 100644
--- a/calibre-db.el
+++ b/calibre-db.el
@@ -153,6 +153,35 @@ If FORCE is non-nil fetch book data from the database."
                       (calibre--books force)))
         (tabulated-list-print)))))
 
+(defun calibre-library--set-header ()
+  "Set the header of the Library buffer."
+  (setf tabulated-list-format (calibre-library--header-format)))
+
+(defun calibre-library--header-format ()
+  "Create the header for the Library buffer.
+Return a vector suitable as the value of `tabulated-list-format'
+with values determined by `calibre-library-columns'."
+  (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))))
+                       :right-align t))
+                 (title `("Title" ,width t))
+                 (authors `("Author(s)" ,width t))
+                 (publishers `("Publisher(s)" ,width t))
+                 (series `("Series" ,width (lambda (a b)
+                                             (calibre-book-sort-by-series (car 
a) (car b)))))
+                 (series-index `("#" ,width (lambda (a b)
+                                              (calibre-book-sort-by-series 
(car a) (car b)))
+                                 :right-align t))
+                 (tags `("Tags" ,width))
+                 (formats `("Formats" ,width)))))
+           calibre-library-columns)))
+
 (defun calibre-book--print-info (book)
   "Return list suitable as a value of `tabulated-list-entries'.
 BOOK is a `calibre-book'."
diff --git a/calibre-library.el b/calibre-library.el
index 1f8ba1a744..7e5b5db7da 100644
--- a/calibre-library.el
+++ b/calibre-library.el
@@ -98,31 +98,6 @@ 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 ()
-  "Create the header for the Library buffer.
-Return a vector suitable as the value of `tabulated-list-format'
-with values determined by `calibre-library-columns'."
-  (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))))
-                       :right-align t))
-                 (title `("Title" ,width t))
-                 (authors `("Author(s)" ,width t))
-                 (publishers `("Publisher(s)" ,width t))
-                 (series `("Series" ,width (lambda (a b)
-                                             (calibre-book-sort-by-series (car 
a) (car b)))))
-                 (series-index `("#" ,width (lambda (a b)
-                                              (calibre-book-sort-by-series 
(car a) (car b)))
-                                 :right-align t))
-                 (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
@@ -133,9 +108,9 @@ with values determined by `calibre-library-columns'."
   "RET" #'calibre-library-open-book)
 
 (define-derived-mode calibre-library-mode tabulated-list-mode
-  (setf tabulated-list-padding 2
-        tabulated-list-format (calibre-library--header-format))
-  (tabulated-list-init-header))
+  (setf tabulated-list-padding 2)
+  (calibre-library--set-header)
+  (add-hook 'tabulated-list-revert-hook #'calibre-library--revert))
 
 ;;;###autoload
 (defun calibre-library ()

Reply via email to