Skip to content

Commit f1a6b1f

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 3d372e3 + d087566 commit f1a6b1f

16 files changed

Lines changed: 843 additions & 414 deletions

File tree

Filelist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ SRC_ALL = \
4141
src/hardcopy.c \
4242
src/hashtab.c \
4343
src/json.c \
44+
src/json_test.c \
4445
src/keymap.h \
4546
src/macros.h \
4647
src/main.c \

runtime/doc/eval.txt

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*eval.txt* For Vim version 7.4. Last change: 2016 Feb 01
1+
*eval.txt* For Vim version 7.4. Last change: 2016 Feb 02
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1810,6 +1810,13 @@ byteidxcomp( {expr}, {nr}) Number byte index of {nr}'th char in {expr}
18101810
call( {func}, {arglist} [, {dict}])
18111811
any call {func} with arguments {arglist}
18121812
ceil( {expr}) Float round {expr} up
1813+
ch_close( {handle}) none close a channel
1814+
ch_open( {address}, {mode} [, {callback}])
1815+
Number open a channel
1816+
ch_sendexpr( {handle}, {expr} [, {callback}])
1817+
any send {expr} over JSON channel {handle}
1818+
ch_sendraw( {handle}, {string} [, {callback}])
1819+
any send {string} over raw channel {handle}
18131820
changenr() Number current change number
18141821
char2nr( {expr}[, {utf8}]) Number ASCII/UTF8 value of first char in {expr}
18151822
cindent( {lnum}) Number C indent for line {lnum}
@@ -1820,8 +1827,6 @@ complete_add( {expr}) Number add completion match
18201827
complete_check() Number check for key typed during completion
18211828
confirm( {msg} [, {choices} [, {default} [, {type}]]])
18221829
Number number of choice picked by user
1823-
connect( {address}, {mode} [, {callback}])
1824-
Number open a channel
18251830
copy( {expr}) any make a shallow copy of {expr}
18261831
cos( {expr}) Float cosine of {expr}
18271832
cosh( {expr}) Float hyperbolic cosine of {expr}
@@ -2029,10 +2034,6 @@ searchpairpos( {start}, {middle}, {end} [, {flags} [, {skip} [...]]])
20292034
List search for other end of start/end pair
20302035
searchpos( {pattern} [, {flags} [, {stopline} [, {timeout}]]])
20312036
List search for {pattern}
2032-
sendexpr( {handle}, {expr} [, {callback}])
2033-
any send {expr} over JSON channel {handle}
2034-
sendraw( {handle}, {string} [, {callback}])
2035-
any send {string} over raw channel {handle}
20362037
server2client( {clientid}, {string})
20372038
Number send reply string
20382039
serverlist() String get a list of available servers
@@ -2666,7 +2667,10 @@ confirm({msg} [, {choices} [, {default} [, {type}]]])
26662667
don't fit, a vertical layout is used anyway. For some systems
26672668
the horizontal layout is always used.
26682669

2669-
connect({address}, {mode} [, {callback}]) *connect()*
2670+
ch_close({handle}) *ch_close()*
2671+
Close channel {handle}. See |channel|.
2672+
2673+
ch_open({address}, {mode} [, {callback}]) *ch_open()*
26702674
Open a channel to {address}. See |channel|.
26712675
Returns the channel handle on success. Returns a negative
26722676
number for failure.
@@ -2680,6 +2684,23 @@ connect({address}, {mode} [, {callback}]) *connect()*
26802684
{callback} is a function that handles received messages on the
26812685
channel. See |channel-callback|.
26822686

2687+
ch_sendexpr({handle}, {expr} [, {callback}]) ch_*sendexpr()*
2688+
Send {expr} over JSON channel {handle}. See |channel-use|.
2689+
2690+
When {callback} is given returns immediately. Without
2691+
{callback} waits for a JSON response and returns the decoded
2692+
expression. When there is an error or timeout returns an
2693+
empty string.
2694+
2695+
When {callback} is zero no response is expected.
2696+
Otherwise {callback} must be a Funcref or the name of a
2697+
function. It is called when the response is received. See
2698+
|channel-callback|.
2699+
2700+
ch_sendraw({handle}, {string} [, {callback}]) *ch_sendraw()*
2701+
Send {string} over raw channel {handle}. See |channel-raw|.
2702+
Works like |ch_sendexpr()|, but does not decode the response.
2703+
26832704
*copy()*
26842705
copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't
26852706
different from using {expr} directly.
@@ -5615,23 +5636,6 @@ searchpos({pattern} [, {flags} [, {stopline} [, {timeout}]]]) *searchpos()*
56155636
< In this example "submatch" is 2 when a lowercase letter is
56165637
found |/\l|, 3 when an uppercase letter is found |/\u|.
56175638

