Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Support for generic file type plug-ins

Thanks to Britton Kerin for the suggestion!
  • Loading branch information...
commit b6b3952940e00c2f010e66376c8520fecf9164a1 1 parent be83d35
Peter Odding authored February 05, 2011
16  README.md
Source Rendered
... ...
@@ -1,18 +1,20 @@
1 1
 # Automatic reloading of Vim scripts
2 2
 
3  
-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:
  3
+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:
4 4
 
5  
- * [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;
  5
+ * [Standard plug-ins](http://vimdoc.sourceforge.net/htmldoc/usr_05.html#standard-plugin) located in `~/.vim/plugin` on UNIX, `~\vimfiles\plugin` on Windows;
6 6
 
7  
- * [Auto-load scripts](http://vimdoc.sourceforge.net/htmldoc/eval.html#autoload) located at `~/.vim/autoload/*.vim` on UNIX, `~\_vimfiles\autoload\*.vim` on Windows;
  7
+ * [Auto-load scripts](http://vimdoc.sourceforge.net/htmldoc/eval.html#autoload) located in or below `~/.vim/autoload` on UNIX, `~\vimfiles\autoload` on Windows;
8 8
 
9  
- * [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;
  9
+ * [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;
10 10
 
11  
- * [Syntax highlighting scripts](http://vimdoc.sourceforge.net/htmldoc/syntax.html#syntax-highlighting) located at `~/.vim/syntax/*.vim` on UNIX, `~\_vimfiles\syntax\*.vim` on Windows;
  11
+ * [Syntax highlighting scripts](http://vimdoc.sourceforge.net/htmldoc/syntax.html#syntax-highlighting) located in `~/.vim/syntax` on UNIX, `~\vimfiles\syntax` on Windows;
12 12
 
13  
- * [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;
  13
+ * [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;
14 14
 
15  
- * [Color scheme scripts](http://vimdoc.sourceforge.net/htmldoc/syntax.html#:colorscheme) located at `~/.vim/colors/*.vim` on UNIX, `~\_vimfiles\colors\*.vim` on Windows.
  15
+ * [Color scheme scripts](http://vimdoc.sourceforge.net/htmldoc/syntax.html#:colorscheme) located in `~/.vim/colors` on UNIX, `~\vimfiles\colors` on Windows.
  16
+
  17
+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.
16 18
 
17 19
 Note that [vimrc scripts][vimrc] are not reloaded because that seems to cause more trouble than it's worth...
18 20
 
43  autoload.vim
... ...
@@ -1,5 +1,5 @@
1 1
 " Vim script
2  
-" Last Change: October 14, 2010
  2
+" Last Change: February 4, 2011
3 3
 " Author: Peter Odding
4 4
 " URL: http://peterodding.com/code/vim/reload/
5 5
 
@@ -15,7 +15,7 @@ if has('win32') || has('win64')
15 15
   let s:scripttypes = [
16 16
         \ ['s:reload_plugin', '\c[\\/]plugin[\\/].\{-}\.vim$'],
17 17
         \ ['s:reload_autoload', '\c[\\/]autoload[\\/].\{-}\.vim$'],
18  
-        \ ['s:reload_ftplugin', '\c[\\/]ftplugin[\\/][^\\/]\+\.vim$'],
  18
+        \ ['s:reload_ftplugin', '\c[\\/]ftplugin[\\/]\([^\\/_]\+\)\%([\\/_]\([^\\/]\+\)\)\?\.vim$'],
19 19
         \ ['s:reload_syntax', '\c[\\/]syntax[\\/][^\\/]\+\.vim$'],
20 20
         \ ['s:reload_indent', '\c[\\/]indent[\\/][^\\/]\+\.vim$'],
21 21
         \ ['s:reload_colors', '\c[\\/]colors[\\/][^\\/]\+\.vim$']]
@@ -23,7 +23,7 @@ else
23 23
   let s:scripttypes = [
24 24
         \ ['s:reload_plugin', '\C/plugin/.\{-}\.vim$'],
25 25
         \ ['s:reload_autoload', '\C/autoload/.\{-}\.vim$'],
26  
-        \ ['s:reload_ftplugin', '\C/ftplugin/[^/]\+\.vim$'],
  26
+        \ ['s:reload_ftplugin', '\C/ftplugin/\([^/_]\+\)\%([/_]\([^/]\+\)\)\?\.vim$'],
27 27
         \ ['s:reload_syntax', '\C/syntax/[^/]\+\.vim$'],
28 28
         \ ['s:reload_indent', '\C/indent/[^/]\+\.vim$'],
29 29
         \ ['s:reload_colors', '\C/colors/[^/]\+\.vim$']]
@@ -41,12 +41,23 @@ if !exists('s:reload_script_active')
41 41
       let filename = s:unresolve_scriptname(a:filename)
42 42
       for [callback, pattern] in s:scripttypes
43 43
         if filename =~ pattern
44  
-          let args = [start_time, filename, fnamemodify(filename, ':~')]
  44
+          let friendly_name = fnamemodify(filename, ':~')
  45
+          if pattern =~ 'ftplugin'
  46
+            " Determine include guard for generic file type plug-ins.
  47
+            let matches = matchlist(filename, pattern)
  48
+            if len(matches) >= 3
  49
+              let s:include_guard = 'b:loaded_' . matches[1] . '_' . matches[2]
  50
+              " s:reload_ftplugin() knows the 2nd argument is really a file type.
  51
+              let filename = matches[1]
  52
+            endif
  53
+          endif
  54
+          let args = [start_time, filename, friendly_name]
45 55
           let result = call(callback, args)
46 56
           if type(result) == type([])
47 57
             call call('xolox#timer#stop', result)
48 58
           endif
49  
-          unlet result
  59
+          unlet! result s:include_guard
  60
+          break
50 61
         endif
51 62
       endfor
52 63
     endif
@@ -56,11 +67,7 @@ endif
56 67
 
57 68
 function! s:reload_plugin(start_time, filename, friendly_name) " {{{1
58 69
   call s:reload_message('plug-in', a:friendly_name)
59  
-  " Clear include guard so full plug-in can be reloaded?
60  
-  let variable = 'g:loaded_' . fnamemodify(a:filename, ':t:r')
61  
-  if exists(variable)
62  
-    execute 'unlet' variable
63  
-  endif
  70
+  unlet! g:loaded_{fnamemodify(a:filename, ':t:r')}
64 71
   execute 'source' fnameescape(a:filename)
65 72
   return ["%s: Reloaded %s plug-in in %s.", s:script, a:friendly_name, a:start_time]
66 73
 endfunction
@@ -73,20 +80,19 @@ if !exists('s:reload_script_active')
73 80
   endfunction
74 81
 endif
75 82
 
76  
-function! s:reload_ftplugin(st, fn, hr) " {{{1
77  
-  return s:reload_buffers(a:st, a:fn, a:hr, 'file type plug-in', 'b:reload_ftplugin')
  83
+function! s:reload_ftplugin(st, ft, hr) " {{{1
  84
+  return s:reload_buffers(a:st, a:ft, a:hr, 'file type plug-in', 'b:reload_ftplugin')
78 85
 endfunction
79 86
 
80 87
 function! s:reload_syntax(st, fn, hr) " {{{1
81  
-  return s:reload_buffers(a:st, a:fn, a:hr, 'syntax script', 'b:reload_syntax')
  88
+  return s:reload_buffers(a:st, fnamemodify(a:fn, ':t:r'), a:hr, 'syntax script', 'b:reload_syntax')
82 89
 endfunction
83 90
 
84 91
 function! s:reload_indent(st, fn, hr) " {{{1
85  
-  return s:reload_buffers(a:st, a:fn, a:hr, 'indent script', 'b:reload_indent')
  92
+  return s:reload_buffers(a:st, fnamemodify(a:fn, ':t:r'), a:hr, 'indent script', 'b:reload_indent')
86 93
 endfunction
87 94
 
88  
-function! s:reload_buffers(start_time, filename, friendly_name, script_type, variable)
89  
-  let type = fnamemodify(a:filename, ':t:r')
  95
+function! s:reload_buffers(start_time, filetype, friendly_name, script_type, variable)
90 96
   " Make sure we can restore the user's context after reloading!
91 97
   let bufnr_save = bufnr('%')
92 98
   let view_save = winsaveview()
@@ -94,7 +100,7 @@ function! s:reload_buffers(start_time, filename, friendly_name, script_type, var
94 100
   " prompt from rearing its ugly head while reloading (in :bufdo below).
95 101
   let s:reloading_buffers = 1
96 102
   call s:reload_message(a:script_type, a:friendly_name)
97  
-  silent hide bufdo if &ft == type | execute 'let' a:variable '= 1' | endif
  103
+  silent hide bufdo if &ft == a:filetype | execute 'let' a:variable '= 1' | endif
98 104
   call xolox#reload#windows()
99 105
   " Restore the user's context.
100 106
   silent execute 'buffer' bufnr_save
@@ -122,6 +128,9 @@ endfunction
122 128
 function! s:reload_window()
123 129
   if exists('b:reload_ftplugin')
124 130
     unlet! b:reload_ftplugin b:did_ftplugin
  131
+    if exists('s:include_guard') && exists(s:include_guard)
  132
+      unlet {s:include_guard}
  133
+    endif
125 134
     let &filetype = &filetype
126 135
   endif
127 136
   if exists('b:reload_syntax')
4  reload.vim
... ...
@@ -1,9 +1,9 @@
1 1
 " Vim script
2  
-" Last Change: October 14, 2010
  2
+" Last Change: February 4, 2011
3 3
 " Author: Peter Odding
4 4
 " URL: http://peterodding.com/code/vim/reload/
5 5
 " License: MIT
6  
-" Version: 0.5.2
  6
+" Version: 0.6
7 7
 
8 8
 " Support for automatic update using the GLVS plug-in.
9 9
 " GetLatestVimScripts: 3148 1 :AutoInstall: reload.zip

0 notes on commit b6b3952

Please sign in to comment.
Something went wrong with that request. Please try again.