Cleanup emacs-lisp-mode's use of Flymake

* lisp/progmodes/elisp-mode.el (elisp-flymake--checkdoc-1):
Delete.
(elisp-flymake-checkdoc): Incorporate old
elisp-flymake--checkdoc-1.
(elisp-flymake--byte-compile-done): Simplify.  Don't cleanup
here.
(elisp-flymake-byte-compile): Remove spurious interactive spec.
Simplify.  Cleanup on every possible exit.
This commit is contained in:
João Távora 2017-10-06 17:51:40 +01:00
parent 0d0265bf50
commit fa92f0c447

View file

@ -1599,8 +1599,11 @@ ARGLIST is either a string, or a list of strings or symbols."
(defvar checkdoc-autofix-flag) (defvar checkdoc-autofix-flag)
(defvar checkdoc-generate-compile-warnings-flag) (defvar checkdoc-generate-compile-warnings-flag)
(defvar checkdoc-diagnostic-buffer) (defvar checkdoc-diagnostic-buffer)
(defun elisp-flymake--checkdoc-1 ()
"Do actual work for `elisp-flymake-checkdoc'." ;;;###autoload
(defun elisp-flymake-checkdoc (report-fn &rest _args)
"A Flymake backend for `checkdoc'.
Calls REPORT-FN directly."
(let (collected) (let (collected)
(let* ((checkdoc-create-error-function (let* ((checkdoc-create-error-function
(lambda (text start end &optional unfixable) (lambda (text start end &optional unfixable)
@ -1608,63 +1611,52 @@ ARGLIST is either a string, or a list of strings or symbols."
nil)) nil))
(checkdoc-autofix-flag nil) (checkdoc-autofix-flag nil)
(checkdoc-generate-compile-warnings-flag nil) (checkdoc-generate-compile-warnings-flag nil)
(buf (generate-new-buffer " *checkdoc-temp*")) (checkdoc-diagnostic-buffer
(checkdoc-diagnostic-buffer buf)) (generate-new-buffer " *checkdoc-temp*")))
(unwind-protect (unwind-protect
(save-excursion (save-excursion
(checkdoc-current-buffer t)) (checkdoc-current-buffer t))
(kill-buffer buf))) (kill-buffer checkdoc-diagnostic-buffer)))
(funcall report-fn
(cl-loop for (text start end _unfixable) in
collected
collect
(flymake-make-diagnostic
(current-buffer)
start end :note text)))
collected)) collected))
;;;###autoload
(defun elisp-flymake-checkdoc (report-fn &rest _args)
"A Flymake backend for `checkdoc'.
Calls REPORT-FN directly."
(unless (derived-mode-p 'emacs-lisp-mode)
(error "Can only work on `emacs-lisp-mode' buffers"))
(funcall report-fn
(cl-loop for (text start end _unfixable) in
(elisp-flymake--checkdoc-1)
collect
(flymake-make-diagnostic
(current-buffer)
start end :note text))))
(defun elisp-flymake--byte-compile-done (report-fn (defun elisp-flymake--byte-compile-done (report-fn
origin-buffer source-buffer
output-buffer output-buffer)
temp-file) (with-current-buffer
(unwind-protect source-buffer
(with-current-buffer (save-excursion
origin-buffer (save-restriction
(save-excursion (widen)
(save-restriction (funcall
(widen) report-fn
(funcall (cl-loop with data =
report-fn (with-current-buffer output-buffer
(cl-loop with data = (goto-char (point-min))
(with-current-buffer output-buffer (search-forward ":elisp-flymake-output-start")
(goto-char (point-min)) (read (point-marker)))
(search-forward ":elisp-flymake-output-start") for (string pos _fill level) in data
(read (point-marker))) do (goto-char pos)
for (string pos _fill level) in data for beg = (if (< (point) (point-max))
do (goto-char pos) (point)
for beg = (if (< (point) (point-max)) (line-beginning-position))
(point) for end = (min
(line-beginning-position)) (line-end-position)
for end = (min (or (cdr
(line-end-position) (bounds-of-thing-at-point 'sexp))
(or (cdr (point-max)))
(bounds-of-thing-at-point 'sexp)) collect (flymake-make-diagnostic
(point-max))) (current-buffer)
collect (flymake-make-diagnostic (if (= beg end) (1- beg) beg)
(current-buffer) end
(if (= beg end) (1- beg) beg) level
end string)))))))
level
string))))))
(kill-buffer output-buffer)
(ignore-errors (delete-file temp-file))))
(defvar-local elisp-flymake--byte-compile-process nil (defvar-local elisp-flymake--byte-compile-process nil
"Buffer-local process started for byte-compiling the buffer.") "Buffer-local process started for byte-compiling the buffer.")
@ -1674,16 +1666,11 @@ Calls REPORT-FN directly."
"A Flymake backend for elisp byte compilation. "A Flymake backend for elisp byte compilation.
Spawn an Emacs process that byte-compiles a file representing the Spawn an Emacs process that byte-compiles a file representing the
current buffer state and calls REPORT-FN when done." current buffer state and calls REPORT-FN when done."
(interactive (list (lambda (stuff)
(message "aha %s" stuff))))
(unless (derived-mode-p 'emacs-lisp-mode)
(error "Can only work on `emacs-lisp-mode' buffers"))
(when elisp-flymake--byte-compile-process (when elisp-flymake--byte-compile-process
(process-put elisp-flymake--byte-compile-process 'elisp-flymake--obsolete t)
(when (process-live-p elisp-flymake--byte-compile-process) (when (process-live-p elisp-flymake--byte-compile-process)
(kill-process elisp-flymake--byte-compile-process))) (kill-process elisp-flymake--byte-compile-process)))
(let ((temp-file (make-temp-file "elisp-flymake-byte-compile")) (let ((temp-file (make-temp-file "elisp-flymake-byte-compile"))
(origin-buffer (current-buffer))) (source-buffer (current-buffer)))
(save-restriction (save-restriction
(widen) (widen)
(write-region (point-min) (point-max) temp-file nil 'nomessage)) (write-region (point-min) (point-max) temp-file nil 'nomessage))
@ -1703,21 +1690,22 @@ current buffer state and calls REPORT-FN when done."
:connection-type 'pipe :connection-type 'pipe
:sentinel :sentinel
(lambda (proc _event) (lambda (proc _event)
(unless (process-live-p proc) (when (eq (process-status proc) 'exit)
(unwind-protect (unwind-protect
(cond (cond
((not (eq proc elisp-flymake--byte-compile-process))
(flymake-log :warning "byte-compile process %s obsolete" proc))
((zerop (process-exit-status proc)) ((zerop (process-exit-status proc))
(elisp-flymake--byte-compile-done report-fn (elisp-flymake--byte-compile-done report-fn
origin-buffer source-buffer
output-buffer output-buffer))
temp-file))
((process-get proc 'elisp-flymake--obsolete)
(flymake-log :warning "byte-compile process %s obsolete" proc))
(t (t
(funcall report-fn (funcall report-fn
:panic :panic
:explanation :explanation
(format "byte-compile process %s died" proc))))))))) (format "byte-compile process %s died" proc))))
(ignore-errors (delete-file temp-file))
(kill-buffer output-buffer))))))
:stderr null-device :stderr null-device
:noquery t))) :noquery t)))