Function: org-babel-do-in-edit-buffer

org-babel-do-in-edit-buffer is an autoloaded macro defined in ob-core.el.gz.

Signature

(org-babel-do-in-edit-buffer &rest BODY)

Documentation

Evaluate BODY in edit buffer if there is a code block at point.

Return t if a code block was found at point, nil otherwise.

Source Code

;; Defined in /usr/src/emacs/lisp/org/ob-core.el.gz
;;;###autoload
(defmacro org-babel-do-in-edit-buffer (&rest body)
  "Evaluate BODY in edit buffer if there is a code block at point.
Return t if a code block was found at point, nil otherwise."
  (declare (debug (body)))
  `(let* ((element (org-element-at-point))
	  ;; This function is not supposed to move point.  However,
	  ;; `org-edit-src-code' always moves point back into the
	  ;; source block.  It is problematic if the point was before
	  ;; the code, e.g., on block's opening line.  In this case,
	  ;; we want to restore this location after executing BODY.
	  (outside-position
	   (and (<= (line-beginning-position)
		   (org-element-post-affiliated element))
		(point-marker)))
	  (org-src-window-setup 'switch-invisibly))
     (when (and (org-babel-where-is-src-block-head element)
		(condition-case nil
                    (org-edit-src-code)
                  (t
                   (org-edit-src-exit)
                   (when outside-position (goto-char outside-position))
                   nil)))
       (unwind-protect (progn ,@body)
	 (org-edit-src-exit)
	 (when outside-position (goto-char outside-position)))
       t)))