Skip to content

Commit c069666

Browse files
committed
go: remove :GoPathClear and use :GoPath "" for reseting the GOPATH
1 parent 299f440 commit c069666

File tree

3 files changed

+113
-119
lines changed

3 files changed

+113
-119
lines changed

autoload/go/path.vim

Lines changed: 110 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -6,163 +6,163 @@ let s:initial_go_path = ""
66

77
" GoPath sets or returns the current GOPATH. If no arguments are passed it
88
" echoes the current GOPATH, if an argument is passed it replaces the current
9-
" GOPATH with it.
9+
" GOPATH with it. If two double quotes are passed (the empty string in go),
10+
" it'll clear the GOPATH and will restore to the initial GOPATH.
1011
function! go#path#GoPath(...)
11-
" we have an argument, replace GOPATH
12-
if len(a:000)
13-
echon "vim-go: " | echohl Function | echon "GOPATH changed to ". a:1 | echohl None
14-
let s:initial_go_path = $GOPATH
15-
let $GOPATH = a:1
16-
return
17-
endif
18-
19-
echo go#path#Detect()
12+
" we have an argument, replace GOPATH
13+
if len(a:000)
14+
" clears the current manually set GOPATH and restores it to the
15+
" initial GOPATH, which was set when Vim was started.
16+
if len(a:000) == 1 && a:1 == '""'
17+
if !empty(s:initial_go_path)
18+
let $GOPATH = s:initial_go_path
19+
let s:initial_go_path = ""
20+
endif
21+
22+
echon "vim-go: " | echohl Function | echon "GOPATH restored to ". $GOPATH | echohl None
23+
return
24+
endif
25+
26+
echon "vim-go: " | echohl Function | echon "GOPATH changed to ". a:1 | echohl None
27+
let s:initial_go_path = $GOPATH
28+
let $GOPATH = a:1
29+
return
30+
endif
31+
32+
echo go#path#Detect()
2033
endfunction
2134

22-
" GoPathClear clears the current manually set GOPATH and restores it to the
23-
" initial GOPATH, which was set when Vim was started.
24-
function! go#path#GoPathClear()
25-
if !empty(s:initial_go_path)
26-
let $GOPATH = s:initial_go_path
27-
let s:initial_go_path = ""
28-
endif
29-
30-
echon "vim-go: " | echohl Function | echon "GOPATH restored to ". $GOPATH | echohl None
31-
endfunction
32-
33-
34-
3535
" Default returns the default GOPATH. If there is a single GOPATH it returns
3636
" it. For multiple GOPATHS separated with a the OS specific separator, only
3737
" the first one is returned
3838
function! go#path#Default()
39-
let go_paths = split($GOPATH, go#util#PathListSep())
39+
let go_paths = split($GOPATH, go#util#PathListSep())
4040

41-
if len(go_paths) == 1
42-
return $GOPATH
43-
endif
41+
if len(go_paths) == 1
42+
return $GOPATH
43+
endif
4444

45-
return go_paths[0]
45+
return go_paths[0]
4646
endfunction
4747

4848
" HasPath checks whether the given path exists in GOPATH environment variable
4949
" or not
5050
function! go#path#HasPath(path)
51-
let go_paths = split($GOPATH, go#util#PathListSep())
52-
let last_char = strlen(a:path) - 1
53-
54-
" check cases of '/foo/bar/' and '/foo/bar'
55-
if a:path[last_char] == go#util#PathSep()
56-
let withSep = a:path
57-
let noSep = strpart(a:path, 0, last_char)
58-
else
59-
let withSep = a:path . go#util#PathSep()
60-
let noSep = a:path
61-
endif
62-
63-
let hasA = index(go_paths, withSep) != -1
64-
let hasB = index(go_paths, noSep) != -1
65-
return hasA || hasB
51+
let go_paths = split($GOPATH, go#util#PathListSep())
52+
let last_char = strlen(a:path) - 1
53+
54+
" check cases of '/foo/bar/' and '/foo/bar'
55+
if a:path[last_char] == go#util#PathSep()
56+
let withSep = a:path
57+
let noSep = strpart(a:path, 0, last_char)
58+
else
59+
let withSep = a:path . go#util#PathSep()
60+
let noSep = a:path
61+
endif
62+
63+
let hasA = index(go_paths, withSep) != -1
64+
let hasB = index(go_paths, noSep) != -1
65+
return hasA || hasB
6666
endfunction
6767

6868
" Detect returns the current GOPATH. If a package manager is used, such
6969
" as Godeps or something like gb (not supported yet), it will modify the
7070
" GOPATH so those directories take precedence over the current GOPATH. It also
7171
" detects diretories whose are outside GOPATH.
7272
function! go#path#Detect()
73-
let gopath = $GOPATH
73+
let gopath = $GOPATH
7474

75-
" don't lookup for godeps if autodetect is disabled.
76-
if !get(g:, "go_autodetect_gopath", 1)
77-
return gopath
78-
endif
75+
" don't lookup for godeps if autodetect is disabled.
76+
if !get(g:, "go_autodetect_gopath", 1)
77+
return gopath
78+
endif
7979

80-
let current_dir = fnameescape(expand('%:p:h'))
80+
let current_dir = fnameescape(expand('%:p:h'))
8181

82-
" TODO(arslan): this should be changed so folders or files should be
83-
" fetched from a customizable list. The user should define any new package
84-
" management tool by it's own.
82+
" TODO(arslan): this should be changed so folders or files should be
83+
" fetched from a customizable list. The user should define any new package
84+
" management tool by it's own.
8585

86-
" src folder outside $GOPATH
87-
let src_root = finddir("src", current_dir .";")
88-
if !empty(src_root)
89-
let src_path = fnamemodify(src_root, ':p:h:h') . go#util#PathSep()
86+
" src folder outside $GOPATH
87+
let src_root = finddir("src", current_dir .";")
88+
if !empty(src_root)
89+
let src_path = fnamemodify(src_root, ':p:h:h') . go#util#PathSep()
9090

91-
if !go#path#HasPath(src_path)
92-
let gopath = src_path . go#util#PathListSep() . gopath
93-
endif
94-
endif
91+
if !go#path#HasPath(src_path)
92+
let gopath = src_path . go#util#PathListSep() . gopath
93+
endif
94+
endif
9595

96-
" Godeps
97-
let godeps_root = finddir("Godeps", current_dir .";")
98-
if !empty(godeps_root)
99-
let godeps_path = join([fnamemodify(godeps_root, ':p:h:h'), "Godeps", "_workspace" ], go#util#PathSep())
96+
" Godeps
97+
let godeps_root = finddir("Godeps", current_dir .";")
98+
if !empty(godeps_root)
99+
let godeps_path = join([fnamemodify(godeps_root, ':p:h:h'), "Godeps", "_workspace" ], go#util#PathSep())
100100

101-
if !go#path#HasPath(godeps_path)
102-
let gopath = godeps_path . go#util#PathListSep() . gopath
103-
endif
104-
endif
101+
if !go#path#HasPath(godeps_path)
102+
let gopath = godeps_path . go#util#PathListSep() . gopath
103+
endif
104+
endif
105105

106-
return gopath
106+
return gopath
107107
endfunction
108108

109109

110110
" BinPath returns the binary path of installed go tools.
111111
function! go#path#BinPath()
112-
let bin_path = ""
113-
114-
" check if our global custom path is set, if not check if $GOBIN is set so
115-
" we can use it, otherwise use $GOPATH + '/bin'
116-
if exists("g:go_bin_path")
117-
let bin_path = g:go_bin_path
118-
elseif $GOBIN != ""
119-
let bin_path = $GOBIN
120-
elseif $GOPATH != ""
121-
let bin_path = expand(go#path#Default() . "/bin/")
122-
else
123-
" could not find anything
124-
endif
125-
126-
return bin_path
112+
let bin_path = ""
113+
114+
" check if our global custom path is set, if not check if $GOBIN is set so
115+
" we can use it, otherwise use $GOPATH + '/bin'
116+
if exists("g:go_bin_path")
117+
let bin_path = g:go_bin_path
118+
elseif $GOBIN != ""
119+
let bin_path = $GOBIN
120+
elseif $GOPATH != ""
121+
let bin_path = expand(go#path#Default() . "/bin/")
122+
else
123+
" could not find anything
124+
endif
125+
126+
return bin_path
127127
endfunction
128128

129129
" CheckBinPath checks whether the given binary exists or not and returns the
130130
" path of the binary. It returns an empty string doesn't exists.
131131
function! go#path#CheckBinPath(binpath)
132-
" remove whitespaces if user applied something like 'goimports '
133-
let binpath = substitute(a:binpath, '^\s*\(.\{-}\)\s*$', '\1', '')
132+
" remove whitespaces if user applied something like 'goimports '
133+
let binpath = substitute(a:binpath, '^\s*\(.\{-}\)\s*$', '\1', '')
134134

135-
" if it's in PATH just return it
136-
if executable(binpath)
137-
return binpath
138-
endif
135+
" if it's in PATH just return it
136+
if executable(binpath)
137+
return binpath
138+
endif
139139

140140

141-
" just get the basename
142-
let basename = fnamemodify(binpath, ":t")
141+
" just get the basename
142+
let basename = fnamemodify(binpath, ":t")
143143

144-
" check if we have an appropriate bin_path
145-
let go_bin_path = go#path#BinPath()
146-
if empty(go_bin_path)
147-
echo "vim-go: could not find '" . basename . "'. Run :GoInstallBinaries to fix it."
148-
return ""
149-
endif
144+
" check if we have an appropriate bin_path
145+
let go_bin_path = go#path#BinPath()
146+
if empty(go_bin_path)
147+
echo "vim-go: could not find '" . basename . "'. Run :GoInstallBinaries to fix it."
148+
return ""
149+
endif
150150

151-
" append our GOBIN and GOPATH paths and be sure they can be found there...
152-
" let us search in our GOBIN and GOPATH paths
153-
let old_path = $PATH
154-
let $PATH = $PATH . go#util#PathListSep() .go_bin_path
151+
" append our GOBIN and GOPATH paths and be sure they can be found there...
152+
" let us search in our GOBIN and GOPATH paths
153+
let old_path = $PATH
154+
let $PATH = $PATH . go#util#PathListSep() .go_bin_path
155155

156-
if !executable(basename)
157-
echo "vim-go: could not find '" . basename . "'. Run :GoInstallBinaries to fix it."
158-
" restore back!
159-
let $PATH = old_path
160-
return ""
161-
endif
156+
if !executable(basename)
157+
echo "vim-go: could not find '" . basename . "'. Run :GoInstallBinaries to fix it."
158+
" restore back!
159+
let $PATH = old_path
160+
return ""
161+
endif
162162

163-
let $PATH = old_path
163+
let $PATH = old_path
164164

165-
return go_bin_path . go#util#PathSep() . basename
165+
return go_bin_path . go#util#PathSep() . basename
166166
endfunction
167167

168168
" vim:ts=4:sw=4:et

doc/vim-go.txt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,9 @@ COMMANDS *go-commands*
114114
:GoPath [path]
115115

116116
GoPath sets and ovverides GOPATH with the given {path}. If no {path} is
117-
given it shows the current GOPATH.
118-
119-
*:GoPathClear*
120-
:GoPathClear
121-
122-
GoPathClear clears the current `GOPATH` which was set with |GoPath| and
123-
restores `GOPATH` back to the inital value which was sourced when Vim was
124-
started.
117+
given it shows the current GOPATH. If `""` is given as path, it clears
118+
current `GOPATH` which was set with |GoPath| and restores `GOPATH` back to
119+
the inital value which was sourced when Vim was started.
125120

126121
*:GoImport*
127122
:GoImport [path]

plugin/go.vim

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ let s:packages = [
2222
command! GoInstallBinaries call s:GoInstallBinaries(-1)
2323
command! GoUpdateBinaries call s:GoInstallBinaries(1)
2424
command! -nargs=? -complete=dir GoPath call go#path#GoPath(<f-args>)
25-
command! GoPathClear call go#path#GoPathClear()
2625

2726
" GoInstallBinaries downloads and install all necessary binaries stated in the
2827
" packages variable. It uses by default $GOBIN or $GOPATH/bin as the binary

0 commit comments

Comments
 (0)