Function: sqlind-syntax-of-line
sqlind-syntax-of-line is a natively compiled function defined in
sql-indent.el.
Signature
(sqlind-syntax-of-line)
Documentation
Return the syntax at the start of the current line.
The function returns a list of (SYNTAX . ANCHOR) cons cells.
SYNTAX is either a symbol or a list starting with a symbol,
ANCHOR is a buffer position which is the reference for the
SYNTAX. sqlind-indentation-syntax-symbols lists the syntax
symbols and their meaning.
The first element in the list is the most specific syntax for the line, the remaining elemens are more generic ones. For example, a line can be inside an SELECT clause which itself is inside a procedure block.
Source Code
;; Defined in /nix/store/jxjf2h9nnkdqnn1w1mr0ag8bqng2rlrs-emacs-packages-deps/share/emacs/site-lisp/elpa/sql-indent-1.7/sql-indent.el
(defun sqlind-syntax-of-line ()
"Return the syntax at the start of the current line.
The function returns a list of (SYNTAX . ANCHOR) cons cells.
SYNTAX is either a symbol or a list starting with a symbol,
ANCHOR is a buffer position which is the reference for the
SYNTAX. `sqlind-indentation-syntax-symbols' lists the syntax
symbols and their meaning.
The first element in the list is the most specific syntax for the
line, the remaining elemens are more generic ones. For example,
a line can be inside an SELECT clause which itself is inside a
procedure block."
(save-excursion
(with-syntax-table sqlind-syntax-table
(let* ((pos (progn (back-to-indentation) (point)))
(sqlind-search-limit (sqlind-beginning-of-directive))
(context-start (progn (sqlind-beginning-of-statement) (point)))
(context (list (cons 'statement-continuation context-start)))
(have-block-context nil))
(goto-char context-start)
(when (or (>= context-start pos)
(and (looking-at sqlind-start-block-regexp)
;; create table/view/index statements are not block
;; contexts
(or (not (looking-at "\\(create\\)\\|\\(alter\\)"))
(catch 'finished (sqlind-maybe-create-statement) nil))
;; A declare statement may or may not be a block context
(or (not (looking-at "declare"))
(catch 'finished (sqlind-maybe-declare-statement) nil))
(not (sqlind-looking-at-begin-transaction))))
(goto-char pos)
;; if we are at the start of a statement, or the nearest statement
;; starts after us, make the enclosing block the starting context
(setq have-block-context t)
(let ((block-info (sqlind-beginning-of-block)))
;; certain kind of blocks end within a statement
;; (e.g. create view). If we found one of those blocks and
;; it is not within our statement, we ignore the block info.
(if (and (listp block-info)
(eq (nth 0 block-info) 'create-statement)
(not (memq (nth 1 block-info) '(function procedure)))
(not (eql context-start (point))))
(progn
(setq context-start (point-min))
(setq context (list (cons 'toplevel context-start))))
;; else
(setq context-start (point))
(setq context (list (cons block-info context-start))))))
(goto-char context-start)
(when (and (eq 'statement-continuation (sqlind-syntax-symbol context))
(looking-at "\\(create\\)\\|\\(alter\\)"))
(let ((create-info (catch 'finished (sqlind-maybe-create-statement t) nil)))
(when create-info
(pop context) ; remove the statement continuation syntax
(push (cons create-info context-start) context))))
(let ((parse-info (syntax-ppss pos)))
(cond ((nth 4 parse-info) ; inside a comment
(push (cons 'comment-continuation (nth 8 parse-info)) context))
((nth 3 parse-info) ; inside a string
(push (cons 'string-continuation (nth 8 parse-info)) context))
((> (nth 0 parse-info) 0) ; nesting
(let ((start (nth 1 parse-info)))
(goto-char (1+ start))
(skip-chars-forward " \t\r\n\f\v" pos)
(if (eq (point) pos)
(push (cons 'nested-statement-open start) context)
(goto-char pos)
(if (looking-at ")")
(push (cons 'nested-statement-close start) context)
(push (cons 'nested-statement-continuation start) context)))))))
;; now let's refine the syntax by adding info about the current line
;; into the mix.
(sqlind-refine-syntax context pos have-block-context)))))