Hi Eli, On 18/03/2025 02:21, Dmitry Gutov wrote: > On 17/03/2025 21:41, Eli Zaretskii wrote: >> Don't forget that >> the target thread could be the main thread. > > Good question what we should do with the main thread in this case - but > even if it receives the signal, it should be more a lot more visible to > the user than in background threads, helping fix whatever misbehavior > that caused it. > > But we'll probably use the same method that's being discussed to declare > a thread an exception, prohibiting its buffer from being killed externally. Here's a patch with implementation: * It's a property of the thread, on by default. * Set to nil for the main thread (currently can be changed from Lisp). * Not a buffer-local variable - and looking more at it, that seems not a good idea, because several threads could have the same buffer current, and some might be okay with this behavior, while others not. * A couple of questions about the finer details of the implementation, see comments in 'thread_all_before_buffer_killed'. * Two tests included. Seems to work well in my testing, and in the diff-hl scenario described in the report: step 5 kills the buffer and sends the signal which I can catch inside condition-case in diff-hl--update-safe. WDYT?