From: Matt Price <moptop99@gmail.com>
To: Org Mode <emacs-orgmode@gnu.org>
Subject: generating org headings from a source block
Date: Mon, 9 Nov 2015 15:29:44 -0500 [thread overview]
Message-ID: <CAN_Dec8v-80hdRUvBiOuwmmWyLkda3qDr+VrMXNU8hyknXcSXA@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2995 bytes --]
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
[-- Attachment #2: Type: text/html, Size: 3994 bytes --]
next reply other threads:[~2015-11-09 20:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-09 20:29 Matt Price [this message]
2015-11-09 21:57 ` generating org headings from a source block Nick Dokos
2015-11-10 14:28 ` Matt Price
2015-11-10 16:16 ` Nick Dokos
2015-11-10 16:31 ` Matt Price
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAN_Dec8v-80hdRUvBiOuwmmWyLkda3qDr+VrMXNU8hyknXcSXA@mail.gmail.com \
--to=moptop99@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.