I often find myself doing this:
- Selecting a region of text in an
- Selecting the converted text in the temporary buffer (can't just do
mark-whole-buffersince for these purposes I'm obviously not interested in the empty Table of Contents I get).
- Killing the temporary buffer and going back to where I was.
EDIT: Here is my question: How can I write a function that will, after selecting a region of text, do all of that for me? In other words, I want a function which will take a region from an
org file, copy the result of
org-md-export-as-markdown to the clipboard, and return to the
org file I called the function from.
Some related attempts:
John Kitchin has a post where he does something similar to what I'm doing. But he uses
texutil, since he wants the output in a format that
org won't export to. I'm assuming what I need would be much simpler than that.
Abo-abo's function is here
(defun ora-org-to-html-to-clipboard () "Export region to HTML, and copy it to the clipboard." (interactive) (org-export-to-file 'html "/tmp/org.html") (apply 'start-process "xclip" "*xclip*" (split-string "xclip -verbose -i /tmp/org.html -t text/html -selection clipboard" " ")))
I presume I can modify something like this by replacing
xclip -verbose -i /tmp/org.html -t text/html -selection clipboard
pbcopy < /tmp/org.html
but I can't quite get it to work.
My own, failed attempt so far:
This was my blind attempt at adapting the function
ora-org-to-html to use
pbcopy instead. (Adapting it to use
org-md-export-to-markdown would be fairly straightforward, I think.)
(defun org-to-html-to-clipboard () "Export region to HTML, and copy it to the clipboard." (interactive) (org-export-to-file 'html "/tmp/org.html") (apply 'start-process "pbcopy" "*pbcopy*" (split-string "pbcopy < /tmp/org.html")))
Running this does create the file
/tmp/org.html but the contents aren't sent to the clipboard. Further, the
html file contains the entirety of the buffer I run the function from (which I gather is what the original function was supposed to do) rather than just the selected region. Finally, this function requires creating a temporary file, rather than just using the temporary buffer that
org-mode generates with the
I'm completely illiterate when it comes to
elisp so any suggestions, no matter how elementary they seem, would be most welcome.