[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rubocop c620a0c 11/64: Add auto-correction commands, minor
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rubocop c620a0c 11/64: Add auto-correction commands, minor mode and a default keymap |
Date: |
Wed, 11 Aug 2021 10:07:55 -0400 (EDT) |
branch: elpa/rubocop
commit c620a0c975064a337cf170fa41ec7db6424d25b3
Author: Bozhidar Batsov <bozhidar@tradeo.com>
Commit: Bozhidar Batsov <bozhidar@tradeo.com>
Add auto-correction commands, minor mode and a default keymap
---
README.md | 16 +++++++++--
rubocop.el | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++----------
2 files changed, 92 insertions(+), 17 deletions(-)
diff --git a/README.md b/README.md
index 253c38d..22fffd0 100644
--- a/README.md
+++ b/README.md
@@ -35,11 +35,21 @@ action.
# Usage
-<kbd>M-x rubocop-run-on-project</kbd>
+Command | Description
| RuboCop mode binding
+------------------------------------------------|------------------------------------------------------------------------------
+<kbd>M-x rubocop-check-project</kbd> | Runs RuboCop on the entire
project | `C-c C-r p`
+<kbd>M-x rubocop-check-directory</kbd> | Prompts from a directory on
which to run RuboCop | `C-c C-r d`
+<kbd>M-x rubocop-check-current-file</kbd> | Runs RuboCop on the
currently visited file | `C-c C-r f`
+<kbd>M-x rubocop-autocorrect-project</kbd> | Runs auto-correct on the
entire project | `C-c C-r P`
+<kbd>M-x rubocop-autocorrect-directory</kbd> | Prompts for a directory on
which to run auto-correct | `C-c C-r D`
+<kbd>M-x rubocop-autocorrect-current-file</kbd> | Runs auto-correct on the
currently visited file. | `C-c C-r F`
-<kbd>M-x rubocop-run-on-directory</kbd>
-<kbd>M-x rubocop-run-on-current-file</kbd>
+If you use them often you might want to enable `rubocop-mode` which will added
some keybindings for them:
+
+```lisp
+(add-hook 'ruby-mode 'rubocop-mode)
+```
# Known issues
diff --git a/rubocop.el b/rubocop.el
index 63f0293..e7a2a02 100644
--- a/rubocop.el
+++ b/rubocop.el
@@ -45,6 +45,19 @@
'(".projectile" ".git" ".hg" ".bzr" "_darcs" "Gemfile")
"A list of files considered to mark the root of a project.")
+(defvar rubocop-check-command
+ "rubocop --format emacs"
+ "The command used to run RuboCop checks.")
+
+(defvar rubocop-autocorrect-command
+ "rubocop -a --format emacs"
+ "The command used to run RuboCop's autocorrection.")
+
+(defcustom rubocop-keymap-prefix (kbd "C-c C-r")
+ "RuboCop keymap prefix."
+ :group 'rubocop
+ :type 'string)
+
(defun rubocop-project-root ()
"Retrieve the root directory of a project if available.
The current directory is assumed to be the project's root otherwise."
@@ -58,44 +71,96 @@ The current directory is assumed to be the project's root
otherwise."
"Generate a name for the RuboCop buffer from FILE-OR-DIR."
(concat "*RuboCop " file-or-dir "*"))
-;;;###autoload
-(defun rubocop-run-on-project ()
- "Run on current project."
- (interactive)
- (rubocop-run-on-directory (rubocop-project-root)))
-
-;;;###autoload
-(defun rubocop-run-on-directory (&optional directory)
- "Run on DIRECTORY if present.
+(defun rubocop--dir-command (command &optional directory)
+ "Run COMMAND on DIRECTORY (if present).
Alternatively prompt user for directory."
- (interactive)
(rubocop-ensure-installed)
(let ((directory
(or directory
(read-directory-name "Select directory:"))))
(compilation-start
- (concat "rubocop --format emacs " directory)
+ (concat command " " directory)
'compilation-mode
(lambda (arg) (message arg) (rubocop-buffer-name directory)))))
;;;###autoload
-(defun rubocop-run-on-current-file ()
- "Run on current file."
+(defun rubocop-check-project ()
+ "Run on current project."
+ (interactive)
+ (rubocop-check-directory (rubocop-project-root)))
+
+;;;###autoload
+(defun rubocop-autocorrect-project ()
+ "Run on current project."
(interactive)
+ (rubocop-autocorrect-directory (rubocop-project-root)))
+
+;;;###autoload
+(defun rubocop-check-directory (&optional directory)
+ "Run on DIRECTORY if present.
+Alternatively prompt user for directory."
+ (interactive)
+ (rubocop--dir-command rubocop-check-command directory))
+
+;;;###autoload
+(defun rubocop-autocorrect-directory (&optional directory)
+ "Run on DIRECTORY if present.
+Alternatively prompt user for directory."
+ (interactive)
+ (rubocop--dir-command rubocop-autocorrect-command directory))
+
+(defun rubocop--file-command (command)
+ "Run COMMAND on currently visited file."
(rubocop-ensure-installed)
(let ((file-name (buffer-file-name (current-buffer))))
(if file-name
(compilation-start
- (concat "rubocop --format emacs " file-name)
+ (concat command " " file-name)
'compilation-mode
(lambda (arg) (rubocop-buffer-name file-name)))
(error "Buffer is not visiting a file"))))
+;;;###autoload
+(defun rubocop-check-current-file ()
+ "Run on current file."
+ (interactive)
+ (rubocop--file-command rubocop-check-command))
+
+;;;###autoload
+(defun rubocop-autocorrect-current-file ()
+ "Run on current file."
+ (interactive)
+ (rubocop--file-command rubocop-autocorrect-command))
+
(defun rubocop-ensure-installed ()
"Check if RuboCop is installed."
(unless (executable-find "rubocop")
(error "RuboCop is not installed")))
+;;; Minor mode
+(defvar rubocop-mode-map
+ (let ((map (make-sparse-keymap)))
+ (let ((prefix-map (make-sparse-keymap)))
+ (define-key prefix-map (kbd "p") 'rubocop-check-project)
+ (define-key prefix-map (kbd "d") 'rubocop-check-directory)
+ (define-key prefix-map (kbd "f") 'rubocop-check-current-file)
+ (define-key prefix-map (kbd "P") 'rubocop-autocorrect-file)
+ (define-key prefix-map (kbd "D") 'rubocop-autocorrect-directory)
+ (define-key prefix-map (kbd "F") 'rubocop-autocorrect-current-file)
+
+ (define-key map rubocop-keymap-prefix prefix-map))
+ map)
+ "Keymap for RuboCop mode.")
+
+;;;###autoload
+(define-minor-mode rubocop-mode
+ "Minor mode to assist project management and navigation.
+
+\\{projectile-mode-map}"
+ :lighter " RuboCop"
+ :keymap rubocop-mode-map
+ :group 'rubocop)
+
(provide 'rubocop)
;;; rubocop.el ends here
- [nongnu] branch elpa/rubocop created (now f5fd18a), ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop f493961 03/64: Check for the presence of the rubocop binary, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 7026b86 04/64: Make rubocop.el usable :-), ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 88d1bbf 09/64: Change commentary so that it doesn't describe projectile, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop c620a0c 11/64: Add auto-correction commands, minor mode and a default keymap,
ELPA Syncer <=
- [nongnu] elpa/rubocop 192d976 02/64: An extremely basic RuboCop interface, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 1e77d3f 18/64: add missing period, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 7446469 21/64: Merge pull request #11 from rranelli/master, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 2b782ec 23/64: Merge pull request #13 from ojab/master, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 405e0fd 28/64: Bump version to 0.4.0, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 14ab46a 01/64: first commit, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop fb98804 24/64: Load tramp dependency, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 322564d 07/64: Update for RuboCop 0.9 (fixes #1) - update rubocop-on-current-file, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop 4aeda22 14/64: Update README.md, ELPA Syncer, 2021/08/11
- [nongnu] elpa/rubocop a192b35 26/64: Fix autocorrect-project binding, ELPA Syncer, 2021/08/11