summaryrefslogtreecommitdiffhomepage
path: root/org
diff options
context:
space:
mode:
Diffstat (limited to 'org')
-rw-r--r--org/jao-org-links.el22
1 files changed, 20 insertions, 2 deletions
diff --git a/org/jao-org-links.el b/org/jao-org-links.el
index b34bb06..614bfaa 100644
--- a/org/jao-org-links.el
+++ b/org/jao-org-links.el
@@ -1,4 +1,5 @@
(require 'jao-org-utils)
+(require 'pdf-info)
(defvar jao-org--sink-dir "./")
@@ -51,14 +52,30 @@
(let ((base (file-name-base (pdf-view-buffer-file-name))))
(capitalize (replace-regexp-in-string "-" " " base))))
+(defvar-local jao--pdf-outline nil)
+
+(defun jao-org--pdf-section-title (&optional page)
+ (when (not jao--pdf-outline)
+ (setq-local jao--pdf-outline (pdf-info-outline)))
+ (let ((page (or page (pdf-view-current-page)))
+ (outline jao--pdf-outline)
+ (cur-page 0)
+ (cur-title (jao-org--pdf-title)))
+ (while (and (car outline) (< cur-page page))
+ (setq cur-page (cdr (assoc 'page (car outline))))
+ (when (<= cur-page page)
+ (setq cur-title (cdr (assoc 'title (car outline)))))
+ (setq outline (cdr outline)))
+ cur-title))
+
(defun jao-org-links--store-pdf-link ()
- (when (eq major-mode 'pdf-view-mode)
+ (when (derived-mode-p 'pdf-view-mode)
(let ((path buffer-file-name)
(page (pdf-view-current-page)))
(org-store-link-props
:type "doc"
:link (format "doc:%s::%d" (file-name-nondirectory path) page)
- :description (format "%s (p. %d)" (jao-org--pdf-title) page)))))
+ :description (format "%s (p. %d)" (jao-org--pdf-section-title) page)))))
;;;###autoload
(defun jao-org-insert-doc (title)
@@ -67,6 +84,7 @@
;;;###autoload
(defun jao-org-links-setup (sink-dir)
+ (interactive)
(org-link-set-parameters "doc"
:follow #'jao-org-links--follow-doc
:complete #'jao-org-links--complete-doc