From 2335f6a2369b28ac5531c98cf73f60a30a4fa171 Mon Sep 17 00:00:00 2001 From: Xi Fu Date: Sun, 10 Jan 2021 15:26:56 -0500 Subject: [PATCH] Usability fix - 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 Addressed: https://github.com/fuxialexander/org-pdftools/issues/60 https://github.com/fuxialexander/org-pdftools/issues/54 --- README.org | 51 ++++++++++++++++++++++++++++++++++--------- org-noter-pdftools.el | 12 +++++----- org-pdftools.el | 20 ++++++++++++----- 3 files changed, 62 insertions(+), 21 deletions(-) diff --git a/README.org b/README.org index 61d2c2d..f6226d5 100644 --- a/README.org +++ b/README.org @@ -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: @@ -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. diff --git a/org-noter-pdftools.el b/org-noter-pdftools.el index 2b43a7c..f14a150 100644 --- a/org-noter-pdftools.el +++ b/org-noter-pdftools.el @@ -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)) diff --git a/org-pdftools.el b/org-pdftools.el index 5c1479c..9d81d90 100644 --- a/org-pdftools.el +++ b/org-pdftools.el @@ -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 @@ -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 @@ -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 @@ -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