Function: org-export-with-buffer-copy

org-export-with-buffer-copy is a macro defined in ox.el.gz.

Signature

(org-export-with-buffer-copy &rest BODY &key TO-BUFFER DROP-VISIBILITY DROP-NARROWING DROP-CONTENTS DROP-LOCALS &allow-other-keys)

Documentation

Apply BODY in a copy of the current buffer.

The copy preserves local variables, visibility and contents of the original buffer. Point is at the beginning of the buffer when BODY is applied.

Optional keys can modify what is being copied and the generated buffer copy. :to-buffer, :drop-visibility, :drop-narrowing,
:drop-contents, and :drop-locals are passed as arguments to
org-export-copy-buffer.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ox.el.gz
(cl-defmacro org-export-with-buffer-copy ( &rest body
                                           &key to-buffer drop-visibility
                                           drop-narrowing drop-contents
                                           drop-locals
                                           &allow-other-keys)
  "Apply BODY in a copy of the current buffer.
The copy preserves local variables, visibility and contents of
the original buffer.  Point is at the beginning of the buffer
when BODY is applied.

Optional keys can modify what is being copied and the generated buffer
copy.  `:to-buffer', `:drop-visibility', `:drop-narrowing',
`:drop-contents', and `:drop-locals' are passed as arguments to
`org-export-copy-buffer'."
  (declare (debug t))
  (org-with-gensyms (buf-copy)
    `(let ((,buf-copy (org-export-copy-buffer
                       :to-buffer ,to-buffer
                       :drop-visibility ,drop-visibility
                       :drop-narrowing ,drop-narrowing
                       :drop-contents ,drop-contents
                       :drop-locals ,drop-locals)))
       (unwind-protect
	   (with-current-buffer ,buf-copy
	     (goto-char (point-min))
             (prog1
                 (progn ,@body)
               ;; `org-export-copy-buffer' carried the value of
               ;; `buffer-file-name' from the original buffer.  When not
               ;; killed, the new buffer copy may become a target of
               ;; `find-file'.  Prevent this.
               (setq buffer-file-name nil)))
	 (and (buffer-live-p ,buf-copy)
	      ;; Kill copy without confirmation.
	      (progn (with-current-buffer ,buf-copy
		       (restore-buffer-modified-p nil))
                     (unless ,to-buffer
		       (kill-buffer ,buf-copy))))))))