Mike Kupfer <kup...@rawbw.com> writes:

> But I can still reproduce the problem, by using a slightly different
> recipe than the original one.
> ...
> #rm -rf ~/.cache/org-persist
> ...
> But, if I uncomment the 'rm' command in the test script and then try to
> reproduce the problem using the modified recipe, I cannot reproduce the
> problem.

I still have a hard time reproducing, but I think that you gave me
enough clues to understand what might be the culprit.
May you try the attached patch?

> Is there a variable that I can use to disable the org-persist stuff?  A
> quick search using 'M-x apropos' didn't show anything promising.

You probably want `org-element-cache-persistent'. org-persist itself is
just a caching library. It cannot be disabled completely.

>From 3ff6eef7c8d699811642755bce8128b5567c33c2 Mon Sep 17 00:00:00 2001
Message-ID: <3ff6eef7c8d699811642755bce8128b5567c33c2.1744529029.git.yanta...@posteo.net>
From: Ihor Radchenko <yanta...@posteo.net>
Date: Sun, 13 Apr 2025 09:18:25 +0200
Subject: [PATCH] org-ctrl-c-ctrl-c: Avoid modifying parser cache by side
 effect

* lisp/org.el (org-ctrl-c-ctrl-c): When modifying list, avoid
modifying cache by side effect.  If writing fails (e.g. read-only
buffer), the modified structure in cache will desync with actual
buffer contents.

Reported-by: Mike Kupfer <kup...@rawbw.com>
Link: https://orgmode.org/list/120667.1742955...@alto.camomileplus.org
---
 lisp/org.el | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lisp/org.el b/lisp/org.el
index e37ed49784..be07e11507 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -17917,6 +17917,8 @@ (defun org-ctrl-c-ctrl-c (&optional arg)
 	     (org-toggle-radio-button arg)
 	   (let* ((box (org-element-property :checkbox context))
 		  (struct (org-element-property :structure context))
+                  ;; Avoid modifying cached structure by side effect.
+                  (struct (copy-tree struct))
 		  (old-struct (copy-tree struct))
 		  (parents (org-list-parents-alist struct))
 		  (prevs (org-list-prevs-alist struct))
@@ -17960,6 +17962,8 @@ (defun org-ctrl-c-ctrl-c (&optional arg)
 	     (org-toggle-radio-button arg)
 	   (let* ((begin (org-element-contents-begin context))
 		  (struct (org-element-property :structure context))
+                  ;; Avoid modifying cached structure by side effect.
+                  (struct (copy-tree struct))
 		  (old-struct (copy-tree struct))
 		  (first-box (save-excursion
 			       (goto-char begin)
-- 
2.47.1

-- 
Ihor Radchenko // yantar92,
Org mode maintainer,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

Reply via email to