Add previously missing SQL-indent

This commit is contained in:
Maciej 2017-12-28 22:30:53 +02:00
parent 866fca1028
commit e122cca29d
Signed by: maciej
GPG key ID: 41D62D42D3B0D765
4 changed files with 28 additions and 4 deletions

View file

@ -22,6 +22,26 @@
(add-hook 'sql-mode-hook 'editor-config-sql)
(add-hook 'sql-mode-hook 'completion-config-sql)
(require 'sql-indent)
;;========== Functions =====================
(defun sql-indent-string ()
"Indents the string under the cursor as SQL."
(interactive)
(save-excursion
(er/mark-inside-quotes)
(let* ((text (buffer-substring-no-properties (region-beginning) (region-end)))
(pos (region-beginning))
(column (progn (goto-char pos) (current-column)))
(formatted-text (with-temp-buffer
(insert text)
(delete-trailing-whitespace)
(sql-indent-buffer)
(replace-string "\n" (concat "\n" (make-string column (string-to-char " "))) nil (point-min) (point-max))
(buffer-string))))
(delete-region (region-beginning) (region-end))
(goto-char pos)
(insert formatted-text))))
;;; sql.el ends here.