Skip to content

Commit ccac3a7

Browse files
blueyedtpope
authored andcommitted
Shorten displayed message to avoid hit-enter prompt
Closes #166
1 parent 64be3b0 commit ccac3a7

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

autoload/dispatch.vim

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,46 @@ function! s:dispatch(request) abort
372372
let response = call('dispatch#'.handler.'#handle', [a:request])
373373
if !empty(response)
374374
let a:request.handler = handler
375+
376+
" Display command, avoiding hit-enter prompt.
375377
redraw
376-
echo ':!'.a:request.expanded s:postfix(a:request)
378+
let msg = ':!'
379+
let suffix = s:postfix(a:request)
380+
let suffix_len = len(substitute(suffix, '.', '.', 'g'))
381+
let max_cmd_len = (&cmdheight * &columns) - 2 - suffix_len - 2
382+
383+
if has('cmdline_info')
384+
let last_has_status = (&laststatus == 2 || (&laststatus == 1 && winnr('$') != 1))
385+
386+
if &ruler && !last_has_status
387+
if empty(&rulerformat)
388+
" Default ruler is 17 chars wide.
389+
let max_cmd_len -= 17
390+
elseif exists('g:rulerwidth')
391+
" User specified width of custom ruler.
392+
let max_cmd_len -= g:rulerwidth
393+
else
394+
" Don't know width of custom ruler, make a conservative guess.
395+
let max_cmd_len -= &columns / 2
396+
endif
397+
let max_cmd_len -= 1
398+
endif
399+
if &showcmd
400+
let max_cmd_len -= 10
401+
if !&ruler || last_has_status
402+
let max_cmd_len -= 1
403+
endif
404+
endif
405+
endif
406+
let cmd = a:request.expanded
407+
let cmd_len = len(substitute(cmd, '.', '.', 'g'))
408+
if cmd_len > max_cmd_len
409+
let msg .= '<' . matchstr(cmd, '\v.{'.(max_cmd_len - 1).'}$')
410+
else
411+
let msg .= cmd
412+
endif
413+
let msg .= ' '.suffix
414+
echo msg
377415
return response
378416
endif
379417
endfor

0 commit comments

Comments
 (0)