diff options
| author | Michael R. Mauger | 2018-10-01 00:12:51 -0400 |
|---|---|---|
| committer | Michael R. Mauger | 2018-10-01 00:17:23 -0400 |
| commit | 87d0007499d8434f40926c99f1edc3c4a700a79d (patch) | |
| tree | c0d46b70e7a66d0e1c759b1c790e546e65454f05 | |
| parent | d2111c5f72ccae7c3b31b476cce2a0bf458bc38d (diff) | |
| download | emacs-87d0007499d8434f40926c99f1edc3c4a700a79d.tar.gz emacs-87d0007499d8434f40926c99f1edc3c4a700a79d.zip | |
Automate support for `sql-indent' ELPA package
* progmodes/lisp/sql.el (sql-use-indent-support): New variable.
(sql-is-indent-available): New function.
(sql-indent-enable): Use above.
(sql-mode-hook, sql-interactive-mode-hook): Add `sql-indent-enable'.
| -rw-r--r-- | etc/NEWS | 23 | ||||
| -rw-r--r-- | lisp/progmodes/sql.el | 37 |
2 files changed, 55 insertions, 5 deletions
| @@ -365,6 +365,29 @@ better emulate 'M-.' in both Bash and zsh, since the former counts | |||
| 365 | from the beginning of the arguments, while the latter counts from the | 365 | from the beginning of the arguments, while the latter counts from the |
| 366 | end. | 366 | end. |
| 367 | 367 | ||
| 368 | ** SQL | ||
| 369 | |||
| 370 | *** Installation of 'sql-indent' from ELPA is strongly encouraged. | ||
| 371 | This package support sophisticated rules for properly indenting SQL | ||
| 372 | statements. SQL is not like other programming languages like C, Java, | ||
| 373 | or Python where code is sparse and rules for formatting are fairly | ||
| 374 | well established. Instead SQL is more like COBOL (from which it came) | ||
| 375 | and code tends to be very dense and line ending decisions driven by | ||
| 376 | syntax and line length considerations to make readable code. | ||
| 377 | Experienced SQL developers may prefer to rely upon existing Emacs | ||
| 378 | facilities for formatting code but the 'sql-indent' package provides | ||
| 379 | facilities to aid more casual SQL developers layout queries and | ||
| 380 | complex expressions. | ||
| 381 | |||
| 382 | *** 'sql-use-indent-support' (default t) enables SQL indention support. | ||
| 383 | The `sql-indent' package from ELPA must be installed to get the | ||
| 384 | indentation support in 'sql-mode' and 'sql-interactive-mode'. | ||
| 385 | |||
| 386 | *** 'sql-mode-hook' and 'sql-interactive-mode-hook' changed. | ||
| 387 | Both hook variables have had 'sql-indent-enable' added to their | ||
| 388 | default values. If youhave existing customizations to these variables, | ||
| 389 | you should make sure that the new default entry is included. | ||
| 390 | |||
| 368 | ** Term | 391 | ** Term |
| 369 | 392 | ||
| 370 | --- | 393 | --- |
diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el index ba180c2b26c..1cdae35ac30 100644 --- a/lisp/progmodes/sql.el +++ b/lisp/progmodes/sql.el | |||
| @@ -213,7 +213,7 @@ | |||
| 213 | ;; Drew Adams <drew.adams@oracle.com> -- Emacs 20 support | 213 | ;; Drew Adams <drew.adams@oracle.com> -- Emacs 20 support |
| 214 | ;; Harald Maier <maierh@myself.com> -- sql-send-string | 214 | ;; Harald Maier <maierh@myself.com> -- sql-send-string |
| 215 | ;; Stefan Monnier <monnier@iro.umontreal.ca> -- font-lock corrections; | 215 | ;; Stefan Monnier <monnier@iro.umontreal.ca> -- font-lock corrections; |
| 216 | ;; code polish | 216 | ;; code polish; on-going guidance and mentorship |
| 217 | ;; Paul Sleigh <bat@flurf.net> -- MySQL keyword enhancement | 217 | ;; Paul Sleigh <bat@flurf.net> -- MySQL keyword enhancement |
| 218 | ;; Andrew Schein <andrew@andrewschein.com> -- sql-port bug | 218 | ;; Andrew Schein <andrew@andrewschein.com> -- sql-port bug |
| 219 | ;; Ian Bjorhovde <idbjorh@dataproxy.com> -- db2 escape newlines | 219 | ;; Ian Bjorhovde <idbjorh@dataproxy.com> -- db2 escape newlines |
| @@ -222,6 +222,7 @@ | |||
| 222 | ;; Mark Wilkinson <wilkinsonmr@gmail.com> -- file-local variables ignored | 222 | ;; Mark Wilkinson <wilkinsonmr@gmail.com> -- file-local variables ignored |
| 223 | ;; Simen Heggestøyl <simenheg@gmail.com> -- Postgres database completion | 223 | ;; Simen Heggestøyl <simenheg@gmail.com> -- Postgres database completion |
| 224 | ;; Robert Cochran <robert-emacs@cochranmail.com> -- MariaDB support | 224 | ;; Robert Cochran <robert-emacs@cochranmail.com> -- MariaDB support |
| 225 | ;; Alex Harsanyi <alexharsanyi@gmail.com> -- sql-indent package and support | ||
| 225 | ;; | 226 | ;; |
| 226 | 227 | ||
| 227 | 228 | ||
| @@ -723,6 +724,30 @@ This allows highlighting buffers properly when you open them." | |||
| 723 | :group 'SQL | 724 | :group 'SQL |
| 724 | :safe 'symbolp) | 725 | :safe 'symbolp) |
| 725 | 726 | ||
| 727 | ;; SQL indent support | ||
| 728 | |||
| 729 | (defcustom sql-use-indent-support t | ||
| 730 | "If non-nil then use the SQL indent support features of sql-indent. | ||
| 731 | The `sql-indent' package in ELPA provides indentation support for | ||
| 732 | SQL statements with easy customizations to support varied layout | ||
| 733 | requirements. | ||
| 734 | |||
| 735 | The package must be available to be loaded and activated." | ||
| 736 | :group 'SQL | ||
| 737 | :link '(url-link "https://elpa.gnu.org/packages/sql-indent.html") | ||
| 738 | :type 'booleanp | ||
| 739 | :version "27.1") | ||
| 740 | |||
| 741 | (defun sql-is-indent-available () | ||
| 742 | "Check if sql-indent module is available." | ||
| 743 | (when (locate-library "sql-indent") | ||
| 744 | (fboundp 'sqlind-minor-mode))) | ||
| 745 | |||
| 746 | (defun sql-indent-enable () | ||
| 747 | "Enable `sqlind-minor-mode' if available and requested." | ||
| 748 | (when (sql-is-indent-available) | ||
| 749 | (sqlind-minor-mode (if sql-use-indent-support +1 -1)))) | ||
| 750 | |||
| 726 | ;; misc customization of sql.el behavior | 751 | ;; misc customization of sql.el behavior |
| 727 | 752 | ||
| 728 | (defcustom sql-electric-stuff nil | 753 | (defcustom sql-electric-stuff nil |
| @@ -850,15 +875,17 @@ commands when the input history is read, as if you had set | |||
| 850 | 875 | ||
| 851 | ;; The usual hooks | 876 | ;; The usual hooks |
| 852 | 877 | ||
| 853 | (defcustom sql-interactive-mode-hook '() | 878 | (defcustom sql-interactive-mode-hook '(sql-indent-enable) |
| 854 | "Hook for customizing `sql-interactive-mode'." | 879 | "Hook for customizing `sql-interactive-mode'." |
| 855 | :type 'hook | 880 | :type 'hook |
| 856 | :group 'SQL) | 881 | :group 'SQL |
| 882 | :version "27.1") | ||
| 857 | 883 | ||
| 858 | (defcustom sql-mode-hook '() | 884 | (defcustom sql-mode-hook '(sql-indent-enable) |
| 859 | "Hook for customizing `sql-mode'." | 885 | "Hook for customizing `sql-mode'." |
| 860 | :type 'hook | 886 | :type 'hook |
| 861 | :group 'SQL) | 887 | :group 'SQL |
| 888 | :version "27.1") | ||
| 862 | 889 | ||
| 863 | (defcustom sql-set-sqli-hook '() | 890 | (defcustom sql-set-sqli-hook '() |
| 864 | "Hook for reacting to changes of `sql-buffer'. | 891 | "Hook for reacting to changes of `sql-buffer'. |