71 lines
4.1 KiB
EmacsLisp
71 lines
4.1 KiB
EmacsLisp
((nil . ((eval .
|
|
(progn (add-hook
|
|
'after-save-hook
|
|
(lambda ()
|
|
(let* ((file-name (buffer-file-name))
|
|
(would-reformat-cmd
|
|
(format "%s/bin/would-reformat.sh %s"
|
|
(projectile-project-root)
|
|
file-name))
|
|
(res (shell-command-to-string would-reformat-cmd)))
|
|
(progn (message (format "doing %s" file-name))
|
|
(message (format "running command: %s" would-reformat-cmd))
|
|
(cond ((string-equal res "would change")
|
|
(message (format "file `%s' would change (%s)" file-name res)))
|
|
((string-equal res "would not change")
|
|
(message (format "file `%s' would not change (%s)" file-name res)))
|
|
;; ((string-equal "ignoring") t)
|
|
))))
|
|
|
|
nil
|
|
t)
|
|
(global-set-key
|
|
[f1]
|
|
(lambda ()
|
|
(interactive)
|
|
(if (buffer-modified-p)
|
|
(message "save buffer first")
|
|
|
|
(let* ((file-name (buffer-file-name))
|
|
;; tx https://stackoverflow.com/a/23299809
|
|
(do-reformat-cmd
|
|
(format "%s/bin/do-reformat.sh" (projectile-project-root)))
|
|
(result (funcall
|
|
(lambda (program &rest args)
|
|
"Run PROGRAM with ARGS and return the exit code and output in a list."
|
|
;; (interactive)
|
|
(with-temp-buffer
|
|
(list (apply 'call-process program nil (current-buffer) nil args)
|
|
(buffer-string))))
|
|
do-reformat-cmd
|
|
file-name))
|
|
(status (car result))
|
|
(output (car (cdr result))))
|
|
(cond ((= status 0)
|
|
(progn (revert-buffer nil t)
|
|
(message (format "%s" output))))
|
|
((/= status 0)
|
|
(message (format "%s" output)))))))
|
|
)
|
|
(global-set-key
|
|
[(shift f1)]
|
|
(lambda ()
|
|
(interactive)
|
|
(let* ((file-name (buffer-file-name))
|
|
(would-reformat-cmd
|
|
(format "%s/bin/would-reformat.sh %s"
|
|
(projectile-project-root)
|
|
file-name))
|
|
(res (shell-command-to-string would-reformat-cmd)))
|
|
(progn (message (format "doing %s" file-name))
|
|
(message (format "running command: %s" would-reformat-cmd))
|
|
(cond ((string-equal res "would change")
|
|
(message (format "file `%s' would change (%s)" file-name res)))
|
|
((string-equal res "would not change")
|
|
(message (format "file `%s' would not change (%s)" file-name res)))
|
|
((string-equal res "syntax error")
|
|
(message (format "file `%s' has a syntax error (%s)" file-name res)))
|
|
;; ((string-equal "ignoring") t)
|
|
)))))
|
|
)))))
|