vim-patch:8.2.3969: value of MAXCOL not available in Vim script

Problem:    Value of MAXCOL not available in Vim script.
Solution:   Add v:maxcol. (Naohiro Ono, closes vim/vim#9451)

56200eed62

The variable is always 2147483647, but introducing it makes functions
easier to document.

Co-authored-by: naohiro ono <obcat@icloud.com>
This commit is contained in:
zeertzjq 2023-03-07 11:04:36 +08:00
parent 7a44231832
commit 2882b1543a
7 changed files with 38 additions and 12 deletions

View File

@ -2890,6 +2890,9 @@ getcharpos({expr})
Get the position for String {expr}. Same as |getpos()| but the Get the position for String {expr}. Same as |getpos()| but the
column number in the returned List is a character index column number in the returned List is a character index
instead of a byte index. instead of a byte index.
If |getpos()| returns a very large column number, equal to
|v:maxcol|, then getcharpos() will return the character index
of the last character.
Example: Example:
With the cursor on '세' in line 5 with text "여보세요": > With the cursor on '세' in line 5 with text "여보세요": >
@ -3064,10 +3067,11 @@ getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
*getcurpos()* *getcurpos()*
getcurpos([{winid}]) getcurpos([{winid}])
Get the position of the cursor. This is like getpos('.'), but Get the position of the cursor. This is like getpos('.'), but
includes an extra "curswant" in the list: includes an extra "curswant" item in the list:
[0, lnum, col, off, curswant] ~ [0, lnum, col, off, curswant] ~
The "curswant" number is the preferred column when moving the The "curswant" number is the preferred column when moving the
cursor vertically. Also see |getcursorcharpos()| and cursor vertically. After |$| command it will be a very large
number equal to |v:maxcol|. Also see |getcursorcharpos()| and
|getpos()|. |getpos()|.
The first "bufnum" item is always zero. The byte position of The first "bufnum" item is always zero. The byte position of
the cursor is returned in "col". To get the character the cursor is returned in "col". To get the character
@ -3389,12 +3393,12 @@ getpos({expr}) Get the position for String {expr}. For possible values of
character. character.
Note that for '< and '> Visual mode matters: when it is "V" Note that for '< and '> Visual mode matters: when it is "V"
(visual line mode) the column of '< is zero and the column of (visual line mode) the column of '< is zero and the column of
'> is a large number. '> is a large number equal to |v:maxcol|.
The column number in the returned List is the byte position The column number in the returned List is the byte position
within the line. To get the character position in the line, within the line. To get the character position in the line,
use |getcharpos()|. use |getcharpos()|.
The column number can be very large, e.g. 2147483647, in which A very large column number equal to |v:maxcol| can be returned,
case it means "after the end of the line". in which case it means "after the end of the line".
If {expr} is invalid, returns a list with all zeros. If {expr} is invalid, returns a list with all zeros.
This can be used to save and restore the position of a mark: > This can be used to save and restore the position of a mark: >
let save_a_mark = getpos("'a") let save_a_mark = getpos("'a")
@ -9407,10 +9411,14 @@ winsaveview() Returns a |Dictionary| that contains information to restore
The return value includes: The return value includes:
lnum cursor line number lnum cursor line number
col cursor column (Note: the first column col cursor column (Note: the first column
zero, as opposed to what getpos() zero, as opposed to what |getcurpos()|
returns) returns)
coladd cursor column offset for 'virtualedit' coladd cursor column offset for 'virtualedit'
curswant column for vertical movement curswant column for vertical movement (Note:
the first column is zero, as opposed
to what |getcurpos()| returns). After
|$| command it will be a very large
number equal to |v:maxcol|.
topline first line in the window topline first line in the window
topfill filler lines, only in diff mode topfill filler lines, only in diff mode
leftcol first column displayed; only used when leftcol first column displayed; only used when

View File

@ -1979,6 +1979,9 @@ v:lnum Line number for the 'foldexpr' |fold-expr|, 'formatexpr',
v:lua Prefix for calling Lua functions from expressions. v:lua Prefix for calling Lua functions from expressions.
See |v:lua-call| for more information. See |v:lua-call| for more information.
*v:maxcol* *maxcol-variable*
v:maxcol Maximum line length.
*v:mouse_win* *mouse_win-variable* *v:mouse_win* *mouse_win-variable*
v:mouse_win Window number for a mouse click obtained with |getchar()|. v:mouse_win Window number for a mouse click obtained with |getchar()|.
First window has number 1, like with |winnr()|. The value is First window has number 1, like with |winnr()|. The value is

View File

@ -251,6 +251,7 @@ static struct vimvar {
VV(VV_ARGV, "argv", VAR_LIST, VV_RO), VV(VV_ARGV, "argv", VAR_LIST, VV_RO),
VV(VV_COLLATE, "collate", VAR_STRING, VV_RO), VV(VV_COLLATE, "collate", VAR_STRING, VV_RO),
VV(VV_EXITING, "exiting", VAR_NUMBER, VV_RO), VV(VV_EXITING, "exiting", VAR_NUMBER, VV_RO),
VV(VV_MAXCOL, "maxcol", VAR_NUMBER, VV_RO),
// Neovim // Neovim
VV(VV_STDERR, "stderr", VAR_NUMBER, VV_RO), VV(VV_STDERR, "stderr", VAR_NUMBER, VV_RO),
VV(VV_MSGPACK_TYPES, "msgpack_types", VAR_DICT, VV_RO), VV(VV_MSGPACK_TYPES, "msgpack_types", VAR_DICT, VV_RO),
@ -451,6 +452,7 @@ void eval_init(void)
set_vim_var_nr(VV_NUMBERMIN, VARNUMBER_MIN); set_vim_var_nr(VV_NUMBERMIN, VARNUMBER_MIN);
set_vim_var_nr(VV_NUMBERSIZE, sizeof(varnumber_T) * 8); set_vim_var_nr(VV_NUMBERSIZE, sizeof(varnumber_T) * 8);
set_vim_var_special(VV_EXITING, kSpecialVarNull); set_vim_var_special(VV_EXITING, kSpecialVarNull);
set_vim_var_nr(VV_MAXCOL, MAXCOL);
set_vim_var_nr(VV_ECHOSPACE, sc_col - 1); set_vim_var_nr(VV_ECHOSPACE, sc_col - 1);

View File

@ -157,6 +157,7 @@ typedef enum {
VV_ARGV, VV_ARGV,
VV_COLLATE, VV_COLLATE,
VV_EXITING, VV_EXITING,
VV_MAXCOL,
// Nvim // Nvim
VV_STDERR, VV_STDERR,
VV_MSGPACK_TYPES, VV_MSGPACK_TYPES,

View File

@ -40,6 +40,18 @@ func Test_move_cursor()
quit! quit!
endfunc endfunc
func Test_curswant_maxcol()
new
call setline(1, 'foo')
" Test that after "$" command curswant is set to the same value as v:maxcol.
normal! 1G$
call assert_equal(v:maxcol, getcurpos()[4])
call assert_equal(v:maxcol, winsaveview().curswant)
quit!
endfunc
" Very short version of what matchparen does. " Very short version of what matchparen does.
function s:Highlight_Matching_Pair() function s:Highlight_Matching_Pair()
let save_cursor = getcurpos() let save_cursor = getcurpos()

View File

@ -921,7 +921,7 @@ func Test_normal14_page()
set nostartofline set nostartofline
exe "norm! $\<c-b>" exe "norm! $\<c-b>"
call assert_equal('92', getline('.')) call assert_equal('92', getline('.'))
call assert_equal([0, 92, 2, 0, 2147483647], getcurpos()) call assert_equal([0, 92, 2, 0, v:maxcol], getcurpos())
" cleanup " cleanup
set startofline set startofline
bw! bw!
@ -966,7 +966,7 @@ func Test_normal15_z_scroll_vert()
norm! >>$ztzb norm! >>$ztzb
call assert_equal(' 30', getline('.')) call assert_equal(' 30', getline('.'))
call assert_equal(30, winsaveview()['topline']+winheight(0)-1) call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
call assert_equal([0, 30, 3, 0, 2147483647], getcurpos()) call assert_equal([0, 30, 3, 0, v:maxcol], getcurpos())
" Test for z- " Test for z-
1 1
@ -2917,7 +2917,7 @@ func Test_normal36_g_cmd5()
call assert_equal([0, 14, 1, 0, 1], getcurpos()) call assert_equal([0, 14, 1, 0, 1], getcurpos())
" count > buffer content " count > buffer content
norm! 120go norm! 120go
call assert_equal([0, 14, 1, 0, 2147483647], getcurpos()) call assert_equal([0, 14, 1, 0, v:maxcol], getcurpos())
" clean up " clean up
bw! bw!
endfunc endfunc
@ -3097,7 +3097,7 @@ func Test_normal42_halfpage()
set nostartofline set nostartofline
exe "norm! $\<c-u>" exe "norm! $\<c-u>"
call assert_equal('95', getline('.')) call assert_equal('95', getline('.'))
call assert_equal([0, 95, 2, 0, 2147483647], getcurpos()) call assert_equal([0, 95, 2, 0, v:maxcol], getcurpos())
" cleanup " cleanup
set startofline set startofline
bw! bw!

View File

@ -209,7 +209,7 @@ func Test_multibyte_op_end_mark()
call assert_equal([0, 1, 7, 0], getpos("']")) call assert_equal([0, 1, 7, 0], getpos("']"))
normal Vyp normal Vyp
call assert_equal([0, 1, 2147483647, 0], getpos("'>")) call assert_equal([0, 1, v:maxcol, 0], getpos("'>"))
call assert_equal([0, 2, 7, 0], getpos("']")) call assert_equal([0, 2, 7, 0], getpos("']"))
bwipe! bwipe!
endfunc endfunc