Add org export-to-clipboard commands & ox-clip
These work from markdown-mode as well as org-mode. Also adds +org/export-to-clipboard-as-rich-text for pasting org/markdown rendered as RTF.
This commit is contained in:
parent
da02fa8c38
commit
838edcea59
2 changed files with 50 additions and 0 deletions
49
modules/lang/org/autoload/org-export.el
Normal file
49
modules/lang/org/autoload/org-export.el
Normal file
|
@ -0,0 +1,49 @@
|
|||
;;; lang/org/autoload/org-export.el -*- lexical-binding: t; -*-
|
||||
;;;###if (featurep! +export)
|
||||
|
||||
(defun +org--yank-html-buffer (buffer)
|
||||
(with-current-buffer buffer
|
||||
(require 'ox-clip)
|
||||
(cond ((or IS-WINDOWS IS-MAC)
|
||||
(shell-command-on-region
|
||||
(point-min)
|
||||
(point-max)
|
||||
(cond (IS-WINDOWS ox-clip-w32-cmd)
|
||||
(IS-MAC ox-clip-osx-cmd))))
|
||||
(IS-LINUX
|
||||
(let ((html (buffer-string)))
|
||||
(with-temp-file "/tmp/ox-clip-md.html"
|
||||
(insert html))
|
||||
(apply
|
||||
'start-process "ox-clip" "*ox-clip*"
|
||||
(split-string ox-clip-linux-cmd " ")))))))
|
||||
|
||||
|
||||
;;
|
||||
;;; Commands
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/export-to-clipboard (backend)
|
||||
"Exports the current buffer/selection to the clipboard.
|
||||
|
||||
Prompts for what BACKEND to use. See `org-export-backends' for options."
|
||||
(interactive
|
||||
(list (intern (completing-read "Export to: " org-export-backends))))
|
||||
(let ((buffer (org-export-to-buffer backend "*Formatted Copy*" nil nil t t)))
|
||||
(unwind-protect
|
||||
(with-current-buffer buffer
|
||||
(kill-new (buffer-string)))
|
||||
(kill-buffer (current-buffer)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +org/export-to-clipboard-as-rich-text (beg end)
|
||||
"Export the current buffer to HTML then copies it to clipboard as rich text.
|
||||
|
||||
Supports org-mode, markdown-mode, and gfm-mode buffers. In any other mode,
|
||||
htmlize is used (takes what you see in Emacs and converts it to html, text
|
||||
properties and font-locking et all)."
|
||||
(interactive "r")
|
||||
(pcase major-mode
|
||||
((or `markdown-mode `gfm-mode)
|
||||
(+org--yank-html-buffer (markdown)))
|
||||
(_ (ox-clip-formatted-copy beg end))))
|
Loading…
Add table
Add a link
Reference in a new issue