Function: indent-code-rigidly

indent-code-rigidly is an interactive and byte-compiled function defined in lisp-mode.el.gz.

Signature

(indent-code-rigidly START END ARG &optional NOCHANGE-REGEXP)

Documentation

Indent all lines of code, starting in the region, sideways by ARG columns.

Does not affect lines starting inside comments or strings, assuming that the start of the region is not inside them.

Called from a program, takes args START, END, COLUMNS and NOCHANGE-REGEXP. The last is a regexp which, if matched at the beginning of a line, means don't indent that line.

View in manual

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/lisp-mode.el.gz
(defun indent-code-rigidly (start end arg &optional nochange-regexp)
  "Indent all lines of code, starting in the region, sideways by ARG columns.
Does not affect lines starting inside comments or strings, assuming that
the start of the region is not inside them.

Called from a program, takes args START, END, COLUMNS and NOCHANGE-REGEXP.
The last is a regexp which, if matched at the beginning of a line,
means don't indent that line."
  (interactive "r\np")
  (let (state)
    (save-excursion
      (goto-char end)
      (setq end (point-marker))
      (goto-char start)
      (or (bolp)
	  (setq state (parse-partial-sexp (point)
					  (progn
					    (forward-line 1) (point))
					  nil nil state)))
      (while (< (point) end)
	(or (car (nthcdr 3 state))
	    (and nochange-regexp
		 (looking-at nochange-regexp))
	    ;; If line does not start in string, indent it
	    (let ((indent (current-indentation)))
	      (delete-region (point) (progn (skip-chars-forward " \t") (point)))
	      (or (eolp)
		  (indent-to (max 0 (+ indent arg)) 0))))
	(setq state (parse-partial-sexp (point)
					(progn
					  (forward-line 1) (point))
					nil nil state))))))