Function: c-snug-do-while

c-snug-do-while is a byte-compiled function defined in cc-align.el.gz.

Signature

(c-snug-do-while SYNTAX POS)

Documentation

Dynamically calculate brace hanginess for do-while statements.

Using this function, while clauses that end a do-while block will remain on the same line as the brace that closes that block.

See c-hanging-braces-alist for how to utilize this function as an ACTION associated with block-close syntax.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-align.el.gz
(defun c-snug-do-while (syntax _pos)
  "Dynamically calculate brace hanginess for do-while statements.
Using this function, `while' clauses that end a `do-while' block will
remain on the same line as the brace that closes that block.

See `c-hanging-braces-alist' for how to utilize this function as an
ACTION associated with `block-close' syntax."
  (save-excursion
    (let (langelem)
      (if (and (eq syntax 'block-close)
	       (setq langelem (assq 'block-close c-syntactic-context))
	       (progn (goto-char (c-langelem-pos langelem))
		      (if (eq (char-after) ?{)
			  (c-safe (c-forward-sexp -1)))
		      (looking-at "\\_<do\\_>")))
	  '(before)
	'(before after)))))