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

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

[elpa] externals/sql-indent e511ced 01/13: `sqlind-search-backward` find


From: Alex Harsanyi
Subject: [elpa] externals/sql-indent e511ced 01/13: `sqlind-search-backward` finds things at the same nesting level (#68) (#69)
Date: Thu, 20 Jun 2019 05:25:44 -0400 (EDT)

branch: externals/sql-indent
commit e511ced9075b68f8170023f5971b08aadadf7865
Author: Alex Harsányi <address@hidden>
Commit: GitHub <address@hidden>

    `sqlind-search-backward` finds things at the same nesting level (#68) (#69)
    
    * sql-indent.el (sqlind-search-backward): use
    `sqlind-same-level-statement` to check if the position is at the
    same nesting level as the starting point
    
    * (sqlind-same-level-statement): fix to check that the point has the
    same nesting, in-comment and in-string status as start.
---
 sql-indent-test.el     |  3 +++
 sql-indent.el          | 19 ++++++++++---------
 test-data/pr68-syn.eld | 15 +++++++++++++++
 test-data/pr68.sql     |  7 +++++++
 4 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/sql-indent-test.el b/sql-indent-test.el
index c9bc933..df79c07 100644
--- a/sql-indent-test.el
+++ b/sql-indent-test.el
@@ -378,4 +378,7 @@ information read from DATA-FILE (as generated by
 (ert-deftest sqlind-ert-pr67 ()
   (sqlind-ert-check-file-syntax "test-data/pr67.sql" "test-data/pr67-syn.eld"))
 
+(ert-deftest sqlind-ert-pr68 ()
+  (sqlind-ert-check-file-syntax "test-data/pr68.sql" "test-data/pr68-syn.eld"))
+
 ;;; sql-indent-test.el ends here
diff --git a/sql-indent.el b/sql-indent.el
index 8d77f9a..562485d 100644
--- a/sql-indent.el
+++ b/sql-indent.el
@@ -140,7 +140,7 @@ to LIMIT and nil is returned."
   (let ((done nil))
     (while (and (not done)
                 (re-search-backward regexp limit 'noerror))
-      (unless (sqlind-in-comment-or-string (point))
+      (when (sqlind-same-level-statement (point) start)
         (setq done (point))))
     done))
 
@@ -163,12 +163,13 @@ block label might be empty."
 (defun sqlind-same-level-statement (point start)
   "Return t if POINT is at the same syntactic level as START.
 This means that POINT is at the same nesting level and not inside
-a strinf or comment."
+a string or comment."
   (save-excursion
-    (let ((parse-info (parse-partial-sexp start point)))
-      (not (or (nth 3 parse-info)                 ; inside a string
-               (nth 4 parse-info)                 ; inside a comment
-               (> (nth 0 parse-info) 0))))))      ; inside a nested paren
+    (let ((ppss-point (syntax-ppss point))
+          (ppss-start (syntax-ppss start)))
+      (and (equal (nth 3 ppss-point) (nth 3 ppss-start)) ; string
+           (equal (nth 4 ppss-start) (nth 4 ppss-start)) ; comment
+           (= (nth 0 ppss-point) (nth 0 ppss-start)))))) ; same nesting
 
 (defun sqlind-column-definition-start (pos limit)
   "Find the beginning of a column definition in a select statement.
@@ -1002,9 +1003,9 @@ reverse order (a stack) and is used to skip over nested 
blocks."
               (forward-char -1)
               (sqlind-backward-syntactic-ws)
               (unless (looking-at ",")
-                ;; yep, we are in the from section.
-                ;; if this line starts with 'on' or the previous line
-                ;; ends with 'on' we have a join condition
+                ;; We are in the from section.  If this line starts with 'on'
+                ;; or the previous line ends with 'on' we have a join
+                ;; condition
                 (goto-char pos)
                 (when (or (looking-at "on")
                           (progn (forward-word -1) (looking-at "on")))
diff --git a/test-data/pr68-syn.eld b/test-data/pr68-syn.eld
new file mode 100644
index 0000000..a3fdcc2
--- /dev/null
+++ b/test-data/pr68-syn.eld
@@ -0,0 +1,15 @@
+(((toplevel . 1))
+ ((select-clause . 1)
+  (statement-continuation . 1))
+ ((select-table-continuation . 12)
+  (statement-continuation . 1))
+ ((nested-statement-open . 34)
+  (statement-continuation . 34))
+ ((nested-statement-continuation . 34)
+  (statement-continuation . 34))
+ ((nested-statement-close . 34)
+  (statement-continuation . 34))
+ ((select-join-condition . 29)
+  (statement-continuation . 1))
+ ((select-table-continuation . 12)
+  (statement-continuation . 1)))
\ No newline at end of file
diff --git a/test-data/pr68.sql b/test-data/pr68.sql
new file mode 100644
index 0000000..313fa8a
--- /dev/null
+++ b/test-data/pr68.sql
@@ -0,0 +1,7 @@
+SELECT *
+  FROM t1
+         JOIN (
+           t2
+           LEFT JOIN t3 USING (k2)
+         )
+             ON t1.k1 = t2.k1



reply via email to

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