From c4997a1f0060f06428b451637e934bfa36afd561 Mon Sep 17 00:00:00 2001 From: Peter Odding Date: Mon, 20 May 2013 06:00:17 +0200 Subject: Add xolox#misc#timer#force() function --- autoload/xolox/misc/compat.vim | 2 +- autoload/xolox/misc/msg.vim | 4 +--- autoload/xolox/misc/timer.vim | 15 ++++++++++----- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/autoload/xolox/misc/compat.vim b/autoload/xolox/misc/compat.vim index 3f3a42c..e6c9a0c 100644 --- a/autoload/xolox/misc/compat.vim +++ b/autoload/xolox/misc/compat.vim @@ -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 = 8 " Remember the directory where the miscellaneous scripts are loaded from " so the user knows which plug-in to update if incompatibilities arise. diff --git a/autoload/xolox/misc/msg.vim b/autoload/xolox/misc/msg.vim index 38eb474..0104b67 100644 --- a/autoload/xolox/misc/msg.vim +++ b/autoload/xolox/misc/msg.vim @@ -1,7 +1,7 @@ " Functions to interact with the user. " " Author: Peter Odding -" Last Change: May 19, 2013 +" Last Change: May 20, 2013 " URL: http://peterodding.com/code/vim/misc/ if !exists('g:xolox_message_buffer') @@ -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 diff --git a/autoload/xolox/misc/timer.vim b/autoload/xolox/misc/timer.vim index d7fc32d..31072f5 100644 --- a/autoload/xolox/misc/timer.vim +++ b/autoload/xolox/misc/timer.vim @@ -1,7 +1,7 @@ " Timing of long during operations. " " Author: Peter Odding -" Last Change: May 19, 2013 +" Last Change: May 20, 2013 " URL: http://peterodding.com/code/vim/misc/ if !exists('g:timer_enabled') @@ -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 @@ -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 -- cgit v1.2.3 From 5812878c6c35ea37d2eae70c7276e37326ff058f Mon Sep 17 00:00:00 2001 From: Peter Odding Date: Mon, 20 May 2013 06:04:12 +0200 Subject: Remove line continuation from xolox#misc#os script --- autoload/xolox/misc/os.vim | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/autoload/xolox/misc/os.vim b/autoload/xolox/misc/os.vim index 4dcf64d..157affe 100644 --- a/autoload/xolox/misc/os.vim +++ b/autoload/xolox/misc/os.vim @@ -63,9 +63,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 -- cgit v1.2.3 From d3f9a897819ded974886a40e51b64e30e5c75c57 Mon Sep 17 00:00:00 2001 From: Peter Odding Date: Mon, 20 May 2013 14:00:59 +0200 Subject: Add xolox#misc#os#find_vim() function --- autoload/xolox/misc/compat.vim | 2 +- autoload/xolox/misc/os.vim | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/autoload/xolox/misc/compat.vim b/autoload/xolox/misc/compat.vim index e6c9a0c..b1fd30b 100644 --- a/autoload/xolox/misc/compat.vim +++ b/autoload/xolox/misc/compat.vim @@ -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 = 8 +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. diff --git a/autoload/xolox/misc/os.vim b/autoload/xolox/misc/os.vim index 157affe..9554947 100644 --- a/autoload/xolox/misc/os.vim +++ b/autoload/xolox/misc/os.vim @@ -1,16 +1,45 @@ " Operating system interfaces. " " Author: Peter Odding -" 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). -- cgit v1.2.3 From 8b60a4117e4456cd193d067014a6dc8b7dc5047d Mon Sep 17 00:00:00 2001 From: Peter Odding Date: Mon, 20 May 2013 14:43:43 +0200 Subject: Update documentation in README --- README.md | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e1d97f8..7b99976 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,16 @@ merges, so that a repository checkout of a plug-in contains everything that's needed to get started. This means the git repository of the miscellaneous scripts is only used to track changes in a central, public place. -## Documentation for the included functions +## Function documentation -The documentation of the 41 functions below was extracted from 12 Vim scripts -on May 19, 2013 at 23:27. +Below is the documentation for the functions included in the miscellaneous +scripts. The function descriptions given below were extracted from the source +code using a bit of Python code. + + + +The documentation of the 43 functions below was extracted from +12 Vim scripts on May 20, 2013 at 14:42. ### Handling of special buffers @@ -75,10 +81,15 @@ worst possible moments :-). #### The `xolox#misc#compat#check()` function -Expects two arguments: The name of a Vim plug-in and the version of the -miscellaneous scripts expected by the plug-in. When the active version of -the miscellaneous scripts has a different version, this will raise an -error message that explains what went wrong. +Expects three arguments: + +1. The name of the Vim plug-in that is using the miscellaneous scripts +2. The version of the Vim plug-in that is using the miscellaneous scripts +3. The version of the miscellaneous scripts expected by the plug-in + +When the loaded version of the miscellaneous scripts is different from the +version expected by the plug-in, this function will raise an error message +that explains what went wrong. ### Tab completion for user defined commands @@ -160,8 +171,6 @@ 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' - ### Integration between Vim and its environment #### The `xolox#misc#open#file()` function @@ -249,6 +258,15 @@ otherwise (so by default) a list with all matches is returned. Returns 1 (true) when on Microsoft Windows, 0 (false) otherwise. +#### The `xolox#misc#os#find_vim()` function + +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 + #### The `xolox#misc#os#exec()` function Execute an external command (hiding the console on Microsoft Windows when @@ -395,12 +413,21 @@ to be embedded, you write `%s` and you pass the list returned by [verbose]: http://vimdoc.sourceforge.net/htmldoc/options.html#'verbose' [printf]: http://vimdoc.sourceforge.net/htmldoc/eval.html#printf() +#### The `xolox#misc#timer#force()` function + +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. + #### The `xolox#misc#timer#format_timespan()` function Format a time stamp (a string containing a formatted floating point number) into a human friendly format, for example 70 seconds is phrased as "1 minute and 10 seconds". + + ## Management of changes to the miscellaneous scripts ### How does it work? -- cgit v1.2.3