Mercurial > vim
comparison runtime/doc/eval.txt @ 16660:04c2614af21c v8.1.1332
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
commit https://github.com/vim/vim/commit/fe1ade0a78a70a4c7ddaebb6964497f037f4997a
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue May 14 21:20:36 2019 +0200
patch 8.1.1332: cannot flush listeners without redrawing, mix of changes
Problem: Cannot flush change listeners without also redrawing. The line
numbers in the list of changes may become invalid.
Solution: Add listener_flush(). Invoke listeners before adding a change
that makes line numbers invalid.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 14 May 2019 21:30:06 +0200 |
parents | a7f06505ad39 |
children | ca1814eeecf5 |
comparison
equal
deleted
inserted
replaced
16659:155423e5a8fd | 16660:04c2614af21c |
---|---|
2457 line2byte({lnum}) Number byte count of line {lnum} | 2457 line2byte({lnum}) Number byte count of line {lnum} |
2458 lispindent({lnum}) Number Lisp indent for line {lnum} | 2458 lispindent({lnum}) Number Lisp indent for line {lnum} |
2459 list2str({list} [, {utf8}]) String turn numbers in {list} into a String | 2459 list2str({list} [, {utf8}]) String turn numbers in {list} into a String |
2460 listener_add({callback} [, {buf}]) | 2460 listener_add({callback} [, {buf}]) |
2461 Number add a callback to listen to changes | 2461 Number add a callback to listen to changes |
2462 listener_flush([{buf}]) none invoke listener callbacks | |
2462 listener_remove({id}) none remove a listener callback | 2463 listener_remove({id}) none remove a listener callback |
2463 localtime() Number current time | 2464 localtime() Number current time |
2464 log({expr}) Float natural logarithm (base e) of {expr} | 2465 log({expr}) Float natural logarithm (base e) of {expr} |
2465 log10({expr}) Float logarithm of Float {expr} to base 10 | 2466 log10({expr}) Float logarithm of Float {expr} to base 10 |
2466 luaeval({expr} [, {expr}]) any evaluate |Lua| expression | 2467 luaeval({expr} [, {expr}]) any evaluate |Lua| expression |
6320 {buf} refers to a buffer name or number. For the accepted | 6321 {buf} refers to a buffer name or number. For the accepted |
6321 values, see |bufname()|. When {buf} is omitted the current | 6322 values, see |bufname()|. When {buf} is omitted the current |
6322 buffer is used. | 6323 buffer is used. |
6323 Returns a unique ID that can be passed to |listener_remove()|. | 6324 Returns a unique ID that can be passed to |listener_remove()|. |
6324 | 6325 |
6325 The {callback} is invoked with a list of items that indicate a | 6326 The {callback} is invoked with four arguments: |
6326 change. The list cannot be changed. Each list item is a | 6327 a:bufnr the buffer that was changed |
6328 a:start first changed line number | |
6329 a:end first line number below the change | |
6330 a:added total number of lines added, negative if lines | |
6331 were deleted | |
6332 a:changes a List of items with details about the changes | |
6333 | |
6334 Example: > | |
6335 func Listener(bufnr, start, end, added, changes) | |
6336 echo 'lines ' .. a:start .. ' until ' .. a:end .. ' changed' | |
6337 endfunc | |
6338 call listener_add('Listener', bufnr) | |
6339 | |
6340 < The List cannot be changed. Each item in a:changes is a | |
6327 dictionary with these entries: | 6341 dictionary with these entries: |
6328 lnum the first line number of the change | 6342 lnum the first line number of the change |
6329 end the first line below the change | 6343 end the first line below the change |
6330 added number of lines added; negative if lines were | 6344 added number of lines added; negative if lines were |
6331 deleted | 6345 deleted |
6335 character has a value of one. | 6349 character has a value of one. |
6336 When lines are inserted the values are: | 6350 When lines are inserted the values are: |
6337 lnum line below which the new line is added | 6351 lnum line below which the new line is added |
6338 end equal to "lnum" | 6352 end equal to "lnum" |
6339 added number of lines inserted | 6353 added number of lines inserted |
6340 col one | 6354 col 1 |
6341 When lines are deleted the values are: | 6355 When lines are deleted the values are: |
6342 lnum the first deleted line | 6356 lnum the first deleted line |
6343 end the line below the first deleted line, before | 6357 end the line below the first deleted line, before |
6344 the deletion was done | 6358 the deletion was done |
6345 added negative, number of lines deleted | 6359 added negative, number of lines deleted |
6346 col one | 6360 col 1 |
6347 When lines are changed: | 6361 When lines are changed: |
6348 lnum the first changed line | 6362 lnum the first changed line |
6349 end the line below the last changed line | 6363 end the line below the last changed line |
6350 added zero | 6364 added 0 |
6351 col first column with a change or one | 6365 col first column with a change or 1 |
6352 | 6366 |
6353 The entries are in the order the changes was made, thus the | 6367 The entries are in the order the changes were made, thus the |
6354 most recent change is at the end. One has to go through the | 6368 most recent change is at the end. The line numbers are valid |
6355 list from end to start to compute the line numbers in the | 6369 when the callback is invoked, but later changes may make them |
6356 current state of the text. | 6370 invalid, thus keeping a copy for later might not work. |
6357 | 6371 |
6358 When using the same function for multiple buffers, you can | 6372 The {callback} is invoked just before the screen is updated, |
6359 pass the buffer to that function using a |Partial|. | 6373 when |listener_flush()| is called or when a change is being |
6360 Example: > | 6374 made that changes the line count in a way it causes a line |
6361 func Listener(bufnr, changes) | 6375 number in the list of changes to become invalid. |
6362 " ... | 6376 |
6363 endfunc | 6377 The {callback} is invoked with the text locked, see |
6364 let bufnr = ... | 6378 |textlock|. If you do need to make changes to the buffer, use |
6365 call listener_add(function('Listener', [bufnr]), bufnr) | 6379 a timer to do this later |timer_start()|. |
6366 | |
6367 < The {callback} is invoked just before the screen is updated. | |
6368 To trigger this in a script use the `:redraw` command. | |
6369 | 6380 |
6370 The {callback} is not invoked when the buffer is first loaded. | 6381 The {callback} is not invoked when the buffer is first loaded. |
6371 Use the |BufReadPost| autocmd event to handle the initial text | 6382 Use the |BufReadPost| autocmd event to handle the initial text |
6372 of a buffer. | 6383 of a buffer. |
6373 The {callback} is also not invoked when the buffer is | 6384 The {callback} is also not invoked when the buffer is |
6374 unloaded, use the |BufUnload| autocmd event for that. | 6385 unloaded, use the |BufUnload| autocmd event for that. |
6386 | |
6387 listener_flush([{buf}]) *listener_flush()* | |
6388 Invoke listener callbacks for buffer {buf}. If there are no | |
6389 pending changes then no callbacks are invoked. | |
6390 | |
6391 {buf} refers to a buffer name or number. For the accepted | |
6392 values, see |bufname()|. When {buf} is omitted the current | |
6393 buffer is used. | |
6375 | 6394 |
6376 listener_remove({id}) *listener_remove()* | 6395 listener_remove({id}) *listener_remove()* |
6377 Remove a listener previously added with listener_add(). | 6396 Remove a listener previously added with listener_add(). |
6378 | 6397 |
6379 localtime() *localtime()* | 6398 localtime() *localtime()* |