#5 Error when changing Viki buffers

closed
nobody
Module (7)
5
2010-02-20
2010-02-20
Marko Mahnič
No

To reproduce:
buffer 1 = A.viki: 200 lines, all folds closed
buffer 2 = B.viki: 98 lines, all folds closed
:b1
G
:b2

After this Vim prints the following errors:
Error detected while processing function viki#CheckInexistent..viki#MarkInexistentInRange..vik
i#SaveCursorPosition:
line 13:
E315: ml_get: invalid lnum: 201
E315: ml_get: invalid lnum: 200
E315: ml_get: invalid lnum: 199
Error detected while processing function viki#CheckInexistent:
line 2:
E171: Missing :endif

Discussion

  • Tom Link
    Tom Link
    2010-02-20

    Which version (including patches) of vim do you use? In my experience those ml_get errors point to internal problems. See also :h e315. I cannot reproduce this with my setup. I currently use 7.2-119.

     
  • Marko Mahnič
    Marko Mahnič
    2010-02-20

    vim --version
    VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Dec 17 2009 21:59:10)
    Included patches: 1-320
    (compiled by me, with +python_screen)

    vim.basic --version
    VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Sep 21 2009 11:22:49)
    Included patches: 1-245
    (Ubuntu)

    From the above description it seems that viki is trying to save the current
    position in the old buffer while the new buffer is already active.
    It tries to get lines 199-201, but the new buffer only has 98.

     
  • Tom Link
    Tom Link
    2010-02-20

    The ml_get errors still point to an internal problem. But I get your point and updated the handling of cursor positions. Please let me know if there are further problems.

     
  • Tom Link
    Tom Link
    2010-02-20

    • status: open --> closed
     
  • Marko Mahnič
    Marko Mahnič
    2010-02-20

    If found the solution to the problem. It is hidden in the handling
    of scrolloff, and the solution is funny - you need to add:
    let &scrolloff=&scrolloff
    and the problem disappears.

    Without this and when scrolloff != 0 (I tested with so=3), Vim gives
    an error after the combination:
    keepjumps norm! H
    let s:cursorWinTLine = line('.')
    It is obviously a Vim bug.

    Full code with some debugging message in try/catch.

    " Save the cursor position
    " TODO: adapt for vim7
    function! viki#SaveCursorPosition() "{{{3
    let ve = &virtualedit
    set virtualedit=all
    let &scrolloff=&scrolloff
    " let s:lazyredraw = &lazyredraw
    " set nolazyredraw
    try
    let s:cursorSet = 1
    let s:cursorCol = col('.')
    let s:cursorEol = (col('.') == col('$'))
    let s:cursorVCol = virtcol('.')
    if s:cursorEol
    let s:cursorVCol = s:cursorVCol + 1
    endif
    let s:cursorLine = line('.')
    keepjumps norm! H
    let s:cursorWinTLine = line('.')
    call cursor(s:cursorLine, s:cursorCol)
    catch /.*/
    echom "Problems in SaveCursorPosition, b=" . bufnr('%') . ", so=" . &scrolloff
    endtry
    let &virtualedit = ve
    " call viki#DebugCursorPosition()
    return ''
    endf

     
  • Marko Mahnič
    Marko Mahnič
    2010-02-20

    One more thing. When I was echo-ing s:cursorLine and s:cursorWinTLine I always got 1 for both.
    Could the reason for this be, that I had no wiki-links in files A and B?

     
  • Marko Mahnič
    Marko Mahnič
    2010-02-20

    Your latest fix seems to work.
    Thanks.