quickfix.vim 1.1 KB

123456789101112131415161718192021222324252627282930
  1. " Last Modified: 2023-09-11
  2. function! cargo#quickfix#CmdPre() abort
  3. if &filetype ==# 'rust' && get(b:, 'current_compiler', '') ==# 'cargo' &&
  4. \ &makeprg =~ '\V\^cargo\ \.\*'
  5. " Preserve the current directory, and 'lcd' to the nearest Cargo file.
  6. let b:rust_compiler_cargo_qf_has_lcd = haslocaldir()
  7. let b:rust_compiler_cargo_qf_prev_cd = getcwd()
  8. let b:rust_compiler_cargo_qf_prev_cd_saved = 1
  9. let l:nearest = fnamemodify(cargo#nearestRootCargo(0), ':h')
  10. execute 'lchdir! '.l:nearest
  11. else
  12. let b:rust_compiler_cargo_qf_prev_cd_saved = 0
  13. endif
  14. endfunction
  15. function! cargo#quickfix#CmdPost() abort
  16. if exists("b:rust_compiler_cargo_qf_prev_cd_saved") && b:rust_compiler_cargo_qf_prev_cd_saved
  17. " Restore the current directory.
  18. if b:rust_compiler_cargo_qf_has_lcd
  19. execute 'lchdir! '.b:rust_compiler_cargo_qf_prev_cd
  20. else
  21. execute 'chdir! '.b:rust_compiler_cargo_qf_prev_cd
  22. endif
  23. let b:rust_compiler_cargo_qf_prev_cd_saved = 0
  24. endif
  25. endfunction
  26. " vim: set et sw=4 sts=4 ts=8: