branch: externals/sql-indent
commit b3c00b270ea8d33602e2a2e97f52a9e23274c7b8
Author: Pierre Téchoueyres <[email protected]>
Commit: Alex Harsányi <[email protected]>
Correct detection of labels in `sqlind-maybe-loop-statement'. (#49)
Correct detection of labels in `sqlind-maybe-loop-statement'
---
sql-indent-test.el | 3 +++
sql-indent.el | 5 +++--
test-data/pr49-syn.eld | 44 ++++++++++++++++++++++++++++++++++++++++++++
test-data/pr49.sql | 19 +++++++++++++++++++
4 files changed, 69 insertions(+), 2 deletions(-)
diff --git a/sql-indent-test.el b/sql-indent-test.el
index 69be7e2..7c4a7ba 100644
--- a/sql-indent-test.el
+++ b/sql-indent-test.el
@@ -345,4 +345,7 @@ information read from DATA-FILE (as generated by
(ert-deftest sqlind-ert-pr48 ()
(sqlind-ert-check-file-syntax "test-data/pr48.sql" "test-data/pr48-syn.eld"))
+(ert-deftest sqlind-ert-pr49 ()
+ (sqlind-ert-check-file-syntax "test-data/pr49.sql" "test-data/pr49-syn.eld"))
+
;;; sql-indent-test.el ends here
diff --git a/sql-indent.el b/sql-indent.el
index 586166f..ec5bf3a 100644
--- a/sql-indent.el
+++ b/sql-indent.el
@@ -531,8 +531,9 @@ See also `sqlind-beginning-of-block'"
(or (sqlind-maybe-end-statement)
(progn
(let ((posn (point)))
- (forward-word -1)
- (sqlind-beginning-of-statement)
+ (unless (looking-at "<<") ;; whe're inside an label.
+ (forward-word -1)
+ (back-to-indentation))
(let ((loop-label (if (looking-at "<<\\([a-z0-9_]+\\)>>")
(sqlind-match-string 1) "")))
(goto-char posn)
diff --git a/test-data/pr49-syn.eld b/test-data/pr49-syn.eld
new file mode 100644
index 0000000..b41629b
--- /dev/null
+++ b/test-data/pr49-syn.eld
@@ -0,0 +1,44 @@
+((((block-start begin)
+ . 1)
+ (toplevel . 1))
+ (((in-begin-block toplevel-block "")
+ . 1))
+ (((in-block if "")
+ . 9))
+ (((in-block if "")
+ . 9))
+ (((in-block loop "my_third_loop")
+ . 48))
+ (((in-block loop "my_third_loop")
+ . 48))
+ (((block-end loop "my_third_loop")
+ . 48)
+ ((in-block loop "my_third_loop")
+ . 48))
+ (((in-block if "")
+ . 9))
+ (((block-end if "")
+ . 9)
+ ((in-block if "")
+ . 9))
+ (((block-end toplevel-block "")
+ . 1)
+ ((in-begin-block toplevel-block "")
+ . 1))
+ ((toplevel . 1))
+ ((toplevel . 1))
+ ((comment-start . 1)
+ (toplevel . 1))
+ ((comment-start . 1)
+ (toplevel . 1))
+ ((comment-start . 1)
+ (toplevel . 1))
+ ((comment-start . 1)
+ (toplevel . 1))
+ ((comment-start . 1)
+ (toplevel . 1))
+ ((comment-start . 1)
+ (toplevel . 1))
+ ((comment-start . 1)
+ (toplevel . 1))
+ ((toplevel . 1)))
diff --git a/test-data/pr49.sql b/test-data/pr49.sql
new file mode 100644
index 0000000..cea9eb9
--- /dev/null
+++ b/test-data/pr49.sql
@@ -0,0 +1,19 @@
+begin
+ if true then
+ <<my_third_loop>>
+ while true loop
+ dbms_output.put_line('in my_second_loop');
+ exit my_third_loop;
+ end loop my_third_loop;
+ dbms_output.put_line('end of my_second_loop');
+ end if;
+end;
+/
+
+-- Local Variables:
+-- indent-tabs-mode: nil
+-- mode: sql
+-- mode: sqlind-minor
+-- sql-product: oracle
+-- tab-width: 2
+-- End: