aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/calibredb-epub-config.el8
-rw-r--r--tests/test-calibredb-epub-config.el9
2 files changed, 13 insertions, 4 deletions
diff --git a/modules/calibredb-epub-config.el b/modules/calibredb-epub-config.el
index c1dba8b5..bf9ec97e 100644
--- a/modules/calibredb-epub-config.el
+++ b/modules/calibredb-epub-config.el
@@ -322,12 +322,12 @@ computed column based on the window text area width."
(t v))))
(defun cj/nov--file-path ()
- "Return the current EPUB file path when in nov-mode, or nil."
+ "Return the current EPUB file path when in nov-mode, or nil.
+Falls back to nov's own `nov-file-name' (set by `nov-mode' from the visited
+file) so the function still resolves when `buffer-file-name' has been cleared."
(when (derived-mode-p 'nov-mode)
- ;; In nov, the buffer visits the .epub; buffer-file-name is usually the EPUB.
(or buffer-file-name
- (and (boundp 'nov-epub-filename) nov-epub-filename)
- (and (boundp 'nov-epub-file) nov-epub-file))))
+ (and (boundp 'nov-file-name) nov-file-name))))
(defun cj/nov-jump-to-calibredb ()
"Open CalibreDB focused on the current EPUB's book entry.
diff --git a/tests/test-calibredb-epub-config.el b/tests/test-calibredb-epub-config.el
index 34f4f49a..48d63835 100644
--- a/tests/test-calibredb-epub-config.el
+++ b/tests/test-calibredb-epub-config.el
@@ -373,6 +373,15 @@ result is a plain string that the jump-to-calibredb query can interpolate."
(setq buffer-file-name "/tmp/sample.epub")
(should (equal "/tmp/sample.epub" (cj/nov--file-path)))))
+(ert-deftest test-calibredb-epub-file-path-falls-back-to-nov-file-name ()
+ "Boundary: in `nov-mode' with no `buffer-file-name', the helper falls back
+to nov.el's own `nov-file-name' (set by `nov-mode' from the visited file)."
+ (with-temp-buffer
+ (setq-local major-mode 'nov-mode)
+ (setq buffer-file-name nil)
+ (setq-local nov-file-name "/tmp/sample.epub")
+ (should (equal "/tmp/sample.epub" (cj/nov--file-path)))))
+
(ert-deftest test-calibredb-epub-file-path-returns-nil-outside-nov-mode ()
"Error: outside `nov-mode' the helper returns nil regardless of file name."
(with-temp-buffer