emacs の major-mode みて、perltify つかったり js-beautify つかったりを自動で分ける。
(defun my-tidy-region (begin end)
(interactive "r")
(save-match-data
(save-restriction
(my-tidy begin end)
)))
(defun my-tidy-buffer ()
(interactive)
(let (cpoint)
(setq cpoint (point))
(save-excursion
(save-match-data
(save-restriction
(mark-whole-buffer)
(my-tidy (point-min) (point-max)))))
(goto-char cpoint)
))
(defun my-tidy (begin end)
(let ((current-major-mode major-mode) cmd)
(setenv "LC_ALL" "C")
(setenv "LANG" "C")
(message (format "%s" current-major-mode))
(cond
((string= "cperl-mode" current-major-mode) (setq cmd "perltidy -q"))
((string= "js3-mode" current-major-mode) (setq cmd "js-beautify.js -f - --good-stuff"))
)
(if (not (null cmd))
(shell-command-on-region begin end cmd nil t)
(progn (indent-region begin end)
(delete-trailing-whitespace)
(delete-blank-lines)
(untabify (point-min) (point-max))
)
)))