branch: externals/sql-indent
commit e96c9fb2108b428747a7e946a9c09b82619b13cf
Author: Alex Harsanyi <[email protected]>
Commit: Alex Harsanyi <[email protected]>

    Introduce a nested-statement-close syntax
    
    This is recognized inside a nested statement when the line to be indented
    starts with a closing bracket.  This is intended to replace
    `sqlind-lineup-close-paren-to-open` and
    `sqlind-lineup-close-paren-to-open-indentation` indentation helpers which 
had
    to be added to too many syntactic symbols.
    
    With the new syntax symbol, using `sqlind-use-anchor-indentation` will 
lineup
    hanging close brackets with the start of the statement and
    `sqlind-use-anchor-indentation` will line them up with the actual opening
    bracket itself.
---
 sql-indent-test.el     | 11 +++-----
 sql-indent.el          | 69 ++++++++------------------------------------------
 sql-indent.org         | 33 +++---------------------
 test-data/m-syn.eld    | 50 +++++++++++++++++-------------------
 test-data/pr40-syn.eld | 14 +++++-----
 5 files changed, 48 insertions(+), 129 deletions(-)

diff --git a/sql-indent-test.el b/sql-indent-test.el
index 6e5a0bc..f3d2e51 100644
--- a/sql-indent-test.el
+++ b/sql-indent-test.el
@@ -242,19 +242,16 @@ information read from DATA-FILE (as generated by
     (delete-clause                 0)
     (update-clause                 0)
     (in-insert-clause              +)
-    (in-select-clause              sqlind-lineup-to-clause-end
-                                   sqlind-lineup-close-paren-to-open)
+    (in-select-clause              sqlind-lineup-to-clause-end)
     (nested-statement-continuation sqlind-lineup-into-nested-statement
-                                   sqlind-align-comma
-                                   sqlind-lineup-close-paren-to-open)
+                                   sqlind-align-comma)
+    (nested-statement-close        sqlind-lineup-to-anchor)
     (select-column                 sqlind-indent-select-column
                                    sqlind-align-comma)
-    (select-column-continuation    sqlind-indent-select-column
-                                   sqlind-lineup-close-paren-to-open)
+    (select-column-continuation    sqlind-indent-select-column)
     (select-table-continuation     sqlind-indent-select-table
                                    sqlind-lineup-joins-to-anchor
                                    sqlind-lineup-open-paren-to-anchor
-                                   sqlind-lineup-close-paren-to-open
                                    sqlind-align-comma)
     ,@sqlind-default-indentation-offsets-alist))
 
diff --git a/sql-indent.el b/sql-indent.el
index 8780adc..34844ae 100644
--- a/sql-indent.el
+++ b/sql-indent.el
@@ -1200,7 +1200,7 @@ not a statement-continuation POS is the same as the
         (syntax-symbol (sqlind-syntax-symbol context)))
     
     (goto-char pos)
