* Setting buffer and point from inside thread
@ 2021-04-10 7:05 Ihor Radchenko
0 siblings, 0 replies; only message in thread
From: Ihor Radchenko @ 2021-04-10 7:05 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
I am trying to play with threading functionality.
In my use-case, thread function depends on point position and current
buffer. Since, user will most likely move the point around in the main
thread, I was trying to find a way to preserve current buffer and point
position for the thread. I came up with the following test code in my
*scratch*:
(make-thread
(lambda ()
(while t
(sleep-for 0.2)
(message "Buffer: %s:%s" (current-buffer) (point))
(thread-yield-safe)
)))
(defun thread-yield-safe (&rest _)
"Call `thread-yield' preserving buffer and point."
(let ((buf-- (current-buffer))
(mk-- (point-marker)))
(thread-yield)
(set-buffer buf--)
(goto-char mk--)))
In theory, buffer and point in message should not change as the thread
is running. However, after C-x C-e running the thread, the point is not
always preserved. The behaviour is actually very strange. Sometimes, the
point is preserved, sometimes not. Sometimes, when I am trying to open
new buffer it somehow becomes read-only. Sometimes, the point is moved
in the new buffer. Once, emacs even crashed.
Clearly, many things are going wrong in this code and Emacs should not
behave so strangely. Could someone knowledgeable explain if I am doing
something wrong. Or maybe it is Emacs bug?
Best,
Ihor
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-04-10 7:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-10 7:05 Setting buffer and point from inside thread Ihor Radchenko
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.