Function: calculate-icon-indent

calculate-icon-indent is a byte-compiled function defined in icon.el.gz.

Signature

(calculate-icon-indent &optional PARSE-START)

Documentation

Return appropriate indentation for current line as Icon code.

In usual case returns an integer: the column to indent to. Returns nil if line starts inside a string, t if in a comment.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/icon.el.gz
(defun calculate-icon-indent (&optional parse-start)
  "Return appropriate indentation for current line as Icon code.
In usual case returns an integer: the column to indent to.
Returns nil if line starts inside a string, t if in a comment."
  (save-excursion
    (beginning-of-line)
    (let ((indent-point (point))
	  (case-fold-search nil)
	  state
	  containing-sexp
	  toplevel)
      (if parse-start
	  (goto-char parse-start)
	(setq toplevel (beginning-of-icon-defun)))
      (while (< (point) indent-point)
	(setq parse-start (point))
	(setq state (parse-partial-sexp (point) indent-point 0))
	(setq containing-sexp (car (cdr state))))
      (cond ((or (nth 3 state) (nth 4 state))
	     ;; return nil or t if should not change this line
	     (nth 4 state))
	    ((and containing-sexp
		  (/= (char-after containing-sexp) ?{))
	     ;; line is expression, not statement:
	     ;; indent to just after the surrounding open.
	     (goto-char (1+ containing-sexp))
	     (current-column))
	    (t
	      (if toplevel
		  ;; Outside any procedures.
		  (progn (icon-backward-to-noncomment (point-min))
			 (if (icon-is-continuation-line)
			     icon-continued-statement-offset 0))
		;; Statement level.
		(if (null containing-sexp)
		    (progn (beginning-of-icon-defun)
			   (setq containing-sexp (point))))
		(goto-char indent-point)
		;; Is it a continuation or a new statement?
		;; Find previous non-comment character.
		(icon-backward-to-noncomment containing-sexp)
		;; Now we get the answer.
		(if (icon-is-continuation-line)
		    ;; This line is continuation of preceding line's statement;
		    ;; indent  icon-continued-statement-offset  more than the
		    ;; first line of the statement.
		    (progn
		      (icon-backward-to-start-of-continued-exp containing-sexp)
		      (+ icon-continued-statement-offset (current-column)
			 (if (save-excursion (goto-char indent-point)
					     (skip-chars-forward " \t")
					     (eq (following-char) ?{))
			     icon-continued-brace-offset 0)))
		  ;; This line starts a new statement.
		  ;; Position following last unclosed open.
		  (goto-char containing-sexp)
		  ;; Is line first statement after an open-brace?
		  (or
		    ;; If no, find that first statement and indent like it.
		    (save-excursion
		      (if (looking-at "procedure\\s ")
			  (forward-sexp 3)
			(forward-char 1))
		      (while (progn (skip-chars-forward " \t\n")
				    (looking-at "#"))
			;; Skip over comments following openbrace.
			(forward-line 1))
		      ;; The first following code counts
		      ;; if it is before the line we want to indent.
		      (and (< (point) indent-point)
			   (current-column)))
		    ;; If no previous statement,
		    ;; indent it relative to line brace is on.
		    ;; For open brace in column zero, don't let statement
		    ;; start there too.  If icon-indent-level is zero,
		    ;; use icon-brace-offset + icon-continued-statement-offset
		    ;; instead.
		    ;; For open-braces not the first thing in a line,
		    ;; add in icon-brace-imaginary-offset.
		    (+ (if (and (bolp) (zerop icon-indent-level))
			   (+ icon-brace-offset
			      icon-continued-statement-offset)
			 icon-indent-level)
		       ;; Move back over whitespace before the openbrace.
		       ;; If openbrace is not first nonwhite thing on the line,
		       ;; add the icon-brace-imaginary-offset.
		       (progn (skip-chars-backward " \t")
			      (if (bolp) 0 icon-brace-imaginary-offset))
		       ;; Get initial indentation of the line we are on.
		       (current-indentation))))))))))