summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/elisp/urweb-mode.el30
-rw-r--r--tests/sql_indent.ur4
2 files changed, 19 insertions, 15 deletions
diff --git a/src/elisp/urweb-mode.el b/src/elisp/urweb-mode.el
index f0696ee4..73b67a17 100644
--- a/src/elisp/urweb-mode.el
+++ b/src/elisp/urweb-mode.el
@@ -535,19 +535,23 @@ If anyone has a good algorithm for this..."
(defun urweb-in-sql ()
"Check if the point is in a block of SQL syntax."
(save-excursion
- (let ((depth 0)
- done)
- (while (and (not done)
- (re-search-backward "[()]" nil t))
- (cond
- ((looking-at ")")
- (decf depth))
- ((looking-at "(")
- (if (looking-at urweb-sql-main-starters-paren-re)
- (setq done t)
- (incf depth)))))
- (and (>= depth 0)
- (looking-at urweb-sql-main-starters-paren-re)))))
+ (let ((start-pos (point))
+ (depth 0)
+ done
+ (good t))
+ (when (re-search-backward urweb-sql-main-starters-paren-re nil t)
+ (forward-char)
+ (while (and (not done) (re-search-forward "[()]" start-pos t))
+ (save-excursion
+ (backward-char)
+ (cond
+ ((looking-at ")")
+ (cond
+ ((= depth 0) (setq done t) (setq good nil))
+ (t (decf depth))))
+ ((looking-at "(")
+ (incf depth)))))
+ good))))
(defun urweb-sql-depth ()
"Check if the point is in a block of SQL syntax.
diff --git a/tests/sql_indent.ur b/tests/sql_indent.ur
index dec1c2d5..958fb070 100644
--- a/tests/sql_indent.ur
+++ b/tests/sql_indent.ur
@@ -1,7 +1,7 @@
table t1 : {A : int, B : string, C : float}
val q1 = (SELECT *
- FROM t1)
+ FROM t1
WHERE A = 0)
val a1 = (INSERT INTO t1
@@ -9,7 +9,7 @@ val a1 = (INSERT INTO t1
val a2 = (UPDATE t1
SET A = 3, B = "4", C = 5.0)
-
+
val a3 = (DELETE FROM t1
WHERE B <> "good")