From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price Subject: Re: generating org headings from a source block Date: Tue, 10 Nov 2015 09:28:53 -0500 Message-ID: References: <87wptqg7k5.fsf@alphaville.usersys.redhat.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7b41411e75c46905243087be Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35456) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zw9up-0008H9-8A for emacs-orgmode@gnu.org; Tue, 10 Nov 2015 09:28:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zw9un-0001Ox-TQ for emacs-orgmode@gnu.org; Tue, 10 Nov 2015 09:28:55 -0500 Received: from mail-ig0-x234.google.com ([2607:f8b0:4001:c05::234]:35257) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zw9un-0001Or-Oj for emacs-orgmode@gnu.org; Tue, 10 Nov 2015 09:28:53 -0500 Received: by igl9 with SMTP id 9so54373713igl.0 for ; Tue, 10 Nov 2015 06:28:53 -0800 (PST) In-Reply-To: <87wptqg7k5.fsf@alphaville.usersys.redhat.com> 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 Cc: Org Mode --047d7b41411e75c46905243087be Content-Type: text/plain; charset=UTF-8 On Mon, Nov 9, 2015 at 4:57 PM, Nick Dokos wrote: > Matt Price writes: > > > 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) > > ...) > > ------------- > > > > 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? > > Have two source blocks? Or use :results output and output the string with > (princ string)? > I ended up with this. It's not so bad, Though I use it enough that I should probably just define another function. Also, I'm interested in how 2 source blocks would have worked... #+BEGIN_SRC elisp :results output raw (let ((sources '( "/home/matt/HackingHistory/readings/Troper-becoming-immigrant-city.pdf" "/home/matt/HackingHistory/readings/historical-authority-hampton.pdf")) (output "")) (dolist (thispdf sources) (message "this pdf is: %s" thispdf) (setq output (concat output (pdf-annot-markups-as-org-text thispdf )))) (princ output)) #+END_SRC > > > (b) the whole output is wrapped in an example block, which I don't > want. Can I do something to fix > > this? > > Maybe :results value raw or :results value verbatim - untested. I can > never remember the right combo off the top of my head. > :results value raw works -- thank you! > > > 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. > > > > Pass the level as a parameter? > Can I pass the level of the current heading as a parameter, e.g.: #+BEGIN_SRC elisp :results output raw :var level=(1+ CURRENT-ORG-LEVEL) where obviously CURRENT-ORG-LEVEL is some function I don't know how to access? Many thanks for your help, Nick! > > -- > Nick > > > > > --047d7b41411e75c46905243087be Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On Mon, Nov 9, 2015 at 4:57 PM, Nick Dokos <ndokos@gmail.com> wrote:
Matt Price <moptop99@gmail.= com> writes:

> I would like to be able to insert into an org-buffer the text extracte= d from a pdf file. PDF-Tools (
> https://github.com/politza/pdf-tools/) provides some e= xcellent tools for doing this.=C2=A0 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)
>=C2=A0 =C2=A0...)
> -------------
>
> I'm sure it is very clumsy, but it sort of works.=C2=A0 I would li= ke to be able to call this function from a
> source block:
>
> #+BEGIN_SRC elisp
> (pdf-annot-export-as-org-heading "/home/matt/HackingHistory/readi= ngs/latour-pandoras-hope.pdf")
> (pdf-annot-export-as-org-heading "/home/matt/HackingHistory/readi= ngs/historical-authority-hampton.pdf")
> #+END_SRC
>
> The results are close to, but not precisely, what I want:
>
> #+RESULTS:
> #+begin_example
> ** historical-authority-hampton
>
> =C2=A0([[file:///home/matt/HackingHistory/readings/historical-authorit= y-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 r= eports the final returned value.
> But :results output gets me nothing.=C2=A0 What should I be doing?

Have two source blocks? Or use :results output and output the string= with (princ string)?

I ended up with t= his.=C2=A0 It's not so bad, Though I use it enough that I should probab= ly just define another function. Also, I'm interested in how 2 source b= locks would have worked...

#+BEGIN_SRC elisp :results output raw=C2=A0 (let ((sources '(
=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 "/h= ome/matt/HackingHistory/readings/Troper-becoming-immigrant-city.pdf"= =C2=A0 "/home/matt/HackingHistory/readings/historical-authority-hampto= n.pdf"))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (output "&= quot;))
=C2=A0=C2=A0=C2=A0 (dolist (thispdf sources)
=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 (message "this pdf is: %s" thispdf)
=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 (setq output (concat output (pdf-annot-markups-as-org= -text thispdf ))))
=C2=A0=C2=A0=C2=A0 (princ output))
#+END_SRC
= =C2=A0

> (b) the whole output is wrapped in an example block, which I don't= want.=C2=A0 Can I do something to fix
> this?

Maybe :results value raw=C2=A0 or :results value verbatim - untested= . I can
never remember the right combo off the top of my head.

:results value raw works -- thank you!

> also, (c): I'd rather set the level of the org heading based on co= ntext. Can I do that when I call from
> a source block? Should I maybe be doing this some other way (e.g., jsu= t write an interactive function
> and call it with M-x? But I like being able to assemble all the readin= gs at one go, if possible.=C2=A0
>

Pass the level as a parameter?

C= an I pass the level of the current heading as a parameter, e.g.:
=C2=A0#= +BEGIN_SRC elisp :results output raw :var level=3D(1+ CURRENT-ORG-LEVEL)
where obviously CURRENT-ORG-LEVEL is some function I don= 9;t know how to access?

Many thanks for your help, Nick!<= br>

--
Nick





--047d7b41411e75c46905243087be--