Skip to content

Commit 5b41cd5

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 7cd3390 + 55fab43 commit 5b41cd5

16 files changed

Lines changed: 668 additions & 123 deletions

File tree

runtime/doc/channel.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*channel.txt* For Vim version 7.4. Last change: 2016 Feb 05
1+
*channel.txt* For Vim version 7.4. Last change: 2016 Feb 06
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -93,7 +93,7 @@ The default is zero, don't wait, which is useful if the server is supposed to
9393
be running already. A negative number waits forever.
9494

9595
"timeout" is the time to wait for a request when blocking, using
96-
ch_sendexpr(). Again in millisecons. The default si 2000 (2 seconds).
96+
ch_sendexpr(). Again in milliseconds. The default is 2000 (2 seconds).
9797

9898
When "mode" is "json" the "msg" argument is the body of the received message,
9999
converted to Vim types.
@@ -104,13 +104,13 @@ possible to receive a message after sending one.
104104

105105
The handler can be added or changed later: >
106106
call ch_setcallback(handle, {callback})
107-
When "callback is empty (zero or an empty string) the handler is removed.
107+
When "callback" is empty (zero or an empty string) the handler is removed.
108108
NOT IMPLEMENTED YET
109109

110110
The timeout can be changed later: >
111111
call ch_settimeout(handle, {msec})
112112
NOT IMPLEMENTED YET
113-
113+
*E906*
114114
Once done with the channel, disconnect it like this: >
115115
call ch_close(handle)
116116

runtime/doc/eval.txt

Lines changed: 99 additions & 14 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 05
1+
*eval.txt* For Vim version 7.4. Last change: 2016 Feb 07
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -37,7 +37,7 @@ done, the features in this document are not available. See |+eval| and
3737

3838
1.1 Variable types ~
3939
*E712*
40-
There are six types of variables:
40+
There are eight types of variables:
4141

4242
Number A 32 or 64 bit signed number. |expr-number| *Number*
4343
Examples: -123 0x10 0177
@@ -49,16 +49,20 @@ Float A floating point number. |floating-point-format| *Float*
4949
String A NUL terminated string of 8-bit unsigned characters (bytes).
5050
|expr-string| Examples: "ab\txx\"--" 'x-z''a,c'
5151

52-
Funcref A reference to a function |Funcref|.
53-
Example: function("strlen")
54-
5552
List An ordered sequence of items |List|.
5653
Example: [1, 2, ['a', 'b']]
5754

5855
Dictionary An associative, unordered array: Each entry has a key and a
5956
value. |Dictionary|
6057
Example: {'blue': "#0000ff", 'red': "#ff0000"}
6158

59+
Funcref A reference to a function |Funcref|.
60+
Example: function("strlen")
61+
62+
Special v:false, v:true, v:none and v:null
63+
64+
Job Used for job control, see |job_start()|.
65+
6266
The Number and String types are converted automatically, depending on how they
6367
are used.
6468

@@ -95,15 +99,16 @@ Note that in the command >
9599
"foo" is converted to 0, which means FALSE. To test for a non-empty string,
96100
use empty(): >
97101
:if !empty("foo")
98-
< *E745* *E728* *E703* *E729* *E730* *E731*
99-
List, Dictionary and Funcref types are not automatically converted.
102+
<
103+
*E745* *E728* *E703* *E729* *E730* *E731* *E908* *E910*
104+
List, Dictionary, Funcref and Job types are not automatically converted.
100105

101106
*E805* *E806* *E808*
102107
When mixing Number and Float the Number is converted to Float. Otherwise
103108
there is no automatic conversion of Float. You can use str2float() for String
104109
to Float, printf() for Float to String and float2nr() for Float to Number.
105110

106-
*E891* *E892* *E893* *E894*
111+
*E891* *E892* *E893* *E894* *E907* *E911*
107112
When expecting a Float a Number can also be used, but nothing else.
108113

109114
*E706* *sticky-type-checking*
@@ -864,7 +869,7 @@ These three can be repeated and mixed. Examples:
864869
expr8 *expr8*
865870
-----
866871
expr8[expr1] item of String or |List| *expr-[]* *E111*
867-
872+
*E909*
868873
If expr8 is a Number or String this results in a String that contains the
869874
expr1'th single byte from expr8. expr8 is used as a String, expr1 as a
870875
Number. This doesn't recognize multi-byte encodings, see |byteidx()| for
@@ -1947,6 +1952,9 @@ invert( {expr}) Number bitwise invert
19471952
isdirectory( {directory}) Number TRUE if {directory} is a directory
19481953
islocked( {expr}) Number TRUE if {expr} is locked
19491954
items( {dict}) List key-value pairs in {dict}
1955+
job_start({command} [, {options}]) Job start a job
1956+
job_status({job}) String get the status of a job
1957+
job_stop({job} [, {how}]) Number stop a job
19501958
join( {list} [, {sep}]) String join {list} items into one String
19511959
jsondecode( {string}) any decode JSON
19521960
jsonencode( {expr}) String encode JSON
@@ -2668,6 +2676,7 @@ confirm({msg} [, {choices} [, {default} [, {type}]]])
26682676

26692677
ch_close({handle}) *ch_close()*
26702678
Close channel {handle}. See |channel|.
2679+
{only available when compiled with the |+channel| feature}
26712680

26722681
ch_open({address} [, {argdict}]) *ch_open()*
26732682
Open a channel to {address}. See |channel|.
@@ -2677,7 +2686,7 @@ ch_open({address} [, {argdict}]) *ch_open()*
26772686
{address} has the form "hostname:port", e.g.,
26782687
"localhost:8765".
26792688

2680-
If {argdict} is given it must be a |Directory|. The optional
2689+
If {argdict} is given it must be a |Dictionary|. The optional
26812690
items are:
26822691
mode "raw" or "json".
26832692
Default "json".
@@ -2686,10 +2695,11 @@ ch_open({address} [, {argdict}]) *ch_open()*
26862695
Default: none.
26872696
waittime Specify connect timeout as milliseconds.
26882697
Negative means forever.
2689-
Default: 0.
2698+
Default: 0 (don't wait)
26902699
timeout Specify response read timeout value as
26912700
milliseconds.
26922701
Default: 2000.
2702+
{only available when compiled with the |+channel| feature}
26932703

26942704
ch_sendexpr({handle}, {expr} [, {callback}]) *ch_sendexpr()*
26952705
Send {expr} over JSON channel {handle}. See |channel-use|.
@@ -2704,10 +2714,14 @@ ch_sendexpr({handle}, {expr} [, {callback}]) *ch_sendexpr()*
27042714
function. It is called when the response is received. See
27052715
|channel-callback|.
27062716

2717+
{only available when compiled with the |+channel| feature}
2718+
27072719
ch_sendraw({handle}, {string} [, {callback}]) *ch_sendraw()*
27082720
Send {string} over raw channel {handle}. See |channel-raw|.
27092721
Works like |ch_sendexpr()|, but does not decode the response.
27102722

2723+
{only available when compiled with the |+channel| feature}
2724+
27112725
*copy()*
27122726
copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't
27132727
different from using {expr} directly.
@@ -2888,9 +2902,12 @@ diff_hlID({lnum}, {col}) *diff_hlID()*
28882902

28892903
empty({expr}) *empty()*
28902904
Return the Number 1 if {expr} is empty, zero otherwise.
2891-
A |List| or |Dictionary| is empty when it does not have any
2892-
items. A Number is empty when its value is zero.
2893-
|v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2905+
- A |List| or |Dictionary| is empty when it does not have any
2906+
items.
2907+
- A Number and Float is empty when its value is zero.
2908+
- |v:false|, |v:none| and |v:null| are empty, |v:true| is not.
2909+
- A Job is empty when it failed to start.
2910+
28942911
For a long |List| this is much faster than comparing the
28952912
length with zero.
28962913

@@ -4286,6 +4303,73 @@ items({dict}) *items()*
42864303
order.
42874304

42884305

4306+
job_start({command} [, {options}]) *job_start()*
4307+
Start a job and return a Job object. Unlike |system()| and
4308+
|:!cmd| this does not wait for the job to finish.
4309+
4310+
{command} can be a string. This works best on MS-Windows. On
4311+
Unix it is split up in white-separated parts to be passed to
4312+
execvp(). Arguments in double quotes can contain white space.
4313+
4314+
{command} can be a list, where the first item is the executable
4315+
and further items are the arguments. All items are converted
4316+
to String. This works best on Unix.
4317+
4318+
The command is executed directly, not through a shell, the
4319+
'shell' option is not used. To use the shell: >
4320+
let job = job_start(["/bin/sh", "-c", "echo hello"])
4321+
< Or: >
4322+
let job = job_start('/bin/sh -c "echo hello"')
4323+
< However, the status of the job will now be the status of the
4324+
shell, and stopping the job means stopping the shell and the
4325+
command may continue to run.
4326+
4327+
On Unix $PATH is used to search for the executable only when
4328+
the command does not contain a slash.
4329+
4330+
The job will use the same terminal as Vim. If it reads from
4331+
stdin the job and Vim will be fighting over input, that
4332+
doesn't work. Redirect stdin and stdout to avoid problems: >
4333+
let job = job_start(['sh', '-c', "myserver </dev/null >/dev/null"])
4334+
<
4335+
The returned Job object can be used to get the status with
4336+
|job_status()| and stop the job with |job_stop()|.
4337+
4338+
{options} must be a Dictionary. It can contain these optional
4339+
items:
4340+
killonexit When non-zero kill the job when Vim
4341+
exits. (default: 0, don't kill)
4342+
4343+
{only available when compiled with the |+channel| feature}
4344+
4345+
job_status({job}) *job_status()*
4346+
Returns a String with the status of {job}:
4347+
"run" job is running
4348+
"fail" job failed to start
4349+
"dead" job died or was stopped after running
4350+
4351+
{only available when compiled with the |+channel| feature}
4352+
4353+
job_stop({job} [, {how}]) *job_stop()*
4354+
Stop the {job}. This can also be used to signal the job.
4355+
4356+
When {how} is omitted or is "term" the job will be terminated
4357+
normally. For Unix SIGTERM is sent.
4358+
Other values:
4359+
"hup" Unix: SIGHUP
4360+
"quit" Unix: SIGQUIT
4361+
"kill" Unix: SIGKILL (strongest way to stop)
4362+
number Unix: signal with that number
4363+
4364+
The result is a Number: 1 if the operation could be executed,
4365+
0 if "how" is not supported on the system.
4366+
Note that even when the operation was executed, whether the
4367+
job was actually stopped needs to be checked with
4368+
job_status().
4369+
The operation will even be done when the job wasn't running.
4370+
4371+
{only available when compiled with the |+channel| feature}
4372+
42894373
join({list} [, {sep}]) *join()*
42904374
Join the items in {list} together into one String.
42914375
When {sep} is specified it is put in between the items. If
@@ -6692,6 +6776,7 @@ type({expr}) The result is a Number, depending on the type of {expr}:
66926776
Float: 5
66936777
Boolean: 6 (v:false and v:true)
66946778
None 7 (v:null and v:none)
6779+
Job 8
66956780
To avoid the magic numbers it should be used this way: >
66966781
:if type(myvar) == type(0)
66976782
:if type(myvar) == type("")

src/channel.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ channel_open(char *hostname, int port_in, int waittime, void (*close_cb)(void))
490490
val = 0;
491491
ioctlsocket(sd, FIONBIO, &val);
492492
#else
493-
fcntl(sd, F_SETFL, 0);
493+
(void)fcntl(sd, F_SETFL, 0);
494494
#endif
495495
}
496496

@@ -878,24 +878,31 @@ channel_exe_cmd(int idx, char_u *cmd, typval_T *arg2, typval_T *arg3)
878878
{
879879
typval_T *tv;
880880
typval_T err_tv;
881-
char_u *json;
881+
char_u *json = NULL;
882882

883883
/* Don't pollute the display with errors. */
884884
++emsg_skip;
885885
tv = eval_expr(arg, NULL);
886-
--emsg_skip;
887886
if (is_eval)
888887
{
889-
if (tv == NULL)
888+
if (tv != NULL)
889+
json = json_encode_nr_expr(arg3->vval.v_number, tv);
890+
if (tv == NULL || (json != NULL && *json == NUL))
890891
{
892+
/* If evaluation failed or the result can't be encoded
893+
* then return the string "ERROR". */
891894
err_tv.v_type = VAR_STRING;
892895
err_tv.vval.v_string = (char_u *)"ERROR";
893896
tv = &err_tv;
897+
json = json_encode_nr_expr(arg3->vval.v_number, tv);
898+
}
899+
if (json != NULL)
900+
{
901+
channel_send(idx, json, "eval");
902+
vim_free(json);
894903
}
895-
json = json_encode_nr_expr(arg3->vval.v_number, tv);
896-
channel_send(idx, json, "eval");
897-
vim_free(json);
898904
}
905+
--emsg_skip;
899906
if (tv != &err_tv)
900907
free_tv(tv);
901908
}
@@ -1499,6 +1506,9 @@ channel_parse_messages(void)
14991506
return ret;
15001507
}
15011508

1509+
/*
1510+
* Mark references to lists used in channels.
1511+
*/
15021512
int
15031513
set_ref_in_channel(int copyID)
15041514
{

0 commit comments

Comments
 (0)