From 3d255535886bb4bae8114f37ebbad11597dd58d6 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Fri, 27 Jan 2012 16:04:09 -0700 Subject: [PATCH] allow customization of the noweb reference syntax Thanks to Sean O'Halpin for suggesting this change. * lisp/ob-tangle.el (org-babel-tangle-clean): Use the customizable noweb wrappers. * lisp/ob.el (org-babel-noweb-wrap-start): Begin a noweb reference. (org-babel-noweb-wrap-end): End a noweb reference. (org-babel-noweb-wrap): Apply the customizable noweb wrappers. (org-babel-expand-noweb-references): Use the customizable noweb wrappers. --- lisp/ob-tangle.el | 2 +- lisp/ob.el | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index d7c4d7e9c..cf507c0a8 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -281,7 +281,7 @@ references." (interactive) (goto-char (point-min)) (while (or (re-search-forward "\\[\\[file:.*\\]\\[.*\\]\\]" nil t) - (re-search-forward "<<[^[:space:]]*>>" nil t)) + (re-search-forward (org-babel-noweb-wrap "[^[:space:]]*") nil t)) (delete-region (save-excursion (beginning-of-line 1) (point)) (save-excursion (end-of-line 1) (forward-char 1) (point))))) diff --git a/lisp/ob.el b/lisp/ob.el index 70c258f76..62969ec5a 100644 --- a/lisp/ob.el +++ b/lisp/ob.el @@ -120,6 +120,21 @@ be used." :group 'org-babel :type 'string) +(defcustom org-babel-noweb-wrap-start "<<" + "String used to begin a noweb reference in a code block. +See also `org-babel-noweb-wrap-end'." + :group 'org-babel + :type 'string) + +(defcustom org-babel-noweb-wrap-end ">>" + "String used to end a noweb reference in a code block. +See also `org-babel-noweb-wrap-start'." + :group 'org-babel + :type 'string) + +(defun org-babel-noweb-wrap (regexp) + (concat org-babel-noweb-wrap-start regexp org-babel-noweb-wrap-end)) + (defvar org-babel-src-name-regexp "^[ \t]*#\\+name:[ \t]*" "Regular expression used to match a source name line.") @@ -2163,7 +2178,8 @@ block but are passed literally to the \"example-block\"." (with-temp-buffer (insert body) (goto-char (point-min)) (setq index (point)) - (while (and (re-search-forward "<<\\([^ \t].+?[^ \t]\\|[^ \t]\\)>>" + (while (and (re-search-forward (org-babel-noweb-wrap + "\\([^ \t].+?[^ \t]\\|[^ \t]\\)") nil t)) (save-match-data (setf source-name (match-string 1))) (save-match-data (setq evaluate (string-match "\(.*\)" source-name))) @@ -2234,7 +2250,7 @@ block but are passed literally to the \"example-block\"." ;; possibly raise an error if named block doesn't exist (if (member lang org-babel-noweb-error-langs) (error "%s" (concat - "<<" source-name ">> " + (org-babel-noweb-wrap source-name) "could not be resolved (see " "`org-babel-noweb-error-langs')")) ""))) -- 2.11.4.GIT