[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
- [elpa] externals/sql-indent updated (87a6b4a -> 47e9ccb), Alex Harsanyi, 2019/06/20
- [elpa] externals/sql-indent 9d5f978 05/13: Fix regexp bug in `sqlind-good-if-candidate` (fixes #76), Alex Harsanyi, 2019/06/20
- [elpa] externals/sql-indent 31c29ed 12/13: Recognize more types of begin transaction statements (fixes #84), Alex Harsanyi, 2019/06/20
- [elpa] externals/sql-indent 2ca9610 09/13: don't be confused by drop function or procedure statements #80, Alex Harsanyi, 2019/06/20
- [elpa] externals/sql-indent f897c11 08/13: Apply advices of `checkdoc' (#77), Alex Harsanyi, 2019/06/20
- [elpa] externals/sql-indent dccd194 02/13: Recognize `select-join-condition` syntax inside nested statements #70 (#71), Alex Harsanyi, 2019/06/20
- [elpa] externals/sql-indent e7e7e85 11/13: Don't recognize select keywords in comments, fixes #83, Alex Harsanyi, 2019/06/20
- [elpa] externals/sql-indent 47e9ccb 13/13: Recognize left and right outer join statements #85, Alex Harsanyi, 2019/06/20
- [elpa] externals/sql-indent e511ced 01/13: `sqlind-search-backward` finds things at the same nesting level (#68) (#69),
Alex Harsanyi <=
- [elpa] externals/sql-indent d9442ed 03/13: Recognize FULL JOIN, UNION ALL and EXCEPT keywords #73 (#74), Alex Harsanyi, 2019/06/20
- [elpa] externals/sql-indent 1974564 10/13: recognize elseif in addition to elif #81, Alex Harsanyi, 2019/06/20
- [elpa] externals/sql-indent 9559ebe 07/13: Fix `sqlind-comment-end' regexp. (#79), Alex Harsanyi, 2019/06/20
- [elpa] externals/sql-indent ba2a690 06/13: also fix sqlind-end-statement-regexp, Alex Harsanyi, 2019/06/20
- [elpa] externals/sql-indent a6da8bd 04/13: Recognize more create keywords (#75), Alex Harsanyi, 2019/06/20