Function: sqlind-calculate-indentation

sqlind-calculate-indentation is a natively compiled function defined in sql-indent.el.

Signature

(sqlind-calculate-indentation SYNTAX &optional BASE-INDENTATION)

Documentation

Return the indentation that should be applied to the current line.

SYNTAX is the syntaxtic information as returned by sqlind-syntax-of-line, BASE-INDENTATION is an indentation offset to start with. When BASE-INDENTATION is nil, it is initialised to the column of the anchor.

The indentation is done as follows: first, the indentation offsets for the current syntactic symbol is looked up in sqlind-indentation-offsets-alist. Than, for each indentation offset, BASE-INDENTATION is adjusted according to that indentation offset. The final value of BASE-INDENTATION is than returned.

Source Code

;; Defined in /nix/store/jxjf2h9nnkdqnn1w1mr0ag8bqng2rlrs-emacs-packages-deps/share/emacs/site-lisp/elpa/sql-indent-1.7/sql-indent.el
(defun sqlind-calculate-indentation (syntax &optional base-indentation)
  "Return the indentation that should be applied to the current line.
SYNTAX is the syntaxtic information as returned by
`sqlind-syntax-of-line', BASE-INDENTATION is an indentation offset
to start with.  When BASE-INDENTATION is nil, it is initialised
to the column of the anchor.

The indentation is done as follows: first, the indentation
offsets for the current syntactic symbol is looked up in
`sqlind-indentation-offsets-alist'.  Than, for each indentation
offset, BASE-INDENTATION is adjusted according to that
indentation offset.  The final value of BASE-INDENTATION is than
returned."
  (if (null syntax)
      base-indentation
      ;; else

      ;; when the user did not specify a base-indentation, we use the
      ;; column of the anchor as a starting point
      (when (null base-indentation)
	(setq base-indentation (save-excursion
				 (goto-char (cdar syntax))
				 (current-column))))

      (let* ((syntax-symbol (sqlind-syntax-symbol syntax))
	     (indent-info (cdr (assoc syntax-symbol
				      sqlind-indentation-offsets-alist)))
	     (new-indentation base-indentation))

	;; the funcall below can create a nil indentation symbol to
	;; abort the indentation process
	(while (and new-indentation indent-info)
	  (let ((i (car indent-info)))
	    (setq new-indentation
		  (cond
		    ((eq i '+) (+ new-indentation sqlind-basic-offset))
		    ((eq i '++) (+ new-indentation (* 2 sqlind-basic-offset)))
		    ((eq i '-) (- new-indentation sqlind-basic-offset))
		    ((eq i '--) (- new-indentation (* 2 sqlind-basic-offset)))
		    ((integerp i) (+ new-indentation i))
		    ((functionp i) (funcall i syntax new-indentation))
		    ;; ignore unknown symbols by default
		    (t new-indentation))))
	  (setq indent-info (cdr indent-info)))
	new-indentation)))