diff --git a/lisp/ox-html.el b/lisp/ox-html.el index e3495f528..4eabad4e1 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -3193,6 +3193,15 @@ is non-nil." (when org-export-show-temporary-export-buffer (switch-to-buffer-other-window outbuf))))) +;;;###autoload +(defun org-html-convert-region-to-html () + "Assume the current region has org-mode syntax, and convert it to HTML. +This can be used in any buffer. For example, you can write an +itemized list in org-mode syntax in an HTML buffer and use this +command to convert it." + (interactive) + (org-export-replace-region-by 'html)) + ;;;###autoload (defun org-html-export-to-html (&optional async subtreep visible-only body-only ext-plist) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index aad92718e..9c0469568 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -2821,6 +2821,15 @@ is non-nil." (when org-export-show-temporary-export-buffer (switch-to-buffer-other-window outbuf))))) +;;;###autoload +(defun org-latex-convert-region-to-latex () + "Assume the current region has org-mode syntax, and convert it to LaTeX. +This can be used in any buffer. For example, you can write an +itemized list in org-mode syntax in an LaTeX buffer and use this +command to convert it." + (interactive) + (org-export-replace-region-by 'latex)) + ;;;###autoload (defun org-latex-export-to-latex (&optional async subtreep visible-only body-only ext-plist) diff --git a/lisp/ox-md.el b/lisp/ox-md.el index 43c92a24a..61f42b864 100644 --- a/lisp/ox-md.el +++ b/lisp/ox-md.el @@ -455,6 +455,15 @@ non-nil." (when org-export-show-temporary-export-buffer (switch-to-buffer-other-window outbuf))))) +;;;###autoload +(defun org-md-convert-region-to-md () + "Assume the current region has org-mode syntax, and convert it to Markdown. +This can be used in any buffer. For example, you can write an +itemized list in org-mode syntax in a Markdown buffer and use +this command to convert it." + (interactive) + (org-export-replace-region-by 'md)) + ;;;###autoload (defun org-md-export-to-markdown (&optional async subtreep visible-only) diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el index dd4e024bc..b5663240a 100644 --- a/lisp/ox-texinfo.el +++ b/lisp/ox-texinfo.el @@ -1779,6 +1779,15 @@ publishing directory. Return output file name." (org-publish-org-to 'texinfo filename ".texi" plist pub-dir)) +;;;###autoload +(defun org-texinfo-convert-region-to-texinfo () + "Assume the current region has org-mode syntax, and convert it to Texinfo. +This can be used in any buffer. For example, you can write an +itemized list in org-mode syntax in an Texinfo buffer and use +this command to convert it." + (interactive) + (org-export-replace-region-by 'texinfo)) + (defun org-texinfo-compile (file) "Compile a texinfo file. diff --git a/lisp/ox.el b/lisp/ox.el index e2c1b5b7a..3618f836f 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -3056,6 +3056,18 @@ Return code as a string." (org-mode) (org-export-as backend nil nil body-only ext-plist))) +;;;###autoload +(defun org-export-replace-region-by (backend) + "Replace the active region by its export to BACKEND." + (if (not (org-region-active-p)) + (user-error "No active region to replace") + (let* ((beg (region-beginning)) + (end (region-end)) + (str (buffer-substring beg end)) rpl) + (setq rpl (org-export-string-as str backend t)) + (delete-region beg end) + (insert rpl)))) + ;;;###autoload (defun org-export-insert-default-template (&optional backend subtreep) "Insert all export keywords with default values at beginning of line.