Skip to content

Commit 64c3c6e

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents d868af1 + 864a28b commit 64c3c6e

32 files changed

Lines changed: 420 additions & 176 deletions

runtime/doc/eval.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,6 +2487,8 @@ ch_status({handle} [, {options}])
24872487
changenr() Number current change number
24882488
char2nr({expr} [, {utf8}]) Number ASCII/UTF8 value of first char in {expr}
24892489
charclass({string}) Number character class of {string}
2490+
charidx({string}, {idx} [, {countcc}])
2491+
Number char index of byte {idx} in {string}
24902492
chdir({dir}) String change current working directory
24912493
cindent({lnum}) Number C indent for line {lnum}
24922494
clearmatches([{win}]) none clear all matches
@@ -3600,6 +3602,31 @@ charclass({string}) *charclass()*
36003602
other specific Unicode class
36013603
The class is used in patterns and word motions.
36023604

3605+
*charidx()*
3606+
charidx({string}, {idx} [, {countcc}])
3607+
Return the character index of the byte at {idx} in {string}.
3608+
The index of the first character is zero.
3609+
If there are no multibyte characters the returned value is
3610+
equal to {idx}.
3611+
When {countcc} is omitted or zero, then composing characters
3612+
are not counted separately, their byte length is added to the
3613+
preceding base character.
3614+
When {countcc} is set to 1, then composing characters are
3615+
counted as separate characters.
3616+
Returns -1 if the arguments are invalid or if {idx} is greater
3617+
than the index of the last byte in {string}. An error is
3618+
given if the first argument is not a string, the second
3619+
argument is not a number or when the third argument is present
3620+
and is not zero or one.
3621+
See |byteidx()| and |byteidxcomp()| for getting the byte index
3622+
from the character index.
3623+
Examples: >
3624+
echo charidx('áb́ć', 3) returns 1
3625+
echo charidx('áb́ć', 6, 1) returns 4
3626+
echo charidx('áb́ć', 16) returns -1
3627+
<
3628+
Can also be used as a |method|: >
3629+
GetName()->charidx(idx)
36033630

36043631
chdir({dir}) *chdir()*
36053632
Change the current working directory to {dir}. The scope of

runtime/doc/options.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6461,7 +6461,9 @@ A jump table for the options with a short description can be found at |Q_op|.
64616461
local to window
64626462
Number of lines to scroll with CTRL-U and CTRL-D commands. Will be
64636463
set to half the number of lines in the window when the window size
6464-
changes. If you give a count to the CTRL-U or CTRL-D command it will
6464+
changes. This may happen when enabling the |status-line| or
6465+
'tabline' option after setting the 'scroll' option.
6466+
If you give a count to the CTRL-U or CTRL-D command it will
64656467
be used as the new value for 'scroll'. Reset to half the window
64666468
height with ":set scroll=0".
64676469

runtime/doc/usr_41.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ String manipulation: *string-functions*
625625
iconv() convert text from one encoding to another
626626
byteidx() byte index of a character in a string
627627
byteidxcomp() like byteidx() but count composing characters
628+
charidx() character index of a byte in a string
628629
repeat() repeat a string multiple times
629630
eval() evaluate a string expression
630631
execute() execute an Ex command and get the output

runtime/doc/vim9.txt

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
THIS IS STILL UNDER DEVELOPMENT - ANYTHING CAN BREAK - ANYTHING CAN CHANGE
88

9-
Vim9 script commands and expressions. *Vim9*
9+
Vim9 script commands and expressions. *Vim9* *vim9*
1010

1111
Most expression help is in |eval.txt|. This file is about the new syntax and
1212
features in Vim9 script.
@@ -113,11 +113,12 @@ In Vi # is a command to list text with numbers. In Vim9 script you can use
113113
114114
To improve readability there must be a space between a command and the #
115115
that starts a comment: >
116-
var = value # comment
117-
var = value# error!
116+
var name = value # comment
117+
var name = value# error!
118118
119-
In legacy script # is also used for the alternate file name. In Vim9 script
120-
you need to use %% instead. Instead of ## use %%% (stands for all arguments).
119+
In legacy Vim script # is also used for the alternate file name. In Vim9
120+
script you need to use %% instead. Instead of ## use %%% (stands for all
121+
arguments).
121122

122123

123124
Vim9 functions ~
@@ -209,13 +210,13 @@ if you are developing a plugin and want to try a new version. If you renamed
209210
something you don't have to worry about the old name still hanging around.
210211

211212
If you do want to keep items, use: >
212-
vimscript noclear
213+
vim9script noclear
213214
214215
You want to use this in scripts that use a `finish` command to bail out at
215216
some point when loaded again. E.g. when a buffer local option is set: >
216-
vimscript noclear
217+
vim9script noclear
217218
setlocal completefunc=SomeFunc
218-
if exists('*SomeFunc') | finish | endif
219+
if exists('*g:SomeFunc') | finish | endif
219220
def g:SomeFunc()
220221
....
221222
@@ -385,9 +386,13 @@ No line break is allowed in the arguments of a lambda up to and including the
385386
This does not work: >
386387
filter(list, (k, v)
387388
=> v > 0)
388-
This also does not work:
389+
This also does not work: >
389390
filter(list, (k,
390391
v) => v > 0)
392+
But you can use a backslash to concatenate the lines before parsing: >
393+
filter(list, (k,
394+
\ v)
395+
\ => v > 0)
391396
392397
Additionally, a lambda can contain statements in {}: >
393398
var Lambda = (arg) => {
@@ -404,8 +409,8 @@ wrap it in parenthesis: >
404409
Automatic line continuation ~
405410

406411
In many cases it is obvious that an expression continues on the next line. In
407-
those cases there is no need to prefix the line with a backslash
408-
|line-continuation|. For example, when a list spans multiple lines: >
412+
those cases there is no need to prefix the line with a backslash (see
413+
|line-continuation|). For example, when a list spans multiple lines: >
409414
var mylist = [
410415
'one',
411416
'two',
@@ -442,6 +447,12 @@ before it: >
442447
var result = MyDict
443448
.member
444449
450+
For commands that have an argument that is a list of commands, the | character
451+
at the start of the line indicates line continuation: >
452+
autocmd BufNewFile *.match if condition
453+
| echo 'match'
454+
| endif
455+
445456
< *E1050*
446457
To make it possible for the operator at the start of the line to be
447458
recognized, it is required to put a colon before a range. This will add
@@ -941,7 +952,7 @@ that you don't do that.
941952

942953

943954
Namespace ~
944-
*:vim9script* *:vim9*
955+
*vim9-namespace*
945956
To recognize a file that can be imported the `vim9script` statement must
946957
appear as the first statement in the file. It tells Vim to interpret the
947958
script in its own namespace, instead of the global namespace. If a file

src/auto/configure

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7823,6 +7823,9 @@ $as_echo "${vi_cv_dll_name_ruby_arm64}" >&6; }
78237823
$as_echo "<none>" >&6; }
78247824
fi
78257825
fi
7826+
if test "X$CLANG_VERSION" != "X" -a "$rubyversion" -ge 30; then
7827+
RUBY_CFLAGS="$RUBY_CFLAGS -fdeclspec"
7828+
fi
78267829
else
78277830
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: not found; disabling Ruby" >&5
78287831
$as_echo "not found; disabling Ruby" >&6; }

src/autocmd.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ typedef struct AutoCmd
5555
char once; // "One shot": removed after execution
5656
char nested; // If autocommands nest here.
5757
char last; // last command in list
58-
#ifdef FEAT_EVAL
5958
sctx_T script_ctx; // script context where defined
60-
#endif
6159
struct AutoCmd *next; // next AutoCmd in list
6260
} AutoCmd;
6361

@@ -1250,8 +1248,8 @@ do_autocmd_event(
12501248
if (ac == NULL)
12511249
return FAIL;
12521250
ac->cmd = vim_strsave(cmd);
1253-
#ifdef FEAT_EVAL
12541251
ac->script_ctx = current_sctx;
1252+
#ifdef FEAT_EVAL
12551253
ac->script_ctx.sc_lnum += SOURCING_LNUM;
12561254
#endif
12571255
if (ac->cmd == NULL)
@@ -1820,8 +1818,8 @@ apply_autocmds_group(
18201818
static int nesting = 0;
18211819
AutoPatCmd patcmd;
18221820
AutoPat *ap;
1823-
#ifdef FEAT_EVAL
18241821
sctx_T save_current_sctx;
1822+
#ifdef FEAT_EVAL
18251823
funccal_entry_T funccal_entry;
18261824
char_u *save_cmdarg;
18271825
long save_cmdbang;
@@ -2030,9 +2028,9 @@ apply_autocmds_group(
20302028
estack_push(ETYPE_AUCMD, NULL, 0);
20312029
ESTACK_CHECK_SETUP
20322030

2033-
#ifdef FEAT_EVAL
20342031
save_current_sctx = current_sctx;
20352032

2033+
#ifdef FEAT_EVAL
20362034
# ifdef FEAT_PROFILE
20372035
if (do_profiling == PROF_YES)
20382036
prof_child_enter(&wait_time); // doesn't count for the caller itself
@@ -2139,8 +2137,8 @@ apply_autocmds_group(
21392137
autocmd_fname_full = save_autocmd_fname_full;
21402138
autocmd_bufnr = save_autocmd_bufnr;
21412139
autocmd_match = save_autocmd_match;
2142-
#ifdef FEAT_EVAL
21432140
current_sctx = save_current_sctx;
2141+
#ifdef FEAT_EVAL
21442142
restore_funccal();
21452143
# ifdef FEAT_PROFILE
21462144
if (do_profiling == PROF_YES)
@@ -2371,9 +2369,7 @@ getnextac(
23712369
if (ac->once)
23722370
au_del_cmd(ac);
23732371
autocmd_nested = ac->nested;
2374-
#ifdef FEAT_EVAL
23752372
current_sctx = ac->script_ctx;
2376-
#endif
23772373
if (ac->last)
23782374
acp->nextcmd = NULL;
23792375
else

src/buffer.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5381,9 +5381,8 @@ chk_modeline(
53815381
int vers;
53825382
int end;
53835383
int retval = OK;
5384-
#ifdef FEAT_EVAL
53855384
sctx_T save_current_sctx;
5386-
#endif
5385+
53875386
ESTACK_CHECK_DECLARATION
53885387

53895388
prev = -1;
@@ -5467,22 +5466,22 @@ chk_modeline(
54675466
if (*s != NUL) // skip over an empty "::"
54685467
{
54695468
int secure_save = secure;
5470-
#ifdef FEAT_EVAL
5469+
54715470
save_current_sctx = current_sctx;
5471+
current_sctx.sc_version = 1;
5472+
#ifdef FEAT_EVAL
54725473
current_sctx.sc_sid = SID_MODELINE;
54735474
current_sctx.sc_seq = 0;
54745475
current_sctx.sc_lnum = lnum;
5475-
current_sctx.sc_version = 1;
54765476
#endif
5477+
54775478
// Make sure no risky things are executed as a side effect.
54785479
secure = 1;
54795480

54805481
retval = do_set(s, OPT_MODELINE | OPT_LOCAL | flags);
54815482

54825483
secure = secure_save;
5483-
#ifdef FEAT_EVAL
54845484
current_sctx = save_current_sctx;
5485-
#endif
54865485
if (retval == FAIL) // stop if error found
54875486
break;
54885487
}

src/configure.ac

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,9 @@ if test "$enable_rubyinterp" = "yes" -o "$enable_rubyinterp" = "dynamic"; then
21322132
AC_MSG_RESULT([<none>])
21332133
fi
21342134
fi
2135+
if test "X$CLANG_VERSION" != "X" -a "$rubyversion" -ge 30; then
2136+
RUBY_CFLAGS="$RUBY_CFLAGS -fdeclspec"
2137+
fi
21352138
else
21362139
AC_MSG_RESULT(not found; disabling Ruby)
21372140
fi

src/errors.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ EXTERN char e_assert_fails_second_arg[]
3131
INIT(= N_("E856: \"assert_fails()\" second argument must be a string or a list with one or two strings"));
3232
EXTERN char e_cannot_index_special_variable[]
3333
INIT(= N_("E909: Cannot index a special variable"));
34-
EXTERN char e_missing_var_str[]
35-
INIT(= N_("E1100: Missing :var: %s"));
34+
#endif
35+
EXTERN char e_command_not_supported_in_vim9_script_missing_var_str[]
36+
INIT(= N_("E1100: Command not supported in Vim9 script (missing :var?): %s"));
37+
#ifdef FEAT_EVAL
3638
EXTERN char e_variable_not_found_str[]
3739
INIT(= N_("E1001: Variable not found: %s"));
3840
EXTERN char e_syntax_error_at_str[]
@@ -113,8 +115,10 @@ EXTERN char e_vim9script_can_only_be_used_in_script[]
113115
INIT(= N_("E1038: \"vim9script\" can only be used in a script"));
114116
EXTERN char e_vim9script_must_be_first_command_in_script[]
115117
INIT(= N_("E1039: \"vim9script\" must be the first command in a script"));
118+
#endif
116119
EXTERN char e_cannot_use_scriptversion_after_vim9script[]
117120
INIT(= N_("E1040: Cannot use :scriptversion after :vim9script"));
121+
#ifdef FEAT_EVAL
118122
EXTERN char e_redefining_script_item_str[]
119123
INIT(= N_("E1041: Redefining script item %s"));
120124
EXTERN char e_export_can_only_be_used_in_vim9script[]

src/evalfunc.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static void f_ceil(typval_T *argvars, typval_T *rettv);
4747
#endif
4848
static void f_changenr(typval_T *argvars, typval_T *rettv);
4949
static void f_char2nr(typval_T *argvars, typval_T *rettv);
50+
static void f_charidx(typval_T *argvars, typval_T *rettv);
5051
static void f_col(typval_T *argvars, typval_T *rettv);
5152
static void f_confirm(typval_T *argvars, typval_T *rettv);
5253
static void f_copy(typval_T *argvars, typval_T *rettv);
@@ -789,6 +790,8 @@ static funcentry_T global_functions[] =
789790
ret_number, f_char2nr},
790791
{"charclass", 1, 1, FEARG_1, NULL,
791792
ret_number, f_charclass},
793+
{"charidx", 2, 3, FEARG_1, NULL,
794+
ret_number, f_charidx},
792795
{"chdir", 1, 1, FEARG_1, NULL,
793796
ret_string, f_chdir},
794797
{"cindent", 1, 1, FEARG_1, NULL,
@@ -2420,6 +2423,57 @@ f_char2nr(typval_T *argvars, typval_T *rettv)
24202423
rettv->vval.v_number = tv_get_string(&argvars[0])[0];
24212424
}
24222425

2426+
/*
2427+
* "charidx()" function
2428+
*/
2429+
static void
2430+
f_charidx(typval_T *argvars, typval_T *rettv)
2431+
{
2432+
char_u *str;
2433+
varnumber_T idx;
2434+
int countcc = FALSE;
2435+
char_u *p;
2436+
int len;
2437+
int (*ptr2len)(char_u *);
2438+
2439+
rettv->vval.v_number = -1;
2440+
2441+
if (argvars[0].v_type != VAR_STRING || argvars[1].v_type != VAR_NUMBER
2442+
|| (argvars[2].v_type != VAR_UNKNOWN
2443+
&& argvars[2].v_type != VAR_NUMBER))
2444+
{
2445+
emsg(_(e_invarg));
2446+
return;
2447+
}
2448+
2449+
str = tv_get_string_chk(&argvars[0]);
2450+
idx = tv_get_number_chk(&argvars[1], NULL);
2451+
if (str == NULL || idx < 0)
2452+
return;
2453+
2454+
if (argvars[2].v_type != VAR_UNKNOWN)
2455+
countcc = (int)tv_get_bool(&argvars[2]);
2456+
if (countcc < 0 || countcc > 1)
2457+
{
2458+
semsg(_(e_using_number_as_bool_nr), countcc);
2459+
return;
2460+
}
2461+
2462+
if (enc_utf8 && countcc)
2463+
ptr2len = utf_ptr2len;
2464+
else
2465+
ptr2len = mb_ptr2len;
2466+
2467+
for (p = str, len = 0; p <= str + idx; len++)
2468+
{
2469+
if (*p == NUL)
2470+
return;
2471+
p += ptr2len(p);
2472+
}
2473+
2474+
rettv->vval.v_number = len > 0 ? len - 1 : 0;
2475+
}
2476+
24232477
win_T *
24242478
get_optional_window(typval_T *argvars, int idx)
24252479
{

0 commit comments

Comments
 (0)