Skip to content

Commit

Permalink
fix(emacs): avoid concurrent buffer reuse
Browse files Browse the repository at this point in the history
If flymake-quicklintjs is run twice concurrently, quick-lint-js output
gets corrupted. This happens because flymake-quicklintjs uses a
*flymake-quicklintjs* buffer if it already exists.

Fix this buffer reuse problem by always generating new buffers, never
reusing buffers.
  • Loading branch information
strager committed Oct 18, 2023
1 parent 1c0506d commit efeebfc
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions plugin/emacs/flymake-quicklintjs.el
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ quick-lint-js process that is passed the current buffer's contents via stdin.
REPORT-FN is Flymake's callback."
(when (process-live-p flymake-quicklintjs--proc)
(kill-process flymake-quicklintjs--proc))
(let ((src-buf (current-buffer)))
(let ((src-buf (current-buffer))
(output-buf (generate-new-buffer " *flymake-quicklintjs*")))
(setq flymake-quicklintjs--proc
(make-process
:name "flymake-quicklintjs"
:connection-type 'pipe
:noquery t
:buffer (get-buffer-create " *flymake-quicklintjs*")
:buffer output-buf
:command `(,flymake-quicklintjs-program
,@(let ((file (buffer-file-name)))
(if file
Expand All @@ -80,7 +81,7 @@ REPORT-FN is Flymake's callback."
(unwind-protect
(when (and (eq 'exit (process-status p))
(eq p flymake-quicklintjs--proc))
(with-current-buffer (process-buffer p)
(with-current-buffer output-buf
(let ((diags (flymake-quicklintjs--make-diagnostics
src-buf
(car (read-from-string
Expand All @@ -95,7 +96,7 @@ REPORT-FN is Flymake's callback."
(point-min) (progn (goto-char (point-min))
(line-end-position))))))))
(unless (process-live-p p)
(kill-buffer (process-buffer p)))))))
(kill-buffer output-buf))))))
(process-send-region flymake-quicklintjs--proc (point-min) (point-max))
(process-send-eof flymake-quicklintjs--proc)))

Expand Down

0 comments on commit efeebfc

Please sign in to comment.