Skip to content

Commit e1a93c7

Browse files
arichiardibbatsov
authored andcommitted
Add lock around REPL type detection
The patch solves, maybe not in the best way, a couple of problems detected when emacs triggers multiple process output filters. See http://blog.jorgenschaefer.de/2014/05/race-conditions-in-emacs-process-filter.html
1 parent 7441d3b commit e1a93c7

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

inf-clojure.el

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,23 @@ often connecting to a remote REPL process."
195195
Its root binding is nil and it can be further customized using
196196
either `setq-local` or an entry in `.dir-locals.el`." )
197197

198-
(defun inf-clojure--detect-type (proc)
198+
(defvar inf-clojure--repl-type-lock nil
199+
"Global lock for protecting against proc filter race conditions.
200+
See http://blog.jorgenschaefer.de/2014/05/race-conditions-in-emacs-process-filter.html")
201+
202+
(defun inf-clojure--detect-repl-type (proc)
199203
"Identifies the current REPL type for PROC."
200-
(cond
201-
((inf-clojure--lumo-p proc) 'lumo)
202-
(t 'clojure)))
204+
(when (not inf-clojure--repl-type-lock)
205+
(let ((inf-clojure--repl-type-lock t))
206+
(cond
207+
((inf-clojure--lumo-p proc) 'lumo)
208+
(t 'clojure)))))
203209

204210
(defun inf-clojure--set-repl-type (proc)
205211
"Set the REPL type if has not already been set.
206212
It requires a REPL PROC for inspecting the correct type."
207213
(if (not inf-clojure-repl-type)
208-
(setq inf-clojure-repl-type (inf-clojure--detect-type proc))
214+
(setq inf-clojure-repl-type (inf-clojure--detect-repl-type proc))
209215
inf-clojure-repl-type))
210216

211217
(defun inf-clojure--send-string (proc string)

0 commit comments

Comments
 (0)