diff src/elisp/urweb-mode.el @ 375:d3de57ce4bca

Fixing overzealous SQL paren-nester
author Adam Chlipala <adamc@hcoop.net>
date Thu, 16 Oct 2008 17:31:24 -0400
parents 1099d083a702
children ef43ed6cd1de
line wrap: on
line diff
--- 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.