@@ -13,11 +13,19 @@ let s:blamer_date_format = get(g:, 'blamer_date_format', '%d/%m/%y %H:%M')
1313let s: blamer_user_name = ' '
1414let s: blamer_user_email = ' '
1515let s: blamer_info_fields = filter (map (split (s: blamer_template , ' ' ), {key , val - > matchstr (val, ' \m\C<\zs.\{-}\ze>' )}), {idx, val - > val != ' ' })
16- let s: blamer_namespace = nvim_create_namespace (' blamer' )
16+ if exists (' *nvim_create_namespace' )
17+ let s: blamer_namespace = nvim_create_namespace (' blamer' )
18+ endif
19+ if exists (' *prop_type_add' )
20+ let s: prop_type_name = ' blamer_popup_marker'
21+ endif
1722let s: blamer_delay = get (g: , ' blamer_delay' , 1000 )
1823let s: blamer_show_in_visual_modes = get (g: , ' blamer_show_in_visual_modes' , 1 )
1924let s: blamer_timer_id = -1
2025
26+ let s: is_windows = has (' win16' ) || has (' win32' ) || has (' win64' ) || has (' win95' )
27+ let s: missing_popup_feature = ! has (' nvim' ) && ! exists (' *popup_create' )
28+
2129function ! s: Head (array) abort
2230 if len (a: array ) == 0
2331 return ' '
@@ -112,8 +120,39 @@ function! blamer#SetVirtualText(buffer_number, line_number, message) abort
112120 call nvim_buf_set_virtual_text (a: buffer_number , s: blamer_namespace , l: line_index , [[s: blamer_prefix . a: message , ' Blamer' ]], {})
113121endfunction
114122
123+ function ! blamer#CreatePopup (buffer_number, line_number, message) abort
124+ let l: col = strlen (getline (a: line_number ))
125+ let l: col = l: col == 0 ? 1 : l: col
126+ let l: propid = a: line_number . l: col
127+
128+ if empty (prop_type_get (s: prop_type_name , {' bufnr' : a: buffer_number }))
129+ call prop_type_add (s: prop_type_name , {' bufnr' : a: buffer_number })
130+ endif
131+
132+ call prop_add (a: line_number , l: col , {
133+ \ ' type' : s: prop_type_name ,
134+ \ ' bufnr' : a: buffer_number ,
135+ \ ' length' : 0 ,
136+ \ ' id' : l: propid ,
137+ \} )
138+
139+ let l: popup_winid = popup_create (s: blamer_prefix . a: message , {
140+ \ ' textprop' : ' blamer_popup_marker' ,
141+ \ ' textpropid' : l: propid ,
142+ \ ' line' : -1 ,
143+ \ ' col' : l: col == 1 ? 1 : 2 ,
144+ \ ' fixed' : 1 ,
145+ \ ' wrap' : 0 ,
146+ \ ' highlight' : ' Blamer'
147+ \} )
148+ endfunction
149+
115150function ! blamer#Show () abort
116- let l: file_path = expand (' %:p' )
151+ if g: blamer_enabled == 0 || s: missing_popup_feature
152+ return
153+ endif
154+
155+ let l: file_path = s: substitute_path_separator (expand (' %:p' ))
117156 if s: IsFileInPath (l: file_path , s: git_root ) == 0
118157 return
119158 endif
@@ -128,13 +167,27 @@ function! blamer#Show() abort
128167
129168 for line_number in l: line_numbers
130169 let l: message = blamer#GetMessage (l: file_path , line_number, ' +1' )
131- call blamer#SetVirtualText (l: buffer_number , line_number, l: message )
170+ if has (' nvim' )
171+ call blamer#SetVirtualText (l: buffer_number , line_number, l: message )
172+ else
173+ call blamer#CreatePopup (l: buffer_number , line_number, l: message )
174+ endif
132175 endfor
133176endfunction
134177
135178function ! blamer#Hide () abort
136179 let l: current_buffer_number = bufnr (' ' )
137- call nvim_buf_clear_namespace (l: current_buffer_number , s: blamer_namespace , 0 , -1 )
180+ if has (' nvim' )
181+ call nvim_buf_clear_namespace (l: current_buffer_number , s: blamer_namespace , 0 , -1 )
182+ else
183+ if ! empty (prop_type_get (s: prop_type_name , {' bufnr' : l: current_buffer_number }))
184+ call prop_remove ({
185+ \ ' type' : s: prop_type_name ,
186+ \ ' bufnr' : l: current_buffer_number ,
187+ \ ' all' : 1 ,
188+ \} )
189+ endif
190+ endif
138191endfunction
139192
140193function ! blamer#Refresh () abort
@@ -172,7 +225,18 @@ function! blamer#Init() abort
172225 return
173226 endif
174227
175- let l: result = split (system (' git rev-parse --show-toplevel 2>/dev/null' ), ' \n' )
228+ if s: missing_popup_feature
229+ echohl ErrorMsg
230+ echomsg ' [blamer.nvim] Needs popup feature.'
231+ echohl None
232+ return
233+ endif
234+
235+ if s: is_windows
236+ let l: result = split (system (' git rev-parse --show-toplevel 2>NUL' ), ' \n' )
237+ else
238+ let l: result = split (system (' git rev-parse --show-toplevel 2>/dev/null' ), ' \n' )
239+ endif
176240 let s: git_root = s: Head (l: result )
177241
178242 if s: git_root == ' '
@@ -189,5 +253,10 @@ function! blamer#Init() abort
189253 augroup END
190254endfunction
191255
256+ " from neomru
257+ function ! s: substitute_path_separator (path ) abort
258+ return s: is_windows ? substitute (a: path , ' \\' , ' /' , ' g' ) : a: path
259+ endfunction
260+
192261let &cpo = s: save_cpo
193262unlet s: save_cpo
0 commit comments