From: Ihor Radchenko <yantar92@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Setting buffer and point from inside thread
Date: Sat, 10 Apr 2021 15:05:31 +0800 [thread overview]
Message-ID: <87wntay5z8.fsf@localhost> (raw)
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
reply other threads:[~2021-04-10 7:05 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wntay5z8.fsf@localhost \
--to=yantar92@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.