Ihor Radchenko <yanta...@posteo.net> writes:

> Also, may I know if you have an FSF copyright assignment? If not, you
> also need to add TINYCHANGE to the commit message - see
> https://orgmode.org/worg/org-contribute.html#first-patch

Yes I have assigned copyright to the FSF already.

> May you please submit a patch against Org mode git repository -
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git, as described at
> https://orgmode.org/worg/org-contribute.html ?
> Please quote `rename-file' and `copy-file' like I do - it is our commit
> message convention (https://orgmode.org/worg/org-contribute.html#orgd7441de)
>
>> -  (mapc (lambda (el) (copy-file el pub-dir t)) (org-babel-tangle-file 
>> filename)))
>> +  (mapc (lambda (el) (rename-file el pub-dir t))
>> +        (org-babel-tangle-file filename)))
>
> I think that it would be nice to add a brief comment why `rename-file'
> to the code as well.  `copy-file' looks innocent there from a first
> glance.

Fixed in attached patch.

>From 9cc194dcb9bf6825d68aac3118f18ae96b8642a5 Mon Sep 17 00:00:00 2001
From: Antero Mejr <ant...@mailbox.org>
Date: Fri, 17 Nov 2023 16:06:53 +0000
Subject: [PATCH] Move files when using `org-babel-tangle-publish'

Fixes `copy-file' error when publishing to the current directory.
Don't leave behind the old tangled files when publishing.

* lisp/ob-tangle.el (org-babel-tangle-publish): Use `rename-file'
instead of `copy-file' on tangled files.
---
 lisp/ob-tangle.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
index b30fd9274..e16b9e42d 100644
--- a/lisp/ob-tangle.el
+++ b/lisp/ob-tangle.el
@@ -219,7 +219,9 @@ Return list of the tangled file names."
   (unless (file-exists-p pub-dir)
     (make-directory pub-dir t))
   (setq pub-dir (file-name-as-directory pub-dir))
-  (mapc (lambda (el) (copy-file el pub-dir t)) (org-babel-tangle-file filename)))
+  ;; Rename files to avoid copying to same file when publishing to ./
+  (mapc (lambda (el) (rename-file el pub-dir t))
+        (org-babel-tangle-file filename)))
 
 ;;;###autoload
 (defun org-babel-tangle (&optional arg target-file lang-re)
-- 
2.41.0

Reply via email to