OCamlPro / ocp-indent

Indentation tool for OCaml, to be used from editors like Emacs and Vim.
http://www.typerex.org/ocp-indent.html
Other
200 stars 63 forks source link

Undoing indent moves cursor to top of file (Vim) #92

Closed jordwalke closed 9 years ago

jordwalke commented 10 years ago

Even if only indenting a visually selected range, undoing an indentation (that was originally caused by =) causes the cursor to move to the top of the file.

smondet commented 10 years ago

Hi, I have the same issue (vim 7.3 and 7.4), I did not manage to fix ocp-indent.vim but I found a temporary hack to put in one's .vimrc:

map <silent> u :call MyUndo()<CR>
function MyUndo()
    let _view=winsaveview()
    :undo
    call winrestview(_view)
endfunction

map <silent> <c-r> :call MyRedo()<CR>
function MyRedo()
    let _view=winsaveview()
    :redo
    call winrestview(_view)
endfunction

hope it helps!

jordwalke commented 10 years ago

Unfortunately, that also resets the cursor position for other undo/redos that actually should move the cursor position.

smondet commented 10 years ago

you're right the hack is far too greedy

I've been trying https://github.com/def-lkb/ocp-indent-vim (instead of the .vim provided by ocp-indent) it seems to work very well (it depends on Python and on other files installed with merlin)

trefis commented 10 years ago

it depends on Python and on other files installed with merlin

Actually, from what I can see the latest version only depends on python; the "magic" that was to be done by vimbufsync has been removed.

jordwalke commented 10 years ago

What is the difference between the two? Why are they named the same thing?

jordwalke commented 10 years ago

I just tried that repo, and it works great. How can we get people to use it instead of whatever comes directly out of OPAM?

AltGr commented 10 years ago

Actually, if there are now no further dependencies than Python, it may well be ok to integrate def-lkb/ocp-indent-vim into ocp-indent/tools for easier installation. If that sounds ok ?

jordwalke commented 10 years ago

https://github.com/def-lkb/ocp-indent-vim has been working wonderfully for me, btw (with the following config):

function! Preserve(command)
  " Preparation: save last search, and cursor position.
  let _s=@/
  let l = line(".")
  let c = col(".")
  " Do the business:
  execute a:command
  " Clean up: restore previous search history, and cursor position
  let @/=_s
  call cursor(l, c)
endfunction
nmap <D-M> :call Preserve("normal gg=G")<CR>