@@ -119,6 +119,28 @@ function! s:shellwords(str) abort
119119 return words
120120endfunction
121121
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+
122144function ! s: format_gist (gist) abort
123145 let files = sort (keys (a: gist .files ))
124146 if empty (files )
@@ -142,12 +164,10 @@ function! s:format_gist(gist) abort
142164 redir = >a |exe " sil sign place buffer=" .bufnr (' ' )|redir end
143165 let signlist = split (a , ' \n' )
144166 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))
151171endfunction
152172
153173" Note: A colon in the file name has side effects on Windows due to NTFS Alternate Data Streams; avoid it.
0 commit comments