fuxialexander / org-pdftools

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

org-store-links breaks on "Wrong number of arguments" #1

Closed matthew-piziak closed 5 years ago

matthew-piziak commented 5 years ago
org-link-store-props: Wrong number of arguments: (lambda (from-org-noter) "Get link from the active pdf buffer." (let* ((path (concat org-pdftools-root-dir (file-relative-name buffer-file-name org-pdftools-root-dir))) (page (image-mode-window-get 'page nil)) (annot-id (if (pdf-view-active-region-p) (pdf-annot-get-id (funcall org-pdftools-markup-pointer-function (pdf-view-active-region t) org-pdftools-markup-pointer-color (list (cons 'opacity org-pdftools-markup-pointer-opacity)))) (if (and (not from-org-noter) (pdf-annot-getannots page)) (condition-case nil (pdf-annot-get-id (pdf-annot-read-annotation "Click the annotation that you want to link to.")) ((debug error) (message "error"))) (if (y-or-n-p "Do you want to create a free pointer annotation for the link?") (pdf-annot-get-id (funcall-interactively #'pdf-annot-add-text-annotation (pdf-util-read-image-position "Click where a new text annotation should be added ...") org-pdftools-free-pointer-icon (list ... ...))) nil)))) (height (cond ((and (boundp 'annot-id) annot-id) (nth 1 (pdf-annot-get (pdf-info-getannot annot-id path) 'edges))) (t (/ (* (or (image-mode-window-get ...) 0) (frame-char-height)) (float (cdr (pdf-view-image-size))))))) (link (concat "pdftools:" path "::" (number-to-string page) "++" (format "%.2f" height) (if annot-id (concat ";;" (symbol-name annot-id)) nil)))) link)), 0

org-pdftools version: d19ba8812a4534b20de48c4edbd4aab2fb989a83 Emacs version: GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.5) of 2019-08-07

Backtrace:

Debugger entered--Lisp error: (wrong-number-of-arguments (lambda (from-org-noter) "Get link from the active pdf buffer." (let* ((path (concat org-pdftools-root-dir (file-relative-name buffer-file-name org-pdftools-root-dir))) (page (image-mode-window-get 'page nil)) (annot-id (if (pdf-view-active-region-p) (pdf-annot-get-id (funcall org-pdftools-markup-pointer-function ... org-pdftools-markup-pointer-color ...)) (if (and ... ...) (condition-case nil ... ...) (if ... ... nil)))) (height (cond ((and ... annot-id) (nth 1 ...)) (t (/ ... ...)))) (link (concat "pdftools:" path "::" (number-to-string page) "++" (format "%.2f" height) (if annot-id (concat ";;" ...) nil)))) link)) 0)
  org-pdftools-get-link()
  (org-link-store-props :type "pdftools" :link (org-pdftools-get-link) :description desc)
  (let ((desc (if (pdf-view-active-region-p) (replace-regexp-in-string "\n" " " (mapconcat 'identity (pdf-view-active-region-text) 32))))) (org-link-store-props :type "pdftools" :link (org-pdftools-get-link) :description desc))
  (cond ((eq major-mode 'pdf-view-mode) (let ((desc (if (pdf-view-active-region-p) (replace-regexp-in-string "\n" " " (mapconcat ... ... 32))))) (org-link-store-props :type "pdftools" :link (org-pdftools-get-link) :description desc))) ((eq major-mode 'pdf-occur-buffer-mode) (let* ((paths (mapconcat #'identity (mapcar #'car pdf-occur-search-documents) "%&%")) (search-string pdf-occur-search-string) (link (concat "pdftools:" paths "@@" search-string))) (org-link-store-props :type "pdftools" :link link :description (concat "Search PDF for: " search-string)))))
  org-pdftools-store-link()
  org-store-link(nil 1)
  funcall-interactively(org-store-link nil 1)
  call-interactively(org-store-link nil nil)
  command-execute(org-store-link)
fuxialexander commented 5 years ago

Thanks for the report! Fixed in e1bbd113e4d878d76a635dc3eaa46904df3cdf7c

matthew-piziak commented 5 years ago

Hey, sorry, I can reproduce this on f0815e4

org-link-store-props: Wrong number of arguments: (lambda (from-org-noter) "Get link from the active pdf buffer." (let* ((path (concat org-pdftools-root-dir (file-relative-name buffer-file-name org-pdftools-root-dir))) (page (image-mode-window-get 'page nil)) (annot-id (if (pdf-view-active-region-p) (pdf-annot-get-id (funcall org-pdftools-markup-pointer-function (pdf-view-active-region t) org-pdftools-markup-pointer-color (list (cons 'opacity org-pdftools-markup-pointer-opacity)))) (if (and (not from-org-noter) (pdf-annot-getannots page)) (condition-case nil (pdf-annot-get-id (pdf-annot-read-annotation "Click the annotation that you want to link to.")) ((debug error) (message "error"))) (if (y-or-n-p "Do you want to create a free pointer annotation for the link?") (pdf-annot-get-id (funcall-interactively #'pdf-annot-add-text-annotation (pdf-util-read-image-position "Click where a new text annotation should be added ...") org-pdftools-free-pointer-icon (list ... ...))) nil)))) (height (cond ((and (boundp 'annot-id) annot-id) (nth 1 (pdf-annot-get (pdf-info-getannot annot-id path) 'edges))) (t (/ (* (or (image-mode-window-get ...) 0) (frame-char-height)) (float (cdr (pdf-view-image-size))))))) (link (concat "pdftools:" path "::" (number-to-string page) "++" (format "%.2f" height) (if annot-id (concat ";;" (symbol-name annot-id)) nil)))) link)), 0
fuxialexander commented 5 years ago

@matthew-piziak I was not able to reproduce that. What's the version of your Emacs and Org? And what happened before that error?

matthew-piziak commented 5 years ago

Versions GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.5) of 2019-08-07 Org mode version 9.2.4 (release_9.2.4-423-ge059c1 @ /home/matt/.emacs.d/straight/build/org/)

Without org-pdftools I get something like this instead: Stored: file:<filename>.pdf::%PDF-1.6 %. Unfortunately the drawback there is that it does not link to a particular location, just to the file.

fuxialexander commented 5 years ago

Could you try to change the code:

(org-link-store-props
            :type "pdftools"
            :link (org-pdftools-get-link)
            :description desc)))

to

(org-link-store-props
            :type "pdftools"
            :link (org-pdftools-get-link nil)
            :description desc)))

and check whether the error exist?

matthew-piziak commented 5 years ago

Strange...now I get this:

pdf-info-query: epdfinfo: Error opening /home/matt/org../log/pdfs/7Sketches.pdf:No such file or directory

The PDF in question is located at /home/matt/log/pdfs/7Sketches.pdf. No idea why the path is mangled like that. Unfortunately the error returns no backtrace.

fuxialexander commented 5 years ago

Ah! You need to set org-pdftools-root-dir to /home/matt/log/pdfs Sorry for didn't make it clear...

matthew-piziak commented 5 years ago

That works! (provided you add a trailing slash)

Thanks for the help @fuxialexander.