5618-
sendexpr({handle}, {expr} [, {callback}]) *sendexpr()*
5619-
Send {expr} over JSON channel {handle}. See |channel-use|.
5620-
5621-
When {callback} is given returns immediately. Without
5622-
{callback} waits for a JSON response and returns the decoded
5623-
expression. When there is an error or timeout returns an
5624-
empty string.
5625-
5626-
When {callback} is zero no response is expected.
5627-
Otherwise {callback} must be a Funcref or the name of a
5628-
function. It is called when the response is received. See
5629-
|channel-callback|.
5630-
5631-
sendraw({handle}, {string} [, {callback}]) *sendraw()*
5632-
Send {string} over raw channel {handle}. See |channel-raw|.
5633-
Works like |sendexpr()|, but does not decode the response.
5634-
56355639
server2client( {clientid}, {string}) *server2client()*
56365640
Send a reply string to {clientid}. The most recent {clientid}
56375641
that sent a string can be retrieved with expand("<client>").

runtime/tools/demoserver.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
#!/usr/bin/python
2+
#
23
# Server that will accept connections from a Vim channel.
34
# Run this server and then in Vim you can open the channel:
4-
# :let handle = connect('localhost:8765', 'json')
5+
# :let handle = ch_open('localhost:8765', 'json')
56
#
67
# Then Vim can send requests to the server:
7-
# :let response = sendexpr(handle, 'hello!')
8+
# :let response = ch_sendexpr(handle, 'hello!')
89
#
910
# And you can control Vim by typing a JSON message here, e.g.:
1011
# ["ex","echo 'hi there'"]
1112
#
13+
# There is no prompt, just type a line and press Enter.
14+
# To exit cleanly type "quit<Enter>".
15+
#
1216
# See ":help channel-demo" in Vim.
17+
#
18+
# This requires Python 2.6 or later.
1319

1420
from __future__ import print_function
1521
import json

src/GvimExt/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ gvimext.obj: gvimext.h
5252
$(cc) $(cflags) -DFEAT_GETTEXT $(cvarsmt) $*.cpp
5353

5454
gvimext.res: gvimext.rc
55-
$(rc) $(rcflags) $(rcvars) gvimext.rc
55+
$(rc) /nologo $(rcflags) $(rcvars) gvimext.rc
5656

5757
clean:
5858
- if exist gvimext.dll del gvimext.dll

src/Make_mvc.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@ $(OUTDIR)/xpm_w32.obj: $(OUTDIR) xpm_w32.c
12941294
$(OUTDIR)/vim.res: $(OUTDIR) vim.rc gvim.exe.mnf version.h tools.bmp \
12951295
tearoff.bmp vim.ico vim_error.ico \
12961296
vim_alert.ico vim_info.ico vim_quest.ico
1297-
$(RC) /l 0x409 /Fo$(OUTDIR)/vim.res $(RCFLAGS) vim.rc
1297+
$(RC) /nologo /l 0x409 /Fo$(OUTDIR)/vim.res $(RCFLAGS) vim.rc
12981298

12991299
iid_ole.c if_ole.h vim.tlb: if_ole.idl
13001300
midl /nologo /error none /proxy nul /iid iid_ole.c /tlb vim.tlb \

src/Makefile

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,11 +1562,13 @@ EXTRA_SRC = hangulin.c if_lua.c if_mzsch.c auto/if_perl.c if_perlsfio.c \
15621562
$(GRESOURCE_SRC)
15631563

15641564
# Unittest files
1565+
JSON_TEST_SRC = json_test.c
1566+
JSON_TEST_TARGET = json_test$(EXEEXT)
15651567
MEMFILE_TEST_SRC = memfile_test.c
15661568
MEMFILE_TEST_TARGET = memfile_test$(EXEEXT)
15671569

1568-
UNITTEST_SRC = $(MEMFILE_TEST_SRC)
1569-
UNITTEST_TARGETS = $(MEMFILE_TEST_TARGET)
1570+
UNITTEST_SRC = $(JSON_TEST_SRC) $(MEMFILE_TEST_SRC)
1571+
UNITTEST_TARGETS = $(JSON_TEST_TARGET) $(MEMFILE_TEST_TARGET)
15701572

