Thursday, July 18, 2013

Re: using formatoptions +a autoflow

Eric Smith <es@fruitcom.com> 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 vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment