On Fri, Mar 27, 2026 at 20:18 (-0300), Jim wrote:

> On Fri, Mar 27, 2026 at 22:46 (+0100), Arash Esbati wrote:

>> Jim <[email protected]> writes:

>>> And there is one more nasty problem, which my .* would not have taken care
>>> of.  When the argument is the   [...]   version, it can extend over
>>> multiple lines.  So someone could say (for example)
>>>         \startdocument[title={Blah blah},
>>> before=<something>,
>>> after=<someOtherThing>]
>>> So it may need something a bit more complex to skip a   [...]  argument.

>>> Having said that, a solution that works in most cases is nicer than no
>>> solution at all.

>> As Jamie Zawinski once said:

>> Some people, when confronted with a problem, think “I know, I'll use
>> regular expressions.”  Now they have two problems.

> Ha!  Good one!

>> How about this:

>> --8<---------------cut here---------------start------------->8---
>> diff --git a/context.el b/context.el
>> index 64f1179a..9a396e25 100644
>> --- a/context.el
>> +++ b/context.el
>> @@ -1257,14 +1257,17 @@ header is at the start of a line."
>>    (concat
>>     (regexp-quote TeX-esc)
>>     (ConTeXt-environment-start-name)
>> -   ConTeXt-text))
>> +   (regexp-opt `( ,ConTeXt-text "component" "document" "MPpage"
>> +                  "product" "TEXpage"))
>> +   "\\(?:[ \t]*\\[[^]]+\\]\\|.*$\\)"))

Sorry for the incomplete last response.

The good news: with your new and improved regexp, C-c C-r does The Right
Thing in my tests.  I tested with a simple
        \startcomponent abc
as well as
        \startcomponent [title=abc,
        otherstuff]
and all is good.

(I didn't try with
        \startcomponent [title={This has a ] of all things},
        otherstuff]
but sometimes people who do really weird things deserve what they get.)


However, when there is a master file, doing C-c C-b in the chapter file
creates a _region_.tex file which has no content from the TeX-master file.

(I am guessing this is not the expected behaviour?  Presumably (*cough*) in
LaTeX if you do C-c C-b in a "chapter" file, AUCTeX runs off to the master
file to find the preamble?)

Not going to the master file for its preamble will work for the case where
each sub-file itself has all the needed
        \environment <file>
commands in its own preamble, but I think that is not a nice structured way
to do things.

Summary: works perfect for C-c C-r
         not for C-c C-b

Thanks.
                                 Jim

Reply via email to