branch: elpa/rubocop
commit 03bf15558a6eb65e4f74000cab29412efd46660e
Author: Daniel Luna <dancl...@gmail.com>
Commit: Bozhidar Batsov <bozhidar.bat...@gmail.com>

    Run auto-correct automatically on save (#29)
---
 rubocop.el | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/rubocop.el b/rubocop.el
index 26913f4..7a65b3a 100644
--- a/rubocop.el
+++ b/rubocop.el
@@ -68,6 +68,11 @@
   :group 'rubocop
   :type 'string)
 
+(defcustom rubocop-autocorrect-on-save nil
+  "Runs `rubocop-autocorrect-current-file' automatically on save."
+  :group 'rubocop
+  :type 'boolean)
+
 (defcustom rubocop-prefer-system-executable nil
   "Runs rubocop with the system executable even if inside a bundled project."
   :group 'rubocop
@@ -187,6 +192,10 @@ Alternatively prompt user for directory."
   (interactive)
   (rubocop--file-command rubocop-autocorrect-command))
 
+(defun rubocop-autocorrect-current-file-silent ()
+  (if rubocop-autocorrect-on-save
+      (save-window-excursion (rubocop-autocorrect-current-file))))
+
 (defun rubocop-bundled-p ()
   "Check if RuboCop has been bundled."
   (let ((gemfile-lock (expand-file-name "Gemfile.lock" 
(rubocop-project-root))))
@@ -220,7 +229,10 @@ Alternatively prompt user for directory."
   "Minor mode to interface with RuboCop."
   :lighter " RuboCop"
   :keymap rubocop-mode-map
-  :group 'rubocop)
+  :group 'rubocop
+  (cond
+   (rubocop-mode (add-hook 'before-save-hook 
'rubocop-autocorrect-current-file-silent nil t))
+   (t (remove-hook 'before-save-hook 'rubocop-autocorrect-current-file-silent 
t))))
 
 (provide 'rubocop)
 

Reply via email to