From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id SCaqBZfP3mLsGgEAbAwnHQ (envelope-from ) for ; Mon, 25 Jul 2022 19:15:03 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id cL/ABZfP3mJtjwAA9RJhRA (envelope-from ) for ; Mon, 25 Jul 2022 19:15:03 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 9146D373FB for ; Mon, 25 Jul 2022 19:15:02 +0200 (CEST) Received: from localhost ([::1]:54268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oG1fZ-0001GG-5W for larch@yhetil.org; Mon, 25 Jul 2022 13:15:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36550) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oG1eW-0001Fm-Sz for emacs-orgmode@gnu.org; Mon, 25 Jul 2022 13:13:56 -0400 Received: from mout02.posteo.de ([185.67.36.66]:59491) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oG1eU-0005Bi-EX for emacs-orgmode@gnu.org; Mon, 25 Jul 2022 13:13:56 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 24433240109 for ; Mon, 25 Jul 2022 19:13:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1658769232; bh=d3PsNl5DehiHwjRtEtmWBtMUgSXFHe80s4yrYFUExuk=; h=From:To:Cc:Subject:Date:From; b=f6DH/WpQrAO1s3110p+NmcEzig1qWVJF87UkMSFLDcvBYPs4osasJ42Cu6aRekHEE mFmBPHZYKhb1xOjbxMfKyA+ft/IUSakcWjP+2G8VxE+ezKYxse95ZVnVG/jzNp+d3e WrKukozeQr6/0dJSJKg+JBUPTUfADrcrwvkvwastbDmJ2M9WO1mPQXnuXmQA0auT7H zvUzd3cEeeAAMOmZn/1025mQUwU4ULAhtQMig70bif1xf9M89sL6nLxGh1RJXTuP2h xL37QppPOhciTqlW9dJv1cLV4+f3dOvXiVYiVOzGgm1M/SVs1t5IRbiMsFPaNhipPn nr+g6nawE7PnA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Ls68H0m7fz9rxF; Mon, 25 Jul 2022 19:13:50 +0200 (CEST) From: =?utf-8?Q?Juan_Manuel_Mac=C3=ADas?= To: Ihor Radchenko Cc: orgmode Subject: Re: [Patch] ob-tangle.el: New value 'ascii' for the header argument ':comments' References: <87o7z0tltj.fsf@posteo.net> <87bkuzdahc.fsf@localhost> <87wndna1lp.fsf@posteo.net> <87y1xzq4k9.fsf@localhost> <87o7yvlctx.fsf@posteo.net> <87y1xzwjar.fsf@localhost> <87k086h96l.fsf@posteo.net> <878rohuxij.fsf@localhost> Date: Mon, 25 Jul 2022 17:13:48 +0000 In-Reply-To: <878rohuxij.fsf@localhost> (Ihor Radchenko's message of "Mon, 25 Jul 2022 21:34:12 +0800") Message-ID: <87czdt3yk3.fsf@posteo.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.66; envelope-from=maciaschain@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1658769302; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=oxMOmXkjKO9NhnvnR8GAaS5DleWV4XNRINrp7e6wZNs=; b=V0vjYsJ1gQYrMz0b4CrPRpqOJjvSbs3DHx9KhgP9rXKGlImGy5PEcmJNV1vwmpI14QWzn2 Ikl/ZT21R+DKUl0NV3dgNt8VNZERxSy4J4CsbF3x9GejqQlAube14tlpy0Jj3/lW0UOTQG L7FcfHrcBhWircsXIHFvELQdhqWe5sHv8bXNBMZTlnjB0FlIhYHhlI6D3zwjdtQA7iQ3zA DeEs/deOEx/pC8PycnZU7Nk1ly9f59byAKTBj33IW5YJ02J30t7WYzSQ2eNvRIQZl77FYC G85ZmvlUkHnq8vs6iouLlW/RxcglRHesOmY7KO8JxfnF5UPjmw2h20W5Ob6avg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1658769302; a=rsa-sha256; cv=none; b=uq76qxLFdnstdJty58H3WG8R/3lzu+FQKWw9C5jzsz9X+Q9qPpNCVDlLFOOoICc3774elC AXG7W5mKt5VkodIefFm/1JlAqW8p81kzxDcbtPHTBMEUAyfS4JHd3j96f/7vDuQ+xh/rYi ghQBVg23aji852lka1Gv/DFQRrYhvnu1eLm9sOmwhoT5NkxbtcIi+vTLprW0NYeKQJOEWb mHT34l92mwAb7Zo7tp7P9IXrAEKGhIqMLsoTNQtUQjTJ23nLODnti5/ARRUg/coNKjIClk Fhe2mVfhfWDLl8AcEqAX5KZMQVW1O0HMQrldRi+rNiSIferA3vhNj/8eNx2heg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b="f6DH/WpQ"; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -9.43 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b="f6DH/WpQ"; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 9146D373FB X-Spam-Score: -9.43 X-Migadu-Scanner: scn0.migadu.com X-TUID: x8UbRUkSRhf9 --=-=-= Content-Type: text/plain 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 way... Best regards, Juan Manuel --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-lisp-ob-tangle.el-The-org-value-for-comments-is-now-.patch >From b500fcb1475b0a2e8eee532f031bb5cd236560fb Mon Sep 17 00:00:00 2001 From: Juan Manuel Macias 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 comments. --- 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 (save-excursion (org-back-to-heading t) ; Sets match data - (match-end 0)) + (match-beginning 0)) (error (point-min))) (save-excursion (if (re-search-backward -- 2.37.1 --=-=-=--