Skip to content

Commit 59716a2

Browse files
committed
patch 8.0.0396: 'balloonexpr' only works synchronously
Problem: 'balloonexpr' only works synchronously. Solution: Add balloon_show(). (Jusufadis Bakamovic, closes #1449)
1 parent f8ab1b1 commit 59716a2

File tree

5 files changed

+57
-6
lines changed

5 files changed

+57
-6
lines changed

runtime/doc/eval.txt

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,19 +1981,20 @@ argidx() Number current index in the argument list
19811981
arglistid([{winnr} [, {tabnr}]]) Number argument list id
19821982
argv({nr}) String {nr} entry of the argument list
19831983
argv() List the argument list
1984-
assert_equal({exp}, {act} [, {msg}]) none assert {exp} is equal to {act}
1985-
assert_exception({error} [, {msg}]) none assert {error} is in v:exception
1986-
assert_fails({cmd} [, {error}]) none assert {cmd} fails
1987-
assert_false({actual} [, {msg}]) none assert {actual} is false
1984+
assert_equal({exp}, {act} [, {msg}]) none assert {exp} is equal to {act}
1985+
assert_exception({error} [, {msg}]) none assert {error} is in v:exception
1986+
assert_fails({cmd} [, {error}]) none assert {cmd} fails
1987+
assert_false({actual} [, {msg}]) none assert {actual} is false
19881988
assert_inrange({lower}, {upper}, {actual} [, {msg}])
19891989
none assert {actual} is inside the range
1990-
assert_match({pat}, {text} [, {msg}]) none assert {pat} matches {text}
1990+
assert_match({pat}, {text} [, {msg}]) none assert {pat} matches {text}
19911991
assert_notequal({exp}, {act} [, {msg}]) none assert {exp} is not equal {act}
19921992
assert_notmatch({pat}, {text} [, {msg}]) none assert {pat} not matches {text}
1993-
assert_true({actual} [, {msg}]) none assert {actual} is true
1993+
assert_true({actual} [, {msg}]) none assert {actual} is true
19941994
asin({expr}) Float arc sine of {expr}
19951995
atan({expr}) Float arc tangent of {expr}
19961996
atan2({expr1}, {expr2}) Float arc tangent of {expr1} / {expr2}
1997+
balloon_show({msg}) none show {msg} inside the balloon
19971998
browse({save}, {title}, {initdir}, {default})
19981999
String put up a file requester
19992000
browsedir({title}, {initdir}) String put up a directory requester
@@ -2619,6 +2620,25 @@ atan2({expr1}, {expr2}) *atan2()*
26192620
< 2.356194
26202621
{only available when compiled with the |+float| feature}
26212622

2623+
balloon_show({msg}) *balloon_show()*
2624+
Show {msg} inside the balloon.
2625+
Example: >
2626+
func GetBalloonContent()
2627+
" initiate getting the content
2628+
return ''
2629+
endfunc
2630+
set balloonexpr=GetBalloonContent()
2631+
2632+
func BalloonCallback(result)
2633+
call balloon_show(a:result)
2634+
endfunc
2635+
<
2636+
The intended use is that fetching the content of the balloon
2637+
is initiated from 'balloonexpr'. It will invoke an
2638+
asynchronous method, in which a callback invokes
2639+
balloon_show(). The 'balloonexpr' itself can return an
2640+
empty string or a placeholder.
2641+
{only available when compiled with the +beval feature}
26222642

26232643
*browse()*
26242644
browse({save}, {title}, {initdir}, {default})

src/evalfunc.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ static void f_asin(typval_T *argvars, typval_T *rettv);
5858
static void f_atan(typval_T *argvars, typval_T *rettv);
5959
static void f_atan2(typval_T *argvars, typval_T *rettv);
6060
#endif
61+
#ifdef FEAT_BEVAL
62+
static void f_balloon_show(typval_T *argvars, typval_T *rettv);
63+
#endif
6164
static void f_browse(typval_T *argvars, typval_T *rettv);
6265
static void f_browsedir(typval_T *argvars, typval_T *rettv);
6366
static void f_bufexists(typval_T *argvars, typval_T *rettv);
@@ -483,6 +486,9 @@ static struct fst
483486
#ifdef FEAT_FLOAT
484487
{"atan", 1, 1, f_atan},
485488
{"atan2", 2, 2, f_atan2},
489+
#endif
490+
#ifdef FEAT_BEVAL
491+
{"balloon_show", 1, 1, f_balloon_show},
486492
#endif
487493
{"browse", 4, 4, f_browse},
488494
{"browsedir", 2, 2, f_browsedir},
@@ -1362,6 +1368,17 @@ f_atan2(typval_T *argvars, typval_T *rettv)
13621368
}
13631369
#endif
13641370

1371+
/*
1372+
* "balloon_show()" function
1373+
*/
1374+
#ifdef FEAT_BEVAL
1375+
static void
1376+
f_balloon_show(typval_T *argvars, typval_T *rettv UNUSED)
1377+
{
1378+
gui_mch_post_balloon(balloonEval, get_tv_string_chk(&argvars[0]));
1379+
}
1380+
#endif
1381+
13651382
/*
13661383
* "browse(save, title, initdir, default)" function
13671384
*/

src/os_unix.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,12 @@ mch_inchar(
467467
if ((wait_time < 0 || wait_time > 100L) && channel_any_readahead())
468468
wait_time = 10L;
469469
#endif
470+
#ifdef FEAT_BEVAL
471+
if (p_beval && wait_time > 100L)
472+
/* The 'balloonexpr' may indirectly invoke a callback while waiting
473+
* for a character, need to check often. */
474+
wait_time = 100L;
475+
#endif
470476

471477
/*
472478
* We want to be interrupted by the winch signal

src/os_win32.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,6 +1467,12 @@ WaitForChar(long msec)
14671467
dwWaitTime = 10;
14681468
}
14691469
#endif
1470+
#ifdef FEAT_BEVAL
1471+
if (p_beval && dwWaitTime > 100)
1472+
/* The 'balloonexpr' may indirectly invoke a callback while
1473+
* waiting for a character, need to check often. */
1474+
dwWaitTime = 100;
1475+
#endif
14701476
#ifdef FEAT_MZSCHEME
14711477
if (mzthreads_allowed() && p_mzq > 0
14721478
&& (msec < 0 || (long)dwWaitTime > p_mzq))

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
396,
767769
/**/
768770
395,
769771
/**/

0 commit comments

Comments
 (0)