@@ -119,6 +119,28 @@ function! s:shellwords(str) abort
119
119
return words
120
120
endfunction
121
121
122
+ function ! s: truncate (str, num)
123
+ let mx_first = ' ^\(.\)\(.*\)$'
124
+ let str = a: str
125
+ let ret = ' '
126
+ let width = 0
127
+ while 1
128
+ let char = substitute (str, mx_first, ' \1' , ' ' )
129
+ let cells = strdisplaywidth (char)
130
+ if cells == 0 || width + cells > a: num
131
+ break
132
+ endif
133
+ let width = width + cells
134
+ let ret .= char
135
+ let str = substitute (str, mx_first, ' \2' , ' ' )
136
+ endwhile
137
+ while width + 1 <= a: num
138
+ let ret .= " "
139
+ let width = width + 1
140
+ endwhile
141
+ return ret
142
+ endfunction
143
+
122
144
function ! s: format_gist (gist) abort
123
145
let files = sort (keys (a: gist .files ))
124
146
if empty (files )
@@ -142,12 +164,10 @@ function! s:format_gist(gist) abort
142
164
redir = >a |exe " sil sign place buffer=" .bufnr (' ' )|redir end
143
165
let signlist = split (a , ' \n' )
144
166
let width = winwidth (0 ) - ((&number || &relativenumber ) ? &numberwidth : 0 ) - &foldcolumn - (len (signlist) > 2 ? 2 : 0 )
145
- let s: gistlen = 33
146
- if ! exists (" g:gist_namelength" )
147
- let g: gist_namelength= 30
148
- endif
149
- let s: desclen = width- (s: gistlen+ g: gist_namelength+ 10 )
150
- return printf (' gist: %-*s %-*s %-*s' , s: gistlen , a: gist .id, g: gist_namelength+ 1 , strpart (name, 0 , g: gist_namelength ), s: desclen+ 1 , strpart (desc, 0 , s: desclen ))
167
+ let idlen = 33
168
+ let namelen = get (g: , ' gist_namelength' , 30 )
169
+ let desclen = width - (idlen + namelen + 10 )
170
+ return printf (' gist: %s %s %s' , s: truncate (a: gist .id, idlen), s: truncate (name, namelen), s: truncate (desc, desclen))
151
171
endfunction
152
172
153
173
" Note: A colon in the file name has side effects on Windows due to NTFS Alternate Data Streams; avoid it.
0 commit comments