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

    fix anchor point for case statement syntax (#29)
    
    code that was looking for the "when" keyword was moving the point, resulting
    in the incorrect anchor point being used for '(in-block case ...) syntax.
    Updated tests to reflect fixed code.
    
    Also added `sqlind-syntax-keyword` helper function, to be used by 
indentation
    functions.
---
 sql-indent.el          | 16 ++++++++++++++--
 test-data/pr18-syn.eld | 14 +++++++-------
 test-data/pr28-syn.eld | 14 +++++++-------
 test-data/pr29-syn.eld | 24 ++++++++++++------------
 4 files changed, 40 insertions(+), 28 deletions(-)

diff --git a/sql-indent.el b/sql-indent.el
index c9d28d6..73f716d 100644
--- a/sql-indent.el
+++ b/sql-indent.el
@@ -204,6 +204,17 @@ See `sqlind-syntax-of-line' for the definition of CONTEXT."
           syntax-part
         (car syntax-part)))))
 
+(defun sqlind-syntax-keyword (context)
+  "Return the syntax keyword for the most specific syntax of CONTEXT.
+This is used for complex syntax symbols like '(in-block case
+\"\"), in that case, it will return the 'case symbol.  See
+`sqlind-syntax-of-line' for the definition of CONTEXT."
+  (when context
+    (let ((syntax-part (caar context)))
+      (if (symbolp syntax-part)
+          nil                           ; no KEYWORD
+        (nth 1 syntax-part)))))
+
 (defun sqlind-anchor-point (context)
   "Return the anchor point for the most specifc syntax of CONTEXT.
 See `sqlind-syntax-of-line' for the definition of CONTEXT."
@@ -422,8 +433,9 @@ See also `sqlind-beginning-of-block'"
             (setq case-label
                   (if case-label (substring case-label 2 -2) ""))
             (if (null sqlind-end-stmt-stack)
-                 (when (sqlind-search-backward start-pos "\\_<when\\_>" 
(point))
-                   (throw 'finished (list 'in-block 'case case-label)))
+                 (save-excursion
+                   (when (sqlind-search-backward start-pos "\\_<when\\_>" 
(point))
+                     (throw 'finished (list 'in-block 'case case-label))))
                 ;; else
                 (cl-destructuring-bind (pos kind label)
                     (pop sqlind-end-stmt-stack)
diff --git a/test-data/pr18-syn.eld b/test-data/pr18-syn.eld
index 46d4b11..3b45d7a 100644
--- a/test-data/pr18-syn.eld
+++ b/test-data/pr18-syn.eld
@@ -33,19 +33,19 @@
   ((in-block case "")
    . 290))
  (((block-start when)
-   . 301)
+   . 290)
   ((in-block case "")
-   . 301))
+   . 290))
  (((block-start when)
-   . 301)
+   . 290)
   ((in-block case "")
-   . 301))
+   . 290))
  (((block-start else)
-   . 301)
+   . 290)
   ((in-block case "")
-   . 301))
+   . 290))
  (((block-end case "")
-   . 301)
+   . 290)
   ((in-block else "")
    . 392))
  (((in-begin-block toplevel-block "")
diff --git a/test-data/pr28-syn.eld b/test-data/pr28-syn.eld
index a993d4b..a236d25 100644
--- a/test-data/pr28-syn.eld
+++ b/test-data/pr28-syn.eld
@@ -37,19 +37,19 @@
   ((in-block case "")
    . 215))
  (((block-start when)
-   . 228)
+   . 215)
   ((in-block case "")
-   . 228))
+   . 215))
  (((block-start when)
-   . 228)
+   . 215)
   ((in-block case "")
-   . 228))
+   . 215))
  (((block-start else)
-   . 228)
+   . 215)
   ((in-block case "")
-   . 228))
+   . 215))
  (((block-end case "")
-   . 228)
+   . 215)
   ((in-block else "")
    . 325))
  (((block-start exception)
diff --git a/test-data/pr29-syn.eld b/test-data/pr29-syn.eld
index a206aee..b84660a 100644
--- a/test-data/pr29-syn.eld
+++ b/test-data/pr29-syn.eld
@@ -31,39 +31,39 @@
  (((in-block when)
    . 184)
   ((in-block case "")
-   . 184))
+   . 173))
  (((in-block when)
    . 184)
   ((in-block case "")
-   . 184))
+   . 173))
  (((block-start when)
-   . 184)
+   . 173)
   ((in-block case "")
-   . 184))
+   . 173))
  (((in-block when)
    . 239)
   ((in-block case "")
-   . 184))
+   . 173))
  (((in-block when)
    . 239)
   ((in-block case "")
-   . 184))
+   . 173))
  (((block-start when)
-   . 184)
+   . 173)
   ((in-block case "")
-   . 184))
+   . 173))
  (((in-block when)
    . 294)
   ((in-block case "")
-   . 184))
+   . 173))
  (((block-start else)
-   . 184)
+   . 173)
   ((in-block case "")
-   . 184))
+   . 173))
  (((in-block else "")
    . 329))
  (((block-end case "")
-   . 184)
+   . 173)
   ((in-block else "")
    . 329))
  (((block-end toplevel-block "")

Reply via email to