From: Michael R. Mauger Date: Mon, 1 Oct 2018 04:12:51 +0000 (-0400) Subject: Automate support for `sql-indent' ELPA package X-Git-Tag: emacs-27.0.90~4357 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=87d0007499d8434f40926c99f1edc3c4a700a79d;p=emacs.git 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'. --- diff --git a/etc/NEWS b/etc/NEWS index a54abd7a638..daacf49e62d 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -365,6 +365,29 @@ better emulate 'M-.' in both Bash and zsh, since the former counts from the beginning of the arguments, while the latter counts from the end. +** SQL + +*** Installation of 'sql-indent' from ELPA is strongly encouraged. +This package support sophisticated rules for properly indenting SQL +statements. SQL is not like other programming languages like C, Java, +or Python where code is sparse and rules for formatting are fairly +well established. Instead SQL is more like COBOL (from which it came) +and code tends to be very dense and line ending decisions driven by +syntax and line length considerations to make readable code. +Experienced SQL developers may prefer to rely upon existing Emacs +facilities for formatting code but the 'sql-indent' package provides +facilities to aid more casual SQL developers layout queries and +complex expressions. + +*** 'sql-use-indent-support' (default t) enables SQL indention support. +The `sql-indent' package from ELPA must be installed to get the +indentation support in 'sql-mode' and 'sql-interactive-mode'. + +*** 'sql-mode-hook' and 'sql-interactive-mode-hook' changed. +Both hook variables have had 'sql-indent-enable' added to their +default values. If youhave existing customizations to these variables, +you should make sure that the new default entry is included. + ** Term --- 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 @@ ;; Drew Adams -- Emacs 20 support ;; Harald Maier -- sql-send-string ;; Stefan Monnier -- font-lock corrections; -;; code polish +;; code polish; on-going guidance and mentorship ;; Paul Sleigh -- MySQL keyword enhancement ;; Andrew Schein -- sql-port bug ;; Ian Bjorhovde -- db2 escape newlines @@ -222,6 +222,7 @@ ;; Mark Wilkinson -- file-local variables ignored ;; Simen Heggestøyl -- Postgres database completion ;; Robert Cochran -- MariaDB support +;; Alex Harsanyi -- sql-indent package and support ;; @@ -723,6 +724,30 @@ This allows highlighting buffers properly when you open them." :group 'SQL :safe 'symbolp) +;; SQL indent support + +(defcustom sql-use-indent-support t + "If non-nil then use the SQL indent support features of sql-indent. +The `sql-indent' package in ELPA provides indentation support for +SQL statements with easy customizations to support varied layout +requirements. + +The package must be available to be loaded and activated." + :group 'SQL + :link '(url-link "https://elpa.gnu.org/packages/sql-indent.html") + :type 'booleanp + :version "27.1") + +(defun sql-is-indent-available () + "Check if sql-indent module is available." + (when (locate-library "sql-indent") + (fboundp 'sqlind-minor-mode))) + +(defun sql-indent-enable () + "Enable `sqlind-minor-mode' if available and requested." + (when (sql-is-indent-available) + (sqlind-minor-mode (if sql-use-indent-support +1 -1)))) + ;; misc customization of sql.el behavior (defcustom sql-electric-stuff nil @@ -850,15 +875,17 @@ commands when the input history is read, as if you had set ;; The usual hooks -(defcustom sql-interactive-mode-hook '() +(defcustom sql-interactive-mode-hook '(sql-indent-enable) "Hook for customizing `sql-interactive-mode'." :type 'hook - :group 'SQL) + :group 'SQL + :version "27.1") -(defcustom sql-mode-hook '() +(defcustom sql-mode-hook '(sql-indent-enable) "Hook for customizing `sql-mode'." :type 'hook - :group 'SQL) + :group 'SQL + :version "27.1") (defcustom sql-set-sqli-hook '() "Hook for reacting to changes of `sql-buffer'.