comparison autoload/lawrencium.vim @ 152:62e054a2c4f0

Correctly reset HGPLAIN after use. Based on 0jrp0's comments (github issue #20).
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 08 Nov 2021 10:37:27 -0800
parents 59c51f0d6008
children 40181bd0ffcd
comparison
equal deleted inserted replaced
151:59c51f0d6008 152:62e054a2c4f0
326 return l:hg_command 326 return l:hg_command
327 endfunction 327 endfunction
328 328
329 " Runs a Mercurial command in the repo. 329 " Runs a Mercurial command in the repo.
330 function! s:HgRepo.RunCommand(command, ...) abort 330 function! s:HgRepo.RunCommand(command, ...) abort
331 " Use 'plain mode', and forward the command and all params to RunCommandEx
331 let l:all_args = [1, a:command] + a:000 332 let l:all_args = [1, a:command] + a:000
332 return call(self['RunCommandEx'], l:all_args, self) 333 return call(self['RunCommandEx'], l:all_args, self)
333 endfunction 334 endfunction
334 335
335 function! s:HgRepo.RunCommandEx(plain_mode, command, ...) abort 336 function! s:HgRepo.RunCommandEx(plain_mode, command, ...) abort
336 let l:prev_hgplain = $HGPLAIN 337 let l:envvars = environ()
337 if a:plain_mode 338 if a:plain_mode
338 let $HGPLAIN = 'true' 339 let $HGPLAIN = 'true'
339 endif 340 endif
340 let l:all_args = [a:command] + a:000 341 let l:all_args = [a:command] + a:000
341 let l:hg_command = call(self['GetCommand'], l:all_args, self) 342 let l:hg_command = call(self['GetCommand'], l:all_args, self)
342 call lawrencium#trace("Running Mercurial command: " . l:hg_command) 343 call lawrencium#trace("Running Mercurial command: " . l:hg_command)
343 let l:cmd_out = system(l:hg_command) 344 let l:cmd_out = system(l:hg_command)
344 if a:plain_mode 345 if a:plain_mode
345 let $HGPLAIN = l:prev_hgplain 346 if has_key(l:envvars, "HGPLAIN")
347 let $HGPLAIN = l:envvars["HGPLAIN"]
348 else
349 unlet $HGPLAIN
350 endif
346 endif 351 endif
347 return l:cmd_out 352 return l:cmd_out
348 endfunction 353 endfunction
349 354
350 " Runs a Mercurial command in the repo and reads its output into the current 355 " Runs a Mercurial command in the repo and reads its output into the current
351 " buffer. 356 " buffer.
352 function! s:HgRepo.ReadCommandOutput(command, ...) abort 357 function! s:HgRepo.ReadCommandOutput(command, ...) abort
353 function! s:PutOutputIntoBuffer(command_line) 358 function! s:PutOutputIntoBuffer(command_line)
354 let l:prev_hgplain = $HGPLAIN 359 let l:envvars = environ()
355 let $HGPLAIN = 'true' 360 let $HGPLAIN = 'true'
356 361
357 let l:was_buffer_empty = (line('$') == 1 && getline(1) == '') 362 let l:was_buffer_empty = (line('$') == 1 && getline(1) == '')
358 execute '0read!' . escape(a:command_line, '%#\') 363 execute '0read!' . escape(a:command_line, '%#\')
359 if l:was_buffer_empty " (Always true?) 364 if l:was_buffer_empty " (Always true?)
363 " contents of the last fold (since Vim may close them all by 368 " contents of the last fold (since Vim may close them all by
364 " default). 369 " default).
365 normal! zRG"_dd 370 normal! zRG"_dd
366 endif 371 endif
367 372
368 let $HGPLAIN = l:prev_hgplain 373 if has_key(l:envvars, "HGPLAIN")
374 let $HGPLAIN = l:envvars["HGPLAIN"]
375 else
376 unlet $HGPLAIN
377 endif
369 endfunction 378 endfunction
370 379
371 let l:all_args = [a:command] + a:000 380 let l:all_args = [a:command] + a:000
372 let l:hg_command = call(self['GetCommand'], l:all_args, self) 381 let l:hg_command = call(self['GetCommand'], l:all_args, self)
373 call lawrencium#trace("Running Mercurial command: " . l:hg_command) 382 call lawrencium#trace("Running Mercurial command: " . l:hg_command)