fuxialexander / org-pdftools

A custom org link type for pdf-tools
GNU General Public License v3.0
335 stars 36 forks source link

org-pdftools-root-dir not included when creating skeleton #11

Closed nanjigen closed 4 years ago

nanjigen commented 4 years ago

Not sure how to create an issue on your booster branch, but I'm having an issue whereby the resultant links generated by org-noter-create-skeleton aren't including the directory of the PDF in question, thus creating a dud link.

Expected: pdftools:~/Documents/PDF/roberts2013.pdf::3++..... Observed: pdftools:roberts2013.pdf::3++.....

Here is an excerpt after following the function on my system:

 (defun org-noter-create-skeleton ()
  "Create notes skeleton with the PDF outline or annotations.
Only available with PDF Tools."
  (interactive)
  (org-noter--with-valid-session
   (cond
    ((eq (org-noter--session-doc-mode session) 'pdf-view-mode)
     (let* ((ast (org-noter--parse-root))
            (top-level (org-element-property :level ast))
            (options '(("Outline" . (outline))
                       ("Annotations" . (annots))
                       ("Both" . (outline annots))))
            answer output-data)
       (with-current-buffer (org-noter--session-doc-buffer session)
         (setq answer (assoc (completing-read "What do you want to import? " options nil t) options))

         (when (memq 'outline answer)
           (dolist (item (pdf-info-outline))
             (let ((type  (alist-get 'type item))
                   (page  (alist-get 'page item))
                   (depth (alist-get 'depth item))
                   (title (alist-get 'title item))
                   (top   (alist-get 'top item))
                   pdftools-link path)
               (when (and (eq type 'goto-dest)
                          (> page 0))
                 (when org-noter-use-pdftools-link-location
                   (setq path (file-relative-name
                               (expand-file-name
                                (org-noter--session-property-text
                                 session))
                               org-pdftools-root-dir))
                   (if title
                       (setq pdftools-link
                             (concat
                              "pdftools:"
                              path
                              "::"
                              (number-to-string page)
                              "++"
                              (number-to-string top)
                              "$$"
                              (replace-regexp-in-string
                               " "
                               "%20"
                               title)))
                     (setq pdftools-link
                           (concat
                            "pdftools:"
                            path
                            "::"
                            (number-to-string page)
                            "++"
                            (number-to-string top)))))
                 (push
                  (vector
                   title
                   (if org-noter-use-pdftools-link-location pdftools-link
                     (cons page top))
                   (1+ depth)
                   nil)
                  output-data)))))

I can see org-pdftools-root-dir referenced, and it is defined in my init.el, but I don't have the elisp-foo to troubleshoot this effectively.

Additionally, attempting to follow an org-pdftools link while in an org-noter session throws an error: org-pdftools-open-pdftools: Invalid function: org-noter--with-valid-session

Storing links using org-store-link works as expected

smallzhan commented 4 years ago

Maybe you can remove the *.elc files for org-pdftools and try again, last week I've met the same issue of `org-noter--with-valid-session' and solve it by removing the elc files.

nanjigen commented 4 years ago

I must have done something right, because now it all works fine. Thanks everyone.

In case someone else encounters this, I'm using Spacemacs and reinstalling or finding all .elc and recompiling with spacemacs/recompile-elpa may have helped.

fuxialexander commented 4 years ago

Closed as it's been solved. Sorry for the late action though...