diff options
author | Franck Cuny <franckcuny@gmail.com> | 2016-10-31 17:43:44 -0700 |
---|---|---|
committer | Franck Cuny <franckcuny@gmail.com> | 2016-10-31 17:43:44 -0700 |
commit | 659230db11a09b0157dc8dbebc912c8bb8ddb7ba (patch) | |
tree | ab29e331d0dfc61ad675f52bc316b01155e6a181 | |
parent | Use 'ivy' instead of 'helm'. (diff) | |
download | pants.el-659230db11a09b0157dc8dbebc912c8bb8ddb7ba.tar.gz |
Add a function `pants-run-fmt` to autoformat Python code.
This function runs the 'fmt' command to autoformat the source files. This only works for Python.
-rw-r--r-- | pants.el | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/pants.el b/pants.el index 75606ec..d213ac1 100644 --- a/pants.el +++ b/pants.el @@ -73,6 +73,11 @@ (let ((compile-command (format "%s test %s" (pants--build-command) target))) (pants--compile compile-command))) +(defun pants--fmt-action (target) + "Executes the `fmt' command" + (let ((compile-command (format "%s fmt.isort %s" (pants--build-command) target))) + (pants--compile compile-command))) + (defun pants--compilation-setup () "Sets the local configuration for the compile buffer" (set (make-local-variable 'compilation-scroll-output) 'first-error) @@ -151,4 +156,13 @@ (pants--build-target-list build-file 'pants--test-action) (error "Could not find %s" pants-build-file)))) +;;;###autoload +(defun pants-run-fmt () + "Runs fmt on a target file to sort the import files (Python only)." + (interactive) + (let ((build-file (pants--get-build-file-for-current-buffer))) + (if build-file + (pants--build-target-list build-file 'pants--ifmt-action) + (error "Could not find %s" pants-build-file)))) + (provide 'pants) |