From db8f915cb711c2fdfa3279bf353161f22bb1791a Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 22 Oct 2019 03:15:45 +0200 Subject: [PATCH 1/3] Use v:echospace to avoid hit-Enter prompts Fixes https://github.com/tpope/vim-dispatch/issues/166 Followup-to https://github.com/tpope/vim-dispatch/pull/167 --- autoload/dispatch.vim | 89 ++++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 39 deletions(-) diff --git a/autoload/dispatch.vim b/autoload/dispatch.vim index 436b98ce..548706ab 100644 --- a/autoload/dispatch.vim +++ b/autoload/dispatch.vim @@ -363,6 +363,54 @@ function! s:postfix(request) abort return '(' . a:request.handler.'/'.(!empty(pid) ? pid : '?') . ')' endfunction +function! s:echo_without_hitenter(msg, suffix) abort + if exists('v:echospace') + if strwidth(a:msg.' '.a:suffix) > v:echospace + let msg = printf('%.*S...', v:echospace - 3 - len(a:suffix), a:msg) + else + let msg = a:msg + endif + echom msg.' '.a:suffix + return + endif + + redraw + 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 + let msg = '<' . matchstr(a:msg, '\v.{'.(max_cmd_len - 1).'}$') + else + let msg = a:msg + endif + echom 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')) || @@ -374,44 +422,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_without_hitenter(':!'.a:request.expanded, s:postfix(a:request)) return response endif endfor @@ -1210,7 +1221,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_without_hitenter(printf('%s !%s', label, request.expanded), s:postfix(request)) if !a:0 checktime endif From e7b14d31f6f6ec6029a5367c430d32c539448e2e Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 22 Oct 2019 06:29:01 +0200 Subject: [PATCH 2/3] use echo --- autoload/dispatch.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/dispatch.vim b/autoload/dispatch.vim index 548706ab..ff1d7c1a 100644 --- a/autoload/dispatch.vim +++ b/autoload/dispatch.vim @@ -370,7 +370,7 @@ function! s:echo_without_hitenter(msg, suffix) abort else let msg = a:msg endif - echom msg.' '.a:suffix + echo msg.' '.a:suffix return endif @@ -408,7 +408,7 @@ function! s:echo_without_hitenter(msg, suffix) abort else let msg = a:msg endif - echom msg.' '.a:suffix + echo msg.' '.a:suffix endfunction function! s:dispatch(request) abort From e27fec88b6ead84769018afc202a729fe57cbd9b Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 22 Oct 2019 07:12:04 +0200 Subject: [PATCH 3/3] rename, redraw always --- autoload/dispatch.vim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/autoload/dispatch.vim b/autoload/dispatch.vim index ff1d7c1a..6b8f5ae2 100644 --- a/autoload/dispatch.vim +++ b/autoload/dispatch.vim @@ -363,7 +363,9 @@ function! s:postfix(request) abort return '(' . a:request.handler.'/'.(!empty(pid) ? pid : '?') . ')' endfunction -function! s:echo_without_hitenter(msg, suffix) abort +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) @@ -374,7 +376,6 @@ function! s:echo_without_hitenter(msg, suffix) abort return endif - redraw let suffix_len = len(substitute(a:suffix, '.', '.', 'g')) let max_cmd_len = (&cmdheight * &columns) - 2 - suffix_len - 2 @@ -422,7 +423,7 @@ function! s:dispatch(request) abort let a:request.handler = handler " Display command, avoiding hit-enter prompt. - call s:echo_without_hitenter(':!'.a:request.expanded, s:postfix(a:request)) + call s:echo_truncated(':!'.a:request.expanded, s:postfix(a:request)) return response endif endfor @@ -1221,7 +1222,7 @@ function! dispatch#complete(file, ...) abort call s:cwindow(request, 0, status, '', 'make') redraw! endif - call s:echo_without_hitenter(printf('%s !%s', label, request.expanded), s:postfix(request)) + call s:echo_truncated(printf('%s !%s', label, request.expanded), s:postfix(request)) if !a:0 checktime endif