emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/sql-indent ce2002c 2/4: don't recognize "begin transact


From: Stefan Monnier
Subject: [elpa] externals/sql-indent ce2002c 2/4: don't recognize "begin transaction" as a block
Date: Thu, 25 Oct 2018 08:37:08 -0400 (EDT)

branch: externals/sql-indent
commit ce2002ca8fe039ed1fc58b6d26246b09ca90b89f
Author: Alex Harsanyi <address@hidden>
Commit: Alex Harsanyi <address@hidden>

    don't recognize "begin transaction" as a block
    
    "begin transaction;" is a statement, and the code used to confuse the 
"begin"
    with a block begin, breaking some indentation.
---
 sql-indent-test.el     |  3 +++
 sql-indent.el          | 17 +++++++++++++++--
 test-data/pr66-syn.eld | 25 +++++++++++++++++++++++++
 test-data/pr66.sql     | 17 +++++++++++++++++
 4 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/sql-indent-test.el b/sql-indent-test.el
index 0cc3be1..a5d107d 100644
--- a/sql-indent-test.el
+++ b/sql-indent-test.el
@@ -372,4 +372,7 @@ information read from DATA-FILE (as generated by
 (ert-deftest sqlind-ert-pr64 ()
   (sqlind-ert-check-file-syntax "test-data/pr64.sql" "test-data/pr64-syn.eld"))
 
+(ert-deftest sqlind-ert-pr66 ()
+  (sqlind-ert-check-file-syntax "test-data/pr66.sql" "test-data/pr66-syn.eld"))
+
 ;;; sql-indent-test.el ends here
diff --git a/sql-indent.el b/sql-indent.el
index a928310..748aae4 100644
--- a/sql-indent.el
+++ b/sql-indent.el
@@ -245,6 +245,14 @@ symbols and their meaning."
         (t
          (sqlind-find-context syntax-symbol (sqlind-outer-context context)))))
 
+(defun sqlind-looking-at-begin-transaction ()
+  "Return t if the point is on a \"begin transaction\" statement."
+  (and (looking-at "begin")
+       (save-excursion
+         (forward-word 1)
+         (sqlind-forward-syntactic-ws)
+         (looking-at "transaction"))))
+
 ;;;; Syntactic analysis of SQL code
 
 ;;;;; Find the beginning of the current statement
@@ -331,6 +339,10 @@ But don't go before LIMIT."
                      (sqlind-backward-syntactic-ws)
                      (forward-sexp -1)
                      (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))))))))))
 
@@ -556,7 +568,7 @@ keywords in program code are matched, not the ones inside
 expressions.
 
 See also `sqlind-beginning-of-block'"
-  (when (looking-at "begin")
+  (when (and (looking-at "begin") (not (sqlind-looking-at-begin-transaction)))
     ;; a begin statement starts a block unless it is the first begin in a
     ;; procedure over which we need to skip it.
     (prog1  t                           ; make sure we return t
@@ -1491,7 +1503,8 @@ procedure block."
 
         (goto-char context-start)
         (when (or (>= context-start pos)
-                  (looking-at sqlind-start-block-regexp))
+                  (and (looking-at sqlind-start-block-regexp)
+                       (not (sqlind-looking-at-begin-transaction))))
           (goto-char pos)
           ;; if we are at the start of a statement, or the nearest statement
           ;; starts after us, make the enclosing block the starting context
diff --git a/test-data/pr66-syn.eld b/test-data/pr66-syn.eld
new file mode 100644
index 0000000..23482ec
--- /dev/null
+++ b/test-data/pr66-syn.eld
@@ -0,0 +1,25 @@
+((((block-start begin)
+   . 1)
+  (toplevel . 1))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ (((block-start begin)
+   . 1)
+  (toplevel . 1))
+ ((statement-continuation . 89))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ (((block-start begin)
+   . 1)
+  (toplevel . 1))
+ ((statement-continuation . 179))
+ ((statement-continuation . 179))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ ((toplevel . 1)))
+ 
\ No newline at end of file
diff --git a/test-data/pr66.sql b/test-data/pr66.sql
new file mode 100644
index 0000000..dceb878
--- /dev/null
+++ b/test-data/pr66.sql
@@ -0,0 +1,17 @@
+begin transaction;
+create table my_table ( id text );
+select id from my_table;
+commit;
+
+begin
+  transaction;
+create table my_table ( id text );
+select id from my_table;
+commit;
+
+begin -- a comment
+
+  transaction;
+create table my_table ( id text );
+select id from my_table;
+commit;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]