Skip to content

Commit 37211f3

Browse files
committed
Improve xolox#misc#os#find_vim() function
Now accepts a 'vim' or 'gvim' argument to allow callers to indicate their preference independently from 'v:progname'.
1 parent 5082965 commit 37211f3

File tree

4 files changed

+53
-33
lines changed

4 files changed

+53
-33
lines changed

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ from the source code of the miscellaneous scripts using the Python module
3838
<!-- Start of generated documentation -->
3939

4040
The documentation of the 67 functions below was extracted from
41-
15 Vim scripts on June 3, 2013 at 21:23.
41+
15 Vim scripts on June 3, 2013 at 21:53.
4242

4343
### Handling of special buffers
4444

@@ -286,14 +286,18 @@ Returns 1 (true) when on Microsoft Windows, 0 (false) otherwise.
286286

287287
#### The `xolox#misc#os#find_vim()` function
288288

289-
Returns the program name of Vim as a string. On Windows and UNIX this
290-
simply returns [v:progname] [progname] while on Mac OS X there is some
291-
special magic to find MacVim's executable even though it's usually not on
292-
the executable search path. If you want, you can override the value
293-
returned from this function by setting the global variable
289+
Returns the program name of Vim as a string. On Windows and UNIX this just
290+
[v:progname] [] as an absolute pathname while on Mac OS X there is
291+
some special magic to find MacVim's executable even though it's usually
292+
not on the executable search path. If you want, you can override the
293+
value returned from this function by setting the global variable
294294
`g:xolox#misc#os#vim_progname`.
295295

296-
[progname]: http://vimdoc.sourceforge.net/htmldoc/eval.html#v:progname
296+
By default the choice of console Vim vs graphical Vim is made based on
297+
the value of [v:progname] [], but if you have a preference you can pass
298+
the string `vim` or `gvim` as the first and only argument.
299+
300+
[v:progname]: http://vimdoc.sourceforge.net/htmldoc/eval.html#v:progname
297301

298302
#### The `xolox#misc#os#exec()` function
299303

autoload/xolox/misc.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
" Last Change: June 3, 2013
55
" URL: http://peterodding.com/code/vim/misc/
66

7-
let g:xolox#misc#version = '1.5'
7+
let g:xolox#misc#version = '1.6'

autoload/xolox/misc/os.vim

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,59 @@
11
" Operating system interfaces.
22
"
33
" Author: Peter Odding <[email protected]>
4-
" Last Change: June 1, 2013
4+
" Last Change: June 3, 2013
55
" URL: http://peterodding.com/code/vim/misc/
66

77
function! xolox#misc#os#is_win() " {{{1
88
" Returns 1 (true) when on Microsoft Windows, 0 (false) otherwise.
99
return has('win16') || has('win32') || has('win64')
1010
endfunction
1111

