Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support for generic file type plug-ins

Thanks to Britton Kerin for the suggestion!
  • Loading branch information...
commit b6b3952940e00c2f010e66376c8520fecf9164a1 1 parent be83d35
@xolox authored
Showing with 37 additions and 26 deletions.
  1. +9 −7 README.md
  2. +26 −17 autoload.vim
  3. +2 −2 reload.vim
View
16 README.md
@@ -1,18 +1,20 @@
# Automatic reloading of Vim scripts
-The [reload.vim][reload] plug-in automatically reloads various types of [Vim][vim] scripts as they're being edited in Vim to give you instant feedback on the changes you make. For example while writing a Vim syntax script you can open a split window of the relevant file type and every time you [:update][update] your syntax script, [reload.vim][reload] will refresh the syntax highlighting in the split window. Automatic reloading of Vim scripts is currently supported for the following types of scripts:
+The [reload.vim][reload] plug-in automatically reloads various types of [Vim][vim] scripts as you're editing them in Vim to give you instant feedback on the changes you make. For example while writing a Vim syntax script you can open a split window of the relevant file type and every time you [:update][update] your syntax script, [reload.vim][reload] will refresh the syntax highlighting in the split window. Automatic reloading of Vim scripts is currently supported for the following types of scripts:
- * [Standard plug-ins](http://vimdoc.sourceforge.net/htmldoc/usr_05.html#standard-plugin) located at `~/.vim/plugin/*.vim` on UNIX, `~\_vimfiles\plugin\*.vim` on Windows;
+ * [Standard plug-ins](http://vimdoc.sourceforge.net/htmldoc/usr_05.html#standard-plugin) located in `~/.vim/plugin` on UNIX, `~\vimfiles\plugin` on Windows;
- * [Auto-load scripts](http://vimdoc.sourceforge.net/htmldoc/eval.html#autoload) located at `~/.vim/autoload/*.vim` on UNIX, `~\_vimfiles\autoload\*.vim` on Windows;
+ * [Auto-load scripts](http://vimdoc.sourceforge.net/htmldoc/eval.html#autoload) located in or below `~/.vim/autoload` on UNIX, `~\vimfiles\autoload` on Windows;
- * [File-type plug-ins](http://vimdoc.sourceforge.net/htmldoc/filetype.html#filetype-plugins) located at `~/.vim/ftplugin/*.vim` on UNIX, `~\_vimfiles\ftplugin\*.vim` on Windows;
+ * [File-type plug-ins](http://vimdoc.sourceforge.net/htmldoc/filetype.html#filetype-plugins) located in or below `~/.vim/ftplugin` on UNIX, `~\vimfiles\ftplugin` on Windows;
- * [Syntax highlighting scripts](http://vimdoc.sourceforge.net/htmldoc/syntax.html#syntax-highlighting) located at `~/.vim/syntax/*.vim` on UNIX, `~\_vimfiles\syntax\*.vim` on Windows;
+ * [Syntax highlighting scripts](http://vimdoc.sourceforge.net/htmldoc/syntax.html#syntax-highlighting) located in `~/.vim/syntax` on UNIX, `~\vimfiles\syntax` on Windows;
- * [File-type indentation plug-ins](http://vimdoc.sourceforge.net/htmldoc/usr_30.html#30.3) located at `~/.vim/indent/*.vim` on UNIX, `~\_vimfiles\indent\*.vim` on Windows;
+ * [File-type indentation plug-ins](http://vimdoc.sourceforge.net/htmldoc/usr_30.html#30.3) located in `~/.vim/indent` on UNIX, `~\vimfiles\indent` on Windows;
- * [Color scheme scripts](http://vimdoc.sourceforge.net/htmldoc/syntax.html#:colorscheme) located at `~/.vim/colors/*.vim` on UNIX, `~\_vimfiles\colors\*.vim` on Windows.
+ * [Color scheme scripts](http://vimdoc.sourceforge.net/htmldoc/syntax.html#:colorscheme) located in `~/.vim/colors` on UNIX, `~\vimfiles\colors` on Windows.
+
+The directories listed above are Vim's defaults but you're free to change the ['runtimepath'](http://vimdoc.sourceforge.net/htmldoc/options.html#%27runtimepath%27) and reloading will still work.
Note that [vimrc scripts][vimrc] are not reloaded because that seems to cause more trouble than it's worth...
View
43 autoload.vim
@@ -1,5 +1,5 @@
" Vim script
-" Last Change: October 14, 2010
+" Last Change: February 4, 2011
" Author: Peter Odding
" URL: http://peterodding.com/code/vim/reload/
@@ -15,7 +15,7 @@ if has('win32') || has('win64')
let s:scripttypes = [
\ ['s:reload_plugin', '\c[\\/]plugin[\\/].\{-}\.vim$'],
\ ['s:reload_autoload', '\c[\\/]autoload[\\/].\{-}\.vim$'],
- \ ['s:reload_ftplugin', '\c[\\/]ftplugin[\\/][^\\/]\+\.vim$'],
+ \ ['s:reload_ftplugin', '\c[\\/]ftplugin[\\/]\([^\\/_]\+\)\%([\\/_]\([^\\/]\+\)\)\?\.vim$'],
\ ['s:reload_syntax', '\c[\\/]syntax[\\/][^\\/]\+\.vim$'],
\ ['s:reload_indent', '\c[\\/]indent[\\/][^\\/]\+\.vim$'],
\ ['s:reload_colors', '\c[\\/]colors[\\/][^\\/]\+\.vim$']]
@@ -23,7 +23,7 @@ else
let s:scripttypes = [
\ ['s:reload_plugin', '\C/plugin/.\{-}\.vim$'],
\ ['s:reload_autoload', '\C/autoload/.\{-}\.vim$'],
- \ ['s:reload_ftplugin', '\C/ftplugin/[^/]\+\.vim$'],
+ \ ['s:reload_ftplugin', '\C/ftplugin/\([^/_]\+\)\%([/_]\([^/]\+\)\)\?\.vim$'],
\ ['s:reload_syntax', '\C/syntax/[^/]\+\.vim$'],
\ ['s:reload_indent', '\C/indent/[^/]\+\.vim$'],
\ ['s:reload_colors', '\C/colors/[^/]\+\.vim$']]
@@ -41,12 +41,23 @@ if !exists('s:reload_script_active')
let filename = s:unresolve_scriptname(a:filename)
for [callback, pattern] in s:scripttypes
if filename =~ pattern
- let args = [start_time, filename, fnamemodify(filename, ':~')]
+ let friendly_name = fnamemodify(filename, ':~')
+ if pattern =~ 'ftplugin'
+ " Determine include guard for generic file type plug-ins.
+ let matches = matchlist(filename, pattern)
+ if len(matches) >= 3
+ let s:include_guard = 'b:loaded_' . matches[1] . '_' . matches[2]
+ " s:reload_ftplugin() knows the 2nd argument is really a file type.
+ let filename = matches[1]
+ endif
+ endif
+ let args = [start_time, filename, friendly_name]
let result = call(callback, args)
if type(result) == type([])
call call('xolox#timer#stop', result)
endif
- unlet result
+ unlet! result s:include_guard
+ break
endif
endfor
endif
@@ -56,11 +67,7 @@ endif
function! s:reload_plugin(start_time, filename, friendly_name) " {{{1
call s:reload_message('plug-in', a:friendly_name)
- " Clear include guard so full plug-in can be reloaded?
- let variable = 'g:loaded_' . fnamemodify(a:filename, ':t:r')
- if exists(variable)
- execute 'unlet' variable
- endif
+ unlet! g:loaded_{fnamemodify(a:filename, ':t:r')}
execute 'source' fnameescape(a:filename)
return ["%s: Reloaded %s plug-in in %s.", s:script, a:friendly_name, a:start_time]
endfunction
@@ -73,20 +80,19 @@ if !exists('s:reload_script_active')
endfunction
endif
-function! s:reload_ftplugin(st, fn, hr) " {{{1
- return s:reload_buffers(a:st, a:fn, a:hr, 'file type plug-in', 'b:reload_ftplugin')
+function! s:reload_ftplugin(st, ft, hr) " {{{1
+ return s:reload_buffers(a:st, a:ft, a:hr, 'file type plug-in', 'b:reload_ftplugin')
endfunction
function! s:reload_syntax(st, fn, hr) " {{{1
- return s:reload_buffers(a:st, a:fn, a:hr, 'syntax script', 'b:reload_syntax')
+ return s:reload_buffers(a:st, fnamemodify(a:fn, ':t:r'), a:hr, 'syntax script', 'b:reload_syntax')
endfunction
function! s:reload_indent(st, fn, hr) " {{{1
- return s:reload_buffers(a:st, a:fn, a:hr, 'indent script', 'b:reload_indent')
+ return s:reload_buffers(a:st, fnamemodify(a:fn, ':t:r'), a:hr, 'indent script', 'b:reload_indent')
endfunction
-function! s:reload_buffers(start_time, filename, friendly_name, script_type, variable)
- let type = fnamemodify(a:filename, ':t:r')
+function! s:reload_buffers(start_time, filetype, friendly_name, script_type, variable)
" Make sure we can restore the user's context after reloading!
let bufnr_save = bufnr('%')
let view_save = winsaveview()
@@ -94,7 +100,7 @@ function! s:reload_buffers(start_time, filename, friendly_name, script_type, var
" prompt from rearing its ugly head while reloading (in :bufdo below).
let s:reloading_buffers = 1
call s:reload_message(a:script_type, a:friendly_name)
- silent hide bufdo if &ft == type | execute 'let' a:variable '= 1' | endif
+ silent hide bufdo if &ft == a:filetype | execute 'let' a:variable '= 1' | endif
call xolox#reload#windows()
" Restore the user's context.
silent execute 'buffer' bufnr_save
@@ -122,6 +128,9 @@ endfunction
function! s:reload_window()
if exists('b:reload_ftplugin')
unlet! b:reload_ftplugin b:did_ftplugin
+ if exists('s:include_guard') && exists(s:include_guard)
+ unlet {s:include_guard}
+ endif
let &filetype = &filetype
endif
if exists('b:reload_syntax')
View
4 reload.vim
@@ -1,9 +1,9 @@
" Vim script
-" Last Change: October 14, 2010
+" Last Change: February 4, 2011
" Author: Peter Odding
" URL: http://peterodding.com/code/vim/reload/
" License: MIT
-" Version: 0.5.2
+" Version: 0.6
" Support for automatic update using the GLVS plug-in.
" GetLatestVimScripts: 3148 1 :AutoInstall: reload.zip
Please sign in to comment.
Something went wrong with that request. Please try again.