weirdNox / org-noter

Emacs document annotator, using Org-mode
GNU General Public License v3.0
1.07k stars 101 forks source link

Pdf slices notes #81

Open seanvert opened 5 years ago

seanvert commented 5 years ago

I made a function to do this, but it is quite ugly and I'm sure it has bugs. I read pdfs with a lot of diagrams and pictures, so it would be really cool to have some feature like that in the future. It requires org-download

(defun org-noter-insert-pdf-slice-note (event &optional switch-back)
  (interactive "@e")
  (setq current-b (buffer-name))
  (progn (pdf-view-mouse-set-region-rectangle event)
         (pdf-view-extract-region-image pdf-view-active-region
                                        (pdf-view-current-page)
                                        (pdf-view-image-size)
                                        (get-buffer-create "teste")
                                        t)
         (set-buffer "teste")
         (write-file "/tmp/screenshot.png" nil)
         (kill-buffer "screenshot.png")
         (set-buffer current-b)
         (org-noter-insert-note)
         (org-download-screenshot)
         (if switch-back             
             (switch-to-buffer-other-frame current-b))))

(define-key pdf-view-mode-map [C-M-down-mouse-1] 'org-noter-insert-pdf-slice-note)

Thanks!

seanvert commented 4 years ago
(defun org-noter-insert-image-slice-note ()
  (interactive)
  (async-start (shell-command "flameshot gui")
               (progn (shell-command "xdotool key --clearmodifiers super+Tab")
                      (async-start (org-noter-insert-note)
                                   (org-download-clipboard)))))

(define-key org-noter-doc-mode-map (kbd "y") 'org-noter-insert-image-slice-note)

I remade that function to use it with the flameshot. Most people won't want that (progn (shell-command line, but it works great with frames-only-mode. I still need to make some adjustments to it, but it is way better than the other one. It works basically call the function, it opens the flameshot gui, you mess around with its selection/edition tool and then it adds to a new/selected note header with org-download.

rdiaz02 commented 4 years ago

Thanks for that code, Sean!! Works perfectly for me. (I get a error in process sentinel: Invalid function: 0 but images get inserted just fine, and I am not sure it is not something else in my configuration).

In case it helps someone else, for similar problems I've used org-attach-screenshot (https://github.com/dfeich/org-screenshot), generally called without the prefix (so the frame is not hidden while creating the screenshot).

Using your code, I get the image and can add the precise location to the PDF (I am also using org-pdftools and org-noter-pdftools: https://github.com/fuxialexander/org-pdftools). This is really neat. Your code seems to leave the images in a subdirectory (can this be configured?).

With org-attach-screenshot you are prompted for the location of the file and its name, and one would need to invoke "M-i" or similar right before attaching the screenshot to create the note and the precise location in the PDF.

Of course, another difference is that your code is invoked from the buffer with the PDF, whereas org-attach-screenshot would be invoked from the org buffer.

Is there anything else I am missing?

seanvert commented 4 years ago

Using your code, I get the image and can add the precise location to the PDF (I am also using org-pdftools and org-noter-pdftools: https://github.com/fuxialexander/org-pdftools). This is really neat. Your code seems to leave the images in a subdirectory (can this be configured?).

With org-attach-screenshot you are prompted for the location of the file and its name, and one would need to invoke "M-i" or similar right before attaching the screenshot to create the note and the precise location in the PDF.

Yes, you can mess with a org-download-image-dir variable and set it to . or something. I'm going to check that one out, and see if I can figure out something decent, like with the same key and different behaviors depending on the buffer type. I definitely felt the need to use it from the org buffer, and that would be nice.

Of course, another difference is that your code is invoked from the buffer with the PDF, whereas org-attach-screenshot would be invoked from the org buffer.

Is there anything else I am missing?

I'm not sure about that error though. My knowledge about emacs internals is quite poor. So I can't help you out with that error message, I'm also getting some and I'm a bit lost on how to deal with some.

rdiaz02 commented 3 years ago

Yes, you can mess with a org-download-image-dir variable and set it to . or something.

Thanks. Customized to my liking now.

I'm going to check that one out, and see if I can figure out something decent, like with the same key and different behaviors depending on the buffer type. I definitely felt the need to use it from the org buffer, and that would be nice.

Apologies if this is obvious, but I just realized that using org-download-screenshot the capture from the org buffer can be done immediately. It just works. (And there is no prompting for location of file, its name, etc). Not, of course, the more sophisticated behaviour you describe, though (the same key and different behaviors depending on the buffer type).

I'm not sure about that error though. My knowledge about emacs internals is quite poor. So I can't help you out with that error message, I'm also getting some and I'm a bit lost on how to deal with some.

No problem. Things work :)