all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* noweb-start and noweb-end header args
@ 2024-03-05 19:22 Amy Grinn
  2024-03-05 22:41 ` termux
                   ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: Amy Grinn @ 2024-03-05 19:22 UTC (permalink / raw)
  To: emacs-orgmode

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


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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: noweb extra header args --]
[-- Type: text/x-patch, Size: 1480 bytes --]

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

^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2024-07-01  9:56 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-05 19:22 noweb-start and noweb-end header args Amy Grinn
2024-03-05 22:41 ` termux
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
2024-05-11 16:01       ` Amy Grinn
2024-05-12 10:48         ` Ihor Radchenko
2024-05-22 23:17           ` Amy Grinn
2024-05-23 11:27             ` Ihor Radchenko
2024-07-01  9:56               ` Ihor Radchenko

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.