Function: idlwave-calculate-cont-indent

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

Signature

(idlwave-calculate-cont-indent)

Documentation

Calculates the IDL continuation indent column from the previous statement.

Note that here previous statement usually means the beginning of the current statement if this statement is a continuation of the previous line. Various special types of continuations, including assignments, routine definitions, and parenthetical groupings, are treated separately.

Source Code

;; Defined in /usr/src/emacs/lisp/obsolete/idlwave.el.gz
(defun idlwave-calculate-cont-indent ()
  "Calculates the IDL continuation indent column from the previous statement.
Note that here previous statement usually means the beginning of the
current statement if this statement is a continuation of the previous
line.  Various special types of continuations, including assignments,
routine definitions, and parenthetical groupings, are treated separately."
  (save-excursion
    (let* ((case-fold-search t)
           (end-reg (progn (beginning-of-line) (point)))
	   (beg-last-statement (save-excursion (idlwave-previous-statement)
					       (point)))
           (beg-reg (progn (idlwave-start-of-substatement 'pre)
			   (if (eq (line-beginning-position) end-reg)
			       (goto-char beg-last-statement)
			     (point))))
	   (basic-indent (+ (idlwave-min-current-statement-indent end-reg)
			    idlwave-continuation-indent))
	   fancy-nonparen-indent fancy-paren-indent)
      (cond
       ;; Align then with its matching if, etc.
       ((let ((matchers '(("\\<if\\>" . "[ \t]*then")
			  ("\\<\\(if\\|end\\(if\\)?\\)\\>" . "[ \t]*else")
			  ("\\<\\(for\\|while\\)\\>" . "[ \t]*do")
			  ("\\<\\(repeat\\|end\\(rep\\)?\\)\\>" .
			   "[ \t]*until")
			  ("\\<case\\>" . "[ \t]*of")))
	      match cont-re)
	  (goto-char end-reg)
	  (and
	   (setq cont-re
		 (catch 'exit
		   (while (setq match (car matchers))
		     (if (looking-at (cdr match))
			 (throw 'exit (car match)))
		     (setq matchers (cdr matchers)))))
	   (idlwave-find-key cont-re -1 'nomark beg-last-statement)))
	(if (looking-at "end") ;; that one's special
	    (- (idlwave-current-indent)
	       (+ idlwave-block-indent idlwave-end-offset))
	  (idlwave-current-indent)))

       ;; Indent in from the previous line for continuing statements
       ((let ((matchers '("\\<then\\>"
			  "\\<do\\>"
			  "\\<repeat\\>"
			  "\\<else\\>"))
	      match)
	  (catch 'exit
	    (goto-char end-reg)
	    (if (/= (forward-line -1) 0)
		(throw 'exit nil))
	    (while (setq match (car matchers))
	      (if (looking-at (concat ".*" match "[ \t]*\\$[ \t]*"
				      "\\(;.*\\)?$"))
		  (throw 'exit t))
	      (setq matchers (cdr matchers)))))
	(+ idlwave-continuation-indent (idlwave-current-indent)))

       ;; Parenthetical indent, either traditional or Kernighan style
       ((setq fancy-paren-indent
	      (let* ((end-reg end-reg)
		    (close-exp (progn
				 (goto-char end-reg)
				 (skip-chars-forward " \t")
				 (looking-at "\\s)")))
		    indent-cons)
		(catch 'loop
		  (while (setq indent-cons (idlwave-calculate-paren-indent
					    beg-reg end-reg close-exp))
		    ;; First permitted containing paren
		    (if (or
			 idlwave-indent-to-open-paren
			 idlwave-indent-parens-nested
                         (null (cdr indent-cons))
			 (< (- (cdr indent-cons) basic-indent)
			    idlwave-max-extra-continuation-indent))
			(throw 'loop (cdr indent-cons)))
		    (setq end-reg (car indent-cons))))))
	fancy-paren-indent)

       ;; A continued assignment, or procedure call/definition
       ((and
	 (> idlwave-max-extra-continuation-indent 0)
	 (setq fancy-nonparen-indent
	       (progn
		 (goto-char beg-reg)
		 (while (idlwave-look-at "&"))  ; skip continued statements
		 (cond
		  ;; A continued Procedure call or definition
		  ((progn
		     (idlwave-look-at "^[ \t]*\\(pro\\|function\\)") ;skip over
		     (looking-at "[ \t]*\\([a-zA-Z0-9.$_]+[ \t]*->[ \t]*\\)?[a-zA-Z][:a-zA-Z0-9$_]*[ \t]*\\(,\\)[ \t]*"))
		   (goto-char (match-end 0))
		   ;; Comment only, or blank line with "$"?  Basic indent.
		   (if (save-match-data (looking-at "[ \t$]*\\(;.*\\)?$"))
		       nil
		     (current-column)))

		  ;; Continued assignment (with =):
		  ((catch 'assign ;
		     (while (looking-at "[^=\n\r]*\\(=\\)[ \t]*")
		       (goto-char (match-end 0))
		       (if (null (idlwave-what-function beg-reg))
			   (throw 'assign t))))
		   (unless (or
			    (idlwave-in-quote)
			    (looking-at "[ \t$]*\\(;.*\\)?$") ; use basic
			    (save-excursion
			      (goto-char beg-last-statement)
			      (eq (caar (idlwave-statement-type)) 'for)))
		     (current-column))))))
	 (< (- fancy-nonparen-indent basic-indent)
	    idlwave-max-extra-continuation-indent))
	(if fancy-paren-indent ;calculated but disallowed paren indent
	    (+ fancy-nonparen-indent idlwave-continuation-indent)
	  fancy-nonparen-indent))

       ;; Basic indent, by default
       (t basic-indent)))))