From fa92f0c44715fc49e19de001ee8b217ce847d954 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Fri, 6 Oct 2017 17:51:40 +0100 Subject: [PATCH] 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. --- lisp/progmodes/elisp-mode.el | 120 ++++++++++++++++------------------- 1 file changed, 54 insertions(+), 66 deletions(-) diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index 3690f673832..99a4841e318 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -1599,8 +1599,11 @@ ARGLIST is either a string, or a list of strings or symbols." (defvar checkdoc-autofix-flag) (defvar checkdoc-generate-compile-warnings-flag) (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* ((checkdoc-create-error-function (lambda (text start end &optional unfixable) @@ -1608,63 +1611,52 @@ ARGLIST is either a string, or a list of strings or symbols." nil)) (checkdoc-autofix-flag nil) (checkdoc-generate-compile-warnings-flag nil) - (buf (generate-new-buffer " *checkdoc-temp*")) - (checkdoc-diagnostic-buffer buf)) + (checkdoc-diagnostic-buffer + (generate-new-buffer " *checkdoc-temp*"))) (unwind-protect (save-excursion (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)) -;;;###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 - origin-buffer - output-buffer - temp-file) - (unwind-protect - (with-current-buffer - origin-buffer - (save-excursion - (save-restriction - (widen) - (funcall - report-fn - (cl-loop with data = - (with-current-buffer output-buffer - (goto-char (point-min)) - (search-forward ":elisp-flymake-output-start") - (read (point-marker))) - for (string pos _fill level) in data - do (goto-char pos) - for beg = (if (< (point) (point-max)) - (point) - (line-beginning-position)) - for end = (min - (line-end-position) - (or (cdr - (bounds-of-thing-at-point 'sexp)) - (point-max))) - collect (flymake-make-diagnostic - (current-buffer) - (if (= beg end) (1- beg) beg) - end - level - string)))))) - (kill-buffer output-buffer) - (ignore-errors (delete-file temp-file)))) + source-buffer + output-buffer) + (with-current-buffer + source-buffer + (save-excursion + (save-restriction + (widen) + (funcall + report-fn + (cl-loop with data = + (with-current-buffer output-buffer + (goto-char (point-min)) + (search-forward ":elisp-flymake-output-start") + (read (point-marker))) + for (string pos _fill level) in data + do (goto-char pos) + for beg = (if (< (point) (point-max)) + (point) + (line-beginning-position)) + for end = (min + (line-end-position) + (or (cdr + (bounds-of-thing-at-point 'sexp)) + (point-max))) + collect (flymake-make-diagnostic + (current-buffer) + (if (= beg end) (1- beg) beg) + end + level + string))))))) (defvar-local elisp-flymake--byte-compile-process nil "Buffer-local process started for byte-compiling the buffer.") @@ -1674,16 +1666,11 @@ Calls REPORT-FN directly." "A Flymake backend for elisp byte compilation. Spawn an Emacs process that byte-compiles a file representing the 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 - (process-put elisp-flymake--byte-compile-process 'elisp-flymake--obsolete t) (when (process-live-p elisp-flymake--byte-compile-process) (kill-process elisp-flymake--byte-compile-process))) (let ((temp-file (make-temp-file "elisp-flymake-byte-compile")) - (origin-buffer (current-buffer))) + (source-buffer (current-buffer))) (save-restriction (widen) (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 :sentinel (lambda (proc _event) - (unless (process-live-p proc) + (when (eq (process-status proc) 'exit) (unwind-protect (cond + ((not (eq proc elisp-flymake--byte-compile-process)) + (flymake-log :warning "byte-compile process %s obsolete" proc)) ((zerop (process-exit-status proc)) (elisp-flymake--byte-compile-done report-fn - origin-buffer - output-buffer - temp-file)) - ((process-get proc 'elisp-flymake--obsolete) - (flymake-log :warning "byte-compile process %s obsolete" proc)) + source-buffer + output-buffer)) (t (funcall report-fn :panic :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 :noquery t))) -- 2.39.5