自动格式化SQL代码


Answers:



3

如果您不介意调用python进程,则可以使用(pip install sqlparse):

(defun sqlparse-region (beg end)
  (interactive "r")
  (shell-command-on-region
   beg end
   "python -c 'import sys, sqlparse; print(sqlparse.format(sys.stdin.read(), reindent=True))'"
   t t))

1

对于您的查询而言,这不是一个完整的答案,但是对于大写保留字,我有一些缩写定义。这是一个简短的示例,仅向您显示(不包括所有保留的sql字)

(define-abbrev-table 'sql-mode abbrev-table 
(mapcar #'(lambda (v) (list v (upcase v) nil 1))
'("absolute" "action" "add" "after" "all" "allocate" "alter" "and" "any" "are" "array" "as" "asc" "asensitive" )
))

0

从版本21.4a开始,Emacs带有sql-mode(sql.el),它可以自动缩进和锁定字体。没有内置的棉绒,但是它允许您使用可自定义的变量sql-linter-programM-x customize-group SQL)定义外部棉绒

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.