12-
function! xolox#misc#os#find_vim() " {{{1
13-
" Returns the program name of Vim as a string. On Windows and UNIX this
14-
" simply returns [v:progname] [progname] while on Mac OS X there is some
15-
" special magic to find MacVim's executable even though it's usually not on
16-
" the executable search path. If you want, you can override the value
17-
" returned from this function by setting the global variable
12+
function! xolox#misc#os#find_vim(...) " {{{1
13+
" Returns the program name of Vim as a string. On Windows and UNIX this just
14+
" [v:progname] [] as an absolute pathname while on Mac OS X there is
15+
" some special magic to find MacVim's executable even though it's usually
16+
" not on the executable search path. If you want, you can override the
17+
" value returned from this function by setting the global variable
1818
" `g:xolox#misc#os#vim_progname`.
1919
"
20-
" [progname]: http://vimdoc.sourceforge.net/htmldoc/eval.html#v:progname
21-
let progname = ''
20+
" By default the choice of console Vim vs graphical Vim is made based on
21+
" the value of [v:progname] [], but if you have a preference you can pass
22+
" the string `vim` or `gvim` as the first and only argument.
23+
"
24+
" [v:progname]: http://vimdoc.sourceforge.net/htmldoc/eval.html#v:progname
25+
if exists('a:1')
26+
let program_name = a:1
27+
else
28+
let program_name = v:progname
29+
endif
2230
if exists('g:xolox#misc#os#vim_progname')
23-
let progname = g:xolox#misc#os#vim_progname
31+
let pathname = g:xolox#misc#os#vim_progname
32+
else
33+
let pathname = ''
2434
endif
25-
if empty(progname) && has('macunix')
35+
if empty(pathname) && has('macunix')
2636
" Special handling for Mac OS X where MacVim is usually not on the $PATH.
37+
" This always returns the "Vim" executable and not "MacVim" (regardless of
38+
" the caller's preference) because "MacVim" has funky dock magic going on.
2739
call xolox#misc#msg#debug("vim-misc %s: Trying MacVim workaround to find Vim executable ..", g:xolox#misc#version)
2840
let segments = xolox#misc#path#split($VIMRUNTIME)
2941
if segments[-3:] == ['Resources', 'vim', 'runtime']
30-
let progname = xolox#misc#path#join(segments[0:-4] + ['MacOS', 'Vim'])
31-
call xolox#misc#msg#debug("vim-misc %s: The MacVim workaround resulted in the Vim executable %s.", g:xolox#misc#version, string(progname))
42+
let pathname = xolox#misc#path#join(segments[0:-4] + ['MacOS', 'Vim'])
43+
call xolox#misc#msg#debug("vim-misc %s: The MacVim workaround resulted in the Vim executable %s.", g:xolox#misc#version, string(pathname))
3244
endif
3345
endif
34-
if empty(progname)
46+
if empty(pathname)
3547
" Default logic.
36-
call xolox#misc#msg#debug("vim-misc %s: Looking for Vim executable named %s on search path ..", g:xolox#misc#version, string(v:progname))
37-
let candidates = xolox#misc#path#which(v:progname)
48+
call xolox#misc#msg#debug("vim-misc %s: Looking for Vim executable named %s on search path ..", g:xolox#misc#version, string(program_name))
49+
let candidates = xolox#misc#path#which(program_name)
3850
if !empty(candidates)
3951
call xolox#misc#msg#debug("vim-misc %s: Found %i candidate(s) on search path: %s.", g:xolox#misc#version, len(candidates), string(candidates))
40-
let progname = candidates[0]
52+
let pathname = candidates[0]
4153
endif
4254
endif
43-
call xolox#misc#msg#debug("vim-misc %s: Reporting Vim executable %s.", g:xolox#misc#version, string(progname))
44-
return progname
55+
call xolox#misc#msg#debug("vim-misc %s: Reporting Vim executable %s.", g:xolox#misc#version, string(pathname))
56+
return pathname
4557
endfunction
4658

4759
function! xolox#misc#os#exec(options) " {{{1

doc/misc.txt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ from the source code of the miscellaneous scripts using the Python module
137137
'vimdoctool.py' included in vim-tools [5].
138138

139139
The documentation of the 67 functions below was extracted from 15 Vim scripts
140-
on June 3, 2013 at 21:23.
140+
on June 3, 2013 at 21:53.
141141

142142
-------------------------------------------------------------------------------
143143
*misc-handling-of-special-buffers*
@@ -401,11 +401,15 @@ Returns 1 (true) when on Microsoft Windows, 0 (false) otherwise.
401401
-------------------------------------------------------------------------------
402402
The *xolox#misc#os#find_vim()* function
403403

404-
Returns the program name of Vim as a string. On Windows and UNIX this simply
405-
returns |v:progname| while on Mac OS X there is some special magic to find
406-
MacVim's executable even though it's usually not on the executable search path.
407-
If you want, you can override the value returned from this function by setting
408-
the global variable 'g:xolox#misc#os#vim_progname'.
404+
Returns the program name of Vim as a string. On Windows and UNIX this just
405+
|v:progname| as an absolute pathname while on Mac OS X there is some special
406+
magic to find MacVim's executable even though it's usually not on the
407+
executable search path. If you want, you can override the value returned from
408+
this function by setting the global variable 'g:xolox#misc#os#vim_progname'.
409+
410+
By default the choice of console Vim vs graphical Vim is made based on the
411+
value of |v:progname|, but if you have a preference you can pass the string
412+
'vim' or 'gvim' as the first and only argument.
409413

410414
-------------------------------------------------------------------------------
411415
The *xolox#misc#os#exec()* function

0 commit comments

Comments
 (0)