dmitrym0 / org-noter-plus

Emacs document annotator, using Org-mode
GNU General Public License v3.0
31 stars 3 forks source link

#+BEGIN_QUOTE and #+END_QUOTE is not working. #4

Open ffsammak opened 1 year ago

ffsammak commented 1 year ago

Hi, Thanks a lot for maintaining this gem package. I wonder how one can get this functionality of quoting text from a PDF by M-i (org-noter-insert-precise-note) to quote text automagically between the #+BEGIN_QUOTE and #+END_QUOTE property drawers. I saw this functionality in your video precisely at 2:40.

Below is my init.el setup:

(use-package org-noter
  ;; sequence should be respected as in org-pdftools description: org-noter then org-pdftools then org-noter-pdftools
  :straight (org-noter-plus
         :host github
         :repo "dmitrym0/org-noter-plus"
         :branch "master")
  :after org-roam
   :bind ("C-c n n" . org-noter)
  :custom
  (setq org-noter-notes-window-location vertical-split)
  (setq org-noter-highlight-selected-text t) ; not working right now jump and actively highlight region
  :config
  (setq org-noter-notes-search-path '("~/Dropbox/roam/refs")) ; optional
  (setq org-noter-default-notes-file-names '("Notes.org"))
  (setq org-noter-separate-notes-from-heading t)
  (require 'org-noter-pdftools)
  (setq org-noter-pdftools-use-org-id t) 
  )

Emacs: GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.33, cairo version 1.16.0) of 2023-02-27

dmitrym0 commented 1 year ago

Hey @ffsammak

You need to add the following to your init.el somewhere:

 (setq org-noter-max-short-selected-text-length 700000)

                     (define-advice org-noter--insert-heading (:after (level title &optional newlines-number location) add-full-body-quote)
                       "Advice for org-noter--insert-heading.

  When inserting a precise note insert the text of the note in the body as an org mode QUOTE block.

  =org-noter-max-short-length= should be set to a large value to short circuit the normal behavior:
  =(setq org-noter-max-short-selected-text-length 80000)="

                       ;; this tells us it's a precise note that's being invoked.
                       (if (consp location)
                           (insert (format "#+BEGIN_QUOTE\n%s\n#+END_QUOTE" title))))
ffsammak commented 1 year ago

unfortunately, I couldn't get it to work. I am now trying to debug. I am using vanilla emacs, straight for package installation and use-package for package configuration. The first problem is that I see two folders under straight repo, one is org-noter and the other is org-noter-plus. This is confusing. My setup code for org-noter package is mentioned above. How can I end up having one single directory under straight?

ffsammak commented 1 year ago

Ok, I figured out that my straight setup was causing the two repos now I get one after straight-remove-unused-repos command. I now have this setup:

(use-package org-noter
  ;; sequence should be respected as in org-pdftools description: org-noter then org-pdftools then org-noter-pdftools
  :straight (org-noter
         :host github
         :repo "dmitrym0/org-noter-plus"
         :branch "master")
  :after org-roam
...

now I can do debugging on this one repo .. debugging in progress...

ffsammak commented 1 year ago

when I forked this repo, I can no longer open PDFs C-c n n. Toggle-debug-on-error shows this backtrace report:

Debugger entered--Lisp error: (error "This document handler is not supported :/")
  signal(error ("This document handler is not supported :/"))
  error("This document handler is not supported :/")
  org-noter--create-session((headline (:raw-value "PDF" :begin 869 :end 6943 :pre-blank 0 :contents-begin 875 :contents-end 6942 :robust-begin 986 :robust-end 6940 :level 1 :priority nil ...) (section ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) ...) "~/Zotero/storage/U8R..." "/home/ffs/Dropbox/ro...")
  org-noter(nil)
  funcall-interactively(org-noter nil)
  call-interactively(org-noter nil nil)
  command-execute(org-noter)

I can only get the org-noter buffer opened in a new frame without its accompanying PDF. I don't know how to proceed from here, any suggestion?

pobermei commented 1 year ago

when I forked this repo, I can no longer open PDFs C-c n n. Toggle-debug-on-error shows this backtrace report:

Debugger entered--Lisp error: (error "This document handler is not supported :/")
  signal(error ("This document handler is not supported :/"))
  error("This document handler is not supported :/")
  org-noter--create-session((headline (:raw-value "PDF" :begin 869 :end 6943 :pre-blank 0 :contents-begin 875 :contents-end 6942 :robust-begin 986 :robust-end 6940 :level 1 :priority nil ...) (section ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ...) (headline ... ...) (headline ... ...) (headline ... ...) (headline ... ...) ...) "~/Zotero/storage/U8R..." "/home/ffs/Dropbox/ro...")
  org-noter(nil)
  funcall-interactively(org-noter nil)
  call-interactively(org-noter nil nil)
  command-execute(org-noter)

I don't know how to proceed from here, any suggestion?

@ffsammak I had the same problem and solved it as described here.

ffsammak commented 1 year ago

@ffsammak I had the same problem and solved it as described here.

@pobermei Thanks a million, that solved many issues, I can now use C-c n n to open PDFs as expected so below is a link to the screencast recording:

https://rapidshare.io/13fL/org-noter-plus-quotes.webm

org-noter-plus-quotes

Summary:

  (setq org-startup-indented nil) ; this will mess up with the appearance of the fringe of org-transclusion
  (setq org-adapt-indentation t)  ; this is enough to get a workable org indentation

All in all, I am happy with the current status of org-noter, although I believe this package can be further developed to unleash its full potential. For reference, I put here my current setup for org-noter-plus:

(use-package org-noter
  ;; sequence should be respected as in org-pdftools description: org-noter then org-pdftools then org-noter-pdftools
  :straight (org-noter
         :host github
         :repo "dmitrym0/org-noter-plus"
         :branch "master"
         :files ("*.el" "modules/*.el" "other/*.el")  ; include modules and auxiliaries
         )
  :after org-roam
  :bind (("C-c n n" . org-noter)
     :map org-noter-doc-mode-map
     ("i" .  org-noter-insert-precise-note)
     ("C-i" . org-noter-insert-note)
     ("I" . org-noter-insert-precise-note-toggle-no-questions)
     ("M-i" . org-noter-insert-note-toggle-no-questions)
         ("M-p" . org-noter-sync-prev-note)
         ("M-." . org-noter-sync-current-note)
         ("M-n" . org-noter-sync-next-note)
         ("C-M-p" . org-noter-sync-prev-page-or-chapter)
         ("C-M-." . org-noter-sync-current-page-or-chapter)
         ("C-M-n" . org-noter-sync-next-page-or-chapter)
     )
  :custom
  (setq org-noter-notes-window-location vertical-split) ; optional horizontal/vertical split
  (setq org-noter-highlight-selected-text t)
  :config
  ;; Explictly load required modules
  (require 'org-noter-pdf)
  (require 'org-noter-dynamic-block)
  ;; Your org-noter config...
  (setq org-noter-notes-search-path '("~/Dropbox/roam/refs")) ; optional
  (setq org-noter-default-notes-file-names '("Notes.org"))
  (setq org-noter-separate-notes-from-heading t)
  (require 'org-noter-pdftools)
  ; optional if nil it will turn off adding org-ids to notes so not to be cached with other org-roam nodes
  (setq org-noter-pdftools-use-org-id nil)
  (setq org-noter-max-short-selected-text-length 700000)
  (define-advice org-noter--insert-heading (:after (level title &optional newlines-number location) add-full-body-quote)
    "Advice for org-noter--insert-heading.  When inserting a precise note insert the text of the note in the body as an org mode QUOTE block. =org-noter-max-short-length= should be set to a large value to short circuit the normal behavior:  =(setq org-noter-max-short-selected-text-length 80000)="
    ;; this tells us it's a precise note that's being invoked.
    (if (consp location)
        (insert (format "#+BEGIN_QUOTE\n%s\n#+END_QUOTE" title))))
  )
ffsammak commented 1 year ago

One more related question: hitting C-M i will get the quoted text in two different places:

This leaves me with a question, which quote text would be useful for org-transclusion, the header entry or the quote drawer? As far as I can tell, entries are not so strongly supported as plain text. So shall I replace the entry quote text with the page number for example? I am just trying to come up with a well thought-out workflow as early as possible before I discover some better setup in the future and re-invent a wheel you may have already honed and tested. What is your workflow?

ffsammak commented 1 year ago

Sorry for coming up with many questions here: but it is related to the old org-noter setup may be, now I have two PDF references showing this old format inside property drawer of the notes:


:PROPERTIES:
:NOTER_PAGE: [[pdf:~/Zotero/storage/U8R3PPTC/airoldiInterleukin12Interleukin12Receptor2002.pdf::4++9.78;;annot-4-2]]
:END:

While the one I see now is the following with org-noter-plus:

:PROPERTIES:
:NOTER_PAGE: (3 . 0.39058458354888775)
:END:

Do you know by chance a method to convert the old locations into the new format? If not, this means I am left with the manual option to do them one by one by hand. Thanks.

pobermei commented 1 year ago

Sorry for coming up with many questions here: but it is related to the old org-noter setup may be, now I have two PDF references showing this old format inside property drawer of the notes:


:PROPERTIES:
:NOTER_PAGE: [[pdf:~/Zotero/storage/U8R3PPTC/airoldiInterleukin12Interleukin12Receptor2002.pdf::4++9.78;;annot-4-2]]
:END:

That's the link format used by org-pdftools for org-noter integration. To convert back-and-forth between that format and the precise org-noter format (your second example), you can reuse its conversion functions org-noter-pdftools--location-cons-to-link and org-noter-pdftools--location-link-to-cons

ffsammak commented 1 year ago

@pobermei Thanks these two functions are indeed handy. However, I could only get the conversion working with one of them: (org-noter-pdftools--location-cons-to-link '(3 . 0.39058458354888775)) gave me after C-x C-e "::3++0.39" which is fine, but I couldn't get the other function to work : (org-noter-pdftools--location-link-to-cons '(pdf:~/Zotero/storage/U8R3PPTC/airoldiInterleukin12Interleukin12Receptor2002.pdf::4++9.78;;annot-4-2))

This gave me End of file during parsing

I also tried: (org-noter-pdftools--location-link-to-cons '("::4++9.78;;annot-4-2")) but threw an error

also (org-noter-pdftools--location-link-to-cons '("::4++9.78")) threw Wrong type argument: org-noter-pdftools--location, (::4++9.78)

Even tried this but to no avail, I ran out of ways how to put the argument. Any help would be very much appreciated. (org-noter-pdftools--location-link-to-cons '("[[pdf:~/Zotero/storage/U8R3PPTC/airoldiInterleukin12Interleukin12Receptor2002.pdf::4++9.78;;annot-4-2]]"))

dmitrym0 commented 1 year ago

👋

@pobermei thank you for the straight correction in #3.

@ffsammak @petermao's fork has a really nice breakdown of how various note insertion methods work in this version vs the original org-noter.

I'm glad you are finding our efforts useful. Peter has done a lot of work trying to bring order to the note insertion options. He's also been trying to contact the original author to see if he's ok with us taking over maintenance. This is why the installation is as cumbersome as it is right now. Our end goal is to have this package continue on under it's original name in MELPA.

ffsammak commented 1 year ago

@dmitrym0 thanks a lot the breakdown by @pobermei makes a lot of sense. However, I don't know what is going on with my setup, I assigned the keybindings mentioned there and started to test one by one, the screencast below shows three note-taking functions: i org-noter-insert-precise-note: it gives a messy quotation formatting C-i org-noter-insert-note: again it gives a messy quotation formatting, any idea why? I for org-noter-insert-precise-note-toggle-no-questions: works really fine.

I used to press M - . to quickly jump from PDView to org-noter-buffer, but I can't do this any longer. Sometimes you just want to leave off the PDF to org-buffer to do some text editing, how would you achieve this given the new keymap not necessarily synching?

Also it would be nice if the quoted text will be formatted to fill the paragraph org-fill-paragraph bound to M-q. I do this each time quotation text is inserted by org-noter, so I suggest to integrate that in the precise notes by default to get the paragraph nicely filled with the text.

org-noter-plus-quote-bug

pobermei commented 1 year ago

@pobermei Thanks these two functions are indeed handy. However, I could only get the conversion working with one of them: (org-noter-pdftools--location-cons-to-link '(3 . 0.39058458354888775)) gave me after C-x C-e "::3++0.39" which is fine, but I couldn't get the other function to work : (org-noter-pdftools--location-link-to-cons '(pdf:~/Zotero/storage/U8R3PPTC/airoldiInterleukin12Interleukin12Receptor2002.pdf::4++9.78;;annot-4-2))

This gave me End of file during parsing

@ffsammak I previously didn't link the correct function for the full conversion which should be org-noter-pdftools--convert-to-location-cons

Hence, this should work now as follows:

(org-noter-pdftools--convert-to-location-cons "pdf:~/Zotero/storage/U8R3PPTC/airoldiInterleukin12Interleukin12Receptor2002.pdf::4++9.78")
=> (4 . 9.78)

@dmitrym0 thanks a lot the breakdown by @pobermei makes a lot of sense.

That is @petermao's great work. I'm just another user.

dmitrym0 commented 1 year ago

@ffsammak lets break this out, if you don't mind (otherwise it's hard to keep track of what's going on):