Function: org-export-to-buffer

org-export-to-buffer is an autoloaded and byte-compiled function defined in ox.el.gz.

Signature

(org-export-to-buffer BACKEND BUFFER &optional ASYNC SUBTREEP VISIBLE-ONLY BODY-ONLY EXT-PLIST POST-PROCESS)

Documentation

Call org-export-as with output to a specified buffer.

BACKEND is either an export back-end, as returned by, e.g., org-export-create-backend, or a symbol referring to a registered back-end.

BUFFER is the name of the output buffer. If it already exists, it will be erased first, otherwise, it will be created.

A non-nil optional argument ASYNC means the process should happen asynchronously. The resulting buffer should then be accessible through the org-export-stack interface. When ASYNC is nil, the buffer is displayed if org-export-show-temporary-export-buffer is non-nil.

Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and EXT-PLIST are similar to those used in org-export-as, which see.

Optional argument POST-PROCESS is a function which should accept no argument. It is always called within the current process, from BUFFER, with point at its beginning. Export back-ends can use it to set a major mode there, e.g.,

  (defun org-latex-export-as-latex
    (&optional async subtreep visible-only body-only ext-plist)
    (interactive)
    (org-export-to-buffer 'latex "*Org LATEX Export*"
      async subtreep visible-only body-only ext-plist
      #'LaTeX-mode))

When expressed as an anonymous function, using lambda, POST-PROCESS needs to be quoted.

This function returns BUFFER.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ox.el.gz
;;;###autoload
(defun org-export-to-buffer
    (backend buffer
	     &optional async subtreep visible-only body-only ext-plist
	     post-process)
  "Call `org-export-as' with output to a specified buffer.

BACKEND is either an export back-end, as returned by, e.g.,
`org-export-create-backend', or a symbol referring to
a registered back-end.

BUFFER is the name of the output buffer.  If it already exists,
it will be erased first, otherwise, it will be created.

A non-nil optional argument ASYNC means the process should happen
asynchronously.  The resulting buffer should then be accessible
through the `org-export-stack' interface.  When ASYNC is nil, the
buffer is displayed if `org-export-show-temporary-export-buffer'
is non-nil.

Optional arguments SUBTREEP, VISIBLE-ONLY, BODY-ONLY and
EXT-PLIST are similar to those used in `org-export-as', which
see.

Optional argument POST-PROCESS is a function which should accept
no argument.  It is always called within the current process,
from BUFFER, with point at its beginning.  Export back-ends can
use it to set a major mode there, e.g.,

  (defun org-latex-export-as-latex
    (&optional async subtreep visible-only body-only ext-plist)
    (interactive)
    (org-export-to-buffer \\='latex \"*Org LATEX Export*\"
      async subtreep visible-only body-only ext-plist
      #\\='LaTeX-mode))

When expressed as an anonymous function, using `lambda',
POST-PROCESS needs to be quoted.

This function returns BUFFER."
  (declare (indent 2))
  (if async
      (org-export-async-start
	  (let ((cs buffer-file-coding-system))
	    (lambda (output)
	      (with-current-buffer (get-buffer-create buffer)
                (erase-buffer)
                (setq buffer-file-coding-system cs)
                (insert output)
                (goto-char (point-min))
                (org-export-add-to-stack (current-buffer) backend)
                (ignore-errors (funcall post-process)))))
	`(org-export-as
	  ',backend ,subtreep ,visible-only ,body-only ',ext-plist))
    (let ((output
	   (org-export-as backend subtreep visible-only body-only ext-plist))
	  (buffer (get-buffer-create buffer))
	  (encoding buffer-file-coding-system))
      (when (and (org-string-nw-p output) (org-export--copy-to-kill-ring-p))
	(org-kill-new output))
      (with-current-buffer buffer
	(erase-buffer)
	(setq buffer-file-coding-system encoding)
	(insert output)
	(goto-char (point-min))
	(and (functionp post-process) (funcall post-process)))
      (when org-export-show-temporary-export-buffer
	(switch-to-buffer-other-window buffer))
      buffer)))