From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price Subject: generating org headings from a source block Date: Mon, 9 Nov 2015 15:29:44 -0500 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7bd76b0424a0a405242174f9 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:59391) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zvt4V-0007ND-9K for emacs-orgmode@gnu.org; Mon, 09 Nov 2015 15:29:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zvt4T-0008OI-LC for emacs-orgmode@gnu.org; Mon, 09 Nov 2015 15:29:47 -0500 Received: from mail-ig0-x22f.google.com ([2607:f8b0:4001:c05::22f]:33685) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zvt4T-0008OA-Fg for emacs-orgmode@gnu.org; Mon, 09 Nov 2015 15:29:45 -0500 Received: by igvi2 with SMTP id i2so83598347igv.0 for ; Mon, 09 Nov 2015 12:29:44 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Org Mode --047d7bd76b0424a0a405242174f9 Content-Type: text/plain; charset=UTF-8 I would like to be able to insert into an org-buffer the text extracted from a pdf file. PDF-Tools (https://github.com/politza/pdf-tools/) provides some excellent tools for doing this. I've written (well, msotly stolen) a defun that finds all my highlights and returns them in the form of an org heading: (defun pdf-annot-export-as-org-heading (pdfpath) "Acquire highlight annotations as text, and insert into existing buffer as org heading" (interactive) (let ((outputstring "") ) (save-excursion (find-file pdfpath) (let ( (annots (sort (pdf-annot-getannots nil (list 'highlight) nil) 'pdf-annot-compare-annotations)) (filename (format "%s.org" (file-name-sans-extension (buffer-name)))) (linktext (concat "[[file://" (buffer-file-name) "][" (file-name-sans-extension (buffer-name)) "]]" ))) (setq outputstring (concat "** " (file-name-sans-extension (buffer-name)) "\n\n")) ;; (insert (concat "#+TITLE: Notes for " (file-name-sans-extension filename))) ;; (org-insert-heading-respect-content) ;; (insert (file-name-sans-extension filename)) (mapc (lambda (annot) ;; traverse all annotations (message "%s" annot) (let ((page (assoc-default 'page annot)) (text (assoc-default 'subject annot)) ) ;;(insert (concat "\n" text " (" linktext ", " (number-to-string page) ")\n")) (setq outputstring (concat outputstring text " (" linktext ", " (number-to-string page) ")\n\n")) ) ) annots) )) ;;(write-file filename t) outputstring )) ------------- I'm sure it is very clumsy, but it sort of works. I would like to be able to call this function from a source block: #+BEGIN_SRC elisp (pdf-annot-export-as-org-heading "/home/matt/HackingHistory/readings/latour-pandoras-hope.pdf") (pdf-annot-export-as-org-heading "/home/matt/HackingHistory/readings/historical-authority-hampton.pdf") #+END_SRC The results are close to, but not precisely, what I want: #+RESULTS: #+begin_example ** historical-authority-hampton ([[file:///home/matt/HackingHistory/readings/historical-authority-hampton.pdf][historical-authority-hampton]], 1) In the Tudor palace at Hampton Court, there is a.... ... #+end_example (a) I only get the last command, because I guess :results value only reports the final returned value. But :results output gets me nothing. What should I be doing? (b) the whole output is wrapped in an example block, which I don't want. Can I do something to fix this? also, (c): I'd rather set the level of the org heading based on context. Can I do that when I call from a source block? Should I maybe be doing this some other way (e.g., jsut write an interactive function and call it with M-x? But I like being able to assemble all the readings at one go, if possible. Thanks as always, Matt --047d7bd76b0424a0a405242174f9 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I would like to be= able to insert into an org-buffer the text extracted from a pdf file. PDF-= Tools (https://github.com= /politza/pdf-tools/) provides some excellent tools for doing this.=C2= =A0 I've written (well, msotly stolen) a defun that finds all my highli= ghts and returns them in the form of an org heading:

(defun pdf-anno= t-export-as-org-heading (pdfpath)
=C2=A0 "Acquire highlight annotat= ions as text, and insert into existing buffer as org heading"
=C2= =A0 (interactive)
=C2=A0 (let ((outputstring "")
=C2=A0=C2= =A0=C2=A0
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 )
=C2=A0=C2=A0= =C2=A0 (save-excursion
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (find-file pdfpath= )
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (let (
=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (annots (sort (pdf-annot-getannots = nil (list 'highlight)=C2=A0 nil) 'pdf-annot-compare-annotations))=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (filen= ame (format "%s.org"
=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (file-name-= sans-extension
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 (buffer-name))))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 (linktext (concat "[[file://" (buffer-file-name)
= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= "][" (file-name-sans-extension (buffer-name)) "]]" )))=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (setq outputstring (concat "** &quo= t; (file-name-sans-extension (buffer-name)) "\n\n"))
=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ;; (insert (concat "#+TITLE: Notes fo= r " (file-name-sans-extension filename)))
=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 ;; (org-insert-heading-respect-content)
=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 ;; (insert (file-name-sans-extension filename))
=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 (mapc
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (lambda (anno= t) ;; traverse all annotations
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 (message "%s" annot)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 (let ((page (assoc-default 'page annot))
=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 (text (assoc-default 'subject annot))
=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 )
=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ;;(insert (concat "= ;\n" text " (" linktext ", " (number-to-string pag= e) ")\n"))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 (setq outputstring (concat outputstring text " (" linkt= ext ", " (number-to-string page) ")\n\n"))
=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 )
=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 )
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 an= nots)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ))
=C2=A0=C2=A0=C2=A0 ;;(write-f= ile filename t)
=C2=A0=C2=A0=C2=A0 outputstring
=C2=A0=C2=A0=C2=A0 ))=

-------------

I'm sure it is very clumsy, but it s= ort of works.=C2=A0 I would like to be able to call this function from a so= urce block:

#+BEGIN_SRC elisp
(pdf-annot-export-as-org-heading &= quot;/home/matt/HackingHistory/readings/latour-pandoras-hope.pdf")
= (pdf-annot-export-as-org-heading "/home/matt/HackingHistory/readings/h= istorical-authority-hampton.pdf")
#+END_SRC

The result= s are close to, but not precisely, what I want:

#+RESULTS:
#+beg= in_example
** historical-authority-hampton

=C2=A0([[file:///home/= matt/HackingHistory/readings/historical-authority-hampton.pdf][historical-a= uthority-hampton]], 1)

In the Tudor palace at Hampton Court, there i= s a....
...
#+end_example

(a) I only get the last = command, because I guess :results value only reports the final returned val= ue. But :results output gets me nothing.=C2=A0 What should I be doing?
<= /div>(b) the whole output is wrapped in an example block, which I don't= want.=C2=A0 Can I do something to fix this?
also, (c): I'd r= ather set the level of the org heading based on context. Can I do that when= I call from a source block? Should I maybe be doing this some other way (e= .g., jsut write an interactive function and call it with M-x? But I like be= ing able to assemble all the readings at one go, if possible.=C2=A0
Thanks as always,
Matt


<= /div> --047d7bd76b0424a0a405242174f9--