Skip to content

Commit

Permalink
Dynamically size column when g:startuptime_event_width = 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
dstein64 committed Jul 28, 2022
1 parent 5be2b6b commit f693d93
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
33 changes: 24 additions & 9 deletions autoload/startuptime.vim
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,19 @@ function! s:ExtractRequireArg(event) abort
return a:event[9:-3]
endfunction

function! s:SimplifiedEvent(item) abort
let l:event = a:item.event
if a:item.type ==# s:sourcing_event_type
if s:IsRequireEvent(l:event)
let l:event = s:ExtractRequireArg(l:event)
else
let l:event = substitute(l:event, '^sourcing ', '', '')
let l:event = fnamemodify(l:event, ':t')
endif
endif
return l:event
endfunction

function! s:ProfileCmd(file) abort
" * If timer_start() is available, vim is quit with a timer. This retains
" all events up to the last event, '--- VIM STARTED ---'.
Expand Down Expand Up @@ -806,15 +819,7 @@ function! s:Tabulate(items, startup) abort
" self+sourced timings are used. These timings include time spent sourcing
" other files, files which will have their own events and timings.
for l:item in a:items
let l:event = l:item.event
if l:item.type ==# s:sourcing_event_type
if s:IsRequireEvent(l:event)
let l:event = s:ExtractRequireArg(l:event)
else
let l:event = substitute(l:event, '^sourcing ', '', '')
let l:event = fnamemodify(l:event, ':t')
endif
endif
let l:event = s:SimplifiedEvent(l:item)
let l:event = strcharpart(l:event, 0, g:startuptime_event_width)
let l:line = printf('%-*S', g:startuptime_event_width, l:event)
let l:time = printf('%.2f', l:item.time)
Expand Down Expand Up @@ -1014,6 +1019,8 @@ function! startuptime#Main(file, winid, bufnr, options, items) abort
redraw!
endif
let l:processing_finished = 0
" Save event width for possible restoring.
let l:event_width = g:startuptime_event_width
try
let l:items = a:items
let l:startup = s:Startup(l:items)
Expand All @@ -1031,6 +1038,13 @@ function! startuptime#Main(file, winid, bufnr, options, items) abort
setlocal modifiable
call s:ClearCurrentBuffer()
call s:RegisterMaps(l:items, a:options, l:startup)
if g:startuptime_event_width ==# 0
for l:item in l:items
let l:event = s:SimplifiedEvent(l:item)
let g:startuptime_event_width =
\ max([strchars(l:event), g:startuptime_event_width])
endfor
endif
let l:field_bounds_table = s:Tabulate(l:items, l:startup)
let l:event_types = map(copy(l:items), 'v:val.type')
if g:startuptime_colorize && (has('gui_running') || &t_Co > 1)
Expand All @@ -1043,6 +1057,7 @@ function! startuptime#Main(file, winid, bufnr, options, items) abort
endtry
setlocal nomodifiable
finally
let g:startuptime_event_width = l:event_width
call win_gotoid(l:winid)
let &eventignore = l:eventignore
endtry
Expand Down
4 changes: 3 additions & 1 deletion doc/startuptime.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ than these options.
'sourced' timings (in addition to
'self' timings) for sourcing events
*g:startuptime_event_width* `20`
Event column width
Event column width. When set to 0,
the column width will be dynamically
set so that no text is truncated.
*g:startuptime_time_width* `6`
Time column width
*g:startuptime_percent_width* `7`
Expand Down

0 comments on commit f693d93

Please sign in to comment.