emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: termux <grinn.amy@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: noweb-start and noweb-end header args
Date: Tue, 05 Mar 2024 17:41:48 -0500	[thread overview]
Message-ID: <s31r0gowbbn.fsf@gmail.com> (raw)
In-Reply-To: <s31cys8xz4w.fsf@gmail.com> (Amy Grinn's message of "Tue, 05 Mar 2024 14:22:07 -0500")

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

Amy Grinn <grinn.amy@gmail.com> writes:

> I would like to add support for setting 'org-babel-noweb-wrap-start and
> 'org-babel-noweb-wrap-end for each src block individually using the
> header args :noweb-start and :noweb-end:

Here's another possible syntax we could use:

:noweb <context> [wrap-start] [wrap-end]

#+name: message
#+begin_src elisp
  "Firewall is now in safe mode."
#+end_src

#+name: firewall-safe-mode
#+begin_src sh :noweb yes
  echo <<message>>
#+end_src

#+name: firewall
#+begin_src sh :noweb yes <<< >>>
  safe_mode () {
      echo "Error encountered, switching to safe mode."
      <<<firewall-safe-mode>>>
      exit 1
  }
#+end_src

#+begin_src sh :noweb yes ":-) " " (-:" :tangle "test.sh"
  # Setup firewall
  :-) firewall (-:

  # Do other things
#+end_src


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Noweb header argument new syntax --]
[-- Type: text/x-patch, Size: 1663 bytes --]

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 4dcfbd3b0..f60b4be12 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -194,15 +194,20 @@ 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-wrap (&optional regexp info)
   "Return regexp matching a Noweb reference.
 
 Match any reference, or only those matching REGEXP, if non-nil.
 
 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)))
+  (let ((noweb (mapcar
+                (lambda (token)
+                  (if (stringp token) token (symbol-name token)))
+                (org-babel-read
+                 (format "'(%s)" (cdr (assq :noweb (nth 2 info))))))))
+    (concat (regexp-quote (or (nth 1 noweb) org-babel-noweb-wrap-start))
+	    (or regexp "\\([^ \t\n]\\(?:.*?[^ \t\n]\\)?\\)")
+	    (regexp-quote (or (nth 2 noweb) org-babel-noweb-wrap-end)))))
 
 (defvar org-babel-src-name-regexp
   "^[ \t]*#\\+name:[ \t]*"
@@ -3116,7 +3121,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-wrap nil info)))))
     (unless (equal (cons parent-buffer
                          (with-current-buffer parent-buffer
                            (buffer-chars-modified-tick)))

  reply	other threads:[~2024-03-05 22:42 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-05 19:22 noweb-start and noweb-end header args Amy Grinn
2024-03-05 22:41 ` termux [this message]
2024-03-06 11:21 ` Ihor Radchenko
2024-03-06 11:40   ` Amy Grinn
2024-03-06 11:47     ` Ihor Radchenko
2024-03-06 12:05       ` Amy Grinn
2024-03-06 13:33         ` Ihor Radchenko
2024-03-06 16:04           ` Amy Grinn
2024-03-07 13:50             ` Ihor Radchenko
2024-03-06 23:07     ` Amy Grinn
2024-03-07 13:58       ` Ihor Radchenko
2024-03-07 14:33         ` Amy Grinn
2024-03-07 14:49           ` Ihor Radchenko
2024-03-07 14:04 ` Ihor Radchenko
2024-03-07 15:06   ` Amy Grinn
2024-04-08 14:04   ` [FR] :noweb-wrap header arg Amy Grinn
2024-04-11 14:03     ` Ihor Radchenko
2024-04-11 18:46       ` Amy Grinn
2024-04-13 13:17         ` Ihor Radchenko

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  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=s31r0gowbbn.fsf@gmail.com \
    --to=grinn.amy@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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

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