Function: org-src--contents-for-write-back

org-src--contents-for-write-back is a byte-compiled function defined in org-src.el.gz.

Signature

(org-src--contents-for-write-back WRITE-BACK-BUF)

Documentation

Populate WRITE-BACK-BUF with contents in the appropriate format.

Assume point is in the corresponding edit buffer.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-src.el.gz
(defun org-src--contents-for-write-back (write-back-buf)
  "Populate WRITE-BACK-BUF with contents in the appropriate format.
Assume point is in the corresponding edit buffer."
  (let ((indentation-offset
	 (if org-src--preserve-indentation 0
	   (+ (or org-src--block-indentation 0)
	      (if (memq org-src--source-type '(example-block src-block))
		  org-src--content-indentation
		0))))
	(use-tabs? (and (> org-src--tab-width 0) t))
        (preserve-fl (eq org-src--source-type 'latex-fragment))
	(source-tab-width org-src--tab-width)
	(contents (org-with-wide-buffer
                   (let ((eol (line-end-position)))
                     (list (buffer-substring (point-min) eol)
                           (buffer-substring eol (point-max))))))
	(write-back org-src--allow-write-back)
        (preserve-blank-line org-src--preserve-blank-line)
        marker)
    (with-current-buffer write-back-buf
      ;; Reproduce indentation parameters from source buffer.
      (setq indent-tabs-mode use-tabs?)
      (when (> source-tab-width 0) (setq tab-width source-tab-width))
      ;; Apply WRITE-BACK function on edit buffer contents.
      (insert (org-no-properties (car contents)))
      (setq marker (point-marker))
      (insert (org-no-properties (car (cdr contents))))
      (goto-char (point-min))
      (when (functionp write-back) (save-excursion (funcall write-back)))
      ;; Add INDENTATION-OFFSET to every line in buffer,
      ;; unless indentation is meant to be preserved.
      (when (> indentation-offset 0)
	(when preserve-fl (forward-line))
        (while (not (eobp))
	  (skip-chars-forward " \t")
          (when (or (not (eolp))                               ; not a blank line
                    (and (eq (point) (marker-position marker)) ; current line
                         preserve-blank-line))
	    (let ((i (current-column)))
	      (delete-region (line-beginning-position) (point))
	      (indent-to (+ i indentation-offset))))
	  (forward-line)))
      (set-marker marker nil))))