all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] Make command org-babel-detangle work interactively
@ 2024-01-19 12:43 gerard.vermeulen
  2024-01-19 15:20 ` Ihor Radchenko
  0 siblings, 1 reply; 6+ messages in thread
From: gerard.vermeulen @ 2024-01-19 12:43 UTC (permalink / raw)
  To: Emacs orgmode

[-- Attachment #1: Type: text/plain, Size: 431 bytes --]

Hi,

org-babel-detangle is an interactive command but
M-x org-babel-detangle always replies "Detangled 0 code blocks"
This patch makes org-babel-detangle prompt for a source code file.

Obviously, I got bitten by this.

The patch contains
(user-error "Source code file does %S not exist" source-code-file)
so it may break code that uses org-babel-detangle in a loop.

I prefer an user-error, but others may not.

Regards -- Gerard

[-- Attachment #2: 0001-Make-command-org-babel-detangle-work-interactively.patch --]
[-- Type: application/octet-stream, Size: 2877 bytes --]

From 7549165451b1ecb1b7d2ad7a9718d1aa98aa28fe Mon Sep 17 00:00:00 2001
From: Gerard Vermeulen <gerard.vermeulen@posteo.net>
Date: Fri, 19 Jan 2024 13:09:54 +0100
Subject: [PATCH] Make command org-babel-detangle work interactively

org-babel-detangle: prompt for a file name when none is given

* lisp/ob-tangle.el (org-babel-detangle): Raise a user-error when the
source code file does not exist after prompting for a file name when
none is given.
---
 lisp/ob-tangle.el | 41 +++++++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 18 deletions(-)

diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
index 933a3eba1..726f733bd 100644
--- a/lisp/ob-tangle.el
+++ b/lisp/ob-tangle.el
@@ -618,27 +618,32 @@ by `org-babel-get-src-block-info'."
 
 ;; de-tangling functions
 (defun org-babel-detangle (&optional source-code-file)
-  "Propagate changes in source file back original to Org file.
+  "Propagate changes in SOURCE-CODE-FILE back to original Org file.
 This requires that code blocks were tangled with link comments
 which enable the original code blocks to be found."
   (interactive)
-  (save-excursion
-    (when source-code-file (find-file source-code-file))
-    (goto-char (point-min))
-    (let ((counter 0) new-body end)
-      (while (re-search-forward org-link-bracket-re nil t)
-        (if (and (match-string 2)
-		 (re-search-forward
-		  (concat " " (regexp-quote (match-string 2)) " ends here") nil t))
-	    (progn (setq end (match-end 0))
-		   (forward-line -1)
-		   (save-excursion
-		     (when (setq new-body (org-babel-tangle-jump-to-org))
-		       (org-babel-update-block-body new-body)))
-		   (setq counter (+ 1 counter)))
-	  (setq end (point)))
-        (goto-char end))
-      (prog1 counter (message "Detangled %d code blocks" counter)))))
+  (unless source-code-file
+    (setq source-code-file (read-file-name "Source code file: ")))
+  (if (file-exists-p source-code-file)
+      (save-excursion
+        (find-file source-code-file)
+        (goto-char (point-min))
+        (let ((counter 0) new-body end)
+          (while (re-search-forward org-link-bracket-re nil t)
+            (if (and (match-string 2)
+		     (re-search-forward
+		      (concat " " (regexp-quote (match-string 2)) " ends here")
+                      nil t))
+	        (progn (setq end (match-end 0))
+		       (forward-line -1)
+		       (save-excursion
+		         (when (setq new-body (org-babel-tangle-jump-to-org))
+		           (org-babel-update-block-body new-body)))
+		       (setq counter (+ 1 counter)))
+	      (setq end (point)))
+            (goto-char end))
+          (prog1 counter (message "Detangled %d code blocks" counter))))
+    (user-error "Source code file does %S not exist" source-code-file)))
 
 (defun org-babel-tangle-jump-to-org ()
   "Jump from a tangled code file to the related Org mode file."
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Make command org-babel-detangle work interactively
  2024-01-19 12:43 [PATCH] Make command org-babel-detangle work interactively gerard.vermeulen
@ 2024-01-19 15:20 ` Ihor Radchenko
  2024-01-19 23:14   ` gerard.vermeulen
  0 siblings, 1 reply; 6+ messages in thread
From: Ihor Radchenko @ 2024-01-19 15:20 UTC (permalink / raw)
  To: gerard.vermeulen; +Cc: Emacs orgmode

gerard.vermeulen@posteo.net writes:

> org-babel-detangle is an interactive command but
> M-x org-babel-detangle always replies "Detangled 0 code blocks"
> This patch makes org-babel-detangle prompt for a source code file.
>
> Obviously, I got bitten by this.

I suspect that you may have some misunderstanding about how
`org-babel-detangle' works. Its docstring says:

   Propagate changes in source file back original to Org file.

So, it is expected to run from the tangled file; not from the Org file.

-- 
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] 6+ messages in thread

* Re: [PATCH] Make command org-babel-detangle work interactively
  2024-01-19 15:20 ` Ihor Radchenko
@ 2024-01-19 23:14   ` gerard.vermeulen
  2024-01-20 12:18     ` Ihor Radchenko
  0 siblings, 1 reply; 6+ messages in thread
From: gerard.vermeulen @ 2024-01-19 23:14 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Emacs orgmode



On 19.01.2024 16:20, Ihor Radchenko wrote:
> gerard.vermeulen@posteo.net writes:
> 
>> org-babel-detangle is an interactive command but
>> M-x org-babel-detangle always replies "Detangled 0 code blocks"
>> This patch makes org-babel-detangle prompt for a source code file.
>> 
>> Obviously, I got bitten by this.
> 
> I suspect that you may have some misunderstanding about how
> `org-babel-detangle' works. Its docstring says:
> 
>    Propagate changes in source file back original to Org file.
> 
> So, it is expected to run from the tangled file; not from the Org file.

Yes, I misunderstood this and I see that my patch breaks this.

I think there is a typo in the docstring: "original to" must become "to 
original"
so that it ends with "back to original Org file".




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Make command org-babel-detangle work interactively
  2024-01-19 23:14   ` gerard.vermeulen
@ 2024-01-20 12:18     ` Ihor Radchenko
  2024-01-20 14:10       ` gerard.vermeulen
  0 siblings, 1 reply; 6+ messages in thread
From: Ihor Radchenko @ 2024-01-20 12:18 UTC (permalink / raw)
  To: gerard.vermeulen; +Cc: Emacs orgmode

[-- Attachment #1: Type: text/plain, Size: 539 bytes --]

gerard.vermeulen@posteo.net writes:

>> I suspect that you may have some misunderstanding about how
>> `org-babel-detangle' works. Its docstring says:
>> 
>>    Propagate changes in source file back original to Org file.
>> 
>> So, it is expected to run from the tangled file; not from the Org file.
>
> Yes, I misunderstood this and I see that my patch breaks this.
>
> I think there is a typo in the docstring: "original to" must become "to 
> original"
> so that it ends with "back to original Org file".

How about the attached patch?

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-ob-tangle.el-org-babel-detangle-Improve-docstri.patch --]
[-- Type: text/x-patch, Size: 1183 bytes --]

From 65c8ac3bb1a148106b5673d247ecaaddad291704 Mon Sep 17 00:00:00 2001
Message-ID: <65c8ac3bb1a148106b5673d247ecaaddad291704.1705753074.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Sat, 20 Jan 2024 13:17:43 +0100
Subject: [PATCH] lisp/ob-tangle.el (org-babel-detangle): Improve docstring

---
 lisp/ob-tangle.el | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
index 933a3eba1..f9953ebed 100644
--- a/lisp/ob-tangle.el
+++ b/lisp/ob-tangle.el
@@ -618,9 +618,12 @@ (defun org-babel-tangle-comment-links (&optional info)
 
 ;; de-tangling functions
 (defun org-babel-detangle (&optional source-code-file)
-  "Propagate changes in source file back original to Org file.
+  "Propagate changes from current file back to the original Org file.
 This requires that code blocks were tangled with link comments
-which enable the original code blocks to be found."
+which enable the original code blocks to be found.
+
+SOURCE-CODE-FILE is the file path to be used instead of current
+buffer."
   (interactive)
   (save-excursion
     (when source-code-file (find-file source-code-file))
-- 
2.43.0


[-- Attachment #3: Type: text/plain, Size: 224 bytes --]


-- 
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 related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Make command org-babel-detangle work interactively
  2024-01-20 12:18     ` Ihor Radchenko
@ 2024-01-20 14:10       ` gerard.vermeulen
  2024-01-20 18:36         ` Ihor Radchenko
  0 siblings, 1 reply; 6+ messages in thread
From: gerard.vermeulen @ 2024-01-20 14:10 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Emacs orgmode

[-- Attachment #1: Type: text/plain, Size: 754 bytes --]



On 20.01.2024 13:18, Ihor Radchenko wrote:
> gerard.vermeulen@posteo.net writes:
> 
>>> I suspect that you may have some misunderstanding about how
>>> `org-babel-detangle' works. Its docstring says:
>>> 
>>>    Propagate changes in source file back original to Org file.
>>> 
>>> So, it is expected to run from the tangled file; not from the Org 
>>> file.
>> 
>> Yes, I misunderstood this and I see that my patch breaks this.
>> 
>> I think there is a typo in the docstring: "original to" must become 
>> "to
>> original"
>> so that it ends with "back to original Org file".
> 
> How about the attached patch?

I have attached a modification of your patch.  I think it is clearer 
with
the risk of being too verbose, but the docstring width  is < 80.

[-- Attachment #2: 0001-lisp-ob-tangle.el-org-babel-detangle-Improve-docstri.patch --]
[-- Type: application/octet-stream, Size: 1085 bytes --]

From 2a1b82d6cb97042edbd4ebc6bc07155f50ac8505 Mon Sep 17 00:00:00 2001
From: Ihor Radchenko <yantar92@posteo.net>
Date: Sat, 20 Jan 2024 13:17:43 +0100
Subject: [PATCH] lisp/ob-tangle.el (org-babel-detangle): Improve docstring

---
 lisp/ob-tangle.el | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
index 933a3eba1..eea1fca2c 100644
--- a/lisp/ob-tangle.el
+++ b/lisp/ob-tangle.el
@@ -618,9 +618,11 @@ by `org-babel-get-src-block-info'."
 
 ;; de-tangling functions
 (defun org-babel-detangle (&optional source-code-file)
-  "Propagate changes in source file back original to Org file.
+  "Propagate changes from current source buffer back to the original Org file.
 This requires that code blocks were tangled with link comments
-which enable the original code blocks to be found."
+which enable the original code blocks to be found.
+
+SOURCE-CODE-FILE is a file path that can be used instead of current buffer."
   (interactive)
   (save-excursion
     (when source-code-file (find-file source-code-file))
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Make command org-babel-detangle work interactively
  2024-01-20 14:10       ` gerard.vermeulen
@ 2024-01-20 18:36         ` Ihor Radchenko
  0 siblings, 0 replies; 6+ messages in thread
From: Ihor Radchenko @ 2024-01-20 18:36 UTC (permalink / raw)
  To: gerard.vermeulen; +Cc: Emacs orgmode

gerard.vermeulen@posteo.net writes:

>> How about the attached patch?
>
> I have attached a modification of your patch.  I think it is clearer 
> with
> the risk of being too verbose, but the docstring width  is < 80.

Thanks!
Applied, onto main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=037e3b3eb

-- 
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] 6+ messages in thread

end of thread, other threads:[~2024-01-20 18:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-19 12:43 [PATCH] Make command org-babel-detangle work interactively gerard.vermeulen
2024-01-19 15:20 ` Ihor Radchenko
2024-01-19 23:14   ` gerard.vermeulen
2024-01-20 12:18     ` Ihor Radchenko
2024-01-20 14:10       ` gerard.vermeulen
2024-01-20 18:36         ` Ihor Radchenko

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.