1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
" notify.vim
" @Author: Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2008-09-19.
" @Last Change: 2016-06-28.
" @Revision: 2.3.19
let s:save_cpo = &cpo
set cpo&vim
" :display: tlib#notify#Echo(text, ?style='')
" Print text in the echo area. Temporarily disable 'ruler' and 'showcmd'
" in order to prevent |press-enter| messages.
function! tlib#notify#Echo(text, ...)
TVarArg 'style'
let ruler = &ruler
let showcmd = &showcmd
let text = substitute(a:text, '\n', '|', 'g')
try
set noruler
set noshowcmd
if !empty(style)
exec 'echohl' style
endif
echo strpart(text, 0, &columns - 1)
finally
if !empty(style)
echohl None
endif
let &ruler = ruler
let &showcmd = showcmd
endtry
endf
" Contributed by Erik Falor:
" If the line containing the message is too long, echoing it will cause
" a 'Hit ENTER' prompt to appear. This function cleans up the line so
" that does not happen.
" The echoed line is too long if it is wider than the width of the
" window, minus cmdline space taken up by the ruler and showcmd
" features.
function! tlib#notify#TrimMessage(message) "{{{3
let filler = '...'
" If length of message with tabs converted into spaces + length of
" line number + 2 (for the ': ' that follows the line number) is
" greater than the width of the screen, truncate in the middle
let to_fill = &columns
" TLogVAR to_fill
" Account for space used by elements in the command-line to avoid
" 'Hit ENTER' prompts.
" If showcmd is on, it will take up 12 columns.
" If the ruler is enabled, but not displayed in the statusline, it
" will in its default form take 17 columns. If the user defines a
" custom &rulerformat, they will need to specify how wide it is.
if has('cmdline_info')
if &showcmd
let to_fill -= 12
else
let to_fill -= 1
endif
" TLogVAR &showcmd, to_fill
" TLogVAR &laststatus, &ruler, &rulerformat
if &ruler
if &laststatus == 0 || winnr('$') == 1
if has('statusline')
if &rulerformat == ''
" default ruler is 17 chars wide
let to_fill -= 17
elseif exists('g:MP_rulerwidth')
let to_fill -= g:MP_rulerwidth
else
" tml: fallback: guess length
let to_fill -= strlen(&rulerformat)
endif
else
endif
endif
else
endif
else
let to_fill -= 1
endif
" TLogVAR to_fill
" TLogDBG strlen(a:message)
if strlen(a:message) > to_fill
let front = to_fill / 2 - 1
let back = front
if to_fill % 2 == 0 | let back -= 1 | endif
return strpart(a:message, 0, front) . filler .
\strpart(a:message, strlen(a:message) - back)
else
return a:message
endif
endfunction
function! tlib#notify#PrintError() abort "{{{3
echohl ErrorMsg
echom v:exception
echom v:throwpoint
echohl NONE
endf
let &cpo = s:save_cpo
unlet s:save_cpo
|