From 1e9f020d4ea999202e6d975cc7bae27d50f6d5bb Mon Sep 17 00:00:00 2001 From: JingMatrix Date: Tue, 16 Mar 2021 22:56:15 +0100 Subject: [PATCH] Respect user's &autochdir for not triggered buffer For buffers that won't trigger rooter, we can respect user's &autochdir setting for them unchanged. --- README.mkd | 2 +- doc/rooter.txt | 3 +-- plugin/rooter.vim | 11 ++++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.mkd b/README.mkd index 5e9bd20..63832bd 100644 --- a/README.mkd +++ b/README.mkd @@ -22,7 +22,7 @@ You can turn this off (see below) and use the `:Rooter` command to invoke Rooter When Rooter changes the working directory it emits the autocmd user event `RooterChDir`. -Rooter will unset `&autochdir` if it's set. +For triggered buffers, rooter will unset `&autochdir` if it's set. For other buffers, rooter respect user's setting of `&autochdir`. ## Configuration diff --git a/doc/rooter.txt b/doc/rooter.txt index 58f04b9..2ef2c22 100644 --- a/doc/rooter.txt +++ b/doc/rooter.txt @@ -46,8 +46,7 @@ Rooter manually. When Rooter changes the working directory it emits the |autocmd| |User| event `RooterChDir`. -Rooter will unset 'autochdir' if it's set. - +For triggered buffers, rooter will unset `&autochdir` if it's set. For other buffers, rooter respect user's setting of `&autochdir`. ============================================================================== Configuration *rooter-configuration* diff --git a/plugin/rooter.vim b/plugin/rooter.vim index 4573cbd..4b5614e 100644 --- a/plugin/rooter.vim +++ b/plugin/rooter.vim @@ -14,7 +14,9 @@ if !exists('g:rooter_manual_only') let g:rooter_manual_only = 0 endif +let s:user_autochdir=0 if exists('+autochdir') && &autochdir && !g:rooter_manual_only + let s:user_autochdir=1 set noautochdir endif @@ -66,7 +68,14 @@ augroup END function! s:rooter() - if !s:activate() | return | endif + if !s:activate() + if s:user_autochdir + setl autochdir + endif + return + endif + + set noautochdir let root = getbufvar('%', 'rootDir') if empty(root)