15711573
# All sources, also the ones that are not configured
15721574
ALL_SRC = $(BASIC_SRC) $(ALL_GUI_SRC) $(UNITTEST_SRC) $(EXTRA_SRC)
@@ -1605,9 +1607,8 @@ OBJ_COMMON = \
16051607
$(HANGULIN_OBJ) \
16061608
objects/if_cscope.o \
16071609
objects/if_xcmdsrv.o \
1608-
objects/json.o \
16091610
objects/mark.o \
1610-
objects/memline.o \
1611+
objects/memline.o \
16111612
objects/menu.o \
16121613
objects/message.o \
16131614
objects/misc1.o \
@@ -1649,11 +1650,17 @@ OBJ_COMMON = \
16491650
$(WSDEBUG_OBJ)
16501651

16511652
OBJ = $(OBJ_COMMON) \
1653+
objects/json.o \
16521654
objects/main.o \
16531655
objects/memfile.o
16541656

1657+
JSON_TEST_OBJ = $(OBJ_COMMON) \
1658+
objects/json_test.o \
1659+
objects/memfile.o
1660+
16551661
MEMFILE_TEST_OBJ = $(OBJ_COMMON) \
1656-
objects/memfile_test.o
1662+
objects/json.o \
1663+
objects/memfile_test.o
16571664

16581665
PRO_AUTO = \
16591666
blowfish.pro \
@@ -1931,6 +1938,7 @@ types.vim: $(TAGS_SRC) $(TAGS_INCL)
19311938
ctags --c-kinds=gstu -o- $(TAGS_SRC) $(TAGS_INCL) |\
19321939
awk 'BEGIN{printf("syntax keyword Type\t")}\
19331940
{printf("%s ", $$1)}END{print ""}' > $@
1941+
echo "syn keyword Constant OK FAIL TRUE FALSE MAYBE" >> $@
19341942

19351943
# Execute the test scripts. Run these after compiling Vim, before installing.
19361944
# This doesn't depend on $(VIMTARGET), because that won't work when configure
@@ -1965,6 +1973,12 @@ unittest unittests: $(UNITTEST_TARGETS)
19651973
./$$t || exit 1; echo $$t passed; \
19661974
done
19671975

1976+
run_json_test: $(JSON_TEST_TARGET)
1977+
./$(JSON_TEST_TARGET)
1978+
1979+
run_memfile_test: $(MEMFILE_TEST_TARGET)
1980+
./$(MEMFILE_TEST_TARGET)
1981+
19681982
# Run individual OLD style test, assuming that Vim was already compiled.
19691983
test1 \
19701984
test_autocmd_option \
@@ -2057,6 +2071,13 @@ testclean:
20572071

20582072
# Unittests
20592073
# It's build just like Vim to satisfy all dependencies.
2074+
$(JSON_TEST_TARGET): auto/config.mk objects $(JSON_TEST_OBJ)
2075+
$(CCC) version.c -o objects/version.o
2076+
@LINK="$(PURIFY) $(SHRPENV) $(CClink) $(ALL_LIB_DIRS) $(LDFLAGS) \
2077+
-o $(JSON_TEST_TARGET) $(JSON_TEST_OBJ) $(ALL_LIBS)" \
2078+
MAKE="$(MAKE)" LINK_AS_NEEDED=$(LINK_AS_NEEDED) \
2079+
sh $(srcdir)/link.sh
2080+
20602081
$(MEMFILE_TEST_TARGET): auto/config.mk objects $(MEMFILE_TEST_OBJ)
20612082
$(CCC) version.c -o objects/version.o
20622083
@LINK="$(PURIFY) $(SHRPENV) $(CClink) $(ALL_LIB_DIRS) $(LDFLAGS) \
@@ -2837,6 +2858,9 @@ objects/integration.o: integration.c
28372858
objects/json.o: json.c
28382859
$(CCC) -o $@ json.c
28392860

2861+
objects/json_test.o: json_test.c
2862+
$(CCC) -o $@ json_test.c
2863+
28402864
objects/main.o: main.c
28412865
$(CCC) -o $@ main.c
28422866

@@ -3360,6 +3384,10 @@ objects/gui_at_fs.o: gui_at_fs.c vim.h auto/config.h feature.h os_unix.h \
33603384
objects/pty.o: pty.c vim.h auto/config.h feature.h os_unix.h auto/osdef.h ascii.h \
33613385
keymap.h term.h macros.h option.h structs.h regexp.h gui.h gui_beval.h \
33623386
proto/gui_beval.pro alloc.h ex_cmds.h proto.h globals.h farsi.h arabic.h
3387+
objects/json_test.o: json_test.c main.c vim.h auto/config.h feature.h os_unix.h \
3388+
auto/osdef.h ascii.h keymap.h term.h macros.h option.h structs.h \
3389+
regexp.h gui.h gui_beval.h proto/gui_beval.pro alloc.h ex_cmds.h proto.h \
3390+
globals.h farsi.h arabic.h farsi.c arabic.c json.c
33633391
objects/memfile_test.o: memfile_test.c main.c vim.h auto/config.h feature.h \
33643392
os_unix.h auto/osdef.h ascii.h keymap.h term.h macros.h option.h \
33653393
structs.h regexp.h gui.h gui_beval.h proto/gui_beval.pro alloc.h \

src/channel.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,8 @@ channel_read_json(int ch_idx)
565565
/* TODO: make reader work properly */
566566
/* reader.js_buf = channel_peek(ch_idx); */
567567
reader.js_buf = channel_get_all(ch_idx);
568-
reader.js_eof = TRUE;
569-
/* reader.js_eof = FALSE; */
570568
reader.js_used = 0;
569+
reader.js_fill = NULL;
571570
/* reader.js_fill = channel_fill; */
572571
reader.js_cookie = &ch_idx;
573572
if (json_decode(&reader, &listtv) == OK)
@@ -593,6 +592,13 @@ channel_read_json(int ch_idx)
593592
}
594593
}
595594
}
595+
596+
/* Put the unread part back into the channel.
597+
* TODO: insert in front */
598+
if (reader.js_buf[reader.js_used] != NUL)
599+
channel_save(ch_idx, reader.js_buf + reader.js_used,
600+
(int)(reader.js_end - reader.js_buf) - reader.js_used);
601+
vim_free(reader.js_buf);
596602
}
597603

598604
/*
@@ -723,8 +729,9 @@ channel_exe_cmd(int idx, char_u *cmd, typval_T *arg2, typval_T *arg3)
723729

724730
/*
725731
* Invoke a callback for channel "idx" if needed.
732+
* Return OK when a message was handled, there might be another one.
726733
*/
727-
static void
734+
static int
728735
may_invoke_callback(int idx)
729736
{
730737
char_u *msg = NULL;
@@ -736,30 +743,30 @@ may_invoke_callback(int idx)
736743
int json_mode = channels[idx].ch_json_mode;
737744

738745
if (channel_peek(idx) == NULL)
739-
return;
746+
return FALSE;
740747
if (channels[idx].ch_close_cb != NULL)
741748
/* this channel is handled elsewhere (netbeans) */
742-
return;
749+
return FALSE;
743750

744751
if (json_mode)
745752
{
746753
/* Get any json message. Return if there isn't one. */
747754
channel_read_json(idx);
748755
if (channel_get_json(idx, -1, &listtv) == FAIL)
749-
return;
756+
return FALSE;
750757
if (listtv->v_type != VAR_LIST)
751758
{
752759
/* TODO: give error */
753760
clear_tv(listtv);
754-
return;
761+
return FALSE;
755762
}
756763

757764
list = listtv->vval.v_list;
758765
if (list->lv_len < 2)
759766
{
760767
/* TODO: give error */
761768
clear_tv(listtv);
762-
return;
769+
return FALSE;
763770
}
764771

765772
argv[1] = list->lv_first->li_next->li_tv;
@@ -774,14 +781,14 @@ may_invoke_callback(int idx)
774781
arg3 = &list->lv_last->li_tv;
775782
channel_exe_cmd(idx, cmd, &argv[1], arg3);
776783
clear_tv(listtv);
777-
return;
784+
return TRUE;
778785
}
779786

780787
if (typetv->v_type != VAR_NUMBER)
781788
{
782789
/* TODO: give error */
783790
clear_tv(listtv);
784-
return;
791+
return FALSE;
785792
}
786793
seq_nr = typetv->vval.v_number;
787794
}
@@ -811,6 +818,8 @@ may_invoke_callback(int idx)
811818
if (listtv != NULL)
812819
clear_tv(listtv);
813820
vim_free(msg);
821+
822+
return TRUE;
814823
}
815824

816825
/*
@@ -1270,7 +1279,8 @@ channel_parse_messages(void)
12701279
int i;
12711280

12721281
for (i = 0; i < channel_count; ++i)
1273-
may_invoke_callback(i);
1282+
while (may_invoke_callback(i) == OK)
1283+
;
12741284
}
12751285

12761286
#endif /* FEAT_CHANNEL */

0 commit comments

Comments
 (0)