Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use v:echospace to avoid hit-Enter prompts #285

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 51 additions & 39 deletions autoload/dispatch.vim
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,55 @@ function! s:postfix(request) abort
return '(' . a:request.handler.'/'.(!empty(pid) ? pid : '?') . ')'
endfunction

function! s:echo_truncated(msg, suffix) abort
redraw

if exists('v:echospace')
if strwidth(a:msg.' '.a:suffix) > v:echospace
let msg = printf('%.*S...', v:echospace - 3 - len(a:suffix), a:msg)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use the < notation from the other format, not an ellipsis.

else
let msg = a:msg
endif
echo msg.' '.a:suffix
return
blueyed marked this conversation as resolved.
Show resolved Hide resolved
endif

let suffix_len = len(substitute(a:suffix, '.', '.', 'g'))
let max_cmd_len = (&cmdheight * &columns) - 2 - suffix_len - 2

if has('cmdline_info')
let last_has_status = (&laststatus == 2 || (&laststatus == 1 && winnr('$') != 1))

if &ruler && !last_has_status
if empty(&rulerformat)
" Default ruler is 17 chars wide.
let max_cmd_len -= 17
elseif exists('g:rulerwidth')
" User specified width of custom ruler.
let max_cmd_len -= g:rulerwidth
else
" Don't know width of custom ruler, make a conservative guess.
let max_cmd_len -= &columns / 2
endif
let max_cmd_len -= 1
endif
if &showcmd
let max_cmd_len -= 10
if !&ruler || last_has_status
let max_cmd_len -= 1
endif
endif
endif

let msg_len = len(substitute(a:msg, '.', '.', 'g'))
if msg_len > max_cmd_len
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also use strwidth maybe if available?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it ain't broke don't fix it.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the substitute() needed here?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Character length rather than byte length.

let msg = '<' . matchstr(a:msg, '\v.{'.(max_cmd_len - 1).'}$')
else
let msg = a:msg
endif
echo msg.' '.a:suffix
endfunction

function! s:dispatch(request) abort
for handler in g:dispatch_handlers
if get(g:, 'dispatch_no_' . handler . '_' . get(a:request, 'action')) ||
Expand All @@ -374,44 +423,7 @@ function! s:dispatch(request) abort
let a:request.handler = handler

" Display command, avoiding hit-enter prompt.
redraw
let msg = ':!'
let suffix = s:postfix(a:request)
let suffix_len = len(substitute(suffix, '.', '.', 'g'))
let max_cmd_len = (&cmdheight * &columns) - 2 - suffix_len - 2

if has('cmdline_info')
let last_has_status = (&laststatus == 2 || (&laststatus == 1 && winnr('$') != 1))

if &ruler && !last_has_status
if empty(&rulerformat)
" Default ruler is 17 chars wide.
let max_cmd_len -= 17
elseif exists('g:rulerwidth')
" User specified width of custom ruler.
let max_cmd_len -= g:rulerwidth
else
" Don't know width of custom ruler, make a conservative guess.
let max_cmd_len -= &columns / 2
endif
let max_cmd_len -= 1
endif
if &showcmd
let max_cmd_len -= 10
if !&ruler || last_has_status
let max_cmd_len -= 1
endif
endif
endif
let cmd = a:request.expanded
let cmd_len = len(substitute(cmd, '.', '.', 'g'))
if cmd_len > max_cmd_len
let msg .= '<' . matchstr(cmd, '\v.{'.(max_cmd_len - 1).'}$')
else
let msg .= cmd
endif
let msg .= ' '.suffix
echo msg
call s:echo_truncated(':!'.a:request.expanded, s:postfix(a:request))
return response
endif
endfor
Expand Down Expand Up @@ -1210,7 +1222,7 @@ function! dispatch#complete(file, ...) abort
call s:cwindow(request, 0, status, '', 'make')
redraw!
endif
echo label '!'.request.expanded s:postfix(request)
call s:echo_truncated(printf('%s !%s', label, request.expanded), s:postfix(request))
if !a:0
checktime
endif
Expand Down