Function: c-tentative-buffer-changes

c-tentative-buffer-changes is a macro defined in cc-defs.el.gz.

Signature

(c-tentative-buffer-changes &rest BODY)

Documentation

Eval BODY and optionally restore the buffer contents to the state it was in before BODY. Any changes are kept if the last form in BODY returns non-nil. Otherwise it's undone using the undo facility, and various other buffer state that might be affected by the changes is restored. That includes the current buffer, point, mark, mark activation (similar to save-excursion), and the modified state. The state is also restored if BODY exits nonlocally.

If BODY makes a change that unconditionally is undone then wrap this macro inside c-save-buffer-state. That way the change can be done even when the buffer is read-only, and without interference from various buffer change hooks.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-defs.el.gz
(defmacro c-tentative-buffer-changes (&rest body)
  "Eval BODY and optionally restore the buffer contents to the state it
was in before BODY.  Any changes are kept if the last form in BODY
returns non-nil.  Otherwise it's undone using the undo facility, and
various other buffer state that might be affected by the changes is
restored.  That includes the current buffer, point, mark, mark
activation (similar to `save-excursion'), and the modified state.
The state is also restored if BODY exits nonlocally.

If BODY makes a change that unconditionally is undone then wrap this
macro inside `c-save-buffer-state'.  That way the change can be done
even when the buffer is read-only, and without interference from
various buffer change hooks."
  (declare (indent 0) (debug t))
  `(let (-tnt-chng-keep
	 -tnt-chng-state
	 (old-undo-list buffer-undo-list))
     (unwind-protect
	 ;; Insert an undo boundary for use with `undo-more'.  We
	 ;; don't use `undo-boundary' since it doesn't insert one
	 ;; unconditionally.
	 (setq buffer-undo-list
	       (if (eq old-undo-list t)
		   nil
		 (cons nil buffer-undo-list))
	       old-undo-list (if (eq old-undo-list t)
				 t
			       buffer-undo-list)
	       -tnt-chng-state (c-tnt-chng-record-state
				old-undo-list)
	       -tnt-chng-keep (progn ,@body))
       (c-tnt-chng-cleanup -tnt-chng-keep -tnt-chng-state))))