-    
+
     (cond
       ;; do we start a comment?
       ((and (not (eq syntax-symbol 'comment-continuation))
@@ -1414,12 +1414,12 @@ procedure block."
                  (let ((start (nth 1 parse-info)))
                    (goto-char (1+ start))
                    (skip-chars-forward " \t\r\n\f\v" pos)
-                   (push (cons
-                          (if (eq (point) pos)
-                              'nested-statement-open
-                           'nested-statement-continuation)
-                          start)
-                         context)))))
+                   (if (eq (point) pos)
+                       (push (cons 'nested-statement-open start) context)
+                     (goto-char pos)
+                     (if (looking-at ")")
+                         (push (cons 'nested-statement-close start) context)
+                       (push (cons 'nested-statement-continuation start) 
context)))))))
 
         ;; now let's refine the syntax by adding info about the current line
         ;; into the mix.
@@ -1530,6 +1530,9 @@ them ANCHOR points to the start of a statement itself.
 - nested-statement-continuation -- line is inside an opening
   bracket, but not the first element after the bracket.
 
+- nested-statement-close -- line is inside an opening bracket and
+  the line contains the closing bracket as the first character.
+
 The following SYNTAX-es are for statements which are SQL
 code (DML statements).  They are pecialisations on the previous
 statement syntaxes and for all of them a previous generic
@@ -1625,6 +1628,7 @@ clause (select, from, where, etc) in which the current 
point is.
     (statement-continuation         +)
     (nested-statement-open          sqlind-use-anchor-indentation +)
     (nested-statement-continuation  sqlind-use-previous-line-indentation)
+    (nested-statement-close         sqlind-use-anchor-indentation)
 
     (with-clause                    sqlind-use-anchor-indentation)
     (with-clause-cte                +)
@@ -2035,57 +2039,6 @@ function returns BASE-INDENTATION, acting as a no-op."
         (sqlind-lineup-to-anchor syntax base-indentation)
       base-indentation)))
 
-(defun sqlind-lineup-close-paren-to-open (syntax base-indentation)
-  "Align a closing paren with the corresponding open paren.
-If line starts with a closing paren ')', the corresponding
-'nested-statement-continuation syntax is found in SYNTAX and the
-column of the anchor point is returned.  BASE-INDENTATION is
-ignored in that case.
-
-If line does not start with a closing paren, the function return
-BASE-INDENTATION, acting as a no-op.
-
-NOTE: this indentation helper should be added a the end of the
-item list for a syntax symbol.  This way, a normal indentation
-calculation is done and only discarded if the line starts with a
-close paren."
-  (save-excursion
-    (back-to-indentation)
-    (if (looking-at ")")
-        (let ((stx (sqlind-find-context 'nested-statement-continuation 
syntax)))
-          (if stx
-              (progn
-               (goto-char (sqlind-anchor-point stx))
-               (current-column))
-            base-indentation))
-      base-indentation)))
-
-(defun sqlind-lineup-close-paren-to-open-indentation (syntax base-indentation)
-  "Align a closing paren with the indentation of the line containing the open 
paren.
-If line starts with a closing paren ')', the corresponding
-'nested-statement-continuation syntax is found in SYNTAX and the
-column of the anchor point is returned.  BASE-INDENTATION is
-ignored in that case.
-
-If line does not start with a closing paren, the function return
-BASE-INDENTATION, acting as a no-op.
-
-NOTE: this indentation helper should be added a the end of the
-item list for a syntax symbol.  This way, a normal indentation
-calculation is done and only discarded if the line starts with a
-close paren."
-  (save-excursion
-    (back-to-indentation)
-    (if (looking-at ")")
-        (let ((stx (sqlind-find-context 'nested-statement-continuation 
syntax)))
-          (if stx
-              (progn
-                (goto-char (sqlind-anchor-point stx))
-                (back-to-indentation)
-                (current-column))
-            base-indentation))
-      base-indentation)))
-
 (defun sqlind-adjust-comma (_syntax base-indentation)
   "Lineup lines starting with a comma ',' to the word start.
 Adjust BASE-INDENTATION so that the actual word is lined up.  For
diff --git a/sql-indent.org b/sql-indent.org
index 02025b7..28c8608 100644
--- a/sql-indent.org
+++ b/sql-indent.org
@@ -251,36 +251,6 @@ line
 if the line starts with an open paren, discard the current offset and return
 the column of the anchor point.
 
-**** sqlind-lineup-close-paren-to-open
-
-if the line starts with a close paren, discard the current offset and return
-the column of the corresponding open paren.
-
-This helper function should be added to the end of the indentation symbols,
-like so:
-
-#+BEGIN_SRC emacs-lisp
-  (defvar my-sql-indentation-offsets-alist
-    `((in-select-clause + sqlind-lineup-close-paren-to-open)
-      (select-table-continuation + sqlind-lineup-close-paren-to-open)
-      ,@sqlind-default-indentation-offsets-alist))
-#+END_SRC
-
-**** sqlind-lineup-close-paren-to-open-indentation
-
-if the line starts with a close paren, discard the current offset and return
-the indentation of the line containing the open paren.
-
-This helper function should be added to the end of the indentation symbols,
-like so:
-
-#+BEGIN_SRC emacs-lisp
-  (defvar my-sql-indentation-offsets-alist
-    `((in-select-clause + sqlind-lineup-close-paren-to-open-indentation)
-      (select-table-continuation + 
sqlind-lineup-close-paren-to-open-indentation)
-      ,@sqlind-default-indentation-offsets-alist))
-#+END_SRC
-
 **** sqlind-lone-semicolon
 
 if the line contains a single semicolon ';', use the value of
@@ -440,6 +410,9 @@ to the start of a statement itself.
  * ~nested-statement-continuation~ -- line is inside an opening bracket, but
    not the first element after the bracket.
 
+ * ~nested-statement-close~ line is inside an opening bracket and the line
+   contains the closing bracket as the first character.
+
 The following SYNTAX-es are for statements which are SQL code (DML
 statements).  They are specializations on the previous statement syntaxes and
 for all of them a previous generic statement syntax is present earlier in the
diff --git a/test-data/m-syn.eld b/test-data/m-syn.eld
index 472fd34..1bd9c80 100644
--- a/test-data/m-syn.eld
+++ b/test-data/m-syn.eld
@@ -9,7 +9,7 @@
   (statement-continuation . 25))
  ((nested-statement-continuation . 25)
   (statement-continuation . 25))
- ((nested-statement-continuation . 25)
+ ((nested-statement-close . 25)
   (statement-continuation . 25))
  ((insert-clause . 1)
   (statement-continuation . 1))
@@ -29,7 +29,7 @@
   (statement-continuation . 1))
  ((nested-statement-continuation . 242)
   (statement-continuation . 242))
- ((nested-statement-continuation . 242)
+ ((nested-statement-close . 242)
   (statement-continuation . 242))
  ((select-column . 80)
   (statement-continuation . 1))
@@ -37,7 +37,7 @@
   (statement-continuation . 1))
  ((nested-statement-continuation . 327)
   (statement-continuation . 327))
- ((nested-statement-continuation . 327)
+ ((nested-statement-close . 327)
   (statement-continuation . 327))
  ((select-column . 80)
   (statement-continuation . 1))
@@ -66,7 +66,7 @@
   (statement-continuation . 614))
  ((nested-statement-continuation . 614)
   (statement-continuation . 614))
- ((nested-statement-continuation . 614)
+ ((nested-statement-close . 614)
   (statement-continuation . 614))
  ((select-clause . 461)
   (nested-statement-continuation . 459)
@@ -74,46 +74,42 @@
  ((select-table-continuation . 795)
   (nested-statement-continuation . 459)
   (statement-continuation . 459))
- ((select-table-continuation . 795)
-  (nested-statement-continuation . 459)
+ ((nested-statement-close . 459)
   (statement-continuation . 459))
  ((select-clause . 424)
   (nested-statement-continuation . 423)
   (statement-continuation . 423))
  (((in-select-clause "where")
-   . 873)
+   . 865)
   (nested-statement-continuation . 423)
   (statement-continuation . 423))
- (((in-select-clause "where")
-   . 873)
-  (nested-statement-continuation . 423)
+ ((nested-statement-close . 423)
   (statement-continuation . 423))
  ((select-table-continuation . 411)
   (statement-continuation . 1))
  ((select-table-continuation . 411)
   (statement-continuation . 1))
- ((select-column . 940)
-  (nested-statement-continuation . 938)
-  (statement-continuation . 938))
- ((select-column . 940)
-  (nested-statement-continuation . 938)
-  (statement-continuation . 938))
- ((select-clause . 940)
-  (nested-statement-continuation . 938)
-  (statement-continuation . 938))
- ((select-table-continuation . 1002)
-  (nested-statement-continuation . 938)
-  (statement-continuation . 938))
- ((select-table-continuation . 1002)
-  (nested-statement-continuation . 938)
-  (statement-continuation . 938))
+ ((select-column . 928)
+  (nested-statement-continuation . 926)
+  (statement-continuation . 926))
+ ((select-column . 928)
+  (nested-statement-continuation . 926)
+  (statement-continuation . 926))
+ ((select-clause . 928)
+  (nested-statement-continuation . 926)
+  (statement-continuation . 926))
+ ((select-table-continuation . 990)
+  (nested-statement-continuation . 926)
+  (statement-continuation . 926))
+ ((nested-statement-close . 926)
+  (statement-continuation . 926))
  ((select-table-continuation . 411)
   (statement-continuation . 1))
  ((select-clause . 80)
   (statement-continuation . 1))
  (((in-select-clause "group by")
-   . 1067)
+   . 1047)
   (statement-continuation . 1))
  (((in-select-clause "group by")
-   . 1067)
+   . 1047)
   (statement-continuation . 1)))
diff --git a/test-data/pr40-syn.eld b/test-data/pr40-syn.eld
index 4c1646e..f390d84 100644
--- a/test-data/pr40-syn.eld
+++ b/test-data/pr40-syn.eld
@@ -17,7 +17,7 @@
   (statement-continuation . 130))
  ((nested-statement-continuation . 130)
   (statement-continuation . 130))
- ((nested-statement-continuation . 130)
+ ((nested-statement-close . 130)
   (statement-continuation . 130))
  (((block-start is-or-as)
    . 66)
@@ -28,17 +28,17 @@
   ((defun-start "[test]")
    . 66))
  (((in-begin-block defun "[test]")
-   . 211))
+   . 209))
  (((in-begin-block defun "[test]")
-   . 211))
+   . 209))
  (((in-begin-block defun "[test]")
-   . 211))
+   . 209))
  (((in-begin-block defun "[test]")
-   . 211))
+   . 209))
  (((block-end defun "[test]")
-   . 211)
+   . 209)
   ((in-begin-block defun "[test]")
-   . 211))
+   . 209))
  ((comment-start . 66)
   (toplevel . 66))
  ((comment-start . 66)

Reply via email to