Skip to content

Commit f693d93

Browse files
committed
Dynamically size column when g:startuptime_event_width = 0.
1 parent 5be2b6b commit f693d93

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

autoload/startuptime.vim

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,19 @@ function! s:ExtractRequireArg(event) abort
197197
return a:event[9:-3]
198198
endfunction
199199

200+
function! s:SimplifiedEvent(item) abort
201+
let l:event = a:item.event
202+
if a:item.type ==# s:sourcing_event_type
203+
if s:IsRequireEvent(l:event)
204+
let l:event = s:ExtractRequireArg(l:event)
205+
else
206+
let l:event = substitute(l:event, '^sourcing ', '', '')
207+
let l:event = fnamemodify(l:event, ':t')
208+
endif
209+
endif
210+
return l:event
211+
endfunction
212+
200213
function! s:ProfileCmd(file) abort
201214
" * If timer_start() is available, vim is quit with a timer. This retains
202215
" all events up to the last event, '--- VIM STARTED ---'.
@@ -806,15 +819,7 @@ function! s:Tabulate(items, startup) abort
806819
" self+sourced timings are used. These timings include time spent sourcing
807820
" other files, files which will have their own events and timings.
808821
for l:item in a:items
809-
let l:event = l:item.event
810-
if l:item.type ==# s:sourcing_event_type
811-
if s:IsRequireEvent(l:event)
812-
let l:event = s:ExtractRequireArg(l:event)
813-
else
814-
let l:event = substitute(l:event, '^sourcing ', '', '')
815-
let l:event = fnamemodify(l:event, ':t')
816-
endif
817-
endif
822+
let l:event = s:SimplifiedEvent(l:item)
818823
let l:event = strcharpart(l:event, 0, g:startuptime_event_width)
819824
let l:line = printf('%-*S', g:startuptime_event_width, l:event)
820825
let l:time = printf('%.2f', l:item.time)
@@ -1014,6 +1019,8 @@ function! startuptime#Main(file, winid, bufnr, options, items) abort
10141019
redraw!
10151020
endif
10161021
let l:processing_finished = 0
1022+
" Save event width for possible restoring.
1023+
let l:event_width = g:startuptime_event_width
10171024
try
10181025
let l:items = a:items
10191026
let l:startup = s:Startup(l:items)
@@ -1031,6 +1038,13 @@ function! startuptime#Main(file, winid, bufnr, options, items) abort
10311038
setlocal modifiable
10321039
call s:ClearCurrentBuffer()
10331040
call s:RegisterMaps(l:items, a:options, l:startup)
1041+
if g:startuptime_event_width ==# 0
1042+
for l:item in l:items
1043+
let l:event = s:SimplifiedEvent(l:item)
1044+
let g:startuptime_event_width =
1045+
\ max([strchars(l:event), g:startuptime_event_width])
1046+
endfor
1047+
endif
10341048
let l:field_bounds_table = s:Tabulate(l:items, l:startup)
10351049
let l:event_types = map(copy(l:items), 'v:val.type')
10361050
if g:startuptime_colorize && (has('gui_running') || &t_Co > 1)
@@ -1043,6 +1057,7 @@ function! startuptime#Main(file, winid, bufnr, options, items) abort
10431057
endtry
10441058
setlocal nomodifiable
10451059
finally
1060+
let g:startuptime_event_width = l:event_width
10461061
call win_gotoid(l:winid)
10471062
let &eventignore = l:eventignore
10481063
endtry

doc/startuptime.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ than these options.
119119
'sourced' timings (in addition to
120120
'self' timings) for sourcing events
121121
*g:startuptime_event_width* `20`
122-
Event column width
122+
Event column width. When set to 0,
123+
the column width will be dynamically
124+
set so that no text is truncated.
123125
*g:startuptime_time_width* `6`
124126
Time column width
125127
*g:startuptime_percent_width* `7`

0 commit comments

Comments
 (0)