On Mon, Feb 17, 2014 at 1:20 PM, Yan Shoshitaishvili <[email protected]>wrote:

> Hello guys,
>
> I'm writing a plugin (https://github.com/zardus/fuckpep8) that, when the
> file is saved, retabs tabs to spaces (in BufWritePre), saves, then retabs
> spaces to tabs (in BufWritePost). My first version of this had an annoyance
> where, after every save, two new undo entries would be added (one for each
> conversion). I addressed this by prepending the retabs with undojoin.
>
> This would be a pretty nice solution, except that an undo like this still
> "changes" almost every line in the file. The result is that when I hit
> undo, the buffer scrolls all the way to the top, even though in the end,
> maybe only one or two lines (whatever the edit that the conversions were
> undojoined with) change.
>

Wouldn't something like this could work?

let ul=&undolevels             " save previous undolevels
let win = winsaveview()        " save cursor position
setlocal undolevels=-1         " disable undo
setlocal expandtab
retab                          " convert tab to space
setlocal noexpandtab
exec 'setlocal undolevels='.ul " restore undolevels
call winrestview(win)          " restore cursor position

-- 
-- 
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.

Raspunde prin e-mail lui