diff options
Diffstat (limited to 'emacs/.emacs.d/lisp/my/my-nov.el')
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-nov.el | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/emacs/.emacs.d/lisp/my/my-nov.el b/emacs/.emacs.d/lisp/my/my-nov.el index d43a8f3..7cdb2a7 100644 --- a/emacs/.emacs.d/lisp/my/my-nov.el +++ b/emacs/.emacs.d/lisp/my/my-nov.el @@ -28,31 +28,38 @@ (require 'nov) +(defvar my-nov-mode-line-format "%p%% %t: %c") +(defvar-local my-nov-title nil) +(defvar-local my-nov-chapter-title nil) +(defvar-local my-nov-position-percent nil) + ;; override nov-render-title ;; this is because header line does not work with follow mode (defun my-nov-render-title (dom) "Custom <title> rendering function for DOM. Sets `header-line-format' to a combination of the EPUB title and chapter title." - (let ((title (cdr (assq 'title nov-metadata))) - (chapter-title (car (esxml-node-children dom)))) - (when (not chapter-title) - (setq chapter-title "No title")) - ;; this shouldn't happen for properly authored EPUBs - (when (not title) - (setq title "No title")) - ;; TODO: fix mode line update + (setq my-nov-title (cdr (assq 'title nov-metadata)) + my-nov-chapter-title (car (esxml-node-children dom)))) + +(defun my-nov-update-mode-line () + (setq my-nov-position-percent + (/ (* 100 (my-nov-word-position)) my-nov-total-word-count)) + (let ((title (or my-nov-title (propertize "No title" 'face 'italic))) + (chapter-title (or my-nov-chapter-title + (propertize "No title" 'face 'italic)))) (setq mode-line-buffer-identification - (format "%s: %s (%d%%)" - title chapter-title - (/ (* 100 (my-nov-word-position)) my-nov-total-word-count) - )) - )) + (format-spec + my-nov-mode-line-format + `((?c . ,chapter-title) + (?t . ,title) + (?p . ,my-nov-position-percent)))))) (defun my-nov-render-span (dom) (unless (equal (dom-attr dom 'epub:type) "pagebreak") (shr-generic dom))) + (defun my-nov-find-file-with-ipath (file-name ipath) "Find epub file and goto IPATH. @@ -149,15 +156,12 @@ Useful for recoll." (defun my-nov-word-position () "Where are we in terms of word position? -Return n, such that nth word of the epub is at the beginning of the -screen." +Return n, such that nth word of the epub is at point." (my-nov-count-words) (let ((result 0)) (dotimes (i nov-documents-index) (setq result (+ result (cdr (aref my-nov-document-word-counts i))))) - (save-excursion - (move-to-window-line 0) - (setq result (+ result (count-words (point-min) (point))))))) + (setq result (+ result (count-words (point-min) (point)))))) (defun my-nov-skim-forward () "Forward by 3-10% of the book." |