From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id SDRCD2x9TmaZXgEAe85BDQ:P1 (envelope-from ) for ; Thu, 23 May 2024 01:19:08 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id SDRCD2x9TmaZXgEAe85BDQ (envelope-from ) for ; Thu, 23 May 2024 01:19:08 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=BfXSoX12; 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"; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1716419948; 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=zyAOeaKRdLyDFFJPOwHVWcW9VVD3iZ+u+KjYYUQB1PM=; b=SDL9PgywXJuiFE5Bo/YZnlk+sT9YnsG3dQFCaTLPB6cTqHJzJFhuRSuPmvQ1RM9c7h0w+l sKRw5K2VT/S4azUrDUpNrgR/+/zdlonlWZJn4Ky84zMONHngf/ootqEREb71/6HkYw39LU OEYoPX1VTmmnNUZAXWKfN7vZi/yDpUb25lCMJClQtgItXpL2s8atIm6DUbNKJ7gUMC2j7u nOnYTKd7gOkmPCgnQpi1EQ8KmKiFcOm5HJ5Hi1ZDq71nQsQ6q76yrWvkm5BQAZB1RiZZhV Po9+B/Ojc5gC+Tu3eqHMmgQ1kLn0lhHjMVs23VOvb6NOwkrC1HR+tfwy7bM9Pw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=BfXSoX12; 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"; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=key1; d=yhetil.org; t=1716419948; a=rsa-sha256; cv=none; b=gcS3z/XOmIM8X9OgH5D2LfgsIv48m9dJBLTB+8sgIEfubTX0g02AZPulyb/Q4sOqBcxCnR nHN3TroThHyGXItkw8RgdRno4qsCksd/3TgxxWLfA7AEQXlNIpLLUY2uxV2gTQt6YhGMjC YUqKuQHYJE+esLg+UI+lGshpPkiItFl9BprhMCeKwFN1kg0u58Unyrdf+/bCRMLaAtn8F5 3/2W3CFlO/L8La5vXJzPFPHSXJL2uAW6kHbrm/ulD6rmJosqybqfMvI24Ju/JeZgkYstJR ZbYbwpsyZ6dmZn51EBY66E8hCqfF6J9INC7t7l8RmHidvfcMSqlNJYTKCM8gJA== 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 99C1A6EB0B for ; Thu, 23 May 2024 01:19:07 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9vDe-0000uC-Tp; Wed, 22 May 2024 19:18:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9vDc-0000ti-IZ for emacs-orgmode@gnu.org; Wed, 22 May 2024 19:18:00 -0400 Received: from mail-qk1-x735.google.com ([2607:f8b0:4864:20::735]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s9vDW-00067R-82 for emacs-orgmode@gnu.org; Wed, 22 May 2024 19:18:00 -0400 Received: by mail-qk1-x735.google.com with SMTP id af79cd13be357-792b8d989e4so398112585a.2 for ; Wed, 22 May 2024 16:17:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716419871; x=1717024671; darn=gnu.org; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=zyAOeaKRdLyDFFJPOwHVWcW9VVD3iZ+u+KjYYUQB1PM=; b=BfXSoX12fS46cgdApT/k2DQ57ZwDiVQ+D17Sznbg0UdgxsmU85kRl1qFk24T1n97J9 8ActxzWkzl4Yjg/aJkpOjlgdzLR0Sf/G5QKF6/ZPIYL+tq6ibU5cnQZiQknzC4B18Pla Ij3+PnPacleuzumAnALISV68/6AjvJzeUhlHj7QW5wkHUcOwyBpxi28KnplghZes+xOO Q4x48NCHYGptHwoMDYXCMkJG/Hlr0SUmmAlclQ5/84dlaXl6oe9ZKtY0j/LeumaZyDlu RwQ65OoILO+DcSqLCgsXjcPSYFyR4qHMphx0/GgjkF5kYPIq+CbyPxlEaDl6JiNBuICe DjoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716419871; x=1717024671; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=zyAOeaKRdLyDFFJPOwHVWcW9VVD3iZ+u+KjYYUQB1PM=; b=D46UmcLWpC1sa6UUnN6362pZqUr+HTzOzDjV5HL54aBnmF36ql30+yfwAoBQ8+U2rD K8/vMCsvutlp0J746PlP8Ownf8/hUlxh+nnHJrVB9EQmklpQWvz/jFqo2CZ6etsydWyj hujLaFls5eFIOe1cYdLEz0VhCYk2oPDYX9ZtL3G7Vbs8GtRLPD0W5HzL4JSiBN5pIUsJ A7enjWh30yLBjjeeNuzua/JC5i9JsGFlztjT2nKzjd0edrITGyQhO7yahYWMfHGG/wj3 Ly4a+iyXDPAvbmEoyRoBVlNPR95xuniKyHvgiqSWft+ljhuBphMrz/TucFX8z3w+tNYS /J5A== X-Gm-Message-State: AOJu0YzNDd8oyOk88+7niO1NQyVcgGc41clY07M3emLZNzO2mpt72WAM GyidDd4nuAtPk+9lykxxk3TkBqirVY1ixPvSX8rHTaBz9Qs8nkpdLbGN2g== X-Google-Smtp-Source: AGHT+IF9APn9W7C5+61Eei24E+nRGaLXA+98Eg0MVvur9UDli7PVT57KhULg6+jxe2WlTh2wTSpazw== X-Received: by 2002:a05:620a:2881:b0:793:82:ad50 with SMTP id af79cd13be357-7949944139cmr392374785a.23.1716419871060; Wed, 22 May 2024 16:17:51 -0700 (PDT) Received: from Asus (syn-024-236-139-114.res.spectrum.com. [24.236.139.114]) by smtp.gmail.com with ESMTPSA id af79cd13be357-792bf3116b0sm1433634985a.113.2024.05.22.16.17.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 16:17:50 -0700 (PDT) From: Amy Grinn To: Ihor Radchenko Cc: emacs-orgmode@gnu.org Subject: Re: [FR] :noweb-wrap header arg In-Reply-To: <87r0e7s3uo.fsf@localhost> (Ihor Radchenko's message of "Sun, 12 May 2024 10:48:31 +0000") References: <87h6hixhnw.fsf@localhost> <85wmp82boq.fsf_-_@gmail.com> <87y19kxagi.fsf@localhost> <85wmo0l4m1.fsf@gmail.com> <87r0e7s3uo.fsf@localhost> Date: Wed, 22 May 2024 19:17:48 -0400 Message-ID: <85r0dt77xf.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::735; envelope-from=grinn.amy@gmail.com; helo=mail-qk1-x735.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=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-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Spam-Score: -9.68 X-Migadu-Queue-Id: 99C1A6EB0B X-Migadu-Scanner: mx10.migadu.com X-Migadu-Spam-Score: -9.68 X-TUID: ohcsoAGgwn5T --=-=-= Content-Type: text/plain Ihor Radchenko writes: > Amy Grinn writes: > >>> +1 >>> You may even use obsolete alias (add it to lisp/org-compat.el) >> >> Here's a patch to rename org-babel-noweb-wrap to >> org-babel-noweb-make-regexp. > > Thanks! > News entry is not necessary here - we are just renaming a function. > Otherwise, the patch looks good. > I am not yet merging it though - let's have all the patches you plan for > the new noweb-wrap argument first and then apply them together. Got it, not a problem! I've attached both patches here. Regarding the other conversation, >>>> + (while (< (point) (point-max)) >>>> + (unless (looking-at " *\"\\([^\"]+\\)\" *") >>>> + (looking-at " *\\([^ ]+\\)")) >>> >>> May you please explain the rationale behind this regexp? AFAIU, it >>> implies that you want to allow whitespace characters inside :noweb-wrap >>> boundaries. But I do not think that we need to complicate things so much. >> >> That is exactly what I was going for. I thought about the ways this >> could be used and the most general-purpose, non-syntax-breaking, >> easily-recognizable way I could think of was to use the language's >> line-comment construct followed by the standard << >> characters. >> >> # <> >> ;; <> >> // <> >> >> I can see how it might be harder to maintain to allow whitespace in the >> noweb-wrap header arg. I could create a separate org-parse-arg-list >> function to ease that burden somewhat. My opinion is that having the >> option to use the examples above is preferable to using non-standard >> wrappers, from a third-person point-of-view. > > Makes sense. Also, see a similar idea being discussed in > https://list.orgmode.org/orgmode/87o7jlzxgn.fsf@localhost/ > > I recommend the following: > > If the value starts from ", use Elisp's `read': > |"# <<" ">>" > (read (current-buffer)) ; => "# <<" > otherwise, consider read until the first whitespace. > |#<<; >>; > (re-search-forward (rx (1+ (not whitespace)))) > #<<;| > > However, there may be edge cases like > > "<< >>" > "<< >> > << << >> > << "asd" >> I didn't implement this recommendation yet; I still think the regex is a more clear way of putting it, even without using a temporary buffer: ;; If a pair of " is found separated by one or more ;; characters, capture those characters as a group (unless (eq i (string-match (rx (* space) ?\" (group (+ (not ?\"))) ?\" (* space)) raw i)) ;; Otherwise, capture the next non-whitespace group of ;; characters (string-match (rx (* space) (group (* (not space))) (* space)) raw i)) Let me know what you think! --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-lisp-ob-core.el-org-babel-noweb-wrap-renamed-to-org-.patch Content-Description: rename to org-babel-noweb-make-regexp >From 9442c029a7b2f1ec061e42a047b3d1bff88441d8 Mon Sep 17 00:00:00 2001 From: Amy Grinn Date: Wed, 17 Apr 2024 16:01:40 -0400 Subject: [PATCH 1/2] lisp/ob-core.el: (org-babel-noweb-wrap): renamed to org-babel-noweb-make-regexp * lisp/org-compat.el: Declare org-babel-noweb-wrap to be an obselete function alias for org-babel-noweb-make-regexp. * lisp/ob-core.el (org-babel-noweb-make-regexp): Rename the function. (org-babel-goto-named-src-block): (org-babel-expand-noweb-references): * lisp/ob-exp.el (org-babel-exp-code): * lisp/ob-tangle.el (org-babel-tangle-clean): (org-babel-tangle-single-block): Use the new function name. --- lisp/ob-core.el | 8 ++++---- lisp/ob-exp.el | 2 +- lisp/ob-tangle.el | 5 +++-- lisp/org-compat.el | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index c5dd20b0e..1518d7726 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -194,7 +194,7 @@ This string must include a \"%s\" which will be replaced by the results." :package-version '(Org . "9.1") :safe #'booleanp) -(defun org-babel-noweb-wrap (&optional regexp) +(defun org-babel-noweb-make-regexp (&optional regexp) "Return regexp matching a Noweb reference. Match any reference, or only those matching REGEXP, if non-nil. @@ -1976,7 +1976,7 @@ src block, then return nil." (type (org-element-type context)) (noweb-ref (and (memq type '(inline-src-block src-block)) - (org-in-regexp (org-babel-noweb-wrap))))) + (org-in-regexp (org-babel-noweb-make-regexp))))) (cond (noweb-ref (buffer-substring @@ -3125,7 +3125,7 @@ block but are passed literally to the \"example-block\"." (not (equal (cdr v) "no")))))) (noweb-re (format "\\(.*?\\)\\(%s\\)" (with-current-buffer parent-buffer - (org-babel-noweb-wrap))))) + (org-babel-noweb-make-regexp))))) (unless (equal (cons parent-buffer (with-current-buffer parent-buffer (buffer-chars-modified-tick))) @@ -3175,7 +3175,7 @@ block but are passed literally to the \"example-block\"." ((guard (or org-babel-noweb-error-all-langs (member lang org-babel-noweb-error-langs))) (error "Cannot resolve %s (see `org-babel-noweb-error-langs')" - (org-babel-noweb-wrap ,ref))) + (org-babel-noweb-make-regexp ,ref))) (_ "")))) (replace-regexp-in-string noweb-re diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el index 34f12fdcc..33de7a4aa 100644 --- a/lisp/ob-exp.el +++ b/lisp/ob-exp.el @@ -418,7 +418,7 @@ replaced with its value." (setf (nth 1 info) (if (string= "strip-export" (cdr (assq :noweb (nth 2 info)))) (replace-regexp-in-string - (org-babel-noweb-wrap) "" (nth 1 info)) + (org-babel-noweb-make-regexp) "" (nth 1 info)) (if (org-babel-noweb-p (nth 2 info) :export) (org-babel-expand-noweb-references info org-babel-exp-reference-buffer) diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 79fe6448b..4427250ae 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -412,7 +412,7 @@ references." (interactive) (goto-char (point-min)) (while (or (re-search-forward "\\[\\[file:.*\\]\\[.*\\]\\]" nil t) - (re-search-forward (org-babel-noweb-wrap) nil t)) + (re-search-forward (org-babel-noweb-make-regexp) nil t)) (delete-region (save-excursion (forward-line) (point)) (save-excursion (end-of-line 1) (forward-char 1) (point))))) @@ -580,7 +580,8 @@ non-nil, return the full association list to be used by ;; Run the tangle-body-hook. (let ((body (if (org-babel-noweb-p params :tangle) (if (string= "strip-tangle" (cdr (assq :noweb (nth 2 info)))) - (replace-regexp-in-string (org-babel-noweb-wrap) "" (nth 1 info)) + (replace-regexp-in-string (org-babel-noweb-make-regexp) + "" (nth 1 info)) (org-babel-expand-noweb-references info)) (nth 1 info)))) (with-temp-buffer diff --git a/lisp/org-compat.el b/lisp/org-compat.el index 92cad3d6e..ce46fd399 100644 --- a/lisp/org-compat.el +++ b/lisp/org-compat.el @@ -433,7 +433,7 @@ This is a floating point number if the size is too large for an integer." (define-obsolete-function-alias 'org-show-context 'org-fold-show-context "9.6") (define-obsolete-function-alias 'org-show-entry 'org-fold-show-entry "9.6") (define-obsolete-function-alias 'org-show-children 'org-fold-show-children "9.6") - +(define-obsolete-function-alias 'org-babel-noweb-wrap 'org-babel-noweb-make-regexp "9.7") (defmacro org-re (s) "Replace posix classes in regular expression S." -- 2.39.2 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-org-babel-New-header-argument-noweb-wrap.patch Content-Description: new header argument :noweb-wrap >From aad9b3926c711dfed411e2f439ae8b0fe3db7d10 Mon Sep 17 00:00:00 2001 From: Amy Grinn Date: Wed, 17 Apr 2024 16:56:37 -0400 Subject: [PATCH 2/2] org-babel: New header argument :noweb-wrap * lisp/ob-core.el (org-babel-get-noweb-wrap): New API function that parses the :noweb-wrap parameter of a babel src block. (org-babel-noweb-make-regexp): Add a new optional parameter 'wrap' to control how noweb references are wrapped. (org-babel-goto-named-src-block): (org-babel-expand-noweb-references): * lisp/ob-exp.el (org-babel-exp-code): * lisp/ob-tangle.el (org-babel-tangle-single-block): Use the new org-babel-get-noweb-wrap function as the new optional parameter to org-babel-noweb-make-regexp. * lisp/ob-tangle.el (org-babel-tangle-clean): Add an additional warning about not being able to resolve noweb references if :noweb wrap was specified. * etc/ORG-NEWS (New =:noweb-wrap= babel header argument): Describe new argument. * testing/examples/babel.org: * testing/lisp/test-ob-exp.el: * testing/lisp/test-ob.el: Add tests which use alternate wrapping syntax for noweb references. --- etc/ORG-NEWS | 14 +++++++++ lisp/ob-core.el | 57 +++++++++++++++++++++++++++++++------ lisp/ob-exp.el | 3 +- lisp/ob-tangle.el | 12 +++++--- testing/examples/babel.org | 17 +++++++++++ testing/lisp/test-ob-exp.el | 55 +++++++++++++++++++++++++++++++++++ testing/lisp/test-ob.el | 32 +++++++++++++++++++++ 7 files changed, 176 insertions(+), 14 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 585b2b262..e1fb95744 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -589,6 +589,20 @@ Org mode provides 3 possible values for ~org-sort-function~: and on MacOS. 3. Custom function, if the above does not fit the needs. +*** New =:noweb-wrap= babel header argument + +This argument changes the default noweb reference syntax by masking +the options ~org-babel-noweb-wrap-start~ and +~org-babel-noweb-wrap-end~. + +=:noweb-wrap= takes two parameters, start and end, corresponding to +each option. + +For example: +: #+begin_src sh :noweb-wrap <<< >>> +: echo <<>> +: #+end_src + *** =ob-latex= now uses a new option ~org-babel-latex-process-alist~ to generate png output Previously, =ob-latex= used ~org-preview-latex-default-process~ from diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 1518d7726..4f286c64c 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -194,15 +194,21 @@ This string must include a \"%s\" which will be replaced by the results." :package-version '(Org . "9.1") :safe #'booleanp) -(defun org-babel-noweb-make-regexp (&optional regexp) +(defun org-babel-noweb-make-regexp (&optional regexp wrap) "Return regexp matching a Noweb reference. Match any reference, or only those matching REGEXP, if non-nil. +If WRAP is provided, it should be a list of 2 strings describing +the start and end of a noweb reference, such as that returned by +`org-babel-get-noweb-wrap'. Otherwise +`org-babel-noweb-wrap-start' and `org-babel-noweb-wrap-end' will +be used. + When matching, reference is stored in match group 1." - (concat (regexp-quote org-babel-noweb-wrap-start) - (or regexp "\\([^ \t\n]\\(?:.*?[^ \t\n]\\)?\\)") - (regexp-quote org-babel-noweb-wrap-end))) + (concat (regexp-quote (or (car wrap) org-babel-noweb-wrap-start)) + (or regexp "\\([^ \t\n]\\(?:.*?[^ \t\n]\\)?\\)") + (regexp-quote (or (cadr wrap) org-babel-noweb-wrap-end)))) (defvar org-babel-src-name-regexp "^[ \t]*#\\+name:[ \t]*" @@ -1963,6 +1969,33 @@ src block, then return nil." (let ((head (org-babel-where-is-src-block-head))) (if head (goto-char head) (error "Not currently in a code block")))) +(defun org-babel-get-noweb-wrap (&optional info) + "Retrieve a description the :noweb-wrap header arg from INFO. + +The description will be in the form of a list of two of strings +for the start and end of a reference. INFO can be the result of +`org-babel-get-src-block-info' otherwise this function will parse +info at point." + (unless info + (setq info (org-babel-get-src-block-info 'no-eval))) + (when-let* ((raw (cdr (assq :noweb-wrap (nth 2 info)))) + (len (length raw))) + (let ((i 0) result) + (while (< i len) + ;; If a pair of " is found separated by one or more + ;; characters, capture those characters as a group + (unless (eq i (string-match (rx (* space) ?\" + (group (+ (not ?\"))) + ?\" (* space)) + raw i)) + ;; Otherwise, capture the next non-whitespace group of + ;; characters + (string-match (rx (* space) (group (* (not space))) (* space)) + raw i)) + (setq i (match-end 0)) + (push (match-string 1 raw) result)) + (reverse result)))) + ;;;###autoload (defun org-babel-goto-named-src-block (name) "Go to a source-code block with NAME." @@ -1974,14 +2007,18 @@ src block, then return nil." "source-block name: " all-block-names nil t (let* ((context (org-element-context)) (type (org-element-type context)) + (noweb-wrap (org-babel-get-noweb-wrap)) (noweb-ref (and (memq type '(inline-src-block src-block)) - (org-in-regexp (org-babel-noweb-make-regexp))))) + (org-in-regexp (org-babel-noweb-make-regexp + nil noweb-wrap))))) (cond (noweb-ref (buffer-substring - (+ (car noweb-ref) (length org-babel-noweb-wrap-start)) - (- (cdr noweb-ref) (length org-babel-noweb-wrap-end)))) + (+ (car noweb-ref) (length (or (car noweb-wrap) + org-babel-noweb-wrap-start))) + (- (cdr noweb-ref) (length (or (cadr noweb-wrap) + org-babel-noweb-wrap-end))))) ((memq type '(babel-call inline-babel-call)) ;#+CALL: (org-element-property :call context)) ((car (org-element-property :results context))) ;#+RESULTS: @@ -3125,7 +3162,8 @@ block but are passed literally to the \"example-block\"." (not (equal (cdr v) "no")))))) (noweb-re (format "\\(.*?\\)\\(%s\\)" (with-current-buffer parent-buffer - (org-babel-noweb-make-regexp))))) + (org-babel-noweb-make-regexp + nil (org-babel-get-noweb-wrap info)))))) (unless (equal (cons parent-buffer (with-current-buffer parent-buffer (buffer-chars-modified-tick))) @@ -3175,7 +3213,8 @@ block but are passed literally to the \"example-block\"." ((guard (or org-babel-noweb-error-all-langs (member lang org-babel-noweb-error-langs))) (error "Cannot resolve %s (see `org-babel-noweb-error-langs')" - (org-babel-noweb-make-regexp ,ref))) + (org-babel-noweb-make-regexp + ,ref (org-babel-get-noweb-wrap)))) (_ "")))) (replace-regexp-in-string noweb-re diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el index 33de7a4aa..14a32a8e6 100644 --- a/lisp/ob-exp.el +++ b/lisp/ob-exp.el @@ -418,7 +418,8 @@ replaced with its value." (setf (nth 1 info) (if (string= "strip-export" (cdr (assq :noweb (nth 2 info)))) (replace-regexp-in-string - (org-babel-noweb-make-regexp) "" (nth 1 info)) + (org-babel-noweb-make-regexp nil (org-babel-get-noweb-wrap info)) + "" (nth 1 info)) (if (org-babel-noweb-p (nth 2 info) :export) (org-babel-expand-noweb-references info org-babel-exp-reference-buffer) diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 4427250ae..5fcb40443 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -406,9 +406,11 @@ Did you give the decimal value %1$d by mistake?" mode))) "Remove comments inserted by `org-babel-tangle'. Call this function inside of a source-code file generated by `org-babel-tangle' to remove all comments inserted automatically -by `org-babel-tangle'. Warning, this comment removes any lines +by `org-babel-tangle'. Warning, this command removes any lines containing constructs which resemble Org file links or noweb -references." +references. It also cannot determine which noweb syntax is being +used for any given source file, if :noweb-wrap was specified in +the original Org file." (interactive) (goto-char (point-min)) (while (or (re-search-forward "\\[\\[file:.*\\]\\[.*\\]\\]" nil t) @@ -580,8 +582,10 @@ non-nil, return the full association list to be used by ;; Run the tangle-body-hook. (let ((body (if (org-babel-noweb-p params :tangle) (if (string= "strip-tangle" (cdr (assq :noweb (nth 2 info)))) - (replace-regexp-in-string (org-babel-noweb-make-regexp) - "" (nth 1 info)) + (replace-regexp-in-string + (org-babel-noweb-make-regexp + nil (org-babel-get-noweb-wrap info)) + "" (nth 1 info)) (org-babel-expand-noweb-references info)) (nth 1 info)))) (with-temp-buffer diff --git a/testing/examples/babel.org b/testing/examples/babel.org index d46afeb5e..680d4bf3e 100644 --- a/testing/examples/babel.org +++ b/testing/examples/babel.org @@ -346,6 +346,23 @@ Here is a call line with more than just the results exported. echo "1$i" #+END_SRC +* strip noweb references with alternative wrap + :PROPERTIES: + :ID: da9bcfdd-c1bd-47b4-b520-67974b9f9856 + :END: + +#+name: strip-export-2 +#+BEGIN_SRC sh :exports none + i="10" +#+END_SRC + +#+RESULTS: strip-export-2 + +#+BEGIN_SRC sh :noweb strip-export :noweb-wrap #[[ ]] :exports code :results silent + #[[strip-export-2]] + echo "1$i" +#+END_SRC + * use case of reading entry properties :PROPERTIES: :ID: cc5fbc20-bca5-437a-a7b8-2b4d7a03f820 diff --git a/testing/lisp/test-ob-exp.el b/testing/lisp/test-ob-exp.el index d029dadfb..abfda4368 100644 --- a/testing/lisp/test-ob-exp.el +++ b/testing/lisp/test-ob-exp.el @@ -394,6 +394,61 @@ be evaluated." (regexp-quote " :foo :bar \n") ascii)))))) +(ert-deftest ob-exp/noweb-wrap-header-arg () + (let ((org-export-use-babel t)) + (org-test-with-temp-text + " +#+Title: exporting from a temporary buffer + +#+name: foo +#+BEGIN_SRC emacs-lisp + :foo +#+END_SRC + +#+BEGIN_SRC emacs-lisp :noweb yes :noweb-wrap {{ }} :exports results + (list {{foo}}) +#+END_SRC +" + (let* ((ascii (org-export-as 'ascii))) + (should (string-match + (regexp-quote " :foo \n") + ascii)))))) + +(ert-deftest ob-exp/noweb-strip-export-with-wrap () + (org-test-at-id "da9bcfdd-c1bd-47b4-b520-67974b9f9856" + (org-narrow-to-subtree) + (org-babel-next-src-block 1) + (org-babel-execute-src-block) + (let ((result (org-test-with-expanded-babel-code (buffer-string)))) + (should-not (string-match (regexp-quote "#[[strip-export-2]]") result)) + (should-not (string-match (regexp-quote "i=\"10\"") result))))) + +(ert-deftest ob-exp/noweb-wrap-strip-export () + (let ((org-export-use-babel t)) + (org-test-with-temp-text + " +#+Title: exporting from a temporary buffer + +#+name: foo +#+BEGIN_SRC emacs-lisp + :foo +#+END_SRC + +#+name: bar +#+BEGIN_SRC emacs-lisp + :bar +#+END_SRC + +#+BEGIN_SRC emacs-lisp :noweb yes :noweb-wrap {{ }} :exports results + (list {{foo}} {{bar}}) +#+END_SRC +" + (let* ((ascii (org-export-as 'ascii))) + + (should (string-match + (regexp-quote ":foo :bar") + ascii)))))) + (ert-deftest ob-export/export-with-results-before-block () "Test export when results are inserted before source block." (let ((org-export-use-babel t)) diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index 544e68267..b0051d2a2 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -988,6 +988,38 @@ x (search-forward "begin_src") (org-babel-expand-noweb-references))))) +(ert-deftest test-ob/noweb-wrap () + ;; Standard test. + (should + (string= + "bar" + (org-test-with-temp-text "#+begin_src sh :results output :tangle yes :noweb-wrap <<< >>> + <<>> +#+end_src + +#+name: foo +#+begin_src sh + bar +#+end_src" + (org-babel-expand-noweb-references))))) + +(ert-deftest test-ob/get-noweb-wrap () + (should (equal '("<< >>") + (org-babel-get-noweb-wrap + '(nil nil ((:noweb-wrap . "\"<< >>\"")))))) + (should (equal '("\"<<" ">>") + (org-babel-get-noweb-wrap + '(nil nil ((:noweb-wrap . "\"<< >>")))))) + (should (equal '("<<" "<<" ">>") + (org-babel-get-noweb-wrap + '(nil nil ((:noweb-wrap . "<< << >>")))))) + (should (equal '("<<" "asd" ">>") + (org-babel-get-noweb-wrap + '(nil nil ((:noweb-wrap . "<< \"asd\" >>")))))) + (should (equal '("\"\"\"" ">>>") + (org-babel-get-noweb-wrap + '(nil nil ((:noweb-wrap . "\"\"\" >>>"))))))) + (ert-deftest test-ob/splitting-variable-lists-in-references () (org-test-with-temp-text "" (should (= 1 (length (org-babel-ref-split-args -- 2.39.2 --=-=-= Content-Type: text/plain -- Best, Amy --=-=-=--