bir-org-noter.el 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. ;;; bir-org-noter.el --- BIR 🫶 Org-noter -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2021 i-am
  3. ;; Author: i-am <i@fbsd>
  4. ;; Keywords: convenience
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;; BIR intergation with Org-noter and PDF-tools.
  17. ;; TODO: Documentation.
  18. ;;; Code:
  19. (defun org-noter-make-extract ()
  20. "TODO"
  21. (interactive)
  22. (org-noter--with-valid-session
  23. (cond ((eq major-mode 'pdf-view-mode)
  24. (pdf-annot-add-highlight-markup-annotation (pdf-view-active-region) "SkyBlue" '((label . "extract"))))
  25. (t (error "Not in document buffer.")))))
  26. (defun org-noter-import-extract (a)
  27. (if (string= (pdf-annot-get a 'label) "extract")
  28. (org-noter--with-valid-session
  29. (let ((contents (pdf-info-gettext (pdf-view-current-page) (org-noter--pdf-tools-edges-to-region (pdf-annot-get-display-edges a))))
  30. id)
  31. (with-current-buffer (org-noter--session-notes-buffer session)
  32. (widen)
  33. (org-noter-insert-note (org-noter--get-precise-info) contents)
  34. (org-back-to-heading)
  35. (org-set-tags "extract")
  36. (org-set-property "CATEGORY" "Extract")
  37. (setq id (org-id-get (point) t)))
  38. (with-current-buffer (org-noter--session-doc-buffer session)
  39. (pdf-annot-put a 'label "org-id")
  40. (pdf-annot-put a 'contents id))))))
  41. (defun org-noter-goto-annot-note (a)
  42. (if (string= (pdf-annot-get a 'label) "org-id")
  43. (if (org-id-find (pdf-annot-get a 'contents))
  44. (progn (org-id-goto (pdf-annot-get a 'contents))
  45. t)
  46. (message "No org entry with an ID matching \"%s\"" (pdf-annot-get a 'contents))
  47. nil)))
  48. (add-hook 'pdf-annot-activate-handler-functions 'org-noter-import-extract)
  49. (add-hook 'pdf-annot-activate-handler-functions 'org-noter-goto-annot-note)
  50. (provide 'bir-org-noter)
  51. ;;; bir-org-noter.el ends here