Skip to content

Commit 1b9645d

Browse files
committed
patch 8.0.1123: cannot define a toolbar for a window
Problem: Cannot define a toolbar for a window. Solution: Add a window-local toolbar.
1 parent dde403c commit 1b9645d

20 files changed

Lines changed: 679 additions & 238 deletions

File tree

runtime/doc/gui.txt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*gui.txt* For Vim version 8.0. Last change: 2017 Aug 27
1+
*gui.txt* For Vim version 8.0. Last change: 2017 Sep 16
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -784,10 +784,31 @@ In the Win32 and GTK+ GUI, starting a menu name with ']' excludes that menu
784784
from the main menu bar. You must then use the |:popup| or |:tearoff| command
785785
to display it.
786786

787+
*window-toolbar*
788+
Each window can have a local toolbar. This uses the first line of the window,
789+
thus reduces the space for the text by one line.
790+
791+
Only text can be used. When using Unicode special characters can be used to
792+
make the items look like icons.
793+
794+
If the items do not fit then the last ones cannot be used. The toolbar does
795+
not wrap.
796+
797+
Example for debugger tools: >
798+
amenu 1.10 WinBar.Step :Step<CR>
799+
amenu 1.20 WinBar.Next :Next<CR>
800+
amenu 1.30 WinBar.Finish :Finish<CR>
801+
amenu 1.40 WinBar.Cont :Continue<CR>
802+
<
803+
The window toolbar uses the ToolbarLine and ToolbarButton highlight groups.
804+
787805
*popup-menu*
788806
In the Win32, GTK+, Motif, Athena and Photon GUI, you can define the
789807
special menu "PopUp". This is the menu that is displayed when the right mouse
790808
button is pressed, if 'mousemodel' is set to popup or popup_setpos.
809+
Example: >
810+
nnoremenu 1.40 PopUp.&Paste "+gP
811+
menu PopUp
791812
792813
793814
5.3 Showing What Menus Are Mapped To *showing-menus*

runtime/doc/terminal.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*terminal.txt* For Vim version 8.0. Last change: 2017 Sep 14
1+
*terminal.txt* For Vim version 8.0. Last change: 2017 Sep 17
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -226,15 +226,15 @@ Use CTRL-W N (or 'termkey' N) to switch to Terminal-Normal mode. Now the
226226
contents of the terminal window is under control of Vim, the job output is
227227
suspended. CTRL-\ CTRL-N does the same.
228228

229-
Terminal-Job mode is where |tmap| mappings are applied. Keys sent by
229+
Terminal-Job mode is where |:tmap| mappings are applied. Keys sent by
230230
|term_sendkeys()| are not subject to tmap, but keys from |feedkeys()| are.
231231

232232
*E946*
233233
In Terminal-Normal mode you can move the cursor around with the usual Vim
234234
commands, Visually mark text, yank text, etc. But you cannot change the
235235
contents of the buffer. The commands that would start insert mode, such as
236236
'i' and 'a', return to Terminal-Job mode. The window will be updated to show
237-
the contents of the terminal.
237+
the contents of the terminal. |:startinsert| is ineffective.
238238

239239
In Terminal-Normal mode the statusline and window title show "(Terminal)". If
240240
the job ends while in Terminal-Normal mode this changes to
@@ -372,6 +372,14 @@ In the window showing the source code some commands can used to control gdb:
372372
:Finish execute the gdb "finish" command
373373
:Continue execute the gdb "continue" command
374374

375+
The plugin adds a window toolbar with these entries:
376+
Step :Step
377+
Next :Over
378+
Finish :Finish
379+
Cont :Continue
380+
Eval :Evaluate
381+
This way you can use the mouse to perform the most common commands.
382+
375383

376384
Inspecting variables ~
377385

runtime/pack/dist/opt/termdebug/plugin/termdebug.vim

Lines changed: 75 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ func s:StartDebug(cmd)
104104
call win_gotoid(s:gdbwin)
105105

106106
let s:breakpoints = {}
107+
108+
augroup TermDebug
109+
au BufRead * call s:BufRead()
110+
au BufUnload * call s:BufUnloaded()
111+
augroup END
107112
endfunc
108113

109114
func s:EndDebug(job, status)
@@ -120,6 +125,8 @@ func s:EndDebug(job, status)
120125
if s:save_columns > 0
121126
let &columns = s:save_columns
122127
endif
128+
129+
au! TermDebug
123130
endfunc
124131

