Skip to content

Commit

Permalink
Updated miscellaneous scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed May 20, 2013
2 parents 8522483 + 8b60a41 commit 17047ef
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 16 deletions.
2 changes: 1 addition & 1 deletion autoload/xolox/misc/compat.vim
Expand Up @@ -12,7 +12,7 @@
" scripts breaks backwards compatibility. This enables my Vim plug-ins to fail
" early when they detect an incompatible version, instead of breaking at the
" worst possible moments :-).
let g:xolox#misc#compat#version = 7
let g:xolox#misc#compat#version = 9

" Remember the directory where the miscellaneous scripts are loaded from
" so the user knows which plug-in to update if incompatibilities arise.
Expand Down
4 changes: 1 addition & 3 deletions autoload/xolox/misc/msg.vim
@@ -1,7 +1,7 @@
" Functions to interact with the user.
"
" Author: Peter Odding <peter@peterodding.com>
" Last Change: May 19, 2013
" Last Change: May 20, 2013
" URL: http://peterodding.com/code/vim/misc/

if !exists('g:xolox_message_buffer')
Expand Down Expand Up @@ -32,8 +32,6 @@ function! xolox#misc#msg#debug(...) " {{{1
" increased verbosity by setting Vim's ['verbose'] [verbose] option to one
" (1) or higher. This function has the same argument handling as Vim's
" [printf()] [printf] function.
"
" [verbose]: http://vimdoc.sourceforge.net/htmldoc/options.html#'verbose'
if &vbs >= 1
call s:show_message('question', a:000)
endif
Expand Down
37 changes: 32 additions & 5 deletions autoload/xolox/misc/os.vim
@@ -1,16 +1,45 @@
" Operating system interfaces.
"
" Author: Peter Odding <peter@peterodding.com>
" Last Change: May 19, 2013
" Last Change: May 20, 2013
" URL: http://peterodding.com/code/vim/misc/

let g:xolox#misc#os#version = '0.3'
let g:xolox#misc#os#version = '0.4'

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

function! xolox#misc#os#find_vim() " {{{1
" Returns the program name of Vim as a string. On Windows and UNIX this
" simply returns [v:progname] [progname] while on Mac OS X there is some
" special magic to find MacVim's executable even though it's usually not on
" the executable search path.
"
" [progname]: http://vimdoc.sourceforge.net/htmldoc/eval.html#v:progname
let progname = ''
if has('macunix')
" Special handling for Mac OS X where MacVim is usually not on the $PATH.
call xolox#misc#msg#debug("os.vim %s: Trying MacVim workaround to find Vim executable ..", g:xolox#misc#os#version)
let segments = xolox#misc#path#split($VIMRUNTIME)
if segments[-3:] == ['Resources', 'vim', 'runtime']
let progname = xolox#misc#path#join(segments[0:-4] + ['MacOS', 'Vim'])
call xolox#misc#msg#debug("os.vim %s: The MacVim workaround resulted in the Vim executable %s.", g:xolox#misc#os#version, string(progname))
endif
endif
if empty(progname)
call xolox#misc#msg#debug("os.vim %s: Looking for Vim executable named %s on search path ..", g:xolox#misc#os#version, string(v:progname))
let candidates = xolox#misc#path#which(v:progname)
if !empty(candidates)
call xolox#misc#msg#debug("os.vim %s: Found %i candidate(s) on search path: %s.", g:xolox#misc#os#version, len(candidates), string(candidates))
let progname = candidates[0]
endif
endif
call xolox#misc#msg#debug("os.vim %s: Reporting Vim executable %s.", g:xolox#misc#os#version, string(progname))
return progname
endfunction

function! xolox#misc#os#exec(options) " {{{1
" Execute an external command (hiding the console on Microsoft Windows when
" my [vim-shell plug-in] [vim-shell] is installed).
Expand Down Expand Up @@ -63,9 +92,7 @@ function! xolox#misc#os#exec(options) " {{{1
if !async
let tempout = tempname()
let temperr = tempname()
let cmd = printf('(%s) 1>%s 2>%s', cmd,
\ xolox#misc#escape#shell(tempout),
\ xolox#misc#escape#shell(temperr))
let cmd = printf('(%s) 1>%s 2>%s', cmd, xolox#misc#escape#shell(tempout), xolox#misc#escape#shell(temperr))
endif

" If A) we're on Windows, B) the vim-shell plug-in is installed and C) the
Expand Down
15 changes: 10 additions & 5 deletions autoload/xolox/misc/timer.vim
@@ -1,7 +1,7 @@
" Timing of long during operations.
"
" Author: Peter Odding <peter@peterodding.com>
" Last Change: May 19, 2013
" Last Change: May 20, 2013
" URL: http://peterodding.com/code/vim/misc/

if !exists('g:timer_enabled')
Expand All @@ -17,10 +17,7 @@ let s:has_reltime = has('reltime')
function! xolox#misc#timer#start() " {{{1
" Start a timer. This returns a list which can later be passed to
" `xolox#misc#timer#stop()`.
if g:timer_enabled || &verbose >= g:timer_verbosity
return s:has_reltime ? reltime() : [localtime()]
endif
return []
return s:has_reltime ? reltime() : [localtime()]
endfunction

function! xolox#misc#timer#stop(...) " {{{1
Expand All @@ -40,6 +37,14 @@ function! xolox#misc#timer#stop(...) " {{{1
endif
endfunction

function! xolox#misc#timer#force(...) " {{{1
" Show a formatted message to the user. This function has the same argument
" handling as Vim's [printf()] [printf] function with one difference: At the
" point where you want the elapsed time to be embedded, you write `%s` and
" you pass the list returned by `xolox#misc#timer#start()` as an argument.
call call('xolox#misc#msg#info', map(copy(a:000), 's:convert_value(v:val)'))
endfunction

function! s:convert_value(value) " {{{1
if type(a:value) != type([])
return a:value
Expand Down
4 changes: 2 additions & 2 deletions autoload/xolox/reload.vim
Expand Up @@ -3,9 +3,9 @@
" Author: Peter Odding
" URL: http://peterodding.com/code/vim/reload/

let g:xolox#reload#version = '0.6.13'
let g:xolox#reload#version = '0.6.14'

call xolox#misc#compat#check('reload.vim', g:xolox#reload#version, 7)
call xolox#misc#compat#check('reload.vim', g:xolox#reload#version, 9)

" Patterns to match various types of Vim script names. {{{1

Expand Down

0 comments on commit 17047ef

Please sign in to comment.