# HG changeset patch # User Adam Chlipala # Date 1224192684 14400 # Node ID d3de57ce4bcadc09e5406798737983b3774ad4f9 # Parent 1099d083a702820ca5e1e8390b5762055d0351c0 Fixing overzealous SQL paren-nester diff -r 1099d083a702 -r d3de57ce4bca src/elisp/urweb-mode.el --- a/src/elisp/urweb-mode.el Thu Oct 16 17:15:21 2008 -0400 +++ b/src/elisp/urweb-mode.el Thu Oct 16 17:31:24 2008 -0400 @@ -535,19 +535,23 @@ (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 -r 1099d083a702 -r d3de57ce4bca tests/sql_indent.ur --- a/tests/sql_indent.ur Thu Oct 16 17:15:21 2008 -0400 +++ b/tests/sql_indent.ur Thu Oct 16 17:31:24 2008 -0400 @@ -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 a2 = (UPDATE t1 SET A = 3, B = "4", C = 5.0) - + val a3 = (DELETE FROM t1 WHERE B <> "good")