Skip to content

Commit fce3a43

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 64fbbbb + 8a0141d commit fce3a43

File tree

8 files changed

+215
-37
lines changed

8 files changed

+215
-37
lines changed

Filelist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ SRC_UNIX = \
215215
src/config.mk.in \
216216
src/configure \
217217
src/configure.ac \
218+
src/create_cmdidxs.pl \
218219
src/gui_at_fs.c \
219220
src/gui_at_sb.c \
220221
src/gui_at_sb.h \

src/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,16 @@ autoconf:
19011901
-rm -rf autom4te.cache
19021902
-rm -f auto/config.status auto/config.cache
19031903

1904+
# Run Perl to generate the Ex command lookup table. This only needs to be run
1905+
# when a command name has been added or changed.
1906+
# NOTE: Only works when perl and vim executables are available
1907+
cmdidxs: ex_cmds.h
1908+
if test X`perl -e "print 123"` = "X123"; then \
1909+
vim ex_docmd.c -c '/Beginning.*create_cmdidxs/,/End.*create_cmdidxs/! perl create_cmdidxs.pl' -c wq; \
1910+
else \
1911+
echo Cannot run Perl; \
1912+
fi
1913+
19041914
# Re-execute this Makefile to include the new auto/config.mk produced by
19051915
# configure Only used when typing "make" with a fresh auto/config.mk.
19061916
myself:

src/create_cmdidxs.pl

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/perl -w
2+
#
3+
# This script generates the tables cmdidxs1[] and cmdidxs2[][] which,
4+
# given a Ex command, determine the first value to probe to find
5+
# a matching command in cmdnames[] based on the first character
6+
# and the first 2 characters of the command.
7+
# This is used to speed up lookup in cmdnames[].
8+
#
9+
# Script should be run every time new Ex commands are added in Vim,
10+
# from the src/vim directory, since it reads commands from "ex_cmds.h".
11+
12+
# Find the list of Vim commands from cmdnames[] table in ex_cmds.h
13+
my @cmds;
14+
my @skipped;
15+
open(IN, "< ex_cmds.h") or die "can't open ex_cmds.h: $!\n";
16+
while (<IN>) {
17+
if (/^EX\(CMD_\S*,\s*"([a-z][^"]*)"/) {
18+
push (@cmds, $1);
19+
} elsif (/^EX\(CMD_/) {
20+
push (@skipped, $1);
21+
}
22+
}
23+
24+
my %cmdidxs1;
25+
my %cmdidxs2;
26+
27+
for (my $i = $#cmds; $i >= 0; --$i) {
28+
my $cmd = $cmds[$i];
29+
my $c1 = substr($cmd, 0, 1); # First character of command.
30+
31+
$cmdidxs1{$c1} = $i;
32+
33+
if (length($cmd) > 1) {
34+
my $c2 = substr($cmd, 1, 1); # Second character of command.
35+
$cmdidxs2{$c1}{$c2} = $i if (('a' lt $c2) and ($c2 lt 'z'));
36+
}
37+
}
38+
39+
print "/* Beginning of automatically generated code by create_cmdidxs.pl\n",
40+
" *\n",
41+
" * Table giving the index of the first command in cmdnames[] to lookup\n",
42+
" * based on the first letter of a command.\n",
43+
" */\n",
44+
"static const unsigned short cmdidxs1[26] =\n{\n",
45+
join(",\n", map(" /* $_ */ $cmdidxs1{$_}", ('a' .. 'z'))),
46+
"\n};\n",
47+
"\n",
48+
"/*\n",
49+
" * Table giving the index of the first command in cmdnames[] to lookup\n",
50+
" * based on the first 2 letters of a command.\n",
51+
" * Values in cmdidxs2[c1][c2] are relative to cmdidxs1[c1] so that they\n",
52+
" * fit in a byte.\n",
53+
" */\n",
54+
"static const unsigned char cmdidxs2[26][26] =\n",
55+
"{ /* a b c d e f g h i j k l m n o p q r s t u v w x y z */\n";
56+
for my $c1 ('a' .. 'z') {
57+
print " /* $c1 */ {";
58+
for my $c2 ('a' .. 'z') {
59+
if (exists $cmdidxs2{$c1}{$c2}) {
60+
printf "%3d,", $cmdidxs2{$c1}{$c2} - $cmdidxs1{$c1};
61+
} else {
62+
printf " 0,";
63+
}
64+
}
65+
print " }";
66+
print "," unless ($c1 eq 'z');
67+
print "\n";
68+
}
69+
print "};\n",
70+
"\n",
71+
"static int command_count = ", $#cmds + $#skipped + 2 , ";\n",
72+
"\n",
73+
"/* End of automatically generated code by create_cmdidxs.pl */\n";
74+

src/ex_docmd.c

Lines changed: 90 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -502,40 +502,81 @@ static void ex_folddo(exarg_T *eap);
502502
#define DO_DECLARE_EXCMD
503503
#include "ex_cmds.h"
504504

505+
/* Beginning of automatically generated code by create_cmdidxs.pl
506+
*
507+
* Table giving the index of the first command in cmdnames[] to lookup
508+
* based on the first letter of a command.
509+
*/
510+
static const unsigned short cmdidxs1[26] =
511+
{
512+
/* a */ 0,
513+
/* b */ 19,
514+
/* c */ 42,
515+
/* d */ 103,
516+
/* e */ 125,
517+
/* f */ 145,
518+
/* g */ 161,
519+
/* h */ 167,
520+
/* i */ 176,
521+
/* j */ 194,
522+
/* k */ 196,
523+
/* l */ 201,
524+
/* m */ 259,
525+
/* n */ 277,
526+
/* o */ 297,
527+
/* p */ 309,
528+
/* q */ 348,
529+
/* r */ 351,
530+
/* s */ 370,
531+
/* t */ 437,
532+
/* u */ 472,
533+
/* v */ 483,
534+
/* w */ 501,
535+
/* x */ 516,
536+
/* y */ 525,
537+
/* z */ 526
538+
};
539+
505540
/*
506-
* Table used to quickly search for a command, based on its first character.
507-
*/
508-
static cmdidx_T cmdidxs[27] =
509-
{
510-
CMD_append,
511-
CMD_buffer,
512-
CMD_change,
513-
CMD_delete,
514-
CMD_edit,
515-
CMD_file,
516-
CMD_global,
517-
CMD_help,
518-
CMD_insert,
519-
CMD_join,
520-
CMD_k,
521-
CMD_list,
522-
CMD_move,
523-
CMD_next,
524-
CMD_open,
525-
CMD_print,
526-
CMD_quit,
527-
CMD_read,
528-
CMD_substitute,
529-
CMD_t,
530-
CMD_undo,
531-
CMD_vglobal,
532-
CMD_write,
533-
CMD_xit,
534-
CMD_yank,
535-
CMD_z,
536-
CMD_bang
541+
* Table giving the index of the first command in cmdnames[] to lookup
542+
* based on the first 2 letters of a command.
543+
* Values in cmdidxs2[c1][c2] are relative to cmdidxs1[c1] so that they
544+
* fit in a byte.
545+
*/
546+
static const unsigned char cmdidxs2[26][26] =
547+
{ /* a b c d e f g h i j k l m n o p q r s t u v w x y z */
548+
/* a */ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 0, 0, 0, 7, 15, 0, 16, 0, 0, 0, 0, 0, },
549+
/* b */ { 0, 0, 0, 4, 5, 7, 0, 0, 0, 0, 0, 8, 9, 10, 11, 12, 0, 13, 0, 0, 0, 0, 22, 0, 0, 0, },
550+
/* c */ { 0, 10, 12, 14, 16, 18, 21, 0, 0, 0, 0, 29, 33, 36, 42, 51, 53, 54, 55, 0, 57, 0, 60, 0, 0, 0, },
551+
/* d */ { 0, 0, 0, 0, 0, 0, 0, 0, 6, 15, 0, 16, 0, 0, 17, 0, 0, 19, 20, 0, 0, 0, 0, 0, 0, 0, },
552+
/* e */ { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, },
553+
/* f */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, },
554+
/* g */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 4, 5, 0, 0, 0, 0, },
555+
/* h */ { 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
556+
/* i */ { 0, 0, 0, 0, 0, 3, 0, 0, 0, 4, 0, 5, 6, 0, 0, 0, 0, 0, 13, 0, 15, 0, 0, 0, 0, 0, },
557+
/* j */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, },
558+
/* k */ { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
559+
/* l */ { 0, 9, 11, 15, 16, 20, 23, 28, 0, 0, 0, 30, 33, 36, 40, 46, 0, 48, 57, 49, 50, 54, 56, 0, 0, 0, },
560+
/* m */ { 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
561+
/* n */ { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 10, 0, 0, 0, 0, 0, 17, 0, 0, 0, 0, 0, },
562+
/* o */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 5, 0, 0, 0, 0, 0, 0, 9, 0, 11, 0, 0, 0, },
563+
/* p */ { 0, 0, 3, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 0, 0, 16, 17, 26, 0, 27, 0, 28, 0, },
564+
/* q */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
565+
/* r */ { 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 18, 0, 0, 0, 0, },
566+
/* s */ { 0, 6, 15, 0, 18, 22, 0, 24, 25, 0, 0, 28, 30, 34, 38, 40, 0, 48, 0, 49, 0, 61, 62, 0, 63, 0, },
567+
/* t */ { 0, 0, 19, 0, 22, 23, 0, 24, 0, 25, 0, 26, 27, 28, 29, 30, 0, 31, 33, 0, 34, 0, 0, 0, 0, 0, },
568+
/* u */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
569+
/* v */ { 0, 0, 0, 0, 1, 0, 0, 0, 4, 0, 0, 0, 9, 12, 0, 0, 0, 0, 15, 0, 16, 0, 0, 0, 0, 0, },
570+
/* w */ { 0, 0, 0, 0, 0, 0, 0, 3, 4, 0, 0, 0, 0, 8, 0, 9, 10, 0, 12, 0, 13, 14, 0, 0, 0, 0, },
571+
/* x */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 5, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, },
572+
/* y */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
573+
/* z */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }
537574
};
538575

576+
static int command_count = 539;
577+
578+
/* End of automatically generated code by create_cmdidxs.pl */
579+
539580
static char_u dollar_command[2] = {'$', 0};
540581

541582

@@ -621,7 +662,6 @@ restore_dbg_stuff(struct dbg_stuff *dsp)
621662
}
622663
#endif
623664

624-
625665
/*
626666
* do_exmode(): Repeatedly get commands for the "Ex" mode, until the ":vi"
627667
* command is given.
@@ -3215,10 +3255,25 @@ find_command(exarg_T *eap, int *full UNUSED)
32153255
}
32163256
}
32173257

3218-
if (ASCII_ISLOWER(*eap->cmd))
3219-
eap->cmdidx = cmdidxs[CharOrdLow(*eap->cmd)];
3258+
if (ASCII_ISLOWER(eap->cmd[0]))
3259+
{
3260+
int c1 = eap->cmd[0];
3261+
int c2 = eap->cmd[1];
3262+
3263+
if (command_count != (int)CMD_SIZE)
3264+
{
3265+
iemsg((char_u *)_("E943: Command table needs to be updated, run 'make cmdidxs'"));
3266+
getout(1);
3267+
}
3268+
3269+
/* Use a precomputed index for fast look-up in cmdnames[]
3270+
* taking into account the first 2 letters of eap->cmd. */
3271+
eap->cmdidx = cmdidxs1[CharOrdLow(c1)];
3272+
if (ASCII_ISLOWER(c2))
3273+
eap->cmdidx += cmdidxs2[CharOrdLow(c1)][CharOrdLow(c2)];
3274+
}
32203275
else
3221-
eap->cmdidx = cmdidxs[26];
3276+
eap->cmdidx = CMD_bang;
32223277

32233278
for ( ; (int)eap->cmdidx < (int)CMD_SIZE;
32243279
eap->cmdidx = (cmdidx_T)((int)eap->cmdidx + 1))

src/tag.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3203,8 +3203,12 @@ jumpto_tag(
32033203
* open a new tab page. */
32043204
if (postponed_split || cmdmod.tab != 0)
32053205
{
3206-
win_split(postponed_split > 0 ? postponed_split : 0,
3207-
postponed_split_flags);
3206+
if (win_split(postponed_split > 0 ? postponed_split : 0,
3207+
postponed_split_flags) == FAIL)
3208+
{
3209+
--RedrawingDisabled;
3210+
goto erret;
3211+
}
32083212
RESET_BINDING(curwin);
32093213
}
32103214
#endif

src/testdir/test_clientserver.vim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ func Test_client_server()
1111
if cmd == ''
1212
return
1313
endif
14+
if has('unix')
15+
try
16+
call remote_send('xxx', '')
17+
catch
18+
if v:exception =~ 'E240:'
19+
" No connection to the X server, give up.
20+
return
21+
endif
22+
" ignore other errors
23+
endtry
24+
endif
1425

1526
let name = 'XVIMTEST'
1627
let cmd .= ' --servername ' . name

src/testdir/test_quotestar.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ func Do_test_quotestar_for_x11()
3939
if cmd == ''
4040
return 'GetVimCommand() failed'
4141
endif
42+
try
43+
call remote_send('xxx', '')
44+
catch
45+
if v:exception =~ 'E240:'
46+
" No connection to the X server, give up.
47+
return
48+
endif
49+
" ignore other errors
50+
endtry
4251

4352
let name = 'XVIMCLIPBOARD'
4453
let cmd .= ' --servername ' . name

src/version.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,20 @@ static char *(features[]) =
779779

780780
static int included_patches[] =
781781
{ /* Add new patch number below this line */
782+
/**/
783+
510,
784+
/**/
785+
509,
786+
/**/
787+
508,
788+
/**/
789+
507,
790+
/**/
791+
506,
792+
/**/
793+
505,
794+
/**/
795+
504,
782796
/**/
783797
503,
784798
/**/

0 commit comments

Comments
 (0)