Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Export an Org region to RTF and copy it to the clipboard. Ideal for copying source code blocks to Google Docs and preserve syntax highlighting and indentation.
(defun dm/copy-as-rtf ()
"Export region to RTF and copy it to the clipboard."
(interactive)
(save-window-excursion
(let* ((buf (org-export-to-buffer 'html "*Formatted Copy*" nil nil t t))
(html (with-current-buffer buf (buffer-string))))
(with-current-buffer buf
(shell-command-on-region
(point-min)
(point-max)
"textutil -stdin -format html -convert rtf -stdout | pbcopy"))
(kill-buffer buf))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment