emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [FR] :noweb-wrap header arg


From: Amy Grinn
Subject: Re: [FR] :noweb-wrap header arg
Date: Wed, 22 May 2024 19:17:48 -0400
User-agent: Gnus/5.13 (Gnus v5.13)

Ihor Radchenko <yantar92@posteo.net> writes:

> Amy Grinn <grinn.amy@gmail.com> writes:
>
>>> +1
>>> You may even use obsolete alias (add it to lisp/org-compat.el)
>>
>> Here's a patch to rename org-babel-noweb-wrap to
>> org-babel-noweb-make-regexp.
>
> Thanks!
> News entry is not necessary here - we are just renaming a function.
> Otherwise, the patch looks good.
> I am not yet merging it though - let's have all the patches you plan for
> the new noweb-wrap argument first and then apply them together.

Got it, not a problem!  I've attached both patches here.

Regarding the other conversation,

>>>> +        (while (< (point) (point-max))
>>>> +          (unless (looking-at " *\"\\([^\"]+\\)\" *")
>>>> +            (looking-at " *\\([^ ]+\\)"))
>>>
>>> May you please explain the rationale behind this regexp? AFAIU, it
>>> implies that you want to allow whitespace characters inside :noweb-wrap
>>> boundaries. But I do not think that we need to complicate things so much.
>>
>> That is exactly what I was going for.  I thought about the ways this
>> could be used and the most general-purpose, non-syntax-breaking,
>> easily-recognizable way I could think of was to use the language's
>> line-comment construct followed by the standard << >> characters.
>>
>> # <<foo>>
>> ;; <<bar>>
>> // <<baz>>
>>
>> I can see how it might be harder to maintain to allow whitespace in the
>> noweb-wrap header arg.  I could create a separate org-parse-arg-list
>> function to ease that burden somewhat.  My opinion is that having the
>> option to use the examples above is preferable to using non-standard
>> wrappers, from a third-person point-of-view.
>
> Makes sense. Also, see a similar idea being discussed in
> https://list.orgmode.org/orgmode/87o7jlzxgn.fsf@localhost/
>
> I recommend the following:
>
> If the value starts from ", use Elisp's `read':
>    |"# <<" ">>"
>    (read (current-buffer)) ; => "# <<"
>    otherwise, consider read until the first whitespace.
>    |#<<; >>;
>    (re-search-forward (rx (1+ (not whitespace))))
>    #<<;|
>
> However, there may be edge cases like
>
> "<< >>"
> "<< >>
> << << >>
> << "asd" >>

I didn't implement this recommendation yet; I still think the regex is a
more clear way of putting it, even without using a temporary buffer:

    ;; If a pair of " is found separated by one or more
    ;; characters, capture those characters as a group
    (unless (eq i (string-match (rx (* space) ?\"
                                    (group (+ (not ?\")))
                                    ?\" (* space))
                                raw i))
      ;; Otherwise, capture the next non-whitespace group of
      ;; characters
      (string-match (rx (* space) (group (* (not space))) (* space))
                    raw i))

Let me know what you think!

Attachment: 0001-lisp-ob-core.el-org-babel-noweb-wrap-renamed-to-org-.patch
Description: rename to org-babel-noweb-make-regexp

Attachment: 0002-org-babel-New-header-argument-noweb-wrap.patch
Description: new header argument :noweb-wrap

--
Best,

Amy

reply via email to

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