Function: indent-icon-exp
indent-icon-exp is an interactive and byte-compiled function defined
in icon.el.gz.
Signature
(indent-icon-exp)
Documentation
Indent each line of the Icon grouping following point.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/icon.el.gz
(defun indent-icon-exp ()
"Indent each line of the Icon grouping following point."
(interactive)
(let ((indent-stack (list nil))
(contain-stack (list (point)))
(case-fold-search nil)
outer-loop-done inner-loop-done state ostate
this-indent last-depth
at-else at-brace
(opoint (point))
(next-depth 0))
(save-excursion
(forward-sexp 1))
(save-excursion
(setq outer-loop-done nil)
(while (and (not (eobp)) (not outer-loop-done))
(setq last-depth next-depth)
;; Compute how depth changes over this line
;; plus enough other lines to get to one that
;; does not end inside a comment or string.
;; Meanwhile, do appropriate indentation on comment lines.
(setq inner-loop-done nil)
(while (and (not inner-loop-done)
(not (and (eobp) (setq outer-loop-done t))))
(setq ostate state)
(setq state (parse-partial-sexp (point) (progn (end-of-line) (point))
nil nil state))
(setq next-depth (car state))
(if (or (nth 4 ostate))
(icon-indent-line))
(if (or (nth 3 state))
(forward-line 1)
(setq inner-loop-done t)))
(if (<= next-depth 0)
(setq outer-loop-done t))
(if outer-loop-done
nil
(while (> last-depth next-depth)
(setq indent-stack (cdr indent-stack)
contain-stack (cdr contain-stack)
last-depth (1- last-depth)))
(while (< last-depth next-depth)
(setq indent-stack (cons nil indent-stack)
contain-stack (cons nil contain-stack)
last-depth (1+ last-depth)))
(if (null (car contain-stack))
(setcar contain-stack (or (car (cdr state))
(save-excursion (forward-sexp -1)
(point)))))
(forward-line 1)
(skip-chars-forward " \t")
(if (eolp)
nil
(if (and (car indent-stack)
(>= (car indent-stack) 0))
;; Line is on an existing nesting level.
;; Lines inside parens are handled specially.
(if (/= (char-after (car contain-stack)) ?{)
(setq this-indent (car indent-stack))
;; Line is at statement level.
;; Is it a new statement? Is it an else?
;; Find last non-comment character before this line
(save-excursion
(setq at-else (looking-at "else\\W"))
(setq at-brace (= (following-char) ?{))
(icon-backward-to-noncomment opoint)
(if (icon-is-continuation-line)
;; Preceding line did not end in comma or semi;
;; indent this line icon-continued-statement-offset
;; more than previous.
(progn
(icon-backward-to-start-of-continued-exp (car contain-stack))
(setq this-indent
(+ icon-continued-statement-offset (current-column)
(if at-brace icon-continued-brace-offset 0))))
;; Preceding line ended in comma or semi;
;; use the standard indent for this level.
(if at-else
(progn (icon-backward-to-start-of-if opoint)
(setq this-indent (current-indentation)))
(setq this-indent (car indent-stack))))))
;; Just started a new nesting level.
;; Compute the standard indent for this level.
(let ((val (calculate-icon-indent
(if (car indent-stack)
(- (car indent-stack))))))
(setcar indent-stack
(setq this-indent val))))
;; Adjust line indentation according to its contents
(if (or (= (following-char) ?})
(looking-at "end\\b"))
(setq this-indent (- this-indent icon-indent-level)))
(if (= (following-char) ?{)
(setq this-indent (+ this-indent icon-brace-offset)))
;; Put chosen indentation into effect.
(or (= (current-column) this-indent)
(progn
(delete-region (point) (progn (beginning-of-line) (point)))
(indent-to this-indent)))
;; Indent any comment following the text.
(or (looking-at comment-start-skip)
(if (re-search-forward comment-start-skip (line-end-position) t)
(progn (indent-for-comment) (beginning-of-line))))))))))