turning autoformatting on and off

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

turning autoformatting on and off

Kyle Wheeler
In general, email signatures are supposed to be separated from the rest
of the text by "-- ". This is a problem for folks like me who edit email
in vim with "aw" in the formatoptions variable.

I would like to make it so that vim knows that a "-- " line should not
be line-wrapped.

The closest I've come is a function like the following (I got it from
Bob Bell on the mutt-dev list), but it doesn't seem to work all the time
(among other things, it relies on updatetime being very small). Does
anyone have any idea how to do it so that I can accidentally leave a
space at the end of the last line of my email, and not get my signature
reformatted?

Here's what I'm using now that doesn't seem to quite do it:

function~ s:flowed_context()
    if getline(line(".")) =~ "^-- "
        set formatoptions-=aw
    else
        set formatoptions+=aw
    endif
endfunction
function! s:ft_mail()
    "First, mail prefs
    set nosi textwidth=72 expandtab comments+=nb:> formatoptions+=n
    "change updatetime so CursorHold gets used conveniently
    set updatetime=100
    " I don't have a clue how augroups work, but this seems to...
    augroup Mail
        au!
        au CursorHold * call <SID>flowed_context()
    augroup END
endfunc

Thanks,
~Kyle
--
Real Programmers consider "what you see is what you get" to be just as
bad a concept in Text Editors as it is in women. No, the Real Programmer
wants a "you asked for it, you got it" text editor---complicated,
cryptic, powerful, unforgiving, dangerous.
-- Unknown

signature.asc (203 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: turning autoformatting on and off

Suresh Govindachar`
 Kyle Wheeler Sent on 8 Jun 2005 17:42:13 -0500:

> In general, email signatures are supposed to be separated from the
> rest of the text by "-- ". This is a problem for folks like me who
> edit email in vim with "aw" in the formatoptions variable.
>
> I would like to make it so that vim knows that a "-- " line should
> not be line-wrapped.
>
> The closest I've come is a function like the following (I got it
> from Bob Bell on the mutt-dev list), but it doesn't seem to work
> all the time (among other things, it relies on updatetime being
> very small).

Untested suggestion:  

    Instead of the present au CursorHold, how about
    mapping <CR> to "call flowed_context() and then do <CR>"?

> Does anyone have any idea how to do it so that I can accidentally
> leave a space at the end of the last line of my email, and not get
> my signature reformatted?
>
> Here's what I'm using now that doesn't seem to quite do it:
>
> function~ s:flowed_context()
>     if getline(line(".")) =~ "^-- "
Testing for "^--\s\s*" in case you accidentally leave even
more space.

>         set formatoptions-=aw
>     else
>         set formatoptions+=aw
>     endif
> endfunction
> function! s:ft_mail()
>     "First, mail prefs
>     set nosi textwidth=72 expandtab comments+=nb:> formatoptions+=n
>     "change updatetime so CursorHold gets used conveniently
>     set updatetime=100
>     " I don't have a clue how augroups work, but this seems to...
>     augroup Mail
>         au!
>         au CursorHold * call <SID>flowed_context()
>     augroup END
> endfunc
>
> Thanks,
> ~Kyle

--Suresh

Reply | Threaded
Open this post in threaded view
|

Re: turning autoformatting on and off

Kyle Wheeler
On Wednesday, June  8 at 11:29 PM, quoth Suresh Govindachar:

> Kyle Wheeler Sent on 8 Jun 2005 17:42:13 -0500:
>
>> In general, email signatures are supposed to be separated from the
>> rest of the text by "-- ". This is a problem for folks like me who
>> edit email in vim with "aw" in the formatoptions variable.
>>
>> I would like to make it so that vim knows that a "-- " line should
>> not be line-wrapped.
>>
>> The closest I've come is a function like the following (I got it
>> from Bob Bell on the mutt-dev list), but it doesn't seem to work all
>> the time (among other things, it relies on updatetime being very
>> small).
>
> Untested suggestion:
>
>    Instead of the present au CursorHold, how about mapping <CR> to
>    "call flowed_context() and then do <CR>"?
Hmm, the thing is, text gets reflowed every time any character is
inserted, not just <CR>'s.

>> Does anyone have any idea how to do it so that I can accidentally
>> leave a space at the end of the last line of my email, and not get my
>> signature reformatted?
>>
>> Here's what I'm using now that doesn't seem to quite do it:
>>
>> function~ s:flowed_context()
>>     if getline(line(".")) =~ "^-- "
> Testing for "^--\s\s*" in case you accidentally leave even more space.

Not a bad thought.

It just occurred to me to check the preceeding and following lines for
"-- " sequences as well. This seems to be more robust, but still has one
key problem: in insert mode, flowed_context() doesn't get called.

There is also the problem, of course, that if just before the "-- " line
there is a long paragraph that has an extraneous space at the end, when
text is inserted earlier into that paragraph, the auto-formatting will
nab the "-- " line, along with my signature.

Unfortunately, in the long-paragraph case, simply toggling the
formatoptions isn't enough, because I do want the long paragraph
formatted, I just want the "-- " recognized as a paragraph delimiter.

Does anyone know how do I go about setting the paragraph delimiters?

~Kyle
--
Unthinking respect for authority is the greatest enemy of truth.
-- Albert Einstein

signature.asc (203 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: turning autoformatting on and off

Suresh Govindachar`
In reply to this post by Suresh Govindachar`
Actually, instead of messing with formatoptions, here's a
simpler way to achieve what you want (have tested it):

   imap <buffer> <cr> <esc>:s/^--\s\s*$/--/e<cr>o

A good place for the above line would be in the file:
      vimfiles/after/ftplugin/mail.vim

--Suresh

Suresh Govindachar sent on 8 Jun 2005 23:29:40 +0000:

 Kyle Wheeler Sent on 8 Jun 2005 17:42:13 -0500:

> In general, email signatures are supposed to be separated from the
> rest of the text by "-- ". This is a problem for folks like me who
> edit email in vim with "aw" in the formatoptions variable.

--Suresh

Suresh Govindachar sent on 8 Jun 2005 23:29:40 +0000:

 Kyle Wheeler Sent on 8 Jun 2005 17:42:13 -0500:

> In general, email signatures are supposed to be separated from the
> rest of the text by "-- ". This is a problem for folks like me who
> edit email in vim with "aw" in the formatoptions variable.
>
> I would like to make it so that vim knows that a "-- " line should
> not be line-wrapped.
>
> The closest I've come is a function like the following (I got it
> from Bob Bell on the mutt-dev list), but it doesn't seem to work
> all the time (among other things, it relies on updatetime being
> very small).

Untested suggestion:  

    Instead of the present au CursorHold, how about
    mapping <CR> to "call flowed_context() and then do <CR>"?

> Does anyone have any idea how to do it so that I can accidentally
> leave a space at the end of the last line of my email, and not get
> my signature reformatted?
>
> Here's what I'm using now that doesn't seem to quite do it:
>
> function~ s:flowed_context()
>     if getline(line(".")) =~ "^-- "
Testing for "^--\s\s*" in case you accidentally leave even
more space.

>         set formatoptions-=aw
>     else
>         set formatoptions+=aw
>     endif
> endfunction
> function! s:ft_mail()
>     "First, mail prefs
>     set nosi textwidth=72 expandtab comments+=nb:> formatoptions+=n
>     "change updatetime so CursorHold gets used conveniently
>     set updatetime=100
>     " I don't have a clue how augroups work, but this seems to...
>     augroup Mail
>         au!
>         au CursorHold * call <SID>flowed_context()
>     augroup END
> endfunc
>
> Thanks,
> ~Kyle

--Suresh

Reply | Threaded
Open this post in threaded view
|

Re: turning autoformatting on and off

Kyle Wheeler
On Saturday, June 11 at 02:25 PM, quoth Suresh Govindachar:
>Actually, instead of messing with formatoptions, here's a
>simpler way to achieve what you want (have tested it):
>
>   imap <buffer> <cr> <esc>:s/^--\s\s*$/--/e<cr>o
>
>A good place for the above line would be in the file:
>      vimfiles/after/ftplugin/mail.vim

Heh. I don't like remapping <cr> because I could have an email where I
don't press it. Maybe something along the lines of

    augroup Mail
        au!
        au BufEnter * %s/^--\s\s*$/--/g | normal gg
    augroup END

But it seems to me this is cheating, somehow. Maybe not.

~Kyle
--
When ideas fail, words come in very handy.
-- Johann Wolfgang von Goethe

signature.asc (203 bytes) Download Attachment