125132
" Handle a message received from gdb on the GDB/MI interface.
@@ -132,7 +139,7 @@ func s:CommOutput(chan, msg)
132139
let msg = msg[1:]
133140
endif
134141
if msg != ''
135-
if msg =~ '^\*\(stopped\|running\)'
142+
if msg =~ '^\(\*stopped\|\*running\|=thread-selected\)'
136143
call s:HandleCursor(msg)
137144
elseif msg =~ '^\^done,bkpt=' || msg =~ '^=breakpoint-created,'
138145
call s:HandleNewBreakpoint(msg)
@@ -161,6 +168,14 @@ func s:InstallCommands()
161168

162169
" TODO: can the K mapping be restored?
163170
nnoremap K :Evaluate<CR>
171+
172+
if has('menu')
173+
amenu WinBar.Step :Step<CR>
174+
amenu WinBar.Next :Over<CR>
175+
amenu WinBar.Finish :Finish<CR>
176+
amenu WinBar.Cont :Continue<CR>
177+
amenu WinBar.Eval :Evaluate<CR>
178+
endif
164179
endfunc
165180

166181
" Delete installed debugger commands in the current window.
@@ -176,6 +191,15 @@ func s:DeleteCommands()
176191
delcommand Program
177192

178193
nunmap K
194+
195+
if has('menu')
196+
aunmenu WinBar.Step
197+
aunmenu WinBar.Next
198+
aunmenu WinBar.Finish
199+
aunmenu WinBar.Cont
200+
aunmenu WinBar.Eval
201+
endif
202+
179203
exe 'sign unplace ' . s:pc_id
180204
for key in keys(s:breakpoints)
181205
exe 'sign unplace ' . (s:break_id + key)
@@ -232,7 +256,15 @@ endfunc
232256

233257
" Handle the result of data-evaluate-expression
234258
func s:HandleEvaluate(msg)
235-
echomsg '"' . s:evalexpr . '": ' . substitute(a:msg, '.*value="\(.*\)"', '\1', '')
259+
let value = substitute(a:msg, '.*value="\(.*\)"', '\1', '')
260+
let value = substitute(value, '\\"', '"', 'g')
261+
echomsg '"' . s:evalexpr . '": ' . value
262+
263+
if s:evalexpr[0] != '*' && value =~ '^0x' && value !~ '"$'
264+
" Looks like a pointer, also display what it points to.
265+
let s:evalexpr = '*' . s:evalexpr
266+
call term_sendkeys(s:commbuf, '-data-evaluate-expression "' . s:evalexpr . "\"\r")
267+
endif
236268
endfunc
237269

238270
" Handle an error.
@@ -247,10 +279,10 @@ func s:HandleCursor(msg)
247279

248280
if win_gotoid(s:startwin)
249281
let fname = substitute(a:msg, '.*fullname="\([^"]*\)".*', '\1', '')
250-
if a:msg =~ '^\*stopped' && filereadable(fname)
282+
if a:msg =~ '^\(\*stopped\|=thread-selected\)' && filereadable(fname)
251283
let lnum = substitute(a:msg, '.*line="\([^"]*\)".*', '\1', '')
252284
if lnum =~ '^[0-9]*$'
253-
if expand('%:h') != fname
285+
if expand('%:p') != fnamemodify(fname, ':p')
254286
if &modified
255287
" TODO: find existing window
256288
exe 'split ' . fnameescape(fname)
@@ -260,7 +292,7 @@ func s:HandleCursor(msg)
260292
endif
261293
endif
262294
exe lnum
263-
exe 'sign place ' . s:pc_id . ' line=' . lnum . ' name=debugPC file=' . fnameescape(fname)
295+
exe 'sign place ' . s:pc_id . ' line=' . lnum . ' name=debugPC file=' . fname
264296
setlocal signcolumn=yes
265297
endif
266298
else
@@ -288,11 +320,17 @@ func s:HandleNewBreakpoint(msg)
288320

289321
let fname = substitute(a:msg, '.*fullname="\([^"]*\)".*', '\1', '')
290322
let lnum = substitute(a:msg, '.*line="\([^"]*\)".*', '\1', '')
291-
292-
exe 'sign place ' . (s:break_id + nr) . ' line=' . lnum . ' name=debugBreakpoint file=' . fnameescape(fname)
293-
294323
let entry['fname'] = fname
295324
let entry['lnum'] = lnum
325+
326+
if bufloaded(fname)
327+
call s:PlaceSign(nr, entry)
328+
endif
329+
endfunc
330+
331+
func s:PlaceSign(nr, entry)
332+
exe 'sign place ' . (s:break_id + a:nr) . ' line=' . a:entry['lnum'] . ' name=debugBreakpoint file=' . a:entry['fname']
333+
let a:entry['placed'] = 1
296334
endfunc
297335

298336
" Handle deleting a breakpoint
@@ -302,6 +340,33 @@ func s:HandleBreakpointDelete(msg)
302340
if nr == 0
303341
return
304342
endif
305-
exe 'sign unplace ' . (s:break_id + nr)
306-
unlet s:breakpoints[nr]
343+
if has_key(s:breakpoints, nr)
344+
let entry = s:breakpoints[nr]
345+
if has_key(entry, 'placed')
346+
exe 'sign unplace ' . (s:break_id + nr)
347+
unlet entry['placed']
348+
endif
349+
unlet s:breakpoints[nr]
350+
endif
307351
endfunc
352+
353+
" Handle a BufRead autocommand event: place any signs.
354+
func s:BufRead()
355+
let fname = expand('<afile>:p')
356+
for [nr, entry] in items(s:breakpoints)
357+
if entry['fname'] == fname
358+
call s:PlaceSign(nr, entry)
359+
endif
360+
endfor
361+
endfunc
362+
363+
" Handle a BufUnloaded autocommand event: unplace any signs.
364+
func s:BufUnloaded()
365+
let fname = expand('<afile>:p')
366+
for [nr, entry] in items(s:breakpoints)
367+
if entry['fname'] == fname
368+
let entry['placed'] = 0
369+
endif
370+
endfor
371+
endfunc
372+

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,6 +2278,7 @@ test_arglist \
22782278
test_vimscript \
22792279
test_virtualedit \
22802280
test_visual \
2281+
test_winbar \
22812282
test_window_cmd \
22822283
test_window_id \
22832284
test_windows_home \

src/eval.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8252,13 +8252,7 @@ ex_echo(exarg_T *eap)
82528252
void
82538253
ex_echohl(exarg_T *eap)
82548254
{
8255-
int id;
8256-
8257-
id = syn_name2id(eap->arg);
8258-
if (id == 0)
8259-
echo_attr = 0;
8260-
else
8261-
echo_attr = syn_id2attr(id);
8255+
echo_attr = syn_name2attr(eap->arg);
82628256
}
82638257

82648258
/*

src/evalfunc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5229,6 +5229,9 @@ get_win_info(win_T *wp, short tpnr, short winnr)
52295229
dict_add_nr_str(dict, "winnr", winnr, NULL);
52305230
dict_add_nr_str(dict, "winid", wp->w_id, NULL);
52315231
dict_add_nr_str(dict, "height", wp->w_height, NULL);
5232+
#ifdef FEAT_MENU
5233+
dict_add_nr_str(dict, "winbar", wp->w_winbar_height, NULL);
5234+
#endif
52325235
dict_add_nr_str(dict, "width", wp->w_width, NULL);
52335236
dict_add_nr_str(dict, "bufnr", wp->w_buffer->b_fnum, NULL);
52345237

src/if_perl.xs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,11 +1387,8 @@ PerlIOVim_pushed(pTHX_ PerlIO *f, const char *mode,
13871387
{
13881388
PerlIOVim *s = PerlIOSelf(f, PerlIOVim);
13891389
s->attr = 0;
1390-
if (arg && SvPOK(arg)) {
1391-
int id = syn_name2id((char_u *)SvPV_nolen(arg));
1392-
if (id != 0)
1393-
s->attr = syn_id2attr(id);
1394-
}
1390+
if (arg && SvPOK(arg))
1391+
s->attr = syn_name2attr((char_u *)SvPV_nolen(arg));
13951392
return PerlIOBase_pushed(aTHX_ f, mode, (SV *)NULL, tab);
13961393
}
13971394

@@ -1482,11 +1479,7 @@ Msg(text, hl=NULL)
14821479
{
14831480
attr = 0;
14841481
if (hl != NULL)
1485-
{
1486-
id = syn_name2id((char_u *)hl);
1487-
if (id != 0)
1488-
attr = syn_id2attr(id);
1489-
}
1482+
attr = syn_name2attr((char_u *)hl);
14901483
msg_split((char_u *)text, attr);
14911484
}
14921485

0 commit comments

Comments
 (0)