Function: sqlind-beginning-of-statement-1

sqlind-beginning-of-statement-1 is a natively compiled function defined in sql-indent.el.

Signature

(sqlind-beginning-of-statement-1 LIMIT)

Documentation

Return the position of a block start, or nil.

But don't go before LIMIT.

Source Code

;; Defined in /nix/store/jxjf2h9nnkdqnn1w1mr0ag8bqng2rlrs-emacs-packages-deps/share/emacs/site-lisp/elpa/sql-indent-1.7/sql-indent.el
(defun sqlind-beginning-of-statement-1 (limit)
  "Return the position of a block start, or nil.
But don't go before LIMIT."
  (save-excursion
    (catch 'done
      (while (> (point) (or limit (point-min)))
        (when (re-search-backward ";\\|:=\\|\\_<\\(declare\\|\\(begin\\(\\(\\s-+not\\)?\\s-+atomic\\)?\\)\\|cursor\\|for\\|while\\|loop\\|if\\|then\\|else\\|elsif\\|elseif\\)\\_>\\|)\\|\\$\\$"
               limit 'noerror)
          (unless (sqlind-in-comment-or-string (point))
            (let ((candidate-pos (match-end 0)))
              (cond ((looking-at ")")
                     ;; Skip parenthesis expressions, we don't want to find one
                     ;; of the keywords inside one of them and think this is a
                     ;; statement start.
                     (progn (forward-char 1) (forward-sexp -1)))
                    ((looking-at "cursor\\|for")
                     (unless (eq sql-product 'postgres)
                       (throw 'done (point))))
                    ((looking-at "while")
                     (throw 'done (point)))
                    ((looking-at "declare")
                     (when (eq sql-product 'postgres)
                       (throw 'done (point))))
                    ((looking-at "else?if")
                     ;; statement begins at the start of the keyword
                     (throw 'done (point)))
                    ((looking-at "then\\|else")
                     ;; then and else start statements when they are inside
                     ;; blocks, not expressions.
                     (sqlind-backward-syntactic-ws)
                     (when (looking-at ";")
                       ;; Statement begins after the keyword
                       (throw 'done candidate-pos)))
                    ((looking-at "if")
                     (when (sqlind-good-if-candidate)
                       ;; statement begins at the start of the keyword
                       (throw 'done (point))))
                    ((looking-at ":=")
                     ;; assignment statements start at the assigned variable
                     (sqlind-backward-syntactic-ws)
                     (forward-sexp -1)
                     (throw 'done (point)))
                    ((looking-at "\\$\\$")
                     (when (eq sql-product 'postgres)
                       (sqlind-forward-syntactic-ws)
                       (throw 'done (point))))
                    ((sqlind-looking-at-begin-transaction)
                     ;; This is a "begin transaction" call, statement begins
                     ;; at "begin", see #66
                     (throw 'done (point)))
                    ((not (sqlind-in-comment-or-string (point)))
                     (throw 'done candidate-pos))))))))))