On Tue, May 16, 2006 at 08:33:43AM +0200, Jiří Černý wrote:
>
> Here are the scripts and the test case. It is relatively complicated,
> but I did not find a simpler one. It works in vim 7.0 (Included patches:
> 1-17)
I have simplified the example somewhat. I may look at it some more
later, or maybe someone else will take it from here. Save the attached
files foo (unchanged) and format.vim (simplified) and start vim with
$ vim -u NONE +"source format.vim" foo
On the first (blank) line, start Insert mode and type
12345
$67890 1234$ 5678
9012
letting vim do the line breaks. Then <Esc> back to Normal mode and u to
undo: the 9012 line is left and 'modified' is not set.
Curiously, if I *do* add the line break myself after the first
line, the problem seems to go away. The bug seems to surface only when
two lines have been changed by the function.
HTH --Benji Fisher
==========================================
==========================================
set nocp tw=20
set laststatus=2 " so I can watch the 'modified' flag
setlocal formatoptions=tcqr
setlocal formatexpr=MyTeXFormat(v:lnum,v:count)
fun! MyTeXFormat(lnum,count)
let line = getline(a:lnum)
let curlineindent = indent(a:lnum)
let aftercursor = line[col(".")-1:]
let beforecursor = line[:col(".")-2]
let numdollars = len(substitute(beforecursor, '[^$]', '', 'g'))
let evendolars = numdollars % 2
let dolarpos = matchend(beforecursor, '.*\$')
if evendolars == 0
if dolarpos < &tw "vim can do the job
return 1
endif
endif
if beforecursor[dolarpos-1] != ' ' "no space before $
let dolarpos = strridx(beforecursor,' ',dolarpos-1)
let dolarpos = dolarpos + 1
endif
if dolarpos != curlineindent "formula does not start at first char
call setline(a:lnum,strpart(beforecursor,0,dolarpos))
call append(a:lnum,"XX")
let newline = strpart(beforecursor,dolarpos) . aftercursor
call setline(a:lnum+1,newline)
call cursor(a:lnum+1,strlen(beforecursor)-dolarpos+1)
return 0
endif
return 0
endfun