Syntax based indentation for SQL files for GNU Emacs
sql-indent.el is a GNU Emacs minor mode which adds support for syntax-based indentation when editing SQL code: TAB indents the current line based on the syntax of the SQL code on previous lines. This works like the indentation for C and C++ code.
The package also defines align rules so that the
align function works for
SQL statements, see
sqlind-align-rules for which rules are defined. This
can be used to align multiple lines around equal signs or "as" statements,
sqlind-minor-mode together with the align rules can assist in writing tidy
SQL code or formatting existing SQL code. The indentation rules are
customizable and they can be adapted to match your coding style.
See the manual for more details.
You can install a released version of this package from GNU ELPA, by running the following commands in Emacs:
M-x package-install RET sql-indent RET
To install sql-indent from this repository, open the file
Emacs and type:
M-x package-install-from-buffer RET
The syntax-based indentation of SQL code can be turned ON/OFF at any time by
enabling or disabling
M-x sqlind-minor-mode RET
To enable syntax-based indentation for every SQL buffer, you can add
sql-mode-hook. First, bring up the customization
buffer using the command:
M-x customize-variable RET sql-mode-hook RET
Than, click on the "INS" button to add a new entry and put "sqlind-minor-mode" in the text field.