diff options
author | Adam Chlipala <adamc@hcoop.net> | 2008-10-16 16:15:17 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2008-10-16 16:15:17 -0400 |
commit | 0a66597b3498f5863620c3ca5e2713e45eed47f8 (patch) | |
tree | 3d989c71c000d7324852e4d03d417d29e91b3f0c | |
parent | 22236f78bf5acb81d9c404ab71be9aa3d9e3bf26 (diff) |
Indenting SELECT sub-clauses properly
-rw-r--r-- | src/elisp/urweb-mode.el | 11 | ||||
-rw-r--r-- | tests/select.ur | 20 | ||||
-rw-r--r-- | tests/sql_indent.ur | 5 |
3 files changed, 26 insertions, 10 deletions
diff --git a/src/elisp/urweb-mode.el b/src/elisp/urweb-mode.el index 9bfa0c96..5e217e1a 100644 --- a/src/elisp/urweb-mode.el +++ b/src/elisp/urweb-mode.el @@ -512,6 +512,12 @@ If anyone has a good algorithm for this..." (beginning-of-line) (current-indentation))) +(defconst urweb-sql-starters + '("FROM" "WHERE" "GROUP" "ORDER" "HAVING" "LIMIT" "OFFSET")) + +(defconst urweb-sql-starters-re + (urweb-syms-re urweb-sql-starters)) + (defun urweb-calculate-indentation () (save-excursion (beginning-of-line) (skip-chars-forward "\t ") @@ -566,6 +572,11 @@ If anyone has a good algorithm for this..." (urweb-indent-default 'noindent) (current-column)))) + (and (looking-at urweb-sql-starters-re) + (save-excursion + (and (re-search-backward urweb-sql-starters-re nil t) + (current-indentation)))) + (and (setq data (assoc sym urweb-close-paren)) (urweb-indent-relative sym data)) diff --git a/tests/select.ur b/tests/select.ur index d97e6a55..ff3908e9 100644 --- a/tests/select.ur +++ b/tests/select.ur @@ -1,13 +1,13 @@ -val handler = fn x => <html><body> +val handler = fn x => <xml><body> You entered: {cdata x.A} -</body></html> +</body></xml> -val main = fn () => <html><body> - <lform> - <lselect{#A}> - <loption value="A">A</loption> - <loption value="B">B</loption> - </lselect> +val main = fn () => <xml><body> + <form> + <select{#A}> + <option value="A">A</option> + <option value="B">B</option> + </select> <submit action={handler}/> - </lform> -</body></html> + </form> +</body></xml> diff --git a/tests/sql_indent.ur b/tests/sql_indent.ur new file mode 100644 index 00000000..c4a46d71 --- /dev/null +++ b/tests/sql_indent.ur @@ -0,0 +1,5 @@ +table t1 : {A : int, B : string, C : float} + +val q1 = (SELECT * + FROM t1 + WHERE A = 0) |