Skip to content

Instantly share code, notes, and snippets.

@danielmartin
Created July 6, 2019 18:13
Show Gist options
  • Save danielmartin/3c5d3a3a8cd24a3556379c5251651748 to your computer and use it in GitHub Desktop.
Save danielmartin/3c5d3a3a8cd24a3556379c5251651748 to your computer and use it in GitHub Desktop.
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