Mercurial > vim
comparison runtime/doc/eval.txt @ 16648:a7f06505ad39 v8.1.1326
patch 8.1.1326: no test for listener with partial
commit https://github.com/vim/vim/commit/8aad88d8de256e58f04054eb7230c9613e26502f
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun May 12 13:53:50 2019 +0200
patch 8.1.1326: no test for listener with partial
Problem: No test for listener with partial.
Solution: Add a test. Add example to help.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 12 May 2019 14:00:07 +0200 |
parents | 4790302965fc |
children | 04c2614af21c |
comparison
equal
deleted
inserted
replaced
16647:8dc2b6916321 | 16648:a7f06505ad39 |
---|---|
6321 values, see |bufname()|. When {buf} is omitted the current | 6321 values, see |bufname()|. When {buf} is omitted the current |
6322 buffer is used. | 6322 buffer is used. |
6323 Returns a unique ID that can be passed to |listener_remove()|. | 6323 Returns a unique ID that can be passed to |listener_remove()|. |
6324 | 6324 |
6325 The {callback} is invoked with a list of items that indicate a | 6325 The {callback} is invoked with a list of items that indicate a |
6326 change. Each list item is a dictionary with these entries: | 6326 change. The list cannot be changed. Each list item is a |
6327 dictionary with these entries: | |
6327 lnum the first line number of the change | 6328 lnum the first line number of the change |
6328 end the first line below the change | 6329 end the first line below the change |
6329 added number of lines added; negative if lines were | 6330 added number of lines added; negative if lines were |
6330 deleted | 6331 deleted |
6331 col first column in "lnum" that was affected by | 6332 col first column in "lnum" that was affected by |
6347 lnum the first changed line | 6348 lnum the first changed line |
6348 end the line below the last changed line | 6349 end the line below the last changed line |
6349 added zero | 6350 added zero |
6350 col first column with a change or one | 6351 col first column with a change or one |
6351 | 6352 |
6352 The {callback} is invoked just before the screen is updated. | 6353 The entries are in the order the changes was made, thus the |
6354 most recent change is at the end. One has to go through the | |
6355 list from end to start to compute the line numbers in the | |
6356 current state of the text. | |
6357 | |
6358 When using the same function for multiple buffers, you can | |
6359 pass the buffer to that function using a |Partial|. | |
6360 Example: > | |
6361 func Listener(bufnr, changes) | |
6362 " ... | |
6363 endfunc | |
6364 let bufnr = ... | |
6365 call listener_add(function('Listener', [bufnr]), bufnr) | |
6366 | |
6367 < The {callback} is invoked just before the screen is updated. | |
6353 To trigger this in a script use the `:redraw` command. | 6368 To trigger this in a script use the `:redraw` command. |
6354 | 6369 |
6355 The {callback} is not invoked when the buffer is first loaded. | 6370 The {callback} is not invoked when the buffer is first loaded. |
6356 Use the |BufReadPost| autocmd event to handle the initial text | 6371 Use the |BufReadPost| autocmd event to handle the initial text |
6357 of a buffer. | 6372 of a buffer. |
10982 This only works for functions declared with |function|, not for lambda | 10997 This only works for functions declared with |function|, not for lambda |
10983 expressions |expr-lambda|. | 10998 expressions |expr-lambda|. |
10984 | 10999 |
10985 Example: > | 11000 Example: > |
10986 function Something(key, value = 10) | 11001 function Something(key, value = 10) |
10987 echo a:key .. ": " .. value | 11002 echo a:key .. ": " .. a:value |
10988 endfunction | 11003 endfunction |
10989 call Something('empty') "empty: 10" | 11004 call Something('empty') "empty: 10" |
10990 call Something('key, 20) "key: 20" | 11005 call Something('key', 20) "key: 20" |
10991 | 11006 |
10992 The argument default expressions are evaluated at the time of the function | 11007 The argument default expressions are evaluated at the time of the function |
10993 call, not definition. Thus it is possible to use an expression which is | 11008 call, not definition. Thus it is possible to use an expression which is |
10994 invalid the moment the function is defined. The expressions are are also only | 11009 invalid the moment the function is defined. The expressions are are also only |
10995 evaluated when arguments are not specified during a call. | 11010 evaluated when arguments are not specified during a call. |