branch: externals/sql-indent commit 2ca96103dd335a14376a88c3b828ae0a80883b08 Author: Alex Harsanyi <alexharsa...@gmail.com> Commit: Alex Harsányi <alex-...@users.noreply.github.com>
don't be confused by drop function or procedure statements #80 --- sql-indent-test.el | 9 +++++++-- sql-indent.el | 8 ++++++++ test-data/pr80-syn.eld | 11 +++++++++++ test-data/pr80.sql | 6 ++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/sql-indent-test.el b/sql-indent-test.el index b0ca611..00048e0 100644 --- a/sql-indent-test.el +++ b/sql-indent-test.el @@ -387,14 +387,19 @@ information read from DATA-FILE (as generated by (ert-deftest sqlind-ert-pr73 () (sqlind-ert-check-file-syntax "test-data/pr73.sql" "test-data/pr73-syn.eld")) -(ert-deftest sqlind-ert-prXX-postgres () +(ert-deftest sqlind-ert-pr75-postgres () (sqlind-ert-check-file-syntax "test-data/pr75-postgres.sql" "test-data/pr75-postgres-syn.eld")) -(ert-deftest sqlind-ert-prXX-oracle () +(ert-deftest sqlind-ert-pr75-oracle () (sqlind-ert-check-file-syntax "test-data/pr75-oracle.sql" "test-data/pr75-oracle-syn.eld")) +(ert-deftest sqlind-ert-pr80 () + (sqlind-ert-check-file-syntax + "test-data/pr80.sql" + "test-data/pr80-syn.eld")) + ;;; sql-indent-test.el ends here diff --git a/sql-indent.el b/sql-indent.el index 51901f2..b525474 100644 --- a/sql-indent.el +++ b/sql-indent.el @@ -803,6 +803,14 @@ See also `sqlind-beginning-of-block'" ;; not a procedure after all. (throw 'exit nil))) + ;; Find out if it is a drop procedure or function statement + (save-excursion + (sqlind-backward-syntactic-ws) + (forward-word -1) + (when (looking-at "drop") + ;; not a procedure after all + (throw 'exit nil))) + ;; so it is a definition ;; if the procedure starts with "create or replace", move diff --git a/test-data/pr80-syn.eld b/test-data/pr80-syn.eld new file mode 100644 index 0000000..6e0e5b8 --- /dev/null +++ b/test-data/pr80-syn.eld @@ -0,0 +1,11 @@ +(((toplevel . 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/pr80.sql b/test-data/pr80.sql new file mode 100644 index 0000000..a29fbc7 --- /dev/null +++ b/test-data/pr80.sql @@ -0,0 +1,6 @@ +drop function if exists test; + +-- local variables: +-- mode: sql +-- sql-product: postgres +-- end: