branch: externals/sql-indent
commit c941ff6556891d13433b30ce512582e700d24bec
Author: Alex Harsanyi <[email protected]>
Commit: Alex Harsanyi <[email protected]>
new indentation helper function and clarified documentation
added `sqlind-lineup-close-paren-to-open-indentation` function to assist
with
issue #43
---
sql-indent.el | 33 ++++++++++++++++++++++++++++++++-
sql-indent.org | 29 +++++++++++++++++++++++++++--
2 files changed, 59 insertions(+), 3 deletions(-)
diff --git a/sql-indent.el b/sql-indent.el
index f5badef..d4d6c2c 100644
--- a/sql-indent.el
+++ b/sql-indent.el
@@ -2043,7 +2043,12 @@ column of the anchor point is returned.
BASE-INDENTATION is
ignored in that case.
If line does not start with a closing paren, the function return
-BASE-INDENTATION, acting as a no-op."
+BASE-INDENTATION, acting as a no-op.
+
+NOTE: this indentation helper should be added a the end of the
+item list for a syntax symbol. This way, a normal indentation
+calculation is done and only discarded if the line starts with a
+close paren."
(save-excursion
(back-to-indentation)
(if (looking-at ")")
@@ -2055,6 +2060,32 @@ BASE-INDENTATION, acting as a no-op."
base-indentation))
base-indentation)))
+(defun sqlind-lineup-close-paren-to-open-indentation (syntax base-indentation)
+ "Align a closing paren with the indentation of the line containing the open
paren.
+If line starts with a closing paren ')', the corresponding
+'nested-statement-continuation syntax is found in SYNTAX and the
+column of the anchor point is returned. BASE-INDENTATION is
+ignored in that case.
+
+If line does not start with a closing paren, the function return
+BASE-INDENTATION, acting as a no-op.
+
+NOTE: this indentation helper should be added a the end of the
+item list for a syntax symbol. This way, a normal indentation
+calculation is done and only discarded if the line starts with a
+close paren."
+ (save-excursion
+ (back-to-indentation)
+ (if (looking-at ")")
+ (let ((stx (sqlind-find-context 'nested-statement-continuation
syntax)))
+ (if stx
+ (progn
+ (goto-char (sqlind-anchor-point stx))
+ (back-to-indentation)
+ (current-column))
+ base-indentation))
+ base-indentation)))
+
(defun sqlind-adjust-comma (_syntax base-indentation)
"Lineup lines starting with a comma ',' to the word start.
Adjust BASE-INDENTATION so that the actual word is lined up. For
diff --git a/sql-indent.org b/sql-indent.org
index e268dfe..5b75973 100644
--- a/sql-indent.org
+++ b/sql-indent.org
@@ -117,13 +117,13 @@ You can add the following code to your init file:
;; are aligned with the clause start
(defvar my-sql-indentation-offsets-alist
- '((select-clause 0)
+ `((select-clause 0)
(insert-clause 0)
(delete-clause 0)
(update-clause 0)
,@sqlind-default-indentation-offsets-alist))
- (add-hook 'sql-mode-hook
+ (add-hook 'sql-minor-mode-hook
(lambda ()
(setq sqlind-indentation-offsets-alist
my-sql-indentation-offsets-alist)))
@@ -256,6 +256,31 @@ the column of the anchor point.
if the line starts with a close paren, discard the current offset and return
the column of the corresponding open paren.
+This helper function should be added to the end of the indentation symbols,
+like so:
+
+#+BEGIN_SRC emacs-lisp
+ (defvar my-sql-indentation-offsets-alist
+ `((in-select-clause + sqlind-lineup-close-paren-to-open)
+ (select-table-continuation + sqlind-lineup-close-paren-to-open)
+ ,@sqlind-default-indentation-offsets-alist))
+#+END_SRC
+
+**** sqlind-lineup-close-paren-to-open-indentation
+
+if the line starts with a close paren, discard the current offset and return
+the indentation of the line containing the open paren.
+
+This helper function should be added to the end of the indentation symbols,
+like so:
+
+#+BEGIN_SRC emacs-lisp
+ (defvar my-sql-indentation-offsets-alist
+ `((in-select-clause + sqlind-lineup-close-paren-to-open-indentation)
+ (select-table-continuation +
sqlind-lineup-close-paren-to-open-indentation)
+ ,@sqlind-default-indentation-offsets-alist))
+#+END_SRC
+
**** sqlind-lone-semicolon
if the line contains a single semicolon ';', use the value of