emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: Ihor Radchenko <yantar92@gmail.com>
Cc: orgmode <emacs-orgmode@gnu.org>
Subject: Re: [Patch] ob-tangle.el: New value 'ascii' for the header argument ':comments'
Date: Mon, 25 Jul 2022 17:13:48 +0000	[thread overview]
Message-ID: <87czdt3yk3.fsf@posteo.net> (raw)
In-Reply-To: <878rohuxij.fsf@localhost> (Ihor Radchenko's message of "Mon, 25 Jul 2022 21:34:12 +0800")

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

Hi, Ihor,

Here is a new fixed version of the patch, with the addition to NEWS.

Ihor Radchenko writes:

>> -			 (org-back-to-heading t) ; Sets match data
>> -			 (match-end 0))
>> +			 (re-search-backward org-heading-regexp) ; Sets match data
>> +			 (match-beginning 0))
> This will err when the source block is before the first headline in the
> document.

I've reverted the first line to (org-back-to-heading t), keeping the
(match-beginning 0), otherwise you don't get the full headline and all
property drawers would be exported. But it's strange, it doesn't give me
any error when the source block is before the first headline in the
document. Isn't that error prevented with this:

(condition-case nil
(error (point-min)))


By the way, I've noticed that it's not convenient to export numbered
headers, so I've modified org-babel-export-comment-text-as-plain-text so
that it removes header numbering. I don't know if it's ok to do it this

Best regards,

Juan Manuel

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-ob-tangle.el-The-org-value-for-comments-is-now-.patch --]
[-- Type: text/x-patch, Size: 3484 bytes --]

From b500fcb1475b0a2e8eee532f031bb5cd236560fb Mon Sep 17 00:00:00 2001
From: Juan Manuel Macias <maciaschain@posteo.net>
Date: Mon, 25 Jul 2022 18:48:45 +0200
Subject: [PATCH] lisp/ob-tangle.el: The `org' value for `:comments' is now
 plain text

* org-babel-process-comment-text:
`org-babel-export-comment-text-as-plain-text' function is added as a
new default value, which exports the raw Org text as plain text.  This
is useful for removing all org metadata from the source file's
 etc/ORG-NEWS      |  6 ++++++
 lisp/ob-tangle.el | 25 +++++++++++++++++++------
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 478fcf95c..22daa4351 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -375,6 +375,12 @@ purpose of the variable.  The replacement variable
 accepts =listings= and =verbatim= in place of =t= and =nil= (which
 still work, but are no longer listed as valid options).
+*** ~ob-tangle~: the ~org~ value for ~:comments~ is now plain text 
+When the value of the header argument ~:comments~ is ~org~, the text
+collected in the Org document is exported to ASCII before being passed
+to the tangled source file as a comment.
 * Version 9.5
 ** Important announcements and breaking changes
diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
index fdba72278..da14aaa5a 100644
--- a/lisp/ob-tangle.el
+++ b/lisp/ob-tangle.el
@@ -134,11 +134,12 @@ of tangled comments."
   :group 'org-babel
   :type 'boolean)
-(defcustom org-babel-process-comment-text 'org-remove-indentation
-  "Function called to process raw Org text collected to be
-inserted as comments in tangled source-code files.  The function
-should take a single string argument and return a string
-result.  The default value is `org-remove-indentation'."
+(defcustom org-babel-process-comment-text 'org-babel-export-comment-text-as-plain-text
+  +  "Function called to process raw Org text collected to be inserted
++as comments in tangled source-code files.  The function should
++take a single string argument and return a string result.  The
++default value is `org-babel-export-comment-text-as-plain-text'.
++Legacy value is `org-remove-indentation'."
   :group 'org-babel
   :version "24.1"
   :type 'function)
@@ -158,6 +159,18 @@ represented in the file."
   (with-current-buffer (get-file-buffer file)
     (revert-buffer t t t)))
+(defun org-babel-export-comment-text-as-plain-text (text)
+  "Function to process raw Org TEXT collected to be inserted as
+comments in tangled source-code files.  This function is the
+default value for `org-babel-process-comment-text'."
+  ;; Ensure that if TEXT is a header it is not numbered.
+  (let ((text-nonum (with-temp-buffer
+                      (insert text)
+                      (when (not (org-entry-get nil "UNNUMBERED"))
+                        (org-entry-put nil "UNNUMBERED" "t"))
+                      (buffer-string))))
+    (org-export-string-as text-nonum 'ascii t)))
 (defmacro org-babel-with-temp-filebuffer (file &rest body)
   "Open FILE into a temporary buffer execute BODY there like
 `progn', then kill the FILE buffer returning the result of
@@ -534,7 +547,7 @@ non-nil, return the full association list to be used by
 	      (max (condition-case nil
 			 (org-back-to-heading t) ; Sets match data
-			 (match-end 0))
+			 (match-beginning 0))
 		     (error (point-min)))
 		     (if (re-search-backward

  reply	other threads:[~2022-07-25 17:15 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-10 18:28 [Patch] ob-tangle.el: New value 'ascii' for the header argument ':comments' Juan Manuel Macías
2022-06-11  5:39 ` Ihor Radchenko
2022-06-11 11:20   ` Juan Manuel Macías
2022-06-14  3:58     ` Ihor Radchenko
2022-06-14 11:11       ` Juan Manuel Macías
2022-06-14 11:55         ` Ihor Radchenko
2022-06-15 10:30           ` Juan Manuel Macías
2022-07-21 13:44           ` Juan Manuel Macías
2022-07-25 13:34             ` Ihor Radchenko
2022-07-25 17:13               ` Juan Manuel Macías [this message]
2022-07-26  5:35                 ` Ihor Radchenko
2022-06-12 19:18 ` Rudolf Adamkovič
2022-06-12 19:55   ` Juan Manuel Macías
2022-06-13  8:24     ` Rudolf Adamkovič
2022-06-13 10:22       ` Juan Manuel Macías

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87czdt3yk3.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=yantar92@gmail.com \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


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).