Last active
August 2, 2019 20:07
-
-
Save psanford/636cbe569648b8bef85ce22ccedd565b to your computer and use it in GitHub Desktop.
emacs batch reformat directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun reformat-directory (dir) | |
"Reformat all files of extention in directory" | |
(interactive "D") | |
(let* ((ext ".go") | |
(ts) | |
(tmp-buffer) | |
;; disable find-file hooks to speed up processing: | |
;; don't run git commands on every file | |
(find-file-hook '()) | |
(files (split-string (shell-command-to-string (format "find %s -name *%s -print0" dir ext)) "\0" t))) | |
(dolist (f files) | |
(message "[%s] %s start" (format-time-string "%Y-%m-%dT%H:%M:%S.%6N") f) | |
(setq tmp-buffer (find-file f)) | |
(setq ts (current-time)) | |
(with-current-buffer tmp-buffer | |
(mark-whole-buffer) | |
(ignore-errors | |
(indent-region (point-min) (point-max) nil)) | |
(message "[%s] %s stop took=%0.6f" (format-time-string "%Y-%m-%dT%H:%M:%S.%6N") f (float-time (time-since ts))) | |
(save-buffer)) | |
(kill-buffer tmp-buffer)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
GO_MODE="/home/psanford/projects/go-mode.el/go-mode.el" | |
if [ ! -e "$1" ]; then | |
echo "usage: $0 <directory|file>" >&2 | |
exit 1 | |
fi | |
echo "$1" | emacs --batch -q -l $GO_MODE -l reformat-directory.el -f reformat-directory |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment