aboutsummaryrefslogtreecommitdiff
path: root/nov.el
diff options
context:
space:
mode:
authorVasilij Schneidermann <mail@vasilij.de>2018-03-17 11:45:01 +0100
committerVasilij Schneidermann <mail@vasilij.de>2018-03-17 11:45:01 +0100
commit3275a5b59d2b33b66dfad8ee4e71412d8e334d0b (patch)
tree38e2db38e36a63fc9ee44a8b89f9f92133f7b761 /nov.el
parentb0eab94b84464aa4508ccfee59af5b8df49666a2 (diff)
Check whether place can be restored successfully
Closes #29
Diffstat (limited to 'nov.el')
-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)