From 3275a5b59d2b33b66dfad8ee4e71412d8e334d0b Mon Sep 17 00:00:00 2001 From: Vasilij Schneidermann Date: Sat, 17 Mar 2018 11:45:01 +0100 Subject: Check whether place can be restored successfully Closes #29 --- nov.el | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'nov.el') 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) -- cgit v1.2.3