diff options
Diffstat (limited to 'emacs/.emacs.d')
-rw-r--r-- | emacs/.emacs.d/init/ycp-markup.el | 9 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/belf.el | 2 | ||||
-rw-r--r-- | emacs/.emacs.d/lisp/my/my-nov.el | 40 |
3 files changed, 31 insertions, 20 deletions
diff --git a/emacs/.emacs.d/init/ycp-markup.el b/emacs/.emacs.d/init/ycp-markup.el index c90dc6a..c511d55 100644 --- a/emacs/.emacs.d/init/ycp-markup.el +++ b/emacs/.emacs.d/init/ycp-markup.el @@ -114,8 +114,15 @@ (my-override nov-scroll-up) (my-keybind nov-mode-map "Q" #'my-nov-copy-buffer-file-with-staging - "i" #'imenu) + "i" #'imenu + "f" #'nov-scroll-up + "b" #'nov-scroll-down + "F" #'my-nov-skim-forward + "B" #'my-nov-skim-backward) (add-to-list 'nov-shr-rendering-functions '(span . my-nov-render-span)) + (add-hook 'nov-mode-hook + (lambda () + (add-hook 'post-command-hook #'my-nov-update-mode-line nil t))) ) ;;; json-mode diff --git a/emacs/.emacs.d/lisp/my/belf.el b/emacs/.emacs.d/lisp/my/belf.el index 0db79f6..df9b53b 100644 --- a/emacs/.emacs.d/lisp/my/belf.el +++ b/emacs/.emacs.d/lisp/my/belf.el @@ -303,7 +303,7 @@ For EPUB, looks for a cover image in the file." (if-let ((cover-file-name (belf-locate-book-cover file-name))) (concat "file://" cover-file-name) (cond ((equal "epub" (file-name-extension file-name)) - (when-let* ((content-file-name (belf-epub-content-file-name file-name)) + (when-let* ((content-file-name (my-epub-content-file-name file-name)) (cover-file (belf-epub-cover-file-name file-name content-file-name)) (cover-file-name (file-name-with-extension 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." |