emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/rubocop 03bf155 52/64: Run auto-correct automatically on s


From: ELPA Syncer
Subject: [nongnu] elpa/rubocop 03bf155 52/64: Run auto-correct automatically on save (#29)
Date: Wed, 11 Aug 2021 10:08:03 -0400 (EDT)

branch: elpa/rubocop
commit 03bf15558a6eb65e4f74000cab29412efd46660e
Author: Daniel Luna <dancluna@gmail.com>
Commit: Bozhidar Batsov <bozhidar.batsov@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

[Prev in Thread] Current Thread [Next in Thread]