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

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

[elpa] externals/sql-indent 283116d 04/13: Correct the adjustment of ind


From: Stefan Monnier
Subject: [elpa] externals/sql-indent 283116d 04/13: Correct the adjustment of indentation for operators in select (#52)
Date: Sun, 11 Feb 2018 22:24:13 -0500 (EST)

branch: externals/sql-indent
commit 283116d7c3bd4275a169d1631235de61e0da7c01
Author: Pierre Téchoueyres <address@hidden>
Commit: Alex Harsányi <address@hidden>

    Correct the adjustment of indentation for operators in select (#52)
    
    * Correct the adjustment of indentation for operators in select
    
    With this fix the following statement is propely indented
    
    ``` sql
    select mt.myVar
        || '-*-' myVarLabel,
           myVar2
    from   myTable mt;
    ```
    
    instead of
    
    ``` sql
    select mt.myVar
          || '-*-' myVarLabel,
           myVar2
    from   myTable mt;
    ```
    
    * sql-indent.el: Use sqlind syntax table in adjustments functions.
    (sqlind-adjust-operator): Use sqlind syntax table.
    
    * Add test to pr52
---
 sql-indent-test.el         |  3 +++
 sql-indent.el              | 33 +++++++++++++++++----------------
 test-data/pr52-io-left.eld |  1 +
 test-data/pr52.sql         | 12 ++++++++++++
 4 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/sql-indent-test.el b/sql-indent-test.el
index 97d6082..67cdf1e 100644
--- a/sql-indent-test.el
+++ b/sql-indent-test.el
@@ -352,4 +352,7 @@ information read from DATA-FILE (as generated by
   (sqlind-ert-check-file-indentation "test-data/pr50.sql" 
"test-data/pr50-io-left.eld"
                                     sqlind-indentation-left-offsets-alist 2))
 
+(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))
 ;;; sql-indent-test.el ends here
diff --git a/sql-indent.el b/sql-indent.el
index 72028b6..c16dd9a 100644
--- a/sql-indent.el
+++ b/sql-indent.el
@@ -1959,22 +1959,23 @@ example:
 This is an indentation adjuster and needs to be added to the
 `sqlind-indentation-offsets-alist`"
   (save-excursion
-    (back-to-indentation)
-    ;; If there are non-word constituents at the beginning if the line,
-    ;; consider them an operator and line up the line to the first word of 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)
-            (max 0 (- (current-column) ofs))))
-         ('t base-indentation))))
+    (with-syntax-table sqlind-syntax-table
+      (back-to-indentation)
+      ;; If there are non-word constituents at the beginning if the line,
+      ;; consider them an operator and line up the line to the first word of 
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)
+              (max 0 (- (current-column) ofs))))
+           ('t base-indentation)))))
 
 (defun sqlind-lone-semicolon (syntax base-indentation)
   "Indent a lone semicolon with the statement start.  For example:
diff --git a/test-data/pr52-io-left.eld b/test-data/pr52-io-left.eld
new file mode 100644
index 0000000..4a96bab
--- /dev/null
+++ b/test-data/pr52-io-left.eld
@@ -0,0 +1 @@
+(0 4 7 0 0 0 0 0 0 0 0 0 0)
diff --git a/test-data/pr52.sql b/test-data/pr52.sql
new file mode 100644
index 0000000..84b1847
--- /dev/null
+++ b/test-data/pr52.sql
@@ -0,0 +1,12 @@
+select mt.myVar
+    || '-*-' myVarLabel,
+       myVar2
+from   myTable mt;
+
+-- Local Variables:
+-- mode: sql
+-- mode: sqlind-minor
+-- tab-width: 2
+-- indent-tabs-mode: nil
+-- sql-product: oracle
+-- End:



reply via email to

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