Function: c-indent-region

c-indent-region is a byte-compiled function defined in cc-cmds.el.gz.

Signature

(c-indent-region START END &optional QUIET)

Documentation

Indent syntactically lines whose first char is between START and END inclusive.

If the optional argument QUIET is non-nil then no syntactic errors are reported, even if c-report-syntactic-errors is non-nil.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-cmds.el.gz
(defun c-indent-region (start end &optional quiet)
  "Indent syntactically lines whose first char is between START and END inclusive.
If the optional argument QUIET is non-nil then no syntactic
errors are reported, even if `c-report-syntactic-errors' is
non-nil."
  (save-excursion
    (goto-char end)
    (skip-chars-backward " \t\n\r\f\v")
    (setq end (point))
    (goto-char start)
    ;; Advance to first nonblank line.
    (beginning-of-line)
    (skip-chars-forward " \t\n\r\f\v")
    (setq start (point))
    (beginning-of-line)
    (setq c-parsing-error
	  (or (let ((endmark (copy-marker end))
		    (c-parsing-error nil)
		    ;; shut up any echo msgs on indiv lines
		    (c-echo-syntactic-information-p nil)
		    (ml-macro-start	; Start pos of multi-line macro.
		     (and (c-save-buffer-state ()
			    (save-excursion (c-beginning-of-macro)))
			  (eq (char-before (c-point 'eol)) ?\\)
			  start))
		    (c-fix-backslashes nil)
		    syntax)
		(unwind-protect
		    (progn
		      (c-progress-init start end 'c-indent-region)

		      (while (and (bolp) ;; One line each time round the loop.
				  (not (eobp))
				  (< (point) endmark))
			;; update progress
			(c-progress-update)
			;; skip empty lines
			(unless (or (looking-at "\\s *$")
				    (and ml-macro-start (looking-at "\\s *\\\\$")))
			  ;; Get syntax and indent.
			  (c-save-buffer-state nil
			    (setq syntax (c-guess-basic-syntax)))
			  (c-indent-line syntax t t))

			(if ml-macro-start
			    ;; End of current multi-line macro?
			    (when (and c-auto-align-backslashes
				       (not (eq (char-before (c-point 'eol)) ?\\)))
			      ;; Fixup macro backslashes.
			      (c-backslash-region ml-macro-start (c-point 'bonl) nil)
			      (setq ml-macro-start nil))
			  ;; New multi-line macro?
			  (if (and (assq 'cpp-macro syntax)
				   (eq (char-before (c-point 'eol)) ?\\))
			    (setq ml-macro-start (point))))

			(forward-line))

		      (if (and ml-macro-start c-auto-align-backslashes)
			  (c-backslash-region ml-macro-start (c-point 'bopl) nil t)))
		  (set-marker endmark nil)
		  (c-progress-fini 'c-indent-region))
		(c-echo-parsing-error quiet))
	      c-parsing-error))))