~manuel-uberti/flymake-proselint

3a475ee7fe187d1c4744dc9826b1adbd669b69c4 — Manuel Uberti 1 year, 10 months ago a22ed57
Avoid selecting dead buffers
1 files changed, 30 insertions(+), 28 deletions(-)

M flymake-proselint.el
M flymake-proselint.el => flymake-proselint.el +30 -28
@@ 287,34 287,36 @@ Flymake diagnostic objects."
  "Sentinel on PROC for handling Proselint response.
A successfully parsed message is passed onto the function
`flymake-proselint-sentinel-1' for further handling."
  (pcase (process-status proc)
    ('exit
     (let ((report-fn (process-get proc 'report-fn))
           (source (process-get proc 'source)))
       (unwind-protect
           (with-current-buffer (process-buffer proc)
             (goto-char (point-min))
             (cond
              ((with-current-buffer source
                 (not (eq proc flymake-proselint--flymake-proc)))
               (flymake-log :warning "Canceling obsolete check %s" proc))
              ((= (point-max) (point-min))
               (flymake-log :debug "Empty response"))
              ((condition-case err
                   (let ((response (json-parse-buffer :object-type 'plist
                                                      :array-type 'list)))
                     (if (string= (plist-get response :status) "success")
                         (thread-last
                           (plist-get response :data)
                           (flymake-proselint-sentinel-1 source)
                           (funcall report-fn))
                       (flymake-log :error "Check failed")))
                 (json-parse-error
                  (flymake-log :error "Invalid response: %S" err))))))
         (with-current-buffer source
           (setq flymake-proselint--flymake-proc nil))
         (kill-buffer (process-buffer proc)))))
    ('signal (kill-buffer (process-buffer proc)))))
  (let ((buffer (process-buffer proc)))
    (when (buffer-live-p buffer)
      (pcase (process-status proc)
        ('exit
         (let ((report-fn (process-get proc 'report-fn))
               (source (process-get proc 'source)))
           (unwind-protect
               (with-current-buffer buffer
                 (goto-char (point-min))
                 (cond
                  ((with-current-buffer source
                     (not (eq proc flymake-proselint--flymake-proc)))
                   (flymake-log :warning "Canceling obsolete check %s" proc))
                  ((= (point-max) (point-min))
                   (flymake-log :debug "Empty response"))
                  ((condition-case err
                       (let ((response (json-parse-buffer :object-type 'plist
                                                          :array-type 'list)))
                         (if (string= (plist-get response :status) "success")
                             (thread-last
                               (plist-get response :data)
                               (flymake-proselint-sentinel-1 source)
                               (funcall report-fn))
                           (flymake-log :error "Check failed")))
                     (json-parse-error
                      (flymake-log :error "Invalid response: %S" err))))))
             (with-current-buffer source
               (setq flymake-proselint--flymake-proc nil))
             (kill-buffer buffer))))
        ('signal (kill-buffer buffer))))))

(defun flymake-proselint-backend (report-fn &rest _args)
  "Flymake backend for Proselint.