emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: noweb-start and noweb-end header args


From: termux
Subject: Re: noweb-start and noweb-end header args
Date: Tue, 05 Mar 2024 17:41:48 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

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

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 via email to

[Prev in Thread] Current Thread [Next in Thread]