Function: combobulate--consume-node

combobulate--consume-node is a natively compiled function defined in combobulate-manipulation.el.

Signature

(combobulate--consume-node NODE &optional BALANCE)

Documentation

Consume NODE in the current buffer.

If BALANCE is non-nil, more than the requested NODE may be consumeed also (and appended to the final string, including any whitespace between NODE and the balancing node whitespace) if consuming NODE results in one or more ERROR nodes appearing in the tree.

If consuming the balancing node leaves the tree in an error state, then that consume is undone and only the first consume is kept.

Source Code

;; Defined in /nix/store/b5fvrwzi3zvkabyzx0in6gw1cj963z46-emacs-packages-deps/share/emacs/site-lisp/combobulate-manipulation.el
(defun combobulate--consume-node (node &optional balance)
  "Consume NODE in the current buffer.

If BALANCE is non-nil, more than the requested NODE may be consumeed
also (and appended to the final string, including any whitespace
between NODE and the balancing node whitespace) if consuming NODE
results in one or more `ERROR' nodes appearing in the tree.

If consuming the balancing node leaves the tree in an error state,
then that consume is undone and only the first consume is kept."
  (let ((num-errors (length (combobulate-get-error-nodes)))
        (start) (end)
        (node-texts))
    (save-excursion
      ;; use point as the start and not the node so we capture the
      ;; whitespace also.
      (setq start (point)
            end (combobulate-node-end node))
      (push (delete-and-extract-region start end) node-texts)
      (when (and balance (combobulate-get-error-nodes))
        (push (let ((text))
                (combobulate-with-change-group
                  (setq text (delete-and-extract-region
                              (point)
                              (save-excursion
                                (combobulate-skip-whitespace-forward t)
                                (combobulate-node-end (combobulate-node-at-point)))))
                  (when (> (length (combobulate-get-error-nodes)) num-errors)
                    (cancel-changes)
                    (setq text nil)))
                text)
              node-texts)))
    (string-join (nreverse node-texts) "")))