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
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -5186,6 +5186,8 @@
global
Specifies the nroff macros that separate paragraphs. These are pairs
of two letters (see |object-motions|).
+ If it starts with a slash, the rest of the option is taken as regular
+ expression to test against.
*'paste'* *'nopaste'*
'paste' boolean (default off)
@@ -5810,6 +5812,9 @@
two letters (See |object-motions|). The default makes a section start
at the nroff macros ".SH", ".NH", ".H", ".HU", ".nh" and ".sh".
+ If it starts with a slash, the rest of the option is taken as regular
+ expression to test against.
+
*'secure'* *'nosecure'* *E523*
'secure' boolean (default off)
global
diff --git a/src/search.c b/src/search.c
--- a/src/search.c
+++ b/src/search.c
@@ -2726,6 +2726,7 @@
/*
* check if the string 's' is a nroff macro that is in option 'opt'
+ * if 'opt' starts with '/' perform a regular expression search
*/
static int
inmacro(opt, s)
@@ -2734,23 +2735,39 @@
{
char_u *macro;
- for (macro = opt; macro[0]; ++macro)
+ if (*opt == '/')
{
- /* Accept two characters in the option being equal to two characters
- * in the line. A space in the option matches with a space in the
- * line or the line having ended. */
- if ( (macro[0] == s[0]
- || (macro[0] == ' '
- && (s[0] == NUL || s[0] == ' ')))
- && (macro[1] == s[1]
- || ((macro[1] == NUL || macro[1] == ' ')
- && (s[0] == NUL || s[1] == NUL || s[1] == ' '))))
- break;
- ++macro;
- if (macro[0] == NUL)
- break;
+ regmatch_T regmatch;
+
+ regmatch.regprog = vim_regcomp(++opt, RE_MAGIC + RE_STRING);
+ if (regmatch.regprog != NULL)
+ {
+ regmatch.rm_ic = p_ic;
+ return vim_regexec_nl(®match, s, 0);
+ }
+
}
- return (macro[0] != NUL);
+ else
+ {
+ for (macro = opt; macro[0]; ++macro)
+ {
+ /* Accept two characters in the option being equal to two characters
+ * in the line. A space in the option matches with a space in the
+ * line or the line having ended. */
+ if ( (macro[0] == s[0]
+ || (macro[0] == ' '
+ && (s[0] == NUL || s[0] == ' ')))
+ && (macro[1] == s[1]
+ || ((macro[1] == NUL || macro[1] == ' ')
+ && (s[0] == NUL || s[1] == NUL || s[1] == ' '))))
+ break;
+ ++macro;
+ if (macro[0] == NUL)
+ break;
+ }
+ return (macro[0] != NUL);
+ }
+ return 0; /* make gcc shut up ;) */
}
/*
@@ -2772,6 +2789,8 @@
if (*s == '.' && (inmacro(p_sections, s + 1) ||
(!para && inmacro(p_para, s + 1))))
return TRUE;
+ if (*p_sections == '/' || *p_para == '/')
+ return inmacro(p_sections, s) || (!para && inmacro(p_para, s));
return FALSE;
}