* [PATCH] Move files when using org-babel-tangle-publish
@ 2023-11-17 16:30 Antero Mejr
2023-12-08 21:36 ` Ihor Radchenko
0 siblings, 1 reply; 5+ messages in thread
From: Antero Mejr @ 2023-11-17 16:30 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 399 bytes --]
When publishing using org-babel-tangle-publish to the same directory
that contains the org files, copy-file will signal an error, since the
source and destination files refer to the same file. So use rename-file
instead.
When publishing to a different directory, this change also cleans up the
old files, which matches the behavior of the other publishing functions
like org-html-publish-to-html.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Move-files-when-using-org-babel-tangle-publish.patch --]
[-- Type: text/x-patch, Size: 1127 bytes --]
From c122cef65da00275e2f1a76cf74bbcb3838abea9 Mon Sep 17 00:00:00 2001
From: Antero Mejr <antero@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/org/ob-tangle.el (org-babel-tangle-publish): Use rename-file
instead of copy-file on tangled files.
---
lisp/org/ob-tangle.el | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lisp/org/ob-tangle.el b/lisp/org/ob-tangle.el
index a833037ca2b..9c8de839308 100644
--- a/lisp/org/ob-tangle.el
+++ b/lisp/org/ob-tangle.el
@@ -219,7 +219,8 @@ 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)))
+ (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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] Move files when using org-babel-tangle-publish
2023-11-17 16:30 [PATCH] Move files when using org-babel-tangle-publish Antero Mejr
@ 2023-12-08 21:36 ` Ihor Radchenko
2023-12-08 23:08 ` Antero Mejr
0 siblings, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2023-12-08 21:36 UTC (permalink / raw)
To: Antero Mejr; +Cc: emacs-orgmode
Antero Mejr <antero@mailbox.org> writes:
> When publishing using org-babel-tangle-publish to the same directory
> that contains the org files, copy-file will signal an error, since the
> source and destination files refer to the same file. So use rename-file
> instead.
>
> When publishing to a different directory, this change also cleans up the
> old files, which matches the behavior of the other publishing functions
> like org-html-publish-to-html.
Thanks for the patch!
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 ?
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
> Fixes copy-file error when publishing to the current directory.
> Don't leave behind the old tangled files when publishing.
>
> * lisp/org/ob-tangle.el (org-babel-tangle-publish): Use rename-file
> instead of copy-file on tangled files.
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.
--
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>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Move files when using org-babel-tangle-publish
2023-12-08 21:36 ` Ihor Radchenko
@ 2023-12-08 23:08 ` Antero Mejr
2023-12-09 10:29 ` Ihor Radchenko
0 siblings, 1 reply; 5+ messages in thread
From: Antero Mejr @ 2023-12-08 23:08 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 997 bytes --]
Ihor Radchenko <yantar92@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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Move-files-when-using-org-babel-tangle-publish.patch --]
[-- Type: text/x-patch, Size: 1179 bytes --]
From 9cc194dcb9bf6825d68aac3118f18ae96b8642a5 Mon Sep 17 00:00:00 2001
From: Antero Mejr <antero@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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] Move files when using org-babel-tangle-publish
2023-12-08 23:08 ` Antero Mejr
@ 2023-12-09 10:29 ` Ihor Radchenko
2023-12-09 17:42 ` Bastien Guerry
0 siblings, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2023-12-09 10:29 UTC (permalink / raw)
To: Antero Mejr, Bastien; +Cc: emacs-orgmode
Antero Mejr <antero@mailbox.org> writes:
> Ihor Radchenko <yantar92@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.
Bastien, may you please confirm?
>> 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.
Thanks!
Applied, onto main, adding a link to this thread in the commit message
and an extra sentence to the comment.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=478576749
--
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>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-12-09 17:43 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-17 16:30 [PATCH] Move files when using org-babel-tangle-publish Antero Mejr
2023-12-08 21:36 ` Ihor Radchenko
2023-12-08 23:08 ` Antero Mejr
2023-12-09 10:29 ` Ihor Radchenko
2023-12-09 17:42 ` Bastien Guerry
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).