[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rubocop f5fd18a 64/64: Add the ability to format on save
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rubocop f5fd18a 64/64: Add the ability to format on save |
Date: |
Wed, 11 Aug 2021 10:08:06 -0400 (EDT) |
branch: elpa/rubocop
commit f5fd18aa810c3d3269188cbbd731ddc09006f8f5
Author: Bozhidar Batsov <bozhidar@batsov.com>
Commit: Bozhidar Batsov <bozhidar@batsov.com>
Add the ability to format on save
Basically, that's a subset of the autocorrect on save functionality.
---
README.md | 9 +++++++++
rubocop.el | 23 ++++++++++++++++++++---
2 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 1268dfe..78a7970 100644
--- a/README.md
+++ b/README.md
@@ -71,6 +71,15 @@ The variable `rubocop-autocorrect-on-save` controls whether
to auto-correct auto
(setq rubocop-autocorrect-on-save t)
```
+Alternatively you can enable only automatic code formatting on save
(effectively that's a subset of
+the full auto-correct):
+
+``` emacs-lisp
+(setq rubocop-format-on-save t)
+```
+
+**Note:** Generally you shouldn't enable `rubocop-format-on-save` if
`rubocop-autocorrect-on-save` is enabled.
+
You can change the shell command used by `rubocop-check-*` commands via
`rubocop-check-command`:
``` emacs-lisp
diff --git a/rubocop.el b/rubocop.el
index c7065a0..6353abd 100644
--- a/rubocop.el
+++ b/rubocop.el
@@ -82,6 +82,12 @@ It's basically auto-correction limited to layout cops."
:type 'boolean
:package-version '(rubocop . "0.6.0"))
+(defcustom rubocop-format-on-save nil
+ "Runs `rubocop-format-current-file' automatically on save."
+ :group 'rubocop
+ :type 'boolean
+ :package-version '(rubocop . "0.7.0"))
+
(defcustom rubocop-prefer-system-executable nil
"Runs rubocop with the system executable even if inside a bundled project."
:group 'rubocop
@@ -232,6 +238,12 @@ See also `rubocop-autocorrect-on-save'."
(interactive)
(rubocop--file-command rubocop-format-command))
+(defun rubocop-format-current-file-silent ()
+ "This command is used by the minor mode to format on save.
+See also `rubocop-format-on-save' and `rubocop-autocorrect-on-save'."
+ (when (and rubocop-format-on-save (not rubocop-autocorrect-on-save))
+ (save-window-excursion (rubocop-format-current-file))))
+
(defun rubocop-bundled-p ()
"Check if RuboCop has been bundled."
(let ((gemfile-lock (expand-file-name "Gemfile.lock"
(rubocop-project-root))))
@@ -269,9 +281,14 @@ See also `rubocop-autocorrect-on-save'."
:lighter " RuboCop"
:keymap rubocop-mode-map
: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))))
+ (if rubocop-mode
+ ;; on mode enable
+ (progn
+ (add-hook 'before-save-hook 'rubocop-autocorrect-current-file-silent
nil t)
+ (add-hook 'before-save-hook 'rubocop-format-current-file-silent nil t))
+ ;; on mode disable
+ (remove-hook 'before-save-hook 'rubocop-autocorrect-current-file-silent t)
+ (remove-hook 'before-save-hook 'rubocop-format-current-file-silent t)))
(provide 'rubocop)
- [nongnu] elpa/rubocop b921bec 08/64: Merge pull request #2 from nodo/master, (continued)
- [nongnu] elpa/rubocop b921bec 08/64: Merge pull request #2 from nodo/master, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 6f4928d 15/64: Merge pull request #4 from arthurnn/patch-1, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop c549052 31/64: Merge pull request #19 from syohex/byte-compile-warning, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop fb20a88 33/64: Tweak some docstrings, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop c0cb592 37/64: Kill the dash.el dependency, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 4fdf643 40/64: Add missing space, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 1285711 44/64: [Fix #22] Add a clean way to load RuboCop extensions, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop d4dad32 48/64: Add missing space, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 080454e 54/64: Add a note about rubocop-keymap-prefix, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 6c9c5a9 55/64: Add a bunch of commands for code formatting, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop f5fd18a 64/64: Add the ability to format on save,
ELPA Syncer <=
- [nongnu] elpa/rubocop b0c5bc2 62/64: Tweak a heading, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 608a3c1 58/64: Release 0.6.0, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 0131536 39/64: Fix a docstring, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 1372ee3 60/64: Tweak some wording, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 2c884cd 25/64: Merge pull request #15 from fap-/load_tramp_dependency, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop f947fb0 30/64: Fix byte-compile warning about unused variable, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 02ad056 35/64: [Fix #17] Consider rubocop installed if bundled, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 676cabe 36/64: Expand the project root path, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop a809fa7 42/64: [Fix #24] Always run RuboCop from the project's root when within a, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 03bf155 52/64: Run auto-correct automatically on save (#29), ELPA Syncer, 2021/08/11