branch: externals/sql-indent commit ca2fa754dc32810402765621105a5f392feeed21 Author: Alex Harsányi <alexharsa...@gmail.com> Commit: Alex Harsányi <alexharsa...@gmail.com>
Add support for the postgres support keyword (#101) --- sql-indent-test.el | 5 +++++ sql-indent.el | 10 ++++++++-- test-data/pr101-syn.eld | 30 ++++++++++++++++++++++++++++++ test-data/pr101.sql | 14 ++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/sql-indent-test.el b/sql-indent-test.el index 3fefe94b4e..7c092405ab 100644 --- a/sql-indent-test.el +++ b/sql-indent-test.el @@ -483,6 +483,11 @@ information read from DATA-FILE (as generated by "test-data/pr99.sql" "test-data/pr99-syn.eld")) +(ert-deftest sqlind-ert-pr101 () + (sqlind-ert-check-file-syntax + "test-data/pr101.sql" + "test-data/pr101-syn.eld")) + (ert-deftest sqlind-ert-pr102 () (sqlind-ert-check-file-syntax "test-data/pr102.sql" diff --git a/sql-indent.el b/sql-indent.el index cfd0e4a0ab..b2c9bbee7e 100644 --- a/sql-indent.el +++ b/sql-indent.el @@ -1048,6 +1048,7 @@ reverse order (a stack) and is used to skip over nested blocks." "\\_<\\(" "\\(\\(union\\(\\s-+all\\)?\\)\\|intersect\\|minus\\|except\\)?[ \t\r\n\f]*select\\|" "\\(bulk[ \t\r\n\f]+collect[ \t\r\n\f]+\\)?into\\|" + "perform\\|" "from\\|" "where\\|" "order[ \t\r\n\f]+by\\|" @@ -1110,7 +1111,8 @@ statement is found." (setq clause (replace-regexp-in-string "[ \t\r\n\f]" " " clause)) (when (sqlind-same-level-statement (point) start) (cond - ((looking-at "select\\(\\s *\\_<\\(top\\s +[0-9]+\\|distinct\\|unique\\)\\_>\\)?") + ((or (looking-at "select\\(\\s *\\_<\\(top\\s +[0-9]+\\|distinct\\|unique\\)\\_>\\)?") + (and (eq sql-product 'postgres) (looking-at "perform\\_>"))) ;; we are in the column selection section. (goto-char pos) (if (looking-at ",") @@ -1563,6 +1565,9 @@ not a statement-continuation POS is the same as the (push (sqlind-syntax-in-with pos (point)) context)) ((looking-at "select") (push (sqlind-syntax-in-select pos (point)) context)) + ((and (eq sql-product 'postgres) + (looking-at "perform")) + (push (sqlind-syntax-in-select pos (point)) context)) ((looking-at "insert") (push (sqlind-syntax-in-insert pos (point)) context)) ((looking-at "delete") @@ -2184,7 +2189,8 @@ first column after the SELECT clause we simply add `sqlind-basic-offset'." (save-excursion (goto-char (sqlind-anchor-point syntax)) - (when (looking-at "select\\s *\\(top\\s +[0-9]+\\|distinct\\|unique\\)?") + (when (or (looking-at "select\\s *\\(top\\s +[0-9]+\\|distinct\\|unique\\)?") + (and (eq sql-product 'postgres) (looking-at "perform\\_>"))) (goto-char (match-end 0))) (skip-syntax-forward " ") (if (or (looking-at sqlind-comment-start-skip) diff --git a/test-data/pr101-syn.eld b/test-data/pr101-syn.eld new file mode 100644 index 0000000000..e6b7f87d6f --- /dev/null +++ b/test-data/pr101-syn.eld @@ -0,0 +1,30 @@ +(((comment-start . 1) + (toplevel . 1)) + ((toplevel . 1)) + ((toplevel . 1)) + ((select-column . 47) + (statement-continuation . 47)) + ((select-column . 47) + (statement-continuation . 47)) + ((select-clause . 47) + (statement-continuation . 47)) + ((select-table . 81) + (statement-continuation . 47)) + ((select-clause . 47) + (statement-continuation . 47)) + (((in-select-clause "where") + . 101) + (statement-continuation . 47)) + (((in-select-clause "where") + . 101) + (statement-continuation . 47)) + (((in-select-clause "where") + . 101) + (statement-continuation . 47)) + ((select-clause . 47) + (statement-continuation . 47)) + ((select-clause . 47) + (statement-continuation . 47)) + ((select-clause . 47) + (statement-continuation . 47)) + ((toplevel . 1))) \ No newline at end of file diff --git a/test-data/pr101.sql b/test-data/pr101.sql new file mode 100644 index 0000000000..7eadebffb4 --- /dev/null +++ b/test-data/pr101.sql @@ -0,0 +1,14 @@ +-- -*- mode: sql; sql-product: postgres; -*- + +perform + column_a, + column_b + from + table_1 + where + column_a = 1 + and column_b = 2 + +perform foo(t.column) + from mytable t + where t.column = 1;