Cletip Cletip <clement020...@gmail.com> writes:

> Sorry to bring up the subject again, but I didn't quite understand what the
> solution was: should I modify the function ? Is it modified in a new
> version of org-mode ?

The tentative solution is attached. May you test it?

The previous discussion was mostly about how to best approach the solution.

>From cf9db7b5a602c2c0d4970c69a95d98640cefc9a0 Mon Sep 17 00:00:00 2001
Message-ID: <cf9db7b5a602c2c0d4970c69a95d98640cefc9a0.1701694627.git.yanta...@posteo.net>
From: Ihor Radchenko <yanta...@posteo.net>
Date: Mon, 4 Dec 2023 13:55:05 +0100
Subject: [PATCH] org-babel-tangle: Do note erase the existing tangle target
 before overwriting

* lisp/ob-tangle.el (org-babel-tangle): Do not remove the existing
tangle target file, if any.  `write-region' later will overwrite it
anyway, while removing may be unexpected if the existing target is a
symlink.

Reported-by: Cletip Cletip <clement020...@gmail.com>
Link: https://list.orgmode.org/orgmode/caphku6o9nfvmafme3_ahmpjea_2qm0mjmfx6qppt8uiq94k...@mail.gmail.com/
---
 lisp/ob-tangle.el | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
index b30fd9274..b48269897 100644
--- a/lisp/ob-tangle.el
+++ b/lisp/ob-tangle.el
@@ -310,9 +310,8 @@ (defun org-babel-tangle (&optional arg target-file lang-re)
                                       (compare-buffer-substrings
                                        nil nil nil
                                        tangle-buf nil nil)))))))
-                     ;; erase previous file
-                     (when (file-exists-p file-name)
-                       (delete-file file-name))
+                     ;; We do not erase, but overwrite previous file
+                     ;; to preserve any existing symlinks.
 		     (write-region nil nil file-name)
 		     (mapc (lambda (mode) (set-file-modes file-name mode)) modes))
                    (push file-name path-collector))))))
-- 
2.42.0

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
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