Function: sqlind-maybe-$$-statement

sqlind-maybe-$$-statement is a natively compiled function defined in sql-indent.el.

Signature

(sqlind-maybe-$$-statement)

Documentation

If (point) is on a PostgreSQL $$ quote, report its syntax.

PostgreSQL uses $$ to delimit SQL blocks in create statements, this function tries to determine if the $$ block is a begin or an end block and creates the appropiate syntactic context.

See also sqlind-beginning-of-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-maybe-$$-statement ()
  "If (point) is on a PostgreSQL $$ quote, report its syntax.

PostgreSQL uses $$ to delimit SQL blocks in create statements,
this function tries to determine if the $$ block is a begin or an
end block and creates the appropiate syntactic context.

See also `sqlind-beginning-of-block'"
  (when (looking-at "\\$\\$")
    (prog1 t
      (let* ((saved-pos (point)))
        (ignore-errors (forward-char -1))
        (sqlind-backward-syntactic-ws)
        (cond ((looking-at ";")
               ;; Assume the $$ is ending a statement (previous line is a ';'
               ;; which ends another statement)
               (push (list saved-pos '$$ "") sqlind-end-stmt-stack)
               (goto-char saved-pos))
              ((progn (forward-word -1)
                      (looking-at "end"))
               ;; Assume the $$ is ending a statement (previous line contains
               ;; an "end" keyword)
               (push (list saved-pos '$$ "") sqlind-end-stmt-stack)
               (goto-char saved-pos))
              ((null sqlind-end-stmt-stack)
               (sqlind-beginning-of-statement)
               (let ((syntax (catch 'finished
                               (sqlind-maybe-create-statement)
                               (sqlind-maybe-defun-statement)
                               'toplevel)))
                 (if (and (listp syntax) (eq (nth 0 syntax) 'defun-start))
                     (throw 'finished (list 'in-begin-block 'defun (nth 1 syntax)))
                   (throw 'finished (list 'in-begin-block syntax nil)))))
              (t
               (sqlind-beginning-of-statement)
               (cl-destructuring-bind (pos kind _label) (pop sqlind-end-stmt-stack)
                 (unless (eq kind '$$)
                   (throw 'finished
                     (list 'syntax-error "bad closing for $$ begin block" (point) pos))))))))))