From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ihor Radchenko Newsgroups: gmane.emacs.help Subject: Setting buffer and point from inside thread Date: Sat, 10 Apr 2021 15:05:31 +0800 Message-ID: <87wntay5z8.fsf@localhost> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34628"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Apr 10 09:02:08 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lV7dA-0008wD-6X for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 10 Apr 2021 09:02:08 +0200 Original-Received: from localhost ([::1]:36538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lV7d9-0005eE-86 for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 10 Apr 2021 03:02:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52530) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lV7cN-0005d9-Pj for help-gnu-emacs@gnu.org; Sat, 10 Apr 2021 03:01:20 -0400 Original-Received: from mail-lj1-x236.google.com ([2a00:1450:4864:20::236]:42616) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lV7cK-0004xd-Be for help-gnu-emacs@gnu.org; Sat, 10 Apr 2021 03:01:19 -0400 Original-Received: by mail-lj1-x236.google.com with SMTP id l22so1667963ljc.9 for ; Sat, 10 Apr 2021 00:01:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=nBo4ma/HJ3C/DDxb/kxFZtFKkp1NrkoPMqratkYogok=; b=Und11gvd9WzIAm2pg+S4R6OtzLVg6EI4xL1oAjNyNOE8jP/+kFZsPpEIduZ2YfUorJ q9Cm8Bjqm5Jfw9wt10Sg9+NdCwsowqzS+D+sHG9jARbwkML+F05k7eP4CZgtrVSPZttx Q4ouTdyw8nR3z1ra1IBv3DWd50HuKS/JkxKVpVQWRE0TMx8RRhWZHg9WUmdt2nztsvea zX1r8JF+J9XmKMX1xgnXD0PRbbOBQjXu9WUvEYbTrL1Av6RQq09ok8lxASfe93AFBxQ1 OM5GtLScJ78iqqqQ19HChh511pRK12lA9nKNQba5zCp/rm0fU8KQL8M1DksaVUn6RqvY OE5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=nBo4ma/HJ3C/DDxb/kxFZtFKkp1NrkoPMqratkYogok=; b=cSbc0jzjAF9Q5phK9Bj4mt0Zep8cuAftASv7XexfPk9Wlk/VUzGFyKnreuPEhR9jAL 7oM9b4HuBFezG2nNna7NabUMf/QUv6VPNZWgKRscUgJ83kdg1Yk0RseI8ujaJIjUGNob 7bzRR+lBMEUWaJzmV4ZBs/Aw5ZzlkS9NI/aV8TaLoshqxhs3+iugajfAULxqTKAAlJKZ kyOgvnA5s5ns1KYCcCp2DsZKUKwxGCYvz9oMnvd3JuCVBW+Ibq1omwOqkgUDQaijuzNc 09WjtL5MbHVFbQiydSz+WhIbBUa9NpmGchy1npD2rK3V13LKsSHZXxFa8DIYamSLUNDu HKIg== X-Gm-Message-State: AOAM532Te+NDspEDPMC0KvqGRfl7l5pbavB28JueKx30QMOxPyyMnmaR F4xY8WprPJBgalZHFIUIMF21SbnXcHXxSg== X-Google-Smtp-Source: ABdhPJxbx9vu9TWYeHatWHRn0cRi9zY71hYCQUeuWiqH2IlOn2n+6Cx0jonhve9iELTNG/FyTF/DGg== X-Received: by 2002:a2e:b544:: with SMTP id a4mr11413420ljn.504.1618038071197; Sat, 10 Apr 2021 00:01:11 -0700 (PDT) Original-Received: from localhost ([91.210.107.197]) by smtp.gmail.com with ESMTPSA id b15sm766260lfp.306.2021.04.10.00.01.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Apr 2021 00:01:10 -0700 (PDT) Received-SPF: pass client-ip=2a00:1450:4864:20::236; envelope-from=yantar92@gmail.com; helo=mail-lj1-x236.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:128920 Archived-At: 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