Mercurial > urweb
changeset 373:008afab3a5ce
Indenting simple DML properly
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 16 Oct 2008 16:24:19 -0400 |
parents | fe018cbdd41e |
children | 1099d083a702 |
files | src/elisp/urweb-mode.el tests/sql_indent.ur |
diffstat | 2 files changed, 20 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/elisp/urweb-mode.el Thu Oct 16 16:15:17 2008 -0400 +++ b/src/elisp/urweb-mode.el Thu Oct 16 16:24:19 2008 -0400 @@ -512,9 +512,16 @@ (beginning-of-line) (current-indentation))) +(defconst urweb-sql-main-starters + '("SELECT" "INSERT" "UPDATE" "DELETE")) + (defconst urweb-sql-starters - '("FROM" "WHERE" "GROUP" "ORDER" "HAVING" "LIMIT" "OFFSET")) + (append urweb-sql-main-starters + '("^\\s-+FROM" "WHERE" "GROUP" "ORDER" "HAVING" "LIMIT" "OFFSET" + "VALUES" "SET"))) +(defconst urweb-sql-main-starters-re + (urweb-syms-re urweb-sql-main-starters)) (defconst urweb-sql-starters-re (urweb-syms-re urweb-sql-starters)) @@ -575,7 +582,9 @@ (and (looking-at urweb-sql-starters-re) (save-excursion (and (re-search-backward urweb-sql-starters-re nil t) - (current-indentation)))) + (if (looking-at urweb-sql-main-starters-re) + (current-column) + (current-indentation))))) (and (setq data (assoc sym urweb-close-paren)) (urweb-indent-relative sym data))
--- a/tests/sql_indent.ur Thu Oct 16 16:15:17 2008 -0400 +++ b/tests/sql_indent.ur Thu Oct 16 16:24:19 2008 -0400 @@ -3,3 +3,12 @@ val q1 = (SELECT * FROM t1 WHERE A = 0) + +val a1 = (INSERT INTO t1 + VALUES (0, "1", 2.0)) + +val a2 = (UPDATE t1 + SET A = 3, B = "4", C = 5.0) + +val a3 = (DELETE FROM t1 + WHERE B <> "good")