Extract the common part of ruby-flymake-simple and ruby-flymake-rubocop
* lisp/progmodes/ruby-mode.el (ruby-flymake-simple) (ruby-flymake-rubocop): Extract the common part as ruby-flymake--helper. (ruby--rubocop-flymake-proc): Remove. Use the first proc variable instead.
This commit is contained in:
parent
09944d499a
commit
2d203ffb7e
1 changed files with 64 additions and 77 deletions
|
@ -2261,6 +2261,31 @@ See `font-lock-syntax-table'.")
|
||||||
(unless (executable-find "ruby")
|
(unless (executable-find "ruby")
|
||||||
(error "Cannot find the ruby executable"))
|
(error "Cannot find the ruby executable"))
|
||||||
|
|
||||||
|
(ruby-flymake--helper
|
||||||
|
"ruby-flymake"
|
||||||
|
'("ruby" "-w" "-c")
|
||||||
|
(lambda (_proc source)
|
||||||
|
(goto-char (point-min))
|
||||||
|
(cl-loop
|
||||||
|
while (search-forward-regexp
|
||||||
|
"^\\(?:.*.rb\\|-\\):\\([0-9]+\\): \\(.*\\)$"
|
||||||
|
nil t)
|
||||||
|
for msg = (match-string 2)
|
||||||
|
for (beg . end) = (flymake-diag-region
|
||||||
|
source
|
||||||
|
(string-to-number (match-string 1)))
|
||||||
|
for type = (if (string-match "^warning" msg)
|
||||||
|
:warning
|
||||||
|
:error)
|
||||||
|
collect (flymake-make-diagnostic source
|
||||||
|
beg
|
||||||
|
end
|
||||||
|
type
|
||||||
|
msg)
|
||||||
|
into diags
|
||||||
|
finally (funcall report-fn diags)))))
|
||||||
|
|
||||||
|
(defun ruby-flymake--helper (process-name command parser-fn)
|
||||||
(when (process-live-p ruby--flymake-proc)
|
(when (process-live-p ruby--flymake-proc)
|
||||||
(kill-process ruby--flymake-proc))
|
(kill-process ruby--flymake-proc))
|
||||||
|
|
||||||
|
@ -2270,34 +2295,16 @@ See `font-lock-syntax-table'.")
|
||||||
(setq
|
(setq
|
||||||
ruby--flymake-proc
|
ruby--flymake-proc
|
||||||
(make-process
|
(make-process
|
||||||
:name "ruby-flymake-simple" :noquery t :connection-type 'pipe
|
:name process-name :noquery t :connection-type 'pipe
|
||||||
:buffer (generate-new-buffer " *ruby-flymake*")
|
:buffer (generate-new-buffer (format " *%s*" process-name))
|
||||||
:command '("ruby" "-w" "-c")
|
:command command
|
||||||
:sentinel
|
:sentinel
|
||||||
(lambda (proc _event)
|
(lambda (proc _event)
|
||||||
(when (eq 'exit (process-status proc))
|
(when (eq 'exit (process-status proc))
|
||||||
(unwind-protect
|
(unwind-protect
|
||||||
(if (with-current-buffer source (eq proc ruby--flymake-proc))
|
(if (with-current-buffer source (eq proc ruby--flymake-proc))
|
||||||
(with-current-buffer (process-buffer proc)
|
(with-current-buffer (process-buffer proc)
|
||||||
(goto-char (point-min))
|
(funcall parser-fn proc source))
|
||||||
(cl-loop
|
|
||||||
while (search-forward-regexp
|
|
||||||
"^\\(?:.*.rb\\|-\\):\\([0-9]+\\): \\(.*\\)$"
|
|
||||||
nil t)
|
|
||||||
for msg = (match-string 2)
|
|
||||||
for (beg . end) = (flymake-diag-region
|
|
||||||
source
|
|
||||||
(string-to-number (match-string 1)))
|
|
||||||
for type = (if (string-match "^warning" msg)
|
|
||||||
:warning
|
|
||||||
:error)
|
|
||||||
collect (flymake-make-diagnostic source
|
|
||||||
beg
|
|
||||||
end
|
|
||||||
type
|
|
||||||
msg)
|
|
||||||
into diags
|
|
||||||
finally (funcall report-fn diags)))
|
|
||||||
(flymake-log :debug "Canceling obsolete check %s"
|
(flymake-log :debug "Canceling obsolete check %s"
|
||||||
proc))
|
proc))
|
||||||
(kill-buffer (process-buffer proc)))))))
|
(kill-buffer (process-buffer proc)))))))
|
||||||
|
@ -2311,8 +2318,6 @@ Only takes effect if Rubocop is installed."
|
||||||
:group 'ruby
|
:group 'ruby
|
||||||
:safe 'booleanp)
|
:safe 'booleanp)
|
||||||
|
|
||||||
(defvar-local ruby--rubocop-flymake-proc nil)
|
|
||||||
|
|
||||||
(defcustom ruby-rubocop-config ".rubocop.yml"
|
(defcustom ruby-rubocop-config ".rubocop.yml"
|
||||||
"Configuration file for `ruby-flymake-rubocop'."
|
"Configuration file for `ruby-flymake-rubocop'."
|
||||||
:type 'string
|
:type 'string
|
||||||
|
@ -2324,11 +2329,7 @@ Only takes effect if Rubocop is installed."
|
||||||
(unless (executable-find "rubocop")
|
(unless (executable-find "rubocop")
|
||||||
(error "Cannot find the rubocop executable"))
|
(error "Cannot find the rubocop executable"))
|
||||||
|
|
||||||
(when (process-live-p ruby--rubocop-flymake-proc)
|
(let ((command (list "rubocop" "--stdin" buffer-file-name "--format" "emacs"
|
||||||
(kill-process ruby--rubocop-flymake-proc))
|
|
||||||
|
|
||||||
(let ((source (current-buffer))
|
|
||||||
(command (list "rubocop" "--stdin" buffer-file-name "--format" "emacs"
|
|
||||||
"--cache" "false" ; Work around a bug in old version.
|
"--cache" "false" ; Work around a bug in old version.
|
||||||
"--display-cop-names"))
|
"--display-cop-names"))
|
||||||
config-dir)
|
config-dir)
|
||||||
|
@ -2339,54 +2340,40 @@ Only takes effect if Rubocop is installed."
|
||||||
(setq command (append command (list "--config"
|
(setq command (append command (list "--config"
|
||||||
(expand-file-name ruby-rubocop-config
|
(expand-file-name ruby-rubocop-config
|
||||||
config-dir)))))
|
config-dir)))))
|
||||||
(save-restriction
|
|
||||||
(widen)
|
(ruby-flymake--helper
|
||||||
(setq
|
"rubocop-flymake"
|
||||||
ruby--rubocop-flymake-proc
|
command
|
||||||
(make-process
|
(lambda (proc source)
|
||||||
:name "rubocop-flymake" :noquery t :connection-type 'pipe
|
;; Finding the executable is no guarantee of
|
||||||
:buffer (generate-new-buffer " *rubocop-flymake*")
|
;; rubocop working, especially in the presence
|
||||||
:command command
|
;; of rbenv shims (which cross ruby versions).
|
||||||
:sentinel
|
(unless (zerop (process-exit-status proc))
|
||||||
(lambda (proc _event)
|
(flymake-log :warning "Rubocop returned non-zero status: %s"
|
||||||
(when (eq 'exit (process-status proc))
|
(buffer-string)))
|
||||||
(unwind-protect
|
(goto-char (point-min))
|
||||||
(if (with-current-buffer source (eq proc ruby--rubocop-flymake-proc))
|
(cl-loop
|
||||||
(with-current-buffer (process-buffer proc)
|
while (search-forward-regexp
|
||||||
;; Finding the executable is no guarantee of
|
"^\\(?:.*.rb\\|-\\):\\([0-9]+\\):\\([0-9]+\\): \\(.*\\)$"
|
||||||
;; rubocop working, especially in the presence
|
nil t)
|
||||||
;; of rbenv shims (which cross ruby versions).
|
for msg = (match-string 3)
|
||||||
(unless (zerop (process-exit-status proc))
|
for (beg . end) = (flymake-diag-region
|
||||||
(flymake-log :warning "Rubocop returned non-zero status: %s"
|
source
|
||||||
(buffer-string)))
|
(string-to-number (match-string 1))
|
||||||
(goto-char (point-min))
|
(string-to-number (match-string 2)))
|
||||||
(cl-loop
|
for type = (cond
|
||||||
while (search-forward-regexp
|
((string-match "^[EF]: " msg)
|
||||||
"^\\(?:.*.rb\\|-\\):\\([0-9]+\\):\\([0-9]<<+\\): \\(.*\\)$"
|
:error)
|
||||||
nil t)
|
((string-match "^W: " msg)
|
||||||
for msg = (match-string 3)
|
:warning)
|
||||||
for (beg . end) = (flymake-diag-region
|
(t :note))
|
||||||
source
|
collect (flymake-make-diagnostic source
|
||||||
(string-to-number (match-string 1))
|
beg
|
||||||
(string-to-number (match-string 2)))
|
end
|
||||||
for type = (cond
|
type
|
||||||
((string-match "^[EF]: " msg)
|
(substring msg 3))
|
||||||
:error)
|
into diags
|
||||||
((string-match "^W: " msg)
|
finally (funcall report-fn diags)))))))
|
||||||
:warning)
|
|
||||||
(t :note))
|
|
||||||
collect (flymake-make-diagnostic source
|
|
||||||
beg
|
|
||||||
end
|
|
||||||
type
|
|
||||||
(substring msg 3))
|
|
||||||
into diags
|
|
||||||
finally (funcall report-fn diags)))
|
|
||||||
(flymake-log :debug "Canceling obsolete check %s"
|
|
||||||
proc))
|
|
||||||
(kill-buffer (process-buffer proc)))))))
|
|
||||||
(process-send-region ruby--rubocop-flymake-proc (point-min) (point-max))
|
|
||||||
(process-send-eof ruby--rubocop-flymake-proc)))))
|
|
||||||
|
|
||||||
(defun ruby-flymake-auto (report-fn &rest args)
|
(defun ruby-flymake-auto (report-fn &rest args)
|
||||||
(apply
|
(apply
|
||||||
|
|
Loading…
Add table
Reference in a new issue