emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [Babel] [PATCH] Customize regular expression to match noweb references
@ 2012-01-26  5:59 Sean O'Halpin
  2012-01-27 23:05 ` Eric Schulte
  0 siblings, 1 reply; 3+ messages in thread
From: Sean O'Halpin @ 2012-01-26  5:59 UTC (permalink / raw)
  To: Org Mode

Hi,

Here's a patch I'm using to change the default regular expression used
to match noweb references.
The default regular expression "<<\\(.+?\\)>>" conflicts with Ruby
syntax and confuses syntax highlighting.
I now set this to "«\\(.+?\\)»", i.e. using guillemots instead
(AltGr-z and AltGr-x on my keyboard).

Regards,
Sean


Customizable regular expression to match noweb references.
---
 lisp/ob-tangle.el |    4 +++-
 lisp/ob.el        |    7 ++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
index d7c4d7e..4148774 100644
--- a/lisp/ob-tangle.el
+++ b/lisp/ob-tangle.el
@@ -281,12 +281,14 @@ 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-regexp nil t))
     (delete-region (save-excursion (beginning-of-line 1) (point))
                    (save-excursion (end-of-line 1) (forward-char 1) (point)))))

 (defvar org-stored-links)
 (defvar org-bracket-link-regexp)
+(defvar org-babel-noweb-regexp)
+
 (defun org-babel-tangle-collect-blocks (&optional language)
   "Collect source blocks in the current Org-mode file.
 Return an association list of source-code block specifications of
diff --git a/lisp/ob.el b/lisp/ob.el
index 47be708..bbd6209 100644
--- a/lisp/ob.el
+++ b/lisp/ob.el
@@ -113,6 +113,11 @@ remove code block execution from the C-c C-c keybinding."
   :group 'org-babel
   :type 'boolean)

+(defcustom org-babel-noweb-regexp "<<\\(.+?\\)>>"
+  "Regular expression to use to match noweb references."
+  :group 'org-babel
+  :type 'string)
+
 (defcustom org-babel-results-keyword "RESULTS"
   "Keyword used to name results generated by code blocks.
 Should be either RESULTS or NAME however any capitalization may
@@ -2159,7 +2164,7 @@ 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 "<<\\(.+?\\)>>" nil t))
+        (while (and (re-search-forward org-babel-noweb-regexp nil t))
           (save-match-data (setf source-name (match-string 1)))
           (save-match-data (setq evaluate (string-match "\(.*\)" source-name)))
           (save-match-data
-- 
1.7.0.4

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

* Re: [Babel] [PATCH] Customize regular expression to match noweb references
  2012-01-26  5:59 [Babel] [PATCH] Customize regular expression to match noweb references Sean O'Halpin
@ 2012-01-27 23:05 ` Eric Schulte
  2012-01-28 15:34   ` Sean O'Halpin
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Schulte @ 2012-01-27 23:05 UTC (permalink / raw)
  To: Sean O'Halpin; +Cc: Org Mode

Good idea,

I've changed your implementation to rely on two new customization
variables `org-babel-noweb-wrap-start' and `org-babel-noweb-wrap-end' as
this provides more flexibility to the backend implementation to place
constraints on the properties of the noweb names.

In you're situation you will now want to set...
(setq org-babel-noweb-wrap-start "«"
      org-babel-noweb-wrap-end   "»")

Thanks for the great idea,

"Sean O'Halpin" <sean.ohalpin@gmail.com> writes:

> Hi,
>
> Here's a patch I'm using to change the default regular expression used
> to match noweb references.
> The default regular expression "<<\\(.+?\\)>>" conflicts with Ruby
> syntax and confuses syntax highlighting.
> I now set this to "«\\(.+?\\)»", i.e. using guillemots instead
> (AltGr-z and AltGr-x on my keyboard).
>
> Regards,
> Sean
>
>
> Customizable regular expression to match noweb references.
> ---
>  lisp/ob-tangle.el |    4 +++-
>  lisp/ob.el        |    7 ++++++-
>  2 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
> index d7c4d7e..4148774 100644
> --- a/lisp/ob-tangle.el
> +++ b/lisp/ob-tangle.el
> @@ -281,12 +281,14 @@ 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-regexp nil t))
>      (delete-region (save-excursion (beginning-of-line 1) (point))
>                     (save-excursion (end-of-line 1) (forward-char 1) (point)))))
>
>  (defvar org-stored-links)
>  (defvar org-bracket-link-regexp)
> +(defvar org-babel-noweb-regexp)
> +
>  (defun org-babel-tangle-collect-blocks (&optional language)
>    "Collect source blocks in the current Org-mode file.
>  Return an association list of source-code block specifications of
> diff --git a/lisp/ob.el b/lisp/ob.el
> index 47be708..bbd6209 100644
> --- a/lisp/ob.el
> +++ b/lisp/ob.el
> @@ -113,6 +113,11 @@ remove code block execution from the C-c C-c keybinding."
>    :group 'org-babel
>    :type 'boolean)
>
> +(defcustom org-babel-noweb-regexp "<<\\(.+?\\)>>"
> +  "Regular expression to use to match noweb references."
> +  :group 'org-babel
> +  :type 'string)
> +
>  (defcustom org-babel-results-keyword "RESULTS"
>    "Keyword used to name results generated by code blocks.
>  Should be either RESULTS or NAME however any capitalization may
> @@ -2159,7 +2164,7 @@ 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 "<<\\(.+?\\)>>" nil t))
> +        (while (and (re-search-forward org-babel-noweb-regexp nil t))
>            (save-match-data (setf source-name (match-string 1)))
>            (save-match-data (setq evaluate (string-match "\(.*\)" source-name)))
>            (save-match-data

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

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

* Re: [Babel] [PATCH] Customize regular expression to match noweb references
  2012-01-27 23:05 ` Eric Schulte
@ 2012-01-28 15:34   ` Sean O'Halpin
  0 siblings, 0 replies; 3+ messages in thread
From: Sean O'Halpin @ 2012-01-28 15:34 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Org Mode

On Fri, Jan 27, 2012 at 11:05 PM, Eric Schulte <eric.schulte@gmx.com> wrote:
> Good idea,
>
> I've changed your implementation to rely on two new customization
> variables `org-babel-noweb-wrap-start' and `org-babel-noweb-wrap-end' as
> this provides more flexibility to the backend implementation to place
> constraints on the properties of the noweb names.
>
> In you're situation you will now want to set...
> (setq org-babel-noweb-wrap-start "«"
>      org-babel-noweb-wrap-end   "»")
>
> Thanks for the great idea,
>

Seems to work fine. Thanks for implementing it so quickly and thanks
for org-babel!

Regards,
Sean

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

end of thread, other threads:[~2012-01-28 15:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-26  5:59 [Babel] [PATCH] Customize regular expression to match noweb references Sean O'Halpin
2012-01-27 23:05 ` Eric Schulte
2012-01-28 15:34   ` Sean O'Halpin

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