[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/sql-indent 8a1c4ec 05/13: Correct indentation of column
From: |
Stefan Monnier |
Subject: |
[elpa] externals/sql-indent 8a1c4ec 05/13: Correct indentation of column continuation with operators. (#53) |
Date: |
Sun, 11 Feb 2018 22:24:13 -0500 (EST) |
branch: externals/sql-indent
commit 8a1c4ecdfdc971524e73d4f19dcd8e6bcb1a50fe
Author: Pierre Téchoueyres <address@hidden>
Commit: Alex Harsányi <address@hidden>
Correct indentation of column continuation with operators. (#53)
* Correct indentation of column continuation with operators.
Correct from
```sql
select my_col || chr(10)
|| '-*-' data_type,
x
from dual;
```
to
```sql
select my_col || chr(10)
|| '-*-' data_type,
x
from dual;
```
* sql-indent.el
(sqlind-column-definition-start): find the first column of the
statement.
(sqlind-use-anchor-indentation): use the indentation of the anchor
instead of the indentation of the line containing the anchor.
(sqlind-adjust-operator): search the column start in
select-column-continuation.
* Add test for PR#53.
* Simplify code.
(sqlind-column-definition-start): avoid unnecessary (unless (while ...)).
(sqlind-adjust-operator): avoid complex goto-char.
---
sql-indent-left.el | 4 +++-
sql-indent-test.el | 4 ++++
sql-indent.el | 35 ++++++++++++++++++++++-------------
test-data/pr53-io-left.eld | 1 +
test-data/pr53.sql | 14 ++++++++++++++
5 files changed, 44 insertions(+), 14 deletions(-)
diff --git a/sql-indent-left.el b/sql-indent-left.el
index 17bd067..b0fac9e 100644
--- a/sql-indent-left.el
+++ b/sql-indent-left.el
@@ -194,13 +194,15 @@ select aaa,
(package +)
(package-body +)
(statement-continuation + sqlind-adjust-operator)
+ (nested-statement-open 1)
(nested-statement-continuation 1)
+ (nested-statement-close sqlind-use-anchor-indentation)
(string-continuation 0) ;; or shoult it be a begining of line or aligned
with the previous block ?
;; Anyway. It's really *BAD* to continue a string
accross lines.
(select-column sqlind-indent-select-column-alt
sqlind-adjust-operator
sqlind-lone-semicolon)
- (select-column-continuation sqlind-indent-select-column
+ (select-column-continuation sqlind-indent-select-column-alt
sqlind-adjust-operator
sqlind-lone-semicolon)
(in-select-clause sqlind-lineup-to-clause-end
diff --git a/sql-indent-test.el b/sql-indent-test.el
index 67cdf1e..a14ddf9 100644
--- a/sql-indent-test.el
+++ b/sql-indent-test.el
@@ -355,4 +355,8 @@ information read from DATA-FILE (as generated by
(ert-deftest sqlind-ert-pr52-io-left ()
(sqlind-ert-check-file-indentation "test-data/pr52.sql"
"test-data/pr52-io-left.eld"
sqlind-indentation-left-offsets-alist 2))
+
+(ert-deftest sqlind-ert-pr53-io-left ()
+ (sqlind-ert-check-file-indentation "test-data/pr53.sql"
"test-data/pr53-io-left.eld"
+ sqlind-indentation-left-offsets-alist 2))
;;; sql-indent-test.el ends here
diff --git a/sql-indent.el b/sql-indent.el
index c16dd9a..8d53878 100644
--- a/sql-indent.el
+++ b/sql-indent.el
@@ -185,10 +185,15 @@ statement."
(goto-char pos)
(catch 'found
(while (re-search-backward "," limit 'noerror)
- (when (sqlind-same-level-statement (point) limit)
- (forward-char 1)
- (sqlind-forward-syntactic-ws)
- (throw 'found (point)))))))
+ (when (sqlind-same-level-statement (point) limit)
+ (forward-char 1)
+ (sqlind-forward-syntactic-ws)
+ (throw 'found (point))))
+ ;; nothing was found in (while ...) so try to find the first column
definition.
+ (goto-char limit)
+ (forward-sexp)
+ (sqlind-forward-syntactic-ws)
+ (point))))
(defun sqlind-syntax (context)
"Return the most specific syntax of CONTEXT.
@@ -1940,7 +1945,7 @@ with AND, OR or NOT to be aligned so they sit left under
the WHERE clause."
"\\s-*")
"Regexp to match a SQL expression operator.")
-(defun sqlind-adjust-operator (_syntax base-indentation)
+(defun sqlind-adjust-operator (syntax base-indentation)
"Adjust the indentation for operators in select clauses.
If the line to be indented starts with an operator, the
@@ -1966,14 +1971,18 @@ This is an indentation adjuster and needs to be added
to the
;; line, not the operator
(cond ((looking-at sqlind-operator-regexp)
(let ((ofs (length (match-string 0))))
- (forward-line -1)
- (end-of-line)
- (sqlind-backward-syntactic-ws)
- ;; Previous function leaves us on the first non-white-space
- ;; character. This might be a string terminator (') char, move
- ;; the cursor one to the left, so 'forward-sexp' works correctly.
- (ignore-errors (forward-char 1))
- (forward-sexp -1)
+ (if (eq (sqlind-syntax-symbol syntax)
+ 'select-column-continuation)
+ (goto-char (sqlind-column-definition-start
+ (point) (sqlind-anchor-point syntax)))
+ (forward-line -1)
+ (end-of-line)
+ (sqlind-backward-syntactic-ws)
+ ;; Previous function leaves us on the first non-white-space
+ ;; character. This might be a string terminator (') char, move
+ ;; the cursor one to the left, so 'forward-sexp' works
correctly.
+ (ignore-errors (forward-char 1))
+ (forward-sexp -1))
(max 0 (- (current-column) ofs))))
('t base-indentation)))))
diff --git a/test-data/pr53-io-left.eld b/test-data/pr53-io-left.eld
new file mode 100644
index 0000000..73e263f
--- /dev/null
+++ b/test-data/pr53-io-left.eld
@@ -0,0 +1 @@
+(0 4 7 0 0 0 0 0 0 0 0 0 0 0 0)
diff --git a/test-data/pr53.sql b/test-data/pr53.sql
new file mode 100644
index 0000000..e1d91e6
--- /dev/null
+++ b/test-data/pr53.sql
@@ -0,0 +1,14 @@
+select my_col || chr(10)
+ || '-*-' data_type,
+ x
+from dual;
+
+
+-- Local Variables:
+-- mode: sql
+-- mode: sqlind-minor
+-- tab-width: 2
+-- indent-tabs-mode: nil
+-- sql-product: oracle
+-- End:
+
- [elpa] externals/sql-indent bd39d07 10/13: add explanation on how `sqlind-beginning-of-block` works, (continued)
- [elpa] externals/sql-indent bd39d07 10/13: add explanation on how `sqlind-beginning-of-block` works, Stefan Monnier, 2018/02/11
- [elpa] externals/sql-indent 2c9c17f 07/13: Fix typo in sql-indent.org. (#56), Stefan Monnier, 2018/02/11
- [elpa] externals/sql-indent 283116d 04/13: Correct the adjustment of indentation for operators in select (#52), Stefan Monnier, 2018/02/11
- [elpa] externals/sql-indent 51b17d6 01/13: Update README with instructions on how to install from GNU ELPA, Stefan Monnier, 2018/02/11
- [elpa] externals/sql-indent 0bca299 12/13: Fix travis build. (#58), Stefan Monnier, 2018/02/11
- [elpa] externals/sql-indent 44841a8 13/13: Add .elpaignore file, Stefan Monnier, 2018/02/11
- [elpa] externals/sql-indent 1b4d0e8 03/13: Add CONTRIBUTING.md file (#51), Stefan Monnier, 2018/02/11
- [elpa] externals/sql-indent 3ee7f95 08/13: Fix various typos here and there. (#57), Stefan Monnier, 2018/02/11
- [elpa] externals/sql-indent d56faed 06/13: Updated documentation, Stefan Monnier, 2018/02/11
- [elpa] externals/sql-indent 9f716f6 09/13: Recognize PostgreSQL $$ quote syntax, #54 (#55), Stefan Monnier, 2018/02/11
- [elpa] externals/sql-indent 8a1c4ec 05/13: Correct indentation of column continuation with operators. (#53),
Stefan Monnier <=
- [elpa] externals/sql-indent 1efac21 11/13: Update sql-indent.el to version 1.1, Stefan Monnier, 2018/02/11
- [elpa] externals/sql-indent 146655b 02/13: Add new indentation function for select columns. (#50), Stefan Monnier, 2018/02/11