diff --git a/src/minibuf.c b/src/minibuf.c index abc4866380..b25565d051 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -49,6 +49,10 @@ static Lisp_Object minibuf_save_list; EMACS_INT minibuf_level; +/* A mutex to lock reading from the minibuffer. */ + +Lisp_Object minibuf_mutex; + /* Fread_minibuffer leaves the input here as a string. */ Lisp_Object last_minibuf_string; @@ -489,6 +493,7 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt, record_unwind_protect_void (read_minibuf_unwind); minibuf_level++; + Fmutex_lock (minibuf_mutex); /* We are exiting the minibuffer one way or the other, so run the hook. It should be run before unwinding the minibuf settings. Do it separately from read_minibuf_unwind because we need to make sure that @@ -778,6 +783,7 @@ read_minibuf_unwind (void) /* If this was a recursive minibuffer, tie the minibuffer window back to the outer level minibuffer buffer. */ + Fmutex_unlock (minibuf_mutex); minibuf_level--; window = minibuf_window; @@ -1877,6 +1883,10 @@ void syms_of_minibuf (void) { minibuf_level = 0; + + minibuf_mutex = Fmake_mutex (Qnil); + staticpro (&minibuf_mutex); + minibuf_prompt = Qnil; staticpro (&minibuf_prompt);