Re: Using auto-format with LaTeX

60 views
Skip to first unread message

Christian Brabandt

unread,
Feb 13, 2013, 5:54:09 PM2/13/13
to vim...@googlegroups.com, vim...@googlegroups.com, Marcin Szamotulski
Hi Marcin!

On So, 10 Feb 2013, Marcin Szamotulski wrote:

> On 12:19 Sat 09 Feb , Zyad wrote:
> > Hi,
> >
> > I'm finding the auto-format option very attractive (setl fo+=a), but I'm having trouble getting it to work nicely when editing LaTeX documents.
> >
> > More specifically, I'd like to make it aware of LaTeX keywords so that, for example, when writing the following,
> >
> > This is a paragraph that is properly
> > formatted to have a textwidth of 40.
> > 'auto-format' helps maintain it in a
> > formatted form, even if I edit parts of
> > it.
> > \begin{equation}
> > z^2 = x^2 + y^2
> > \end{equation
> >
> > as soon as I enter '\', the cursor moves to the previous line. Is it possible to have auto-format understand that a keyword like '\begin{' should not be considered part of the paragraph before it? I'm aware of formatoptions' 'w' flag, but it is inconvenient for me since the document is usually edited by others.
> >
> > Thanks,
> > Zyad
>
> The problem is that vim the 'paragraphs' setting accepts only nroff
> macros. ATP (http://atp-vim.sf.net) defined a map gW which detects
> paragraphs and formats them - it is still not what you (and me) wanted
> but it a bit better.

Personally, I have never used nroff macros and I think the 'paragraphs'
and 'sections' setttings are pretty useless, if you can't use regular
expressions.

Does anything speak against having a special casing of the 'paragraphs'
and 'sections' option to use a regular expression pattern to test
against if it starts with a '/'?

Attached is a toy patch.

regards,
Christian
--
Eigentlich wei� man nur, wenn man wenig wei�; mit dem Wissen
w�chst der Zweifel.
-- Goethe, Maximen und Reflektionen, Nr. 418
paragraphs_re.diff

Marcin Szamotulski

unread,
Feb 14, 2013, 1:36:26 AM2/14/13
to vim...@googlegroups.com, vim...@googlegroups.com
Thanks (once again) for the patch!

Here are a few ideas:

It would be nice to end paragraph line before the match for some
patterns. For example if you have

lorem ipsum lorem ipsum
lorem ipsum lorem ipsum
lorem ipsum lorem ipsum
\section{New Aproach}

adding &para='/\\section' and using d} will delete one line to
much. But this should be only for some patters hence this will
require that &para is a list of patterns with some kind of
modifiers, or one would have to make support for multiline patterns.
Using something like &para='/\n\s*\\section' is not working with the
patch.



With the patch and &para='/^\zs\s*$' and the following text:

lorem ipsum lorem ipsum
lorem ipsum lorem ipsum


lorem ipsum lorem ipsum
lorem ipsum lorem ipsum


}, and { stop on the first met empty line, i.e. } will stop on the
top one, and { on the bottom one. But I think this is not a big
deal, though it is inconsistent with the nroff setting. Again
recognising multiple line patterns would help. Something like:

let &para='/^\_s*$'

A solution: after matching the line against the &para pattern and moving
the cursor to that line use something like:
:call search(&para, 'bc')


Z wyrazami szacunku :)
Marcin

Bram Moolenaar

unread,
Feb 14, 2013, 4:08:22 PM2/14/13
to Christian Brabandt, vim...@googlegroups.com, vim...@googlegroups.com, Marcin Szamotulski
It's an idea. Several users have asked for a more flexible way to
define paragraph boundaries.

I think the help needs some more work. How is the regular expression
used? What if a two-character part before it already matched?
An example would be helpful.


--
A disclaimer for the disclaimer:
"and before I get a huge amount of complaints , I have no control over the
disclaimer at the end of this mail :-)" (Timothy Aldrich)

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Christian Brabandt

unread,
Feb 16, 2013, 4:14:05 PM2/16/13
to vim...@googlegroups.com, vim...@googlegroups.com, Marcin Szamotulski
Hi Marcin!

On Do, 14 Feb 2013, Marcin Szamotulski wrote:

> Thanks (once again) for the patch!
>
> Here are a few ideas:
>
> It would be nice to end paragraph line before the match for some
> patterns. For example if you have
>
> lorem ipsum lorem ipsum
> lorem ipsum lorem ipsum
> lorem ipsum lorem ipsum
> \section{New Aproach}
>
> adding &para='/\\section' and using d} will delete one line to
> much. But this should be only for some patters hence this will
> require that &para is a list of patterns with some kind of
> modifiers, or one would have to make support for multiline patterns.
> Using something like &para='/\n\s*\\section' is not working with the
> patch.

Oh yes, the motion is exclusive. The old patch did not allow multi-line
patterns. I attach a new, slightly different one. Try this one.
>
>
>
> With the patch and &para='/^\zs\s*$' and the following text:
>
> lorem ipsum lorem ipsum
> lorem ipsum lorem ipsum
>
>
> lorem ipsum lorem ipsum
> lorem ipsum lorem ipsum
>
>
> }, and { stop on the first met empty line, i.e. } will stop on the
> top one, and { on the bottom one.

Yes, paragraph motion is a little bit more clever than I initially
thought. Try the updated patch, but note, that the pattern /^\s*$ does
not work as expected (see the bug report earlier today:
https://groups.google.com/forum/?fromgroups=#!topic/vim_dev/4Qzsf9CkMkE)

The updated patch, works as expected, at least, if you go backwards with
the pattern /^$ but not if you go forward.

If the patch works for you and we don't find any issues I'll start
creating test files. BTW: for documentation updates, what would you set
the paragraphs/section options for latex? So I can document it as
example in the help file.

> Z wyrazami szacunku :)

I had to look up this one. Are you Polish?

regards,
Christian
--
Ich verw�nsche die, die aus dem Irrtum eine eigene Welt machen
und doch unabl�ssig fordern, dass der Mensch n�tzlich sein m�sse.
-- Goethe, Maximen und Reflektionen, Nr. 263
Reply all
Reply to author
Forward
0 new messages