@@ -33,12 +33,23 @@ function! s:set_db() abort
3333endfunction
3434
3535
36+ function ! s: save_cwd () abort
37+ let g: codequery_cwd = getcwd ()
38+ endfunction
39+
40+
41+ function ! s: restore_cwd () abort
42+ execute ' lcd ' . g: codequery_cwd
43+ endfunction
44+
45+
3646
3747" =============================================================================
3848" Entries
3949
4050
4151function ! codequery#run_codequery (args ) abort
52+ call s: save_cwd ()
4253 if ! s: check_filetype (&filetype )
4354 echom ' Not Supported Filetype: ' . &filetype
4455 return
@@ -50,6 +61,7 @@ function! codequery#run_codequery(args) abort
5061 let g: codequery_querytype = 1
5162 let g: codequery_db_path = ' '
5263 if ! s: set_db ()
64+ call s: restore_cwd ()
5365 return
5466 endif
5567
@@ -66,17 +78,20 @@ function! codequery#run_codequery(args) abort
6678 let word = codequery#query#get_final_query_word (iword, cword)
6779 if empty (word)
6880 echom ' Invalid Args: ' . a: args
81+ call s: restore_cwd ()
6982 return
7083 endif
7184
7285 call codequery#query#do_query (word)
7386 else
7487 echom ' Wrong Subcommand !'
7588 endif
89+ call s: restore_cwd ()
7690endfunction
7791
7892
7993function ! codequery#make_codequery_db (args ) abort
94+ call s: save_cwd ()
8095 let args = split (a: args , ' ' )
8196 if empty (args )
8297 let args = [&filetype ]
@@ -126,10 +141,12 @@ function! codequery#make_codequery_db(args) abort
126141 endif
127142 " ----------------------------------------------------------------
128143 endfor
144+ call s: restore_cwd ()
129145endfunction
130146
131147
132148function ! codequery#view_codequery_db (args ) abort
149+ call s: save_cwd ()
133150 let args = split (a: args , ' ' )
134151 if empty (args )
135152 let args = [&filetype ]
@@ -153,10 +170,12 @@ function! codequery#view_codequery_db(args) abort
153170
154171 execute ' !echo "\n(' . db_path . ' ) is update at: " && stat -f "\%Sm" ' . db_path
155172 endfor
173+ call s: restore_cwd ()
156174endfunction
157175
158176
159177function ! codequery#move_codequery_db_to_git_hidden_dir (args ) abort
178+ call s: save_cwd ()
160179 let args = split (a: args , ' ' )
161180 if empty (args )
162181 let args = [&filetype ]
@@ -180,6 +199,7 @@ function! codequery#move_codequery_db_to_git_hidden_dir(args) abort
180199 echom ' Git Dir Not Found or (' . db_name . ' ) Not Found'
181200 endif
182201 endfor
202+ call s: restore_cwd ()
183203endfunction
184204
185205
0 commit comments