Permalink
Browse files

patch 8.0.1309: cannot use 'balloonexpr' in a terminal

Problem:    Cannot use 'balloonexpr' in a terminal.
Solution:   Add 'balloonevalterm' and add code to handle mouse movements in a
            terminal. Initial implementation for Unix with GUI.
  • Loading branch information...
brammool committed Nov 18, 2017
1 parent 234d162 commit 51b0f3701ecb440aa72ab6017c1df6940c0e0f6f
View
@@ -1,4 +1,4 @@
*options.txt* For Vim version 8.0. Last change: 2017 Nov 11
*options.txt* For Vim version 8.0. Last change: 2017 Nov 18
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1127,7 +1127,16 @@ A jump table for the options with a short description can be found at |Q_op|.
{not in Vi}
{only available when compiled with the |+balloon_eval|
feature}
Switch on the |balloon-eval| functionality.
Switch on the |balloon-eval| functionality for the GUI.
*'balloonevalterm'* *'bevalterm'* *'noballoonevalterm'*
*'nobevalterm'*
'balloonevalterm' 'bevalterm' boolean (default off)
global
{not in Vi}
{only available when compiled with the
|+balloon_eval_term| feature}
Switch on the |balloon-eval| functionality for the terminal.
*'balloonexpr'* *'bexpr'*
'balloonexpr' 'bexpr' string (default "")
@@ -3521,6 +3530,8 @@ A jump table for the options with a short description can be found at |Q_op|.
systems without an fsync() implementation, this variable is always
off.
Also see 'swapsync' for controlling fsync() on swap files.
'fsync' also applies to |writefile()|, unless a flag is used to
overrule it.
*'gdefault'* *'gd'* *'nogdefault'* *'nogd'*
'gdefault' 'gd' boolean (default off)
@@ -3944,7 +3955,7 @@ A jump table for the options with a short description can be found at |Q_op|.
toolbar, tabline, etc. Instead, the behavior is similar to
when the window is maximized and will adjust 'lines' and
'columns' to fit to the window. Without the 'k' flag Vim will
try to keep 'lines' and 'columns the same when adding and
try to keep 'lines' and 'columns' the same when adding and
removing GUI components.
*'guipty'* *'noguipty'*
@@ -8221,7 +8232,7 @@ A jump table for the options with a short description can be found at |Q_op|.
number, more intelligent detection process runs.
The "xterm2" value will be set if the xterm version is reported to be
from 95 to 276. The "sgr" value will be set if the xterm version is
277 or highter.
277 or highter and when Vim detects Mac Terminal.app or Iterm2.
If you do not want 'ttymouse' to be set to "xterm2" or "sgr"
automatically, set t_RV to an empty string: >
:set t_RV=
@@ -69,6 +69,11 @@ func s:StartDebug(cmd)
endif
let pty = job_info(term_getjob(s:ptybuf))['tty_out']
let s:ptywin = win_getid(winnr())
if vertical
" Assuming the source code window will get a signcolumn, use two more
" columns for that, thus one less for the terminal window.
exe (&columns / 2 - 1) . "wincmd |"
endif
" Create a hidden terminal window to communicate with gdb
let s:commbuf = term_start('NONE', {
@@ -121,6 +126,15 @@ func s:StartDebug(cmd)
call s:InstallCommands()
call win_gotoid(s:gdbwin)
" Enable showing a balloon with eval info
if has("balloon_eval")
set ballooneval
set balloonexpr=TermDebugBalloonExpr()
if has("balloon_eval_term")
set balloonevalterm
endif
endif
let s:breakpoints = {}
augroup TermDebug
@@ -144,6 +158,14 @@ func s:EndDebug(job, status)
let &columns = s:save_columns
endif
if has("balloon_eval")
set noballooneval
set balloonexpr=
if has("balloon_eval_term")
set noballoonevalterm
endif
endif
au! TermDebug
endfunc
@@ -279,6 +301,11 @@ func s:Run(args)
call s:SendCommand('-exec-run')
endfunc
func s:SendEval(expr)
call s:SendCommand('-data-evaluate-expression "' . a:expr . '"')
let s:evalexpr = a:expr
endfunc
" :Evaluate - evaluate what is under the cursor
func s:Evaluate(range, arg)
if a:arg != ''
@@ -294,25 +321,54 @@ func s:Evaluate(range, arg)
else
let expr = expand('<cexpr>')
endif
call s:SendCommand('-data-evaluate-expression "' . expr . '"')
let s:evalexpr = expr
call s:SendEval(expr)
endfunc
let s:evalFromBalloonExpr = 0
" Handle the result of data-evaluate-expression
func s:HandleEvaluate(msg)
let value = substitute(a:msg, '.*value="\(.*\)"', '\1', '')
let value = substitute(value, '\\"', '"', 'g')
echomsg '"' . s:evalexpr . '": ' . value
if s:evalFromBalloonExpr
if s:evalFromBalloonExprResult == ''
let s:evalFromBalloonExprResult = s:evalexpr . ': ' . value
else
let s:evalFromBalloonExprResult .= ' = ' . value
endif
call balloon_show(s:evalFromBalloonExprResult)
else
echomsg '"' . s:evalexpr . '": ' . value
endif
if s:evalexpr[0] != '*' && value =~ '^0x' && value != '0x0' && value !~ '"$'
" Looks like a pointer, also display what it points to.
let s:evalexpr = '*' . s:evalexpr
call term_sendkeys(s:commbuf, '-data-evaluate-expression "' . s:evalexpr . "\"\r")
call s:SendEval('*' . s:evalexpr)
else
let s:evalFromBalloonExpr = 0
endif
endfunc
" Show a balloon with information of the variable under the mouse pointer,
" if there is any.
func TermDebugBalloonExpr()
if v:beval_winid != s:startwin
return
endif
call s:SendEval(v:beval_text)
let s:evalFromBalloonExpr = 1
let s:evalFromBalloonExprResult = ''
return ''
endfunc
" Handle an error.
func s:HandleError(msg)
if a:msg =~ 'No symbol .* in current context'
\ || a:msg =~ 'Cannot access memory at address '
\ || a:msg =~ 'Attempt to use a type name as an expression'
" Result of s:SendEval() failed, ignore.
return
endif
echoerr substitute(a:msg, '.*msg="\(.*\)"', '\1', '')
endfunc
View
@@ -1177,6 +1177,7 @@ edit(
case K_LEFTDRAG:
case K_LEFTRELEASE:
case K_LEFTRELEASE_NM:
case K_MOUSEMOVE:
case K_MIDDLEMOUSE:
case K_MIDDLEDRAG:
case K_MIDDLERELEASE:
View
@@ -1410,7 +1410,7 @@ f_atan2(typval_T *argvars, typval_T *rettv)
f_balloon_show(typval_T *argvars, typval_T *rettv UNUSED)
{
if (balloonEval != NULL)
gui_mch_post_balloon(balloonEval, get_tv_string_chk(&argvars[0]));
post_balloon(balloonEval, get_tv_string_chk(&argvars[0]));
}
#endif
@@ -5589,6 +5589,9 @@ f_has(typval_T *argvars, typval_T *rettv)
"balloon_multiline",
# endif
#endif
#ifdef FEAT_BEVALTERM
"balloon_eval_term",
#endif
#if defined(SOME_BUILTIN_TCAPS) || defined(ALL_BUILTIN_TCAPS)
"builtin_terms",
# ifdef ALL_BUILTIN_TCAPS
View
@@ -1093,21 +1093,21 @@ static timer_T *first_timer = NULL;
static long last_timer_id = 0;
static long
timer_time_left(timer_T *timer, proftime_T *now)
proftime_time_left(proftime_T *due, proftime_T *now)
{
# ifdef WIN3264
LARGE_INTEGER fr;
if (now->QuadPart > timer->tr_due.QuadPart)
if (now->QuadPart > due->QuadPart)
return 0;
QueryPerformanceFrequency(&fr);
return (long)(((double)(timer->tr_due.QuadPart - now->QuadPart)
return (long)(((double)(due->QuadPart - now->QuadPart)
/ (double)fr.QuadPart) * 1000);
# else
if (now->tv_sec > timer->tr_due.tv_sec)
if (now->tv_sec > due->tv_sec)
return 0;
return (timer->tr_due.tv_sec - now->tv_sec) * 1000
+ (timer->tr_due.tv_usec - now->tv_usec) / 1000;
return (due->tv_sec - now->tv_sec) * 1000
+ (due->tv_usec - now->tv_usec) / 1000;
# endif
}
@@ -1219,7 +1219,7 @@ check_due_timer(void)
if (timer->tr_id == -1 || timer->tr_firing || timer->tr_paused)
continue;
this_due = timer_time_left(timer, &now);
this_due = proftime_time_left(&timer->tr_due, &now);
if (this_due <= 1)
{
int save_timer_busy = timer_busy;
@@ -1271,7 +1271,7 @@ check_due_timer(void)
&& timer->tr_emsg_count < 3)
{
profile_setlimit(timer->tr_interval, &timer->tr_due);
this_due = timer_time_left(timer, &now);
this_due = proftime_time_left(&timer->tr_due, &now);
if (this_due < 1)
this_due = 1;
if (timer->tr_repeat > 0)
@@ -1291,6 +1291,27 @@ check_due_timer(void)
if (did_one)
redraw_after_callback(need_update_screen);
#ifdef FEAT_BEVALTERM
if (bevalexpr_due_set)
{
this_due = proftime_time_left(&bevalexpr_due, &now);
if (this_due <= 1)
{
bevalexpr_due_set = FALSE;
if (balloonEval == NULL)
{
balloonEval = (BalloonEval *)alloc(sizeof(BalloonEval));
balloonEvalForTerm = TRUE;
}
if (balloonEval != NULL)
general_beval_cb(balloonEval, 0);
}
else if (this_due > 0 && (next_due == -1 || next_due > this_due))
next_due = this_due;
}
#endif
return current_id != last_timer_id ? 1 : next_due;
}
@@ -1358,7 +1379,7 @@ add_timer_info(typval_T *rettv, timer_T *timer)
dict_add_nr_str(dict, "time", (long)timer->tr_interval, NULL);
profile_start(&now);
remaining = timer_time_left(timer, &now);
remaining = proftime_time_left(&timer->tr_due, &now);
dict_add_nr_str(dict, "remaining", (long)remaining, NULL);
dict_add_nr_str(dict, "repeat",
View
@@ -1452,6 +1452,7 @@ getcmdline(
case K_X2MOUSE:
case K_X2DRAG:
case K_X2RELEASE:
case K_MOUSEMOVE:
goto cmdline_not_changed;
#endif /* FEAT_MOUSE */
View
@@ -1328,6 +1328,13 @@
# define FEAT_BEVAL_TIP /* balloon eval used for toolbar tooltip */
#endif
/*
* +balloon_eval_term Allow balloon expression evaluation in the terminal.
*/
#if defined(FEAT_BEVAL) && defined(UNIX) && defined(FEAT_TIMERS)
# define FEAT_BEVALTERM
#endif
/* both Motif and Athena are X11 and share some code */
#if defined(FEAT_GUI_MOTIF) || defined(FEAT_GUI_ATHENA)
# define FEAT_GUI_X11
View
@@ -1792,6 +1792,14 @@ vgetc(void)
*/
may_garbage_collect = FALSE;
#endif
#ifdef FEAT_BEVALTERM
if (c != K_MOUSEMOVE && c != K_IGNORE)
{
/* Don't trigger 'balloonexpr' unless only the mouse was moved. */
bevalexpr_due_set = FALSE;
ui_remove_balloon();
}
#endif
return c;
}
View
@@ -1231,6 +1231,7 @@ EXTERN int no_hlsearch INIT(= FALSE);
#if defined(FEAT_BEVAL) && !defined(NO_X11_INCLUDES)
EXTERN BalloonEval *balloonEval INIT(= NULL);
EXTERN int balloonEvalForTerm INIT(= FALSE);
# if defined(FEAT_NETBEANS_INTG) || defined(FEAT_SUN_WORKSHOP)
EXTERN int bevalServers INIT(= 0);
# define BEVAL_NETBEANS 0x01
@@ -1648,6 +1649,11 @@ EXTERN int did_add_timer INIT(= FALSE);
EXTERN int timer_busy INIT(= 0); /* when timer is inside vgetc() then > 0 */
#endif
#ifdef FEAT_BEVALTERM
EXTERN int bevalexpr_due_set INIT(= FALSE);
EXTERN proftime_T bevalexpr_due;
#endif
#ifdef FEAT_EVAL
EXTERN time_T time_for_testing INIT(= 0);
View
@@ -740,7 +740,10 @@ gui_init(void)
#ifdef FEAT_BEVAL
/* Always create the Balloon Evaluation area, but disable it when
* 'ballooneval' is off */
* 'ballooneval' is off. */
if (balloonEval != NULL)
vim_free(balloonEval);
balloonEvalForTerm = FALSE;
# ifdef FEAT_GUI_GTK
balloonEval = gui_mch_create_beval_area(gui.drawarea, NULL,
&general_beval_cb, NULL);
Oops, something went wrong.

0 comments on commit 51b0f37

Please sign in to comment.