Created
March 31, 2010 05:30
-
-
Save mori-dev/349973 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun sqlf (start end) | |
"リージョンのSQLを整形する" | |
(interactive "r") | |
(let ((case-fold-search t)) | |
(let* ((s (buffer-substring-no-properties start end)) | |
(s (replace-regexp-in-string "\\(select \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(update \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(insert into \\)\\(fuga\\)\\(fuga\\)" "\n\\2\n " s)) | |
(s (replace-regexp-in-string "\\(delete from \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(create table \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(alter table \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(drop constraint \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(from \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(exists \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(where \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(values \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(order by \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(group by \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(having \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(left join \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(left outer join )\\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(right join \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(right outer join \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(inner join \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(cross join \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(union join \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(and \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(or \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(any \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(on update restrict \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(on update cascade \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(on update set null \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(on update no action \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(on delete restrict \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(on delete cascade \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(on delete set null \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(on delete no action \\)" "\n\\1\n " s)) | |
(s (replace-regexp-in-string "\\(,\\)" "\\1\n " s))) | |
(save-excursion | |
(insert s))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment