Function: indent-sexp
indent-sexp is an interactive and byte-compiled function defined in
lisp-mode.el.gz.
Signature
(indent-sexp &optional ENDPOS)
Documentation
Indent each line of the list starting just after point.
If optional arg ENDPOS is given, indent each line, stopping when ENDPOS is encountered.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/lisp-mode.el.gz
(defun indent-sexp (&optional endpos)
"Indent each line of the list starting just after point.
If optional arg ENDPOS is given, indent each line, stopping when
ENDPOS is encountered."
(interactive)
(let* ((parse-state (lisp-indent-initial-state)))
;; We need a marker because we modify the buffer
;; text preceding endpos.
(setq endpos (copy-marker
(if endpos endpos
;; Get error now if we don't have a complete sexp
;; after point.
(save-excursion
(forward-sexp 1)
(let ((eol (line-end-position)))
;; We actually look for a sexp which ends
;; after the current line so that we properly
;; indent things like #s(...). This might not
;; be needed if Bug#15998 is fixed.
(when (and (< (point) eol)
;; Check if eol is within a sexp.
(> (nth 0 (save-excursion
(parse-partial-sexp
(point) eol)))
0))
(condition-case ()
(while (< (point) eol)
(forward-sexp 1))
;; But don't signal an error for incomplete
;; sexps following the first complete sexp
;; after point.
(scan-error nil))))
(point)))))
(save-excursion
(while (let ((indent (lisp-indent-calc-next parse-state))
(ppss (lisp-indent-state-ppss parse-state)))
;; If the line contains a comment indent it now with
;; `indent-for-comment'.
(when (and (nth 4 ppss) (<= (nth 8 ppss) endpos))
(save-excursion
(goto-char (lisp-indent-state-ppss-point parse-state))
(indent-for-comment)
(setf (lisp-indent-state-ppss-point parse-state)
(line-end-position))))
(when (< (point) endpos)
;; Indent the next line, unless it's blank, or just a
;; comment (we will `indent-for-comment' the latter).
(skip-chars-forward " \t")
(unless (or (eolp) (not indent)
(eq (char-syntax (char-after)) ?<))
(indent-line-to indent))
t))))
(move-marker endpos nil)))