Function: sqlind-maybe-create-statement
sqlind-maybe-create-statement is a natively compiled function defined
in sql-indent.el.
Signature
(sqlind-maybe-create-statement &optional ALL-STATEMENTS)
Documentation
If (point) is on a CREATE statement, report its syntax.
See also sqlind-beginning-of-block
Normally, only block start create statements are considered (such as creation of procedures). In particular, create table/view/index statements are ignored unless the ALL-STATEMENTS argument is t
Source Code
;; Defined in /nix/store/jxjf2h9nnkdqnn1w1mr0ag8bqng2rlrs-emacs-packages-deps/share/emacs/site-lisp/elpa/sql-indent-1.7/sql-indent.el
(defun sqlind-maybe-create-statement (&optional all-statements)
"If (point) is on a CREATE statement, report its syntax.
See also `sqlind-beginning-of-block'
Normally, only block start create statements are considered (such
as creation of procedures). In particular, create
table/view/index statements are ignored unless the ALL-STATEMENTS
argument is t"
(when (or (looking-at "create\\_>\\(?:[ \t\n\r\f]+\\)\\(or\\(?:[ \t\n\r\f]+\\)replace\\_>\\)?")
(looking-at "alter\\_>"))
(prog1 t ; make sure we return t
(save-excursion
;; let's see what are we creating
(goto-char (match-end 0))
(sqlind-forward-syntactic-ws)
(sqlind-maybe-skip-create-options)
(let ((what (intern (downcase (buffer-substring-no-properties
(point)
(progn (forward-word) (point))))))
(name (downcase (buffer-substring-no-properties
(progn (sqlind-forward-syntactic-ws)
;; Skip over a possible "if (not)
;; exists", to get the actual name
(when (looking-at "if\\(\\s-\\|[\n]\\)+\\(not\\)?\\(\\s-\\|[\n]\\)exists")
(goto-char (match-end 0))
(sqlind-forward-syntactic-ws))
(point))
(progn (skip-syntax-forward "w_()") (point))))))
(when (and (eq what 'package) (equal name "body"))
(setq what 'package-body)
(setq name (downcase
(buffer-substring-no-properties
(progn (sqlind-forward-syntactic-ws) (point))
(progn (skip-syntax-forward "w_()") (point))))))
;; Keep just the name, not the argument list
(when (string-match "\\(.*?\\)(" name)
(setq name (match-string 1 name)))
(cond
((memq what '(procedure function package package-body))
;; check is name is in the form user.name, if so then suppress user part.
(when (string-match "\\(?:.*\\.\\)?\\(.*\\)" name)
(setq name (match-string 1 name)))
(if (null sqlind-end-stmt-stack)
(throw 'finished
(list (if (memq what '(procedure function)) 'defun-start what)
name))
(cl-destructuring-bind (pos kind label) (pop sqlind-end-stmt-stack)
(when (not (eq kind nil))
(throw 'finished
(list 'syntax-error
"bad closing for create block" (point) pos)))
(unless (sqlind-labels-match label name)
(throw 'finished
(list 'syntax-error
"label mismatch in create block" (point) pos))))))
((memq what '(table view index))
;; Table, view and index creations do not begin blocks and they
;; are ignored unless the ALL-STATEMENTS parameter is t
(when all-statements
(throw 'finished (list 'create-statement what name))))
(t
(unless (null sqlind-end-stmt-stack)
(throw 'finished
(list 'syntax-error "nested create statement" (point) (point))))
(throw 'finished (list 'create-statement what name)))))))))