branch: externals/sql-indent
commit 416c7bb0442103ed113664aa6a2e1814e9456cbd
Author: Alex Harsanyi <[email protected]>
Commit: Alex Harsanyi <[email protected]>
Fix detection of select column start and LIMIT keyword #39
* sql-indent.el (sqlind-column-definition-start): use LIMIT as the
bounds for `sqlind-same-level-statement`, so we search between the
start of the SELECT and the current point.
(sqlind-select-clauses-regexp): recognize LIMIT as a select clause
keyword.
---
sql-indent-test.el | 3 +++
sql-indent.el | 5 +++--
test-data/pr39-syn.eld | 22 ++++++++++++++++++++++
test-data/pr39.sql | 8 ++++++++
4 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/sql-indent-test.el b/sql-indent-test.el
index 71afea4..10f7698 100644
--- a/sql-indent-test.el
+++ b/sql-indent-test.el
@@ -333,4 +333,7 @@ information read from DATA-FILE (as generated by
(sqlind-ert-check-file-indentation "test-data/pr37.sql"
"test-data/pr37-io-left.eld"
sqlind-indentation-left-offsets-alist 2))
+(ert-deftest sqlind-ert-pr39 ()
+ (sqlind-ert-check-file-syntax "test-data/pr39.sql" "test-data/pr39-syn.eld"))
+
;;; sql-indent-test.el ends here
diff --git a/sql-indent.el b/sql-indent.el
index ac66b3c..ba45073 100644
--- a/sql-indent.el
+++ b/sql-indent.el
@@ -186,7 +186,7 @@ statement."
(goto-char pos)
(catch 'found
(while (re-search-backward "," limit 'noerror)
- (when (sqlind-same-level-statement (point) pos)
+ (when (sqlind-same-level-statement (point) limit)
(forward-char 1)
(sqlind-forward-syntactic-ws)
(throw 'found (point)))))))
@@ -835,7 +835,8 @@ reverse order (a stack) and is used to skip over nested
blocks."
"having\\|"
"group[ \t\r\n\f]+by\\|"
"connect[ \t\r\n\f]+by\\|"
- "start[ \t\r\n\f]+with"
+ "start[ \t\r\n\f]+with\\|"
+ "limit"
"\\)\\_>"))
(defconst sqlind-select-join-regexp
diff --git a/test-data/pr39-syn.eld b/test-data/pr39-syn.eld
new file mode 100644
index 0000000..25b4ed8
--- /dev/null
+++ b/test-data/pr39-syn.eld
@@ -0,0 +1,22 @@
+(((toplevel . 1))
+ ((select-column . 1)
+ (statement-continuation . 1))
+ ((case-clause . 23)
+ (select-column-continuation . 1)
+ (statement-continuation . 1))
+ ((case-clause . 23)
+ (select-column-continuation . 1)
+ (statement-continuation . 1))
+ ((case-clause . 23)
+ (select-column-continuation . 1)
+ (statement-continuation . 1))
+ (((block-end case "")
+ . 23)
+ (select-column-continuation . 1)
+ (statement-continuation . 1))
+ ((select-clause . 1)
+ (statement-continuation . 1))
+ ((select-clause . 1)
+ (statement-continuation . 1))
+ ((toplevel . 1)))
+
\ No newline at end of file
diff --git a/test-data/pr39.sql b/test-data/pr39.sql
new file mode 100644
index 0000000..d8433c4
--- /dev/null
+++ b/test-data/pr39.sql
@@ -0,0 +1,8 @@
+select pk_id
+ , case
+ when t1.c1 is null then '(null)'
+ when t1.c1 in ('a', 'b','c','d','e') then 'a'
+ else t1.c1
+ end c1_alt
+ from t1
+ limit 10;