SqlIndent

sql-indent.el — indentation of SQL statements

This package is available from GNU ELPA: https://elpa.gnu.org/packages/sql-indent.html

SqlMode will automatically use it when it’s installed.


This was a very quick hack to indent SQL statements and over the years it grew to something actually usable. You can use it together with SqlMode. The SQL grammar is large so this code may still need improvement in order to reach the level of sophistication Emacs users are used to in other indentation engines. Help welcome.

There are a few other attempts at auto-indenting SQL in Emacs:

Older versions:

As the indentation of SQL statements depends not only on the previous line but also on the current line, empty lines cannot always be indented correctly. Hitting TAB on a line containing only whitespace will remove all whitespace and make the line empty; hitting TAB on an empty line will indent the line to the same column as the previous line; hitting TAB again will indent or outdent the line one step. Hitting TAB after certain keywords will insert a tab character as well as indent the line.


CategorySql