[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
noweb-start and noweb-end header args
From: |
Amy Grinn |
Subject: |
noweb-start and noweb-end header args |
Date: |
Tue, 05 Mar 2024 14:22:07 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
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:
#+name: firewall-safe-mode
#+begin_src sh
echo "Firewall is now in safe mode."
#+end_src
#+name: firewall
#+begin_src sh :noweb yes :noweb-start <<< :noweb-end >>>
safe_mode () {
echo "Error encountered, switching to safe mode."
<<<firewall-safe-mode>>>
exit 1
}
setup-firewall || safe_mode
#+end_src
#+begin_src sh :noweb yes :noweb-start ":-) " :noweb-end " (-:" :tangle
"test.sh"
# Setup firewall
:-) firewall (-:
# Do other things
#+end_src
Here is a simple way to implement this feature.
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 4dcfbd3b0..0be19ff06 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -194,15 +194,17 @@ 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)
+ (concat (regexp-quote (or (cdr (assq :noweb-start (nth 2 info)))
+ org-babel-noweb-wrap-start))
(or regexp "\\([^ \t\n]\\(?:.*?[^ \t\n]\\)?\\)")
- (regexp-quote org-babel-noweb-wrap-end)))
+ (regexp-quote (or (cdr (assq :noweb-end (nth 2 info)))
+ org-babel-noweb-wrap-end))))
(defvar org-babel-src-name-regexp
"^[ \t]*#\\+name:[ \t]*"
@@ -3116,7 +3118,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)))
- noweb-start and noweb-end header args,
Amy Grinn <=
- Re: noweb-start and noweb-end header args, termux, 2024/03/05
- Re: noweb-start and noweb-end header args, Ihor Radchenko, 2024/03/06
- Re: noweb-start and noweb-end header args, Amy Grinn, 2024/03/06
- Re: noweb-start and noweb-end header args, Ihor Radchenko, 2024/03/06
- Re: noweb-start and noweb-end header args, Amy Grinn, 2024/03/06
- Re: noweb-start and noweb-end header args, Ihor Radchenko, 2024/03/06
- Re: noweb-start and noweb-end header args, Amy Grinn, 2024/03/06
- Re: noweb-start and noweb-end header args, Ihor Radchenko, 2024/03/07
- Re: noweb-start and noweb-end header args, Amy Grinn, 2024/03/06
- Re: noweb-start and noweb-end header args, Ihor Radchenko, 2024/03/07