Skip to content

Commit c3719bd

Browse files
committed
patch 8.0.1312: balloon_show() only works in terminal when compiled with GUI
Problem: balloon_show() only works in terminal when compiled with the GUI. Solution: Add FEAT_BEVAL_GUI and refactor to move common code out of the GUI specific file.
1 parent c7d16dc commit c3719bd

35 files changed

Lines changed: 574 additions & 509 deletions

Filelist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ SRC_ALL = \
1212
src/arabic.c \
1313
src/arabic.h \
1414
src/ascii.h \
15+
src/beval.c \
16+
src/beval.h \
1517
src/blowfish.c \
1618
src/buffer.c \
1719
src/channel.c \
@@ -41,7 +43,6 @@ SRC_ALL = \
4143
src/gui.c \
4244
src/gui.h \
4345
src/gui_beval.c \
44-
src/gui_beval.h \
4546
src/hardcopy.c \
4647
src/hashtab.c \
4748
src/json.c \

src/Make_cyg_ming.mak

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ GUIOBJ = $(OUTDIR)/gui.o $(OUTDIR)/gui_w32.o $(OUTDIR)/gui_beval.o $(OUTDIR)/os
642642
CUIOBJ = $(OUTDIR)/iscygpty.o
643643
OBJ = \
644644
$(OUTDIR)/arabic.o \
645+
$(OUTDIR)/beval.o \
645646
$(OUTDIR)/blowfish.o \
646647
$(OUTDIR)/buffer.o \
647648
$(OUTDIR)/charset.o \
@@ -920,8 +921,8 @@ endif
920921
###########################################################################
921922
INCL = vim.h alloc.h arabic.h ascii.h ex_cmds.h farsi.h feature.h globals.h \
922923
keymap.h macros.h option.h os_dos.h os_win32.h proto.h regexp.h \
923-
spell.h structs.h term.h $(NBDEBUG_INCL)
924-
GUI_INCL = gui.h gui_beval.h
924+
spell.h structs.h term.h beval.h $(NBDEBUG_INCL)
925+
GUI_INCL = gui.h
925926
CUI_INCL = iscygpty.h
926927

927928
$(OUTDIR)/if_python.o: if_python.c if_py_both.h $(INCL)
@@ -946,6 +947,9 @@ $(OUTDIR)/gui_dwrite.o: gui_dwrite.cpp $(INCL) gui_dwrite.h
946947
$(OUTDIR)/gui.o: gui.c $(INCL) $(GUI_INCL)
947948
$(CC) -c $(CFLAGS) gui.c -o $(OUTDIR)/gui.o
948949

950+
$(OUTDIR)/beval.o: beval.c $(INCL) $(GUI_INCL)
951+
$(CC) -c $(CFLAGS) beval.c -o $(OUTDIR)/beval.o
952+
949953
$(OUTDIR)/gui_beval.o: gui_beval.c $(INCL) $(GUI_INCL)
950954
$(CC) -c $(CFLAGS) gui_beval.c -o $(OUTDIR)/gui_beval.o
951955

src/Make_mvc.mak

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,10 +683,11 @@ CFLAGS = $(CFLAGS) /Zl /MTd
683683

684684
INCL = vim.h alloc.h arabic.h ascii.h ex_cmds.h farsi.h feature.h globals.h \
685685
keymap.h macros.h option.h os_dos.h os_win32.h proto.h regexp.h \
686-
spell.h structs.h term.h $(NBDEBUG_INCL)
686+
spell.h structs.h term.h beval.h $(NBDEBUG_INCL)
687687

688688
OBJ = \
689689
$(OUTDIR)\arabic.obj \
690+
$(OUTDIR)\beval.obj \
690691
$(OUTDIR)\blowfish.obj \
691692
$(OUTDIR)\buffer.obj \
692693
$(OUTDIR)\charset.obj \
@@ -781,8 +782,7 @@ CFLAGS = $(CFLAGS) -DFEAT_GUI_W32
781782
RCFLAGS = $(RCFLAGS) -DFEAT_GUI_W32
782783
VIM = g$(VIM)
783784
GUI_INCL = \
784-
gui.h \
785-
gui_beval.h
785+
gui.h
786786
GUI_OBJ = \
787787
$(OUTDIR)\gui.obj \
788788
$(OUTDIR)\gui_beval.obj \
@@ -1297,6 +1297,8 @@ testclean:
12971297

12981298
$(OUTDIR)/arabic.obj: $(OUTDIR) arabic.c $(INCL)
12991299

1300+
$(OUTDIR)/beval.obj: $(OUTDIR) beval.c $(INCL)
1301+
13001302
$(OUTDIR)/blowfish.obj: $(OUTDIR) blowfish.c $(INCL)
13011303

13021304
$(OUTDIR)/buffer.obj: $(OUTDIR) buffer.c $(INCL)

src/Make_vms.mms

Lines changed: 85 additions & 81 deletions
Large diffs are not rendered by default.

src/Makefile

Lines changed: 95 additions & 89 deletions
Large diffs are not rendered by default.

src/beval.c

Lines changed: 280 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,280 @@
1+
/* vi:set ts=8 sts=4 sw=4 noet:
2+
*
3+
* VIM - Vi IMproved by Bram Moolenaar
4+
* Visual Workshop integration by Gordon Prieur
5+
*
6+
* Do ":help uganda" in Vim to read copying and usage conditions.
7+
* Do ":help credits" in Vim to see a list of people who contributed.
8+
* See README.txt for an overview of the Vim source code.
9+
*/
10+
11+
#include "vim.h"
12+
13+
#if defined(FEAT_BEVAL) || defined(PROTO)
14+
15+
/*
16+
* Get the text and position to be evaluated for "beval".
17+
* If "getword" is true the returned text is not the whole line but the
18+
* relevant word in allocated memory.
19+
* Returns OK or FAIL.
20+
*/
21+
int
22+
get_beval_info(
23+
BalloonEval *beval,
24+
int getword,
25+
win_T **winp,
26+
linenr_T *lnump,
27+
char_u **textp,
28+
int *colp)
29+
{
30+
win_T *wp;
31+
int row, col;
32+
char_u *lbuf;
33+
linenr_T lnum;
34+
35+
*textp = NULL;
36+
# ifdef FEAT_BEVAL_TERM
37+
# ifdef FEAT_GUI
38+
if (!gui.in_use)
39+
# endif
40+
{
41+
row = mouse_row;
42+
col = mouse_col;
43+
}
44+
# endif
45+
# ifdef FEAT_GUI
46+
if (gui.in_use)
47+
{
48+
row = Y_2_ROW(beval->y);
49+
col = X_2_COL(beval->x);
50+
}
51+
#endif
52+
wp = mouse_find_win(&row, &col);
53+
if (wp != NULL && row < wp->w_height && col < wp->w_width)
54+
{
55+
/* Found a window and the cursor is in the text. Now find the line
56+
* number. */
57+
if (!mouse_comp_pos(wp, &row, &col, &lnum))
58+
{
59+
/* Not past end of the file. */
60+
lbuf = ml_get_buf(wp->w_buffer, lnum, FALSE);
61+
if (col <= win_linetabsize(wp, lbuf, (colnr_T)MAXCOL))
62+
{
63+
/* Not past end of line. */
64+
if (getword)
65+
{
66+
/* For Netbeans we get the relevant part of the line
67+
* instead of the whole line. */
68+
int len;
69+
pos_T *spos = NULL, *epos = NULL;
70+
71+
if (VIsual_active)
72+
{
73+
if (LT_POS(VIsual, curwin->w_cursor))
74+
{
75+
spos = &VIsual;
76+
epos = &curwin->w_cursor;
77+
}
78+
else
79+
{
80+
spos = &curwin->w_cursor;
81+
epos = &VIsual;
82+
}
83+
}
84+
85+
col = vcol2col(wp, lnum, col);
86+
87+
if (VIsual_active
88+
&& wp->w_buffer == curwin->w_buffer
89+
&& (lnum == spos->lnum
90+
? col >= (int)spos->col
91+
: lnum > spos->lnum)
92+
&& (lnum == epos->lnum
93+
? col <= (int)epos->col
94+
: lnum < epos->lnum))
95+
{
96+
/* Visual mode and pointing to the line with the
97+
* Visual selection: return selected text, with a
98+
* maximum of one line. */
99+
if (spos->lnum != epos->lnum || spos->col == epos->col)
100+
return FAIL;
101+
102+
lbuf = ml_get_buf(curwin->w_buffer, VIsual.lnum, FALSE);
103+
len = epos->col - spos->col;
104+
if (*p_sel != 'e')
105+
len += MB_PTR2LEN(lbuf + epos->col);
106+
lbuf = vim_strnsave(lbuf + spos->col, len);
107+
lnum = spos->lnum;
108+
col = spos->col;
109+
}
110+
else
111+
{
112+
/* Find the word under the cursor. */
113+
++emsg_off;
114+
len = find_ident_at_pos(wp, lnum, (colnr_T)col, &lbuf,
115+
FIND_IDENT + FIND_STRING + FIND_EVAL);
116+
--emsg_off;
117+
if (len == 0)
118+
return FAIL;
119+
lbuf = vim_strnsave(lbuf, len);
120+
}
121+
}
122+
123+
*winp = wp;
124+
*lnump = lnum;
125+
*textp = lbuf;
126+
*colp = col;
127+
beval->ts = wp->w_buffer->b_p_ts;
128+
return OK;
129+
}
130+
}
131+
}
132+
133+
return FAIL;
134+
}
135+
136+
/*
137+
* Show a balloon with "mesg".
138+
*/
139+
void
140+
post_balloon(BalloonEval *beval UNUSED, char_u *mesg)
141+
{
142+
# ifdef FEAT_BEVAL_TERM
143+
# ifdef FEAT_GUI
144+
if (!gui.in_use)
145+
# endif
146+
ui_post_balloon(mesg);
147+
# endif
148+
# ifdef FEAT_BEVAL_GUI
149+
if (gui.in_use)
150+
gui_mch_post_balloon(beval, mesg);
151+
# endif
152+
}
153+
154+
/*
155+
* Returns TRUE if the balloon eval has been enabled:
156+
* 'ballooneval' for the GUI and 'balloonevalterm' for the terminal.
157+
* Also checks if the screen isn't scrolled up.
158+
*/
159+
int
160+
can_use_beval(void)
161+
{
162+
return (0
163+
#ifdef FEAT_BEVAL_GUI
164+
|| (gui.in_use && p_beval)
165+
#endif
166+
#ifdef FEAT_BEVAL_TERM
167+
|| (
168+
# ifdef FEAT_GUI
169+
!gui.in_use &&
170+
# endif
171+
p_bevalterm)
172+
#endif
173+
) && msg_scrolled == 0;
174+
}
175+
176+
/*
177+
* Common code, invoked when the mouse is resting for a moment.
178+
*/
179+
void
180+
general_beval_cb(BalloonEval *beval, int state UNUSED)
181+
{
182+
#ifdef FEAT_EVAL
183+
win_T *wp;
184+
int col;
185+
int use_sandbox;
186+
linenr_T lnum;
187+
char_u *text;
188+
static char_u *result = NULL;
189+
long winnr = 0;
190+
char_u *bexpr;
191+
buf_T *save_curbuf;
192+
size_t len;
193+
win_T *cw;
194+
#endif
195+
static int recursive = FALSE;
196+
197+
/* Don't do anything when 'ballooneval' is off, messages scrolled the
198+
* windows up or we have no beval area. */
199+
if (!can_use_beval() || beval == NULL)
200+
return;
201+
202+
/* Don't do this recursively. Happens when the expression evaluation
203+
* takes a long time and invokes something that checks for CTRL-C typed. */
204+
if (recursive)
205+
return;
206+
recursive = TRUE;
207+
208+
#ifdef FEAT_EVAL
209+
if (get_beval_info(beval, TRUE, &wp, &lnum, &text, &col) == OK)
210+
{
211+
bexpr = (*wp->w_buffer->b_p_bexpr == NUL) ? p_bexpr
212+
: wp->w_buffer->b_p_bexpr;
213+
if (*bexpr != NUL)
214+
{
215+
/* Convert window pointer to number. */
216+
for (cw = firstwin; cw != wp; cw = cw->w_next)
217+
++winnr;
218+
219+
set_vim_var_nr(VV_BEVAL_BUFNR, (long)wp->w_buffer->b_fnum);
220+
set_vim_var_nr(VV_BEVAL_WINNR, winnr);
221+
set_vim_var_nr(VV_BEVAL_WINID, wp->w_id);
222+
set_vim_var_nr(VV_BEVAL_LNUM, (long)lnum);
223+
set_vim_var_nr(VV_BEVAL_COL, (long)(col + 1));
224+
set_vim_var_string(VV_BEVAL_TEXT, text, -1);
225+
vim_free(text);
226+
227+
/*
228+
* Temporarily change the curbuf, so that we can determine whether
229+
* the buffer-local balloonexpr option was set insecurely.
230+
*/
231+
save_curbuf = curbuf;
232+
curbuf = wp->w_buffer;
233+
use_sandbox = was_set_insecurely((char_u *)"balloonexpr",
234+
*curbuf->b_p_bexpr == NUL ? 0 : OPT_LOCAL);
235+
curbuf = save_curbuf;
236+
if (use_sandbox)
237+
++sandbox;
238+
++textlock;
239+
240+
vim_free(result);
241+
result = eval_to_string(bexpr, NULL, TRUE);
242+
243+
/* Remove one trailing newline, it is added when the result was a
244+
* list and it's hardly ever useful. If the user really wants a
245+
* trailing newline he can add two and one remains. */
246+
if (result != NULL)
247+
{
248+
len = STRLEN(result);
249+
if (len > 0 && result[len - 1] == NL)
250+
result[len - 1] = NUL;
251+
}
252+
253+
if (use_sandbox)
254+
--sandbox;
255+
--textlock;
256+
257+
set_vim_var_string(VV_BEVAL_TEXT, NULL, -1);
258+
if (result != NULL && result[0] != NUL)
259+
{
260+
post_balloon(beval, result);
261+
recursive = FALSE;
262+
return;
263+
}
264+
}
265+
}
266+
#endif
267+
#ifdef FEAT_NETBEANS_INTG
268+
if (bevalServers & BEVAL_NETBEANS)
269+
netbeans_beval_cb(beval, state);
270+
#endif
271+
#ifdef FEAT_SUN_WORKSHOP
272+
if (bevalServers & BEVAL_WORKSHOP)
273+
workshop_beval_cb(beval, state);
274+
#endif
275+
276+
recursive = FALSE;
277+
}
278+
279+
#endif
280+

src/gui_beval.h renamed to src/beval.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* Do ":help credits" in Vim to see a list of people who contributed.
88
*/
99

10-
#if !defined(GUI_BEVAL_H) && (defined(FEAT_BEVAL) || defined(PROTO))
11-
#define GUI_BEVAL_H
10+
#if !defined(BEVAL__H) && (defined(FEAT_BEVAL) || defined(PROTO))
11+
#define BEVAL__H
1212

1313
#ifdef FEAT_GUI_GTK
1414
# ifdef USE_GTK3
@@ -75,6 +75,9 @@ typedef struct BalloonEvalStruct
7575
#define EVAL_OFFSET_X 15 /* displacement of beval topleft corner from pointer */
7676
#define EVAL_OFFSET_Y 10
7777

78-
#include "gui_beval.pro"
78+
#include "beval.pro"
79+
#ifdef FEAT_BEVAL_GUI
80+
# include "gui_beval.pro"
81+
#endif
7982

80-
#endif /* GUI_BEVAL_H and FEAT_BEVAL */
83+
#endif /* BEVAL__H and FEAT_BEVAL_GUI */

src/evalfunc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5583,13 +5583,13 @@ f_has(typval_T *argvars, typval_T *rettv)
55835583
#ifdef FEAT_AUTOSERVERNAME
55845584
"autoservername",
55855585
#endif
5586-
#ifdef FEAT_BEVAL
5586+
#ifdef FEAT_BEVAL_GUI
55875587
"balloon_eval",
55885588
# ifndef FEAT_GUI_W32 /* other GUIs always have multiline balloons */
55895589
"balloon_multiline",
55905590
# endif
55915591
#endif
5592-
#ifdef FEAT_BEVALTERM
5592+
#ifdef FEAT_BEVAL_TERM
55935593
"balloon_eval_term",
55945594
#endif
55955595
#if defined(SOME_BUILTIN_TCAPS) || defined(ALL_BUILTIN_TCAPS)

0 commit comments

Comments
 (0)