これはそれを行う1つの方法です(あなたが言及したインデント関数を使用して軽くテストしました-私はSQLを使用しませんが、バッファ全体で動作する限り、その場所に任意の関数をプラグインできるはずです):
(defun my-sql-indent-region (beg end)
"Indent the SQL statement in the region."
(interactive "*r")
(save-excursion
(save-restriction
(narrow-to-region beg end)
;; http://www.emacswiki.org/emacs/download/sql-indent.el
(sql-indent-buffer))))
次の sql クエリ ("SELECT" から "f2.PLAYERID" まで) をマークし、elisp 文字列に埋め込んで実行すると、次のようになりますM-x my-sql-indent-region
RET。
(defvar my-sql-query "
SELECT p1.PLAYERID,
f1.PLAYERNAME,
p2.PLAYERID,
f2.PLAYERNAME
FROM PLAYER f1,
PLAYER f2,
PLAYS p1
FULL OUTER JOIN PLAYS p2
ON p1.PLAYERID < p2.PLAYERID
AND p1.TEAMID = p2.TEAMID
GROUP BY p1.PLAYERID,
f1.PLAYERID,
p2.PLAYERID,
f2.PLAYERID
HAVING Count(p1.PLAYERID) = Count(*)
AND Count(p2.PLAYERID) = Count(*)
AND p1.PLAYERID = f1.PLAYERID
AND p2.PLAYERID = f2.PLAYERID;
")
私は最終的に:
(defvar my-sql-query "
SELECT p1.PLAYERID,
f1.PLAYERNAME,
p2.PLAYERID,
f2.PLAYERNAME
FROM PLAYER f1,
PLAYER f2,
PLAYS p1
FULL OUTER JOIN PLAYS p2
ON p1.PLAYERID < p2.PLAYERID
AND p1.TEAMID = p2.TEAMID
GROUP BY p1.PLAYERID,
f1.PLAYERID,
p2.PLAYERID,
f2.PLAYERID
HAVING Count(p1.PLAYERID) = Count(*)
AND Count(p2.PLAYERID) = Count(*)
AND p1.PLAYERID = f1.PLAYERID
AND p2.PLAYERID = f2.PLAYERID;
")