aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasilij Schneidermann <mail@vasilij.de>2020-05-01 16:58:42 +0200
committerVasilij Schneidermann <mail@vasilij.de>2020-05-01 16:58:42 +0200
commit2eec3f2e713baec814999359bb4580fbf2efd5b9 (patch)
treeff27385c474e399b028b77f6c032b6d9174f2e45
parentcd1b264b3f978a9285fa9297e40ad29d1434adf5 (diff)
Rework relative files visiting logic
-rw-r--r--nov.el32
1 files changed, 17 insertions, 15 deletions
diff --git a/nov.el b/nov.el
index 7be29e9..193d1f3 100644
--- a/nov.el
+++ b/nov.el
@@ -648,21 +648,23 @@ the HTML is rendered with `nov-render-html-function'."
(defun nov-visit-relative-file (filename target)
"Visit the document as specified by FILENAME and TARGET."
- (let* ((current-path (cdr (aref nov-documents nov-documents-index)))
- (directory (file-name-directory current-path))
- (path (file-truename (nov-make-path directory filename)))
- (index (nov-find-document
- (lambda (doc) (equal path (file-truename (cdr doc)))))))
- (when (not index)
- (error "Couldn't locate document"))
- (let ((shr-target-id target))
- (nov-goto-document index))
- (when target
- (let ((pos (next-single-property-change (point-min) 'shr-target-id)))
- (when (not pos)
- (error "Couldn't locate target"))
- (goto-char pos)
- (recenter (1- (max 1 scroll-margin)))))))
+ (let ((index nov-documents-index)
+ (shr-target-id target))
+ (when (not (zerop (length filename)))
+ (let* ((current-path (cdr (aref nov-documents nov-documents-index)))
+ (directory (file-name-directory current-path))
+ (path (file-truename (nov-make-path directory filename)))
+ (index (nov-find-document
+ (lambda (doc) (equal path (file-truename (cdr doc)))))))
+ (when (not index)
+ (error "Couldn't locate document"))
+ (nov-goto-document index))))
+ (when target
+ (let ((pos (next-single-property-change (point-min) 'shr-target-id)))
+ (when (not pos)
+ (error "Couldn't locate target"))
+ (goto-char pos)
+ (recenter (1- (max 1 scroll-margin))))))
;; adapted from `shr-browse-url'
(defun nov-browse-url (&optional mouse-event)