aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nov.el15
1 files changed, 12 insertions, 3 deletions
diff --git a/nov.el b/nov.el
index a9c57cd..f3e0a25 100644
--- a/nov.el
+++ b/nov.el
@@ -650,6 +650,11 @@ Saving is only done if `nov-save-place-file' is set."
(with-temp-file nov-save-place-file
(insert (prin1-to-string places))))))
+(defun nov--index-valid-p (documents index)
+ (and (integerp index)
+ (>= index 0)
+ (< index (length documents))))
+
;;;###autoload
(define-derived-mode nov-mode special-mode "EPUB"
"Major mode for reading EPUB documents"
@@ -686,9 +691,13 @@ Saving is only done if `nov-save-place-file' is set."
(if place
(let ((index (cdr (assq 'index place)))
(point (cdr (assq 'point place))))
- (setq nov-documents-index index)
- (nov-render-document)
- (goto-char point))
+ (if (nov--index-valid-p nov-documents index)
+ (progn
+ (setq nov-documents-index index)
+ (nov-render-document)
+ (goto-char point))
+ (warn "Couldn't restore last position")
+ (nov-render-document)))
(nov-render-document))))
(provide 'nov)