using formatoptions +a autoflow

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

using formatoptions +a autoflow

ericmsmith
I like to use autoflow but wish to have it automatically switch
off when editing structured paragraphs.

For example when editing emails, I do not want autoflow to
reformat the headers or the signature.

How could I have it switch off when editing these paragraphs
and on again with other text?

--
Eric Smith

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: using formatoptions +a autoflow

Paul Isambert
Eric Smith <[hidden email]> a écrit:
> I like to use autoflow but wish to have it automatically switch
> off when editing structured paragraphs.
>
> For example when editing emails, I do not want autoflow to
> reformat the headers or the signature.
>
> How could I have it switch off when editing these paragraphs
> and on again with other text?

You could try something like this, which is quite hackish, though:

    function s:checkformat ()
      let ln = line('.')
      let signature = 0
      while ln > 1
        if getline(ln) == '--'
          let signature = 1
          break
        end
        let ln -= 1
      endwhile
      if signature
        set formatoptions-=a
      else
        set formatoptions+=a
      end
      echo &formatoptions
    endfunction

    augroup checkformat
      au!
      " Perhaps you'll want that more specific, e.g. *.eml
      au InsertEnter * call s:checkformat()
    augroup END

This checks whether one of the lines above the current one is “--”,
and if so removes the “a” in “formatoptions”, because it means you’re
in the email signature. The checking occurs whenever you go from
normal to insert mode, so it won’t work when you move from the email’s
body to the signature without leaving and reentering insert mode. To
be sure you miss as few occasions as possible, you could add the
function to the “CursorMovedI” autocommand or even “InsertCharPre”,
but I don’t know how much it would affect performance. Technically you
could check the kind of paragraph you’re in each time the cursor is
moved.

I’ll let you find the rest of the function for header fields :)

Best,
Paul

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: using formatoptions +a autoflow

Benjamin Fritz
In reply to this post by ericmsmith
On Thursday, July 18, 2013 3:41:35 PM UTC-5, Eric Smith wrote:

> I like to use autoflow but wish to have it automatically switch
>
> off when editing structured paragraphs.
>
>
>
> For example when editing emails, I do not want autoflow to
>
> reformat the headers or the signature.
>
>
>
> How could I have it switch off when editing these paragraphs
>
> and on again with other text?
>

I think I'd approach this in one of two ways:

1. Define normal text as a text, and "structured" text as a comment (if possible). Then you can use the 'c' and 't' flags in formatoptions to control where it applies.
2. Create my own formatexpr function that checks on the region it's in before making any changes.

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: using formatoptions +a autoflow

ericmsmith
Cool Ben

I will give this a go. It will hopefully reduce my expletive
count when editing emails :)

--
Eric Smith

Ben Fritz wrote on Fri-19-Jul 13  2:04PM

> On Thursday, July 18, 2013 3:41:35 PM UTC-5, Eric Smith wrote:
> > I like to use autoflow but wish to have it automatically switch
> >
> > off when editing structured paragraphs.
> >
> >
> >
> > For example when editing emails, I do not want autoflow to
> >
> > reformat the headers or the signature.
> >
> >
> >
> > How could I have it switch off when editing these paragraphs
> >
> > and on again with other text?
> >
>
> I think I'd approach this in one of two ways:
>
> 1. Define normal text as a text, and "structured" text as a comment (if possible). Then you can use the 'c' and 't' flags in formatoptions to control where it applies.
> 2. Create my own formatexpr function that checks on the region it's in before making any changes.
>
> --
> --
> You received this message from the "vim_use" 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_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> For more options, visit https://groups.google.com/groups/opt_out.
>

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.