Skip to content

Commit 1d3361d

Browse files
author
yssl
committedAug 7, 2014
CWDPattern -> autocwd
1 parent 39562ec commit 1d3361d

File tree

4 files changed

+62
-60
lines changed

4 files changed

+62
-60
lines changed
 

‎README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# CWDPattern
1+
# autocwd.vim
22

3-
CWDPattern automatically changes the current working directory (CWD) of vim when you change the current buffer.
3+
autocwd.vim automatically changes the current working directory (CWD) of vim when you change the current buffer.
44
You can define patterns that be may included in a name or file path of a buffer, and their working directories in your .vimrc.
55
The predefined working directories can be the directory of the current buffer's file, absolute paths of specific directories, and so on.
66

@@ -15,7 +15,7 @@ Screenshot:
1515
You can define patterns and working directories in your .vimrc as follows:
1616

1717
```
18-
let g:cwdpattern_patternwd_pairs = [
18+
let g:autocwd_patternwd_pairs = [
1919
\[pattern1, working_directory1],
2020
\[pattern2, working_directory2],
2121
...
@@ -33,15 +33,15 @@ For example, '~/test' changes the CWD to ~/test directory and '%:p:h' changes th
3333
(Please refer http://vimdoc.sourceforge.net/htmldoc/cmdline.html#filename-modifiers for more information.)
3434

3535
- If the current buffer matches one of the defined patterns, the CWD will be changed to the corresponding working directory.
36-
Otherwise, the default working directory that have been the CWD before applying `g:cwdpattern_patternwd_pairs` will be restored.
36+
Otherwise, the default working directory that have been the CWD before applying `g:autocwd_patternwd_pairs` will be restored.
3737
You can change the default working directory by `:cd` or other CWD-changing commands (e.g., 'cd' of the NERDTree) when the current buffer does not match any of predefined patterns.
3838

39-
- The order of patterns in `g:cwdpattern_patternwd_pairs` is meaningful.
39+
- The order of patterns in `g:autocwd_patternwd_pairs` is meaningful.
4040
If the current buffer matches both first and second patterns, the working directory corresponding to the first pattern will be the CWD.
4141

4242
An example pattern-wd pairs for the screenshot:
4343
```
44-
let g:cwdpattern_patternwd_pairs = [
44+
let g:autocwd_patternwd_pairs = [
4545
\['*.vim', '%:p:h'],
4646
\['*.py', '%:p:h'],
4747
\['*/vim74/*', '/home/testid/vim74'],
@@ -51,10 +51,10 @@ let g:cwdpattern_patternwd_pairs = [
5151

5252
## Commands
5353

54-
**:CWDPatternPrint**
54+
**:AutoCWDPrint**
5555
Print the buffer name or file path, matched pattern, and working directory of windows in the current tab.
5656

57-
There is no activation commands for CWDPattern.
57+
There is no activation commands for autocwd.vim.
5858
If you install this plugin, it will starts to manage the CWD.
5959

6060
## Motivation
@@ -63,5 +63,5 @@ It is quite useful to set the CWD for each opened file in vim.
6363
Vim provides `:lcd` command for this purpose.
6464
However, it cannot deal with opening other files in the same window because `:lcd` is applied to a specific window, not buffer.
6565

66-
CWDPattern is designed to solve this problem.
66+
autocwd.vim is designed to solve this problem.
6767
Moreover, it provides more convenient way to set CWDs with Unix shell-style patterns.

‎autoload/CWDPattern.vim ‎autoload/autocwd.vim

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
" File: autoload/CWDPattern.vim
2-
" Description: Automatically changes CWD depending on patterns in file path of current buffer.
1+
" File: autoload/autocwd.vim
2+
" Description: Auto current working directory update system
33
" Author: yssl <http://github.com/yssl>
44
" License:
55

66
" wrappers
7-
function! CWDPattern#PrintWorkDirs()
7+
function! autocwd#PrintWorkDirs()
88
call s:PrintWorkDirs()
99
endfunction
1010

@@ -57,7 +57,7 @@ EOF
5757
function! s:GetWorkDir(filepath)
5858
python << EOF
5959
filepath = vim.eval('a:filepath')
60-
patternwd_pairs = vim.eval('g:cwdpattern_patternwd_pairs')
60+
patternwd_pairs = vim.eval('g:autocwd_patternwd_pairs')
6161
inpatternwd = False
6262
for pattern, wd in patternwd_pairs:
6363
wd = vim.eval('expand(\'%s\')'%wd)
@@ -66,15 +66,15 @@ for pattern, wd in patternwd_pairs:
6666
vim.command('return \'%s\''%wd)
6767
break
6868
if inpatternwd==False:
69-
vim.command('return g:cwdpattern_defaultwd')
69+
vim.command('return g:autocwd_defaultwd')
7070
EOF
7171
endfunction
7272

7373
function! s:GetWorkDirPattern(filepath)
7474
python << EOF
7575
import fnmatch
7676
filepath = vim.eval('a:filepath')
77-
patternwd_pairs = vim.eval('g:cwdpattern_patternwd_pairs')
77+
patternwd_pairs = vim.eval('g:autocwd_patternwd_pairs')
7878
inpatternwd = False
7979
for pattern, wd in patternwd_pairs:
8080
wd = vim.eval('expand(\'%s\')'%wd)

‎doc/CWDPattern.txt ‎doc/autocwd.txt

+29-27
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
*CWDPattern.txt* Change CWD automatically by patterns when you change the current buffer.
2-
*CWDPattern*
1+
*autocwd.txt* Change CWD automatically by patterns when you change the current buffer.
2+
*autocwd*
33

44
Author: yssl <http://github.com/yssl>
55

66
==============================================================================
7-
Contents *CWDPattern-contents*
7+
Contents *autocwd-contents*
88

9-
1. Introduction .............................. |CWDPattern-intro|
10-
2. Usage ..................................... |CWDPattern-usage|
11-
3. Commands .................................. |CWDPattern-commands|
12-
4. Motivation ................................ |CWDPattern-arguments|
13-
5. Options ................................... |CWDPattern-options|
14-
6. Changelog ................................. |CWDPattern-changelog|
9+
1. Introduction .............................. |autocwd-intro|
10+
2. Usage ..................................... |autocwd-usage|
11+
3. Commands .................................. |autocwd-commands|
12+
4. Motivation ................................ |autocwd-arguments|
13+
5. Options ................................... |autocwd-options|
14+
6. Changelog ................................. |autocwd-changelog|
1515

1616
==============================================================================
17-
1. Introduction *CWDPattern-intro*
17+
1. Introduction *autocwd-intro*
1818

19-
CWDPattern automatically changes the current working directory (CWD) of vim
19+
autocwd.vim automatically changes the current working directory (CWD) of vim
2020
when you change the current buffer.
2121
You can define patterns that be may included in a name or file path of a buffer,
2222
and their working directories in your .vimrc.
@@ -27,12 +27,12 @@ This plugin requires a version of vim with python support.
2727
You can check your vim with `:echo has('python')`.
2828

2929
==============================================================================
30-
2. Usage *CWDPattern-usage*
30+
2. Usage *autocwd-usage*
3131

3232
You can define patterns and working directories in your .vimrc as follows:
3333

3434
```
35-
let g:cwdpattern_patternwd_pairs = [
35+
let g:autocwd_patternwd_pairs = [
3636
\[pattern1, working_directory1],
3737
\[pattern2, working_directory2],
3838
...
@@ -55,47 +55,47 @@ to the directory of the current buffer's file.
5555
- If the current buffer matches one of the defined patterns, the CWD will
5656
be changed to the corresponding working directory.
5757
Otherwise, the default working directory that have been the CWD before
58-
applying `g:cwdpattern_patternwd_pairs` will be restored.
58+
applying `g:autocwd_patternwd_pairs` will be restored.
5959
You can change the default working directory by `:cd` or other CWD-changing
6060
commands (e.g., 'cd' of the NERDTree) when the current buffer does not
6161
match any of predefined patterns.
6262

63-
- The order of patterns in `g:cwdpattern_patternwd_pairs` is meaningful.
63+
- The order of patterns in `g:autocwd_patternwd_pairs` is meaningful.
6464
If the current buffer matches both first and second patterns, the working
6565
directory corresponding to the first pattern will be the CWD.
6666

6767

6868
==============================================================================
69-
3. Commands *CWDPattern-commands*
69+
3. Commands *autocwd-commands*
7070

71-
*:CWDPatternPrint*
71+
*:AutoCWDPrint*
7272
Print the buffer name or file path, matched pattern, and working directory
7373
of windows in the current tab.
7474

75-
There is no activation commands for CWDPattern.
75+
There is no activation commands for autocwd.vim.
7676
If you install this plugin, it will starts to manage the CWD.
7777

7878
==============================================================================
79-
4. Motivation *CWDPattern-arguments*
79+
4. Motivation *autocwd-arguments*
8080

8181
It is quite useful to set the CWD for each opened file in vim.
8282
Vim provides `:lcd` command for this purpose.
8383
However, it cannot deal with opening other files in the same window because `:lcd` is applied to a specific window, not buffer.
8484

85-
CWDPattern is designed to solve this problem.
85+
autocwd.vim is designed to solve this problem.
8686
Moreover, it provides more convenient way to set CWDs with Unix shell-style patterns.
8787

8888
==============================================================================
89-
5. Options *CWDPattern-options*
89+
5. Options *autocwd-options*
9090

91-
*g:cwdpattern_patternwd_pairs*
91+
*g:autocwd_patternwd_pairs*
9292
A list of [pattern, working_directory] pairs.
9393
Default: >
94-
let g:cwdpattern_patternwd_pairs = []
94+
let g:autocwd_patternwd_pairs = []
9595
<
9696

97-
*g:cwdpattern_not_update_defaultwd_for*
98-
CWDPattern set the default working directory to the return value of the getcwd()
97+
*g:autocwd_not_update_defaultwd_for*
98+
autocwd.vim set the default working directory to the return value of the getcwd()
9999
function when you leave the current buffer.
100100
This behavior assumes that the change of the CWD is caused by a user action
101101
(e.g., :cd command).
@@ -106,11 +106,13 @@ For example, the ControlP plugin window internally changes the CWD.
106106
If you find such cases, please let me know to apply them as the default value
107107
of this option.
108108
Default: >
109-
let g:cwdpattern_not_update_defaultwd_for = ['ControlP']
109+
let g:autocwd_not_update_defaultwd_for = ['ControlP']
110110
<
111111

112112
==============================================================================
113-
6. Changelog *CWDPattern-changelog*
113+
6. Changelog *autocwd-changelog*
114114

115115
1.0.0 2014/06/24
116116
- first version
117+
1.1.0 2014/08/07
118+
- change the name to autocmd.vim from CWDPattern

‎plugin/CWDPattern.vim ‎plugin/autocwd.vim

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
" File: plugin/CWDPattern.vim
2-
" Description: Automatically changes CWD depending on patterns in file path of current buffer.
1+
" File: plugin/autocwd.vim
2+
" Description: Auto current working directory update system
33
" Author: yssl <http://github.com/yssl>
44
" License:
55

6-
if exists("g:loaded_cwdpattern") || &cp
6+
if exists("g:loaded_autocwd") || &cp
77
finish
88
endif
9-
let g:loaded_cwdpattern = 1
9+
let g:loaded_autocwd = 1
1010
let s:keepcpo = &cpo
1111
set cpo&vim
1212
"""""""""""""""""""""""""""""""""""""""""""""
1313

1414
" global variables
15-
if !exists('g:cwdpattern_patternwd_pairs')
16-
let g:cwdpattern_patternwd_pairs = []
15+
if !exists('g:autocwd_patternwd_pairs')
16+
let g:autocwd_patternwd_pairs = []
1717
endif
18-
if !exists('g:cwdpattern_not_update_defaultwd_for')
19-
let g:cwdpattern_not_update_defaultwd_for = ['ControlP']
18+
if !exists('g:autocwd_not_update_defaultwd_for')
19+
let g:autocwd_not_update_defaultwd_for = ['ControlP']
2020
endif
21-
if !exists('g:cwdpattern_defaultwd')
22-
let g:cwdpattern_defaultwd = getcwd()
21+
if !exists('g:autocwd_defaultwd')
22+
let g:autocwd_defaultwd = getcwd()
2323
endif
24-
"if !exists('g:cwdpattern_repodirs')
25-
"let g:cwdpattern_repodirs = ['.git', '.hg', '.svn']
24+
"if !exists('g:autocwd_repodirs')
25+
"let g:autocwd_repodirs = ['.git', '.hg', '.svn']
2626
"endif
2727

2828
" commands
29-
command! CWDPatternPrint call CWDPattern#PrintWorkDirs()
29+
command! AutoCWDPrint call autocwd#PrintWorkDirs()
3030

3131
" autocmd
32-
augroup CWDPatternAutoCmds
32+
augroup AutoCWDAutoCmds
3333
autocmd!
3434
autocmd BufEnter * call s:OnEnterBuf()
3535
autocmd BufLeave * call s:OnLeaveBuf()
@@ -74,7 +74,7 @@ function! s:OnLeaveBuf()
7474
let bufname = getcwd().'/'.bufname
7575
endif
7676

77-
for noupdatename in g:cwdpattern_not_update_defaultwd_for
77+
for noupdatename in g:autocwd_not_update_defaultwd_for
7878
if match(bufname, noupdatename) >= 0
7979
return
8080
endif
@@ -84,7 +84,7 @@ function! s:OnLeaveBuf()
8484

8585
let exist = s:ExistPattern(bufname, buftype)[0]
8686
if exist==0
87-
let g:cwdpattern_defaultwd = getcwd()
87+
let g:autocwd_defaultwd = getcwd()
8888
endif
8989
endfunction
9090

@@ -93,7 +93,7 @@ python << EOF
9393
bufname = vim.eval('a:bufname')
9494
buftype = vim.eval('a:buftype')
9595
filepath = getWinName(bufname, buftype)
96-
patternwd_pairs = vim.eval('g:cwdpattern_patternwd_pairs')
96+
patternwd_pairs = vim.eval('g:autocwd_patternwd_pairs')
9797
inpatternwd = False
9898
for pattern, wd in patternwd_pairs:
9999
wd = vim.eval('expand(\'%s\')'%wd)
@@ -102,7 +102,7 @@ for pattern, wd in patternwd_pairs:
102102
vim.command('return [1, \'%s\']'%wd)
103103
break
104104
if inpatternwd==False:
105-
vim.command('return [0, g:cwdpattern_defaultwd]')
105+
vim.command('return [0, g:autocwd_defaultwd]')
106106
EOF
107107
endfunction
108108

0 commit comments

Comments
 (0)