Skip to content

Commit

Permalink
Usability fix
Browse files Browse the repository at this point in the history
- Incorporated
weirdNox/org-noter@f8349ae
in Usage README
- Added customizable variable ~org-pdftools-use-isearch-link~ and
~org-pdftools-use-freepointer-annot~ to control whether you will get
prompt to create isearch/freepointer link if no existing annotations
are found

Addressed:
#60
#54
  • Loading branch information
fuxialexander committed Jan 10, 2021
1 parent bcf0084 commit 2335f6a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 21 deletions.
51 changes: 41 additions & 10 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,40 @@ You can now install ~org-pdftools~ and ~org-noter-pdftools~ from MELPA!
(use-package org-noter-pdftools
:after org-noter
:config
;; Add a function to ensure precise note is inserted
(defun org-noter-pdftools-insert-precise-note (&optional toggle-no-questions)
(interactive "P")
(org-noter--with-valid-session
(let ((org-noter-insert-note-no-questions (if toggle-no-questions
(not org-noter-insert-note-no-questions)
org-noter-insert-note-no-questions))
(org-pdftools-use-isearch-link t)
(org-pdftools-use-freestyle-annot t))
(org-noter-insert-note (org-noter--get-precise-info)))))

;; fix https://github.com/weirdNox/org-noter/pull/93/commits/f8349ae7575e599f375de1be6be2d0d5de4e6cbf
(defun org-noter-set-start-location (&optional arg)
"When opening a session with this document, go to the current location.
With a prefix ARG, remove start location."
(interactive "P")
(org-noter--with-valid-session
(let ((inhibit-read-only t)
(ast (org-noter--parse-root))
(location (org-noter--doc-approx-location (when (called-interactively-p 'any) 'interactive))))
(with-current-buffer (org-noter--session-notes-buffer session)
(org-with-wide-buffer
(goto-char (org-element-property :begin ast))
(if arg
(org-entry-delete nil org-noter-property-note-location)
(org-entry-put nil org-noter-property-note-location
(org-noter--pretty-print-location location))))))))
(with-eval-after-load 'pdf-annot
(add-hook 'pdf-annot-activate-handler-functions #'org-noter-pdftools-jump-to-note)))
#+END_SRC

* Latest release note
- HTML exported link now have a "#page=n" postfix, which should make browsers like Chrome open the corresponding page.
- You can now customize the link description format using ~org-pdftools-get-desc-function~
- Added ~org-noter-pdftools-embed-org-note-to-pdf~, ~org-noter-pdftools-embed-all-org-note-to-pdf~ to copy one or all *org-noter annotation headings* (the ones with a ~annot-id~ and ~org-pdftools link~) to the corresponding PDF file.
- Added ~org-noter-pdftools-embed-org-buffer-to-pdf~ to copy the whole *org-noter* buffer to a annotation in the left upper corner of the first page in the PDF.
- Added ~org-noter-pdftools-jump-to-note~ config in the README.
- The prefix of pdftools link can now be customized using ~org-pdftools-link-prefix~, and the default is now set to "pdf"
- The ~org-pdftools-search-string-separator~ is now set to ~??~ to avoid org fontification problem
- You can now specify how the path of pdf is stored using two function:
- ~org-pdftools-path-generator~ takes ~buffer-file-name~ as an argument, and output a translated path. Default to ~abbreviate-file-name~
- ~org-pdftools-path-resolver~ takes a translated path as an argument and translate it back to absolute path. Default to ~expand-file-name~
- Incorporated https://github.com/weirdNox/org-noter/pull/93/commits/f8349ae7575e599f375de1be6be2d0d5de4e6cbf in Usage README
- Added customizable variable ~org-pdftools-use-isearch-link~ and ~org-pdftools-use-freepointer-annot~ to control whether you will get prompt to create isearch/freepointer link if no existing annotations are found

* Current features
The provided function includes:
Expand All @@ -47,6 +66,18 @@ The provided function includes:
using pdf-tools markup functions (by default, underline) automatically and the
corresponding annotation id is stored in the link.

- HTML exported link now have a "#page=n" postfix, which should make browsers like Chrome open the corresponding page.
- You can now customize the link description format using ~org-pdftools-get-desc-function~
- Added ~org-noter-pdftools-embed-org-note-to-pdf~, ~org-noter-pdftools-embed-all-org-note-to-pdf~ to copy one or all *org-noter annotation headings* (the ones with a ~annot-id~ and ~org-pdftools link~) to the corresponding PDF file.
- Added ~org-noter-pdftools-embed-org-buffer-to-pdf~ to copy the whole *org-noter* buffer to a annotation in the left upper corner of the first page in the PDF.
- Added ~org-noter-pdftools-jump-to-note~ config in the README.
- The prefix of pdftools link can now be customized using ~org-pdftools-link-prefix~, and the default is now set to "pdf"
- The ~org-pdftools-search-string-separator~ is now set to ~??~ to avoid org fontification problem
- You can now specify how the path of pdf is stored using two function:
- ~org-pdftools-path-generator~ takes ~buffer-file-name~ as an argument, and output a translated path. Default to ~abbreviate-file-name~
- ~org-pdftools-path-resolver~ takes a translated path as an argument and translate it back to absolute path. Default to ~expand-file-name~


* Integration with ~org-noter~
You can use the vanilla ~org-noter~ now.

Expand Down
12 changes: 7 additions & 5 deletions org-noter-pdftools.el
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,18 @@ To use this, `org-noter-pdftools-use-org-id' has to be t."
"Interface for parse PROPERTY link."
(when (org-noter-pdftools--location-link-p property)
(setq property (string-trim property "\\[\\[" "\\]\\]"))
(let ((link-regexp (concat "\\(.*\\)::\\([0-9]*\\)\\+\\+\\([[0-9]\\.*[0-9]*\\)?\\(;;\\|" (regexp-quote org-pdftools-search-string-separator) "\\)\\(.*\\)?")))
(let ((link-regexp (concat "\\(.*\\)::\\([0-9]*\\)\\+\\+\\([[0-9]\\.*[0-9]*\\)\\(;;\\|" (regexp-quote org-pdftools-search-string-separator) "\\)?\\(.*\\)?")))
(string-match link-regexp property)
(let ((path (match-string 1 property))
(page (match-string 2 property))
(height (match-string 3 property))
annot-id search-string)
(cond ((string-equal (match-string 4 property) ";;")
(setq annot-id (match-string 5 property)))
((string-equal (match-string 4 property) org-pdftools-search-string-separator)
(setq search-string (replace-regexp-in-string "%20" " " (match-string 5 property)))))
(condition-case nil
(cond ((string-equal (match-string 4 property) ";;")
(setq annot-id (match-string 5 property)))
((string-equal (match-string 4 property) org-pdftools-search-string-separator)
(setq search-string (replace-regexp-in-string "%20" " " (match-string 5 property)))))
(error nil))
(make-org-noter-pdftools--location
:path path
:page (and page (string-to-number page))
Expand Down
20 changes: 14 additions & 6 deletions org-pdftools.el
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ See `org-pdftools-get-desc-default' as an example."
"Custom function to open linked pdf files."
:group 'org-pdftools
:type '(choice function nil))

(defcustom org-pdftools-use-freepointer-annot nil
"Whether prompt to use freepointer annotation or not. "
:group 'org-pdftools
:type 'boolean)

(defcustom org-pdftools-use-isearch-link nil
"Whether prompt to use isearch link or not. "
:group 'org-pdftools
:type 'boolean)

(defcustom org-pdftools-export-style 'pdftools
"Export style of org-pdftools links.
- pdftools :: export the link as is
Expand Down Expand Up @@ -230,8 +241,7 @@ Can be one of highlight/underline/strikeout/squiggly."
(pdf-annot-read-annotation
"Click the annotation that you want to link to."))
(error
(if (y-or-n-p
"You can click anywhere on the page to add a link to. Do you want to do that? ")
(if org-pdftools-use-freepointer-annot
(pdf-annot-get-id
(funcall-interactively
#'pdf-annot-add-text-annotation
Expand All @@ -241,8 +251,7 @@ Can be one of highlight/underline/strikeout/squiggly."
`((color . ,org-pdftools-free-pointer-color)
(opacity . ,org-pdftools-free-pointer-opacity))))
nil)))
(if (y-or-n-p
"You can click anywhere on the page to add a link to. Do you want to do that? ")
(if org-pdftools-use-freepointer-annot
(pdf-annot-get-id
(funcall-interactively
#'pdf-annot-add-text-annotation
Expand All @@ -269,8 +278,7 @@ Can be one of highlight/underline/strikeout/squiggly."
(cdr (pdf-view-image-size)))))))
;; pdf://path::page++height_percent;;annot_id\\|??search-string
(search-string (if (and (not annot-id)
(y-or-n-p
"Do you want to add a isearch link? "))
org-pdftools-use-isearch-link)
isearch-string
""))
(link (concat
Expand Down

0 comments on commit 2335f6a

Please sign in to comment.