metakirby5 / codi.vim

:notebook_with_decorative_cover: The interactive scratchpad for hackers.
MIT License
3.02k stars 83 forks source link

Syncbind issues in vim 8 #144

Closed lukelbd closed 2 years ago

lukelbd commented 2 years ago

Issue description

Continued from #106. Cursor position syncing fails in vim 8 when the top window line is not the first line of the file.

Here's an example before editing text:

Screen Shot 2022-03-19 at 2 50 04 PM

Then after editing text, the LHS shows the first line of the file (note I use a rephraser to add equals markings):

Screen Shot 2022-03-19 at 2 50 21 PM

The cursor position is only preserved if I ensure codi#update is only ever invoked from the first line using the following function definition and custom autocommands:

" Define kludge
function! s:codi_kludge(trigger)
  return
  if a:trigger
    let winline = line('w0')
    if winline > 1
      let s:codi_view = winsaveview()
      keepjumps 1  " jump to first line
    endif
  else
    if exists('s:codi_view')
      call winrestview(s:codi_view)
      unlet s:codi_view
      normal! kj
    endif
  endif
endfunction
" Add autocommands
augroup codi_mods
  au!
  au User CodiUpdatePre call s:codi_kludge(1)
  au User CodiUpdatePost call s:codi_kludge(0)
augroup END

I also turn on synchronous mode with let g:codi#sync = 1 so that this "kludge" does not cause vim to show the cursor briefly jumping to the first line (which results from the async delay -- otherwise, with set lazyredraw, the cursor movement is not shown). Note that synchronous mode does not resolve this bug.

Tried to implement the "kludge" inside s:codi_handle_done, which I noticed already does lots of line/cursor jumping, but for some reason I couldn't get it to work. Really seems like it should though, since I'm just implementing the exact same logic as in these autocommands... and in fact your existing s:codi_handle_done already has a similar logic...

Environment

Operating system: macOS 12.1

Vim version:

``` VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Dec 26 2021 21:53:24) macOS version - x86_64 Included patches: 1-3901 Compiled by root@Mac-1640554039648.local Huge version without GUI. Features included (+) or not (-): +acl +cursorshape +job +mouse_urxvt +signs +user_commands +arabic +dialog_con +jumplist +mouse_xterm +smartindent +vartabs +autocmd +diff +keymap +multi_byte -sodium +vertsplit +autochdir +digraphs +lambda +multi_lang -sound +virtualedit -autoservername -dnd +langmap -mzscheme +spell +visual -balloon_eval -ebcdic +libcall +netbeans_intg +startuptime +visualextra +balloon_eval_term +emacs_tags +linebreak +num64 +statusline +viminfo -browse +eval +lispindent +packages -sun_workshop +vreplace ++builtin_terms +ex_extra +listcmds +path_extra +syntax +wildignore +byte_offset +extra_search +localmap +perl +tag_binary +wildmenu +channel -farsi -lua +persistent_undo -tag_old_static +windows +cindent +file_in_path +menu +popupwin -tag_any_white +writebackup -clientserver +find_in_path +mksession +postscript -tcl -X11 +clipboard +float +modify_fname +printer +termguicolors -xfontset +cmdline_compl +folding +mouse +profile +terminal -xim +cmdline_hist -footer -mouseshape -python +terminfo -xpm +cmdline_info +fork() +mouse_dec +python3 +termresponse -xsmp +comments +gettext -mouse_gpm +quickfix +textobjects -xterm_clipboard +conceal -hangul_input -mouse_jsbterm +reltime +textprop -xterm_save +cryptv +iconv +mouse_netterm +rightleft +timers +cscope +insert_expand +mouse_sgr -ruby +title +cursorbind +ipv6 -mouse_sysmouse +scrollbind -toolbar system vimrc file: "$VIM/vimrc" user vimrc file: "$HOME/.vimrc" 2nd user vimrc file: "~/.vim/vimrc" user exrc file: "$HOME/.exrc" defaults file: "$VIMRUNTIME/defaults.vim" fall-back for $VIM: "/Users/ldavis/miniconda3/share/vim" Compilation: x86_64-apple-darwin13.4.0-clang -c -I. -Iproto -DHAVE_CONFIG_H -isystem /Users/ldavis/miniconda3/include -mmacosx-version-min=10.9 -DMACOS_X -DMACOS_X_DARWIN -I/Users/ldavis/miniconda3/include -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -isystem /Users/ldavis/miniconda3/include -fd ebug-prefix-map=/Users/runner/miniforge3/conda-bld/vim_1640555354230/work=/usr/local/src/conda/vim-8.2.3901 -fdebug-p refix-map=/Users/ldavis/miniconda3=/usr/local/src/conda-prefix -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 Linking: x86_64-apple-darwin13.4.0-clang -Wl,-pie -Wl,-headerpad_max_install_names -Wl,-dead_strip_dylibs -Wl,-rpath, /Users/ldavis/miniconda3/lib -L/Users/ldavis/miniconda3/lib -o vim -ltinfo -liconv -lintl -framework AppKit -Wl,-pie -Wl,-headerpad_max_install_names -Wl,-dead_strip_dylibs -Wl,-rpath,/Users/ldavis/miniconda3/lib -L/Users/ldavis/minic onda3/lib -fstack-protector-strong -L/Users/ldavis/miniconda3/lib/perl5/5.32/core_perl/CORE -lperl -lm -lutil -lc -L/ Users/ldavis/miniconda3/lib/python3.9/config-3.9-darwin -lpython3.9 -framework CoreFoundation ```

Plugins (result of :PlugStatus from vim-plug):

``` Finished. 0 error(s). [=============================================================] - denops.vim: OK - vim-textobj-line: OK - vim-tmux: OK - vim-characterize: OK - applescript.vim: OK - vim-toml: OK - ddc-around: OK - tcomment_vim: OK - vim-lsp: OK - vim-autoformat: OK - braceless.vim: OK - vim-easy-align: OK - undotree: OK - vim-cython: OK - vim-markdown: OK - vim-eunuch: OK - vim-matchup: OK - vim-textobj-indent: OK - ddc-fuzzy: OK - vim-autopep8: OK - jupytext.vim: OK - vim-superman: OK - ddc-file: OK - vim-obsession: OK - gv.vim: OK - vim-sneak: OK - vim-colorschemes: OK - close-buffers.vim: OK - vim-gitgutter: OK - vim-fahrenheit: OK - HowMuch: OK - vim-isort: OK - vim-textobj-user: OK - ddc-buffer: OK - vim-lsp-ale: OK - vim-vsnip-integ: OK - FastFold: OK - vim-fugitive: OK - denops-popup-preview.vim: OK - colorizer: OK - yowish.vim: OK - vim-test: OK - vim-vsnip: OK - vim-textobj-parameter: OK - vim-speeddating: OK - vim-liquid: OK - ale: OK - .fzf: OK - jedi-vim: OK - fzf.vim: OK - black: OK - splitjoin.vim: OK - jupyter-vim: OK - delimitmate: OK - vim-textobj-entire: OK - ddc-vim-lsp: OK - vim-surround: OK - codi.vim: OK - julia-vim: OK - vim-lsp-settings: OK - ddc.vim: OK ```