tomkersten-vixploder 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +105 -0
- data/PostInstall.txt +21 -0
- data/README.rdoc +131 -0
- data/Rakefile +21 -0
- data/bin/256colors2.pl +63 -0
- data/bin/colortest +365 -0
- data/bin/vixplode +10 -0
- data/lib/dotfiles/aliases +30 -0
- data/lib/dotfiles/gvimrc +20 -0
- data/lib/dotfiles/vim/.VimballRecord +2 -0
- data/lib/dotfiles/vim/after/ftplugin/actionscript_snippets.vim +9 -0
- data/lib/dotfiles/vim/after/ftplugin/aspvbs_snippets.vim +17 -0
- data/lib/dotfiles/vim/after/ftplugin/c_snippets.vim +58 -0
- data/lib/dotfiles/vim/after/ftplugin/css_snippets.vim +30 -0
- data/lib/dotfiles/vim/after/ftplugin/django_model_snippets.vim +61 -0
- data/lib/dotfiles/vim/after/ftplugin/django_template_snippets.vim +32 -0
- data/lib/dotfiles/vim/after/ftplugin/f-script_snippets.vim +14 -0
- data/lib/dotfiles/vim/after/ftplugin/haskell_snippets.vim +9 -0
- data/lib/dotfiles/vim/after/ftplugin/html_snippets.vim +57 -0
- data/lib/dotfiles/vim/after/ftplugin/java_snippets.vim +52 -0
- data/lib/dotfiles/vim/after/ftplugin/javascript_snippets.vim +10 -0
- data/lib/dotfiles/vim/after/ftplugin/latex_snippets.vim +13 -0
- data/lib/dotfiles/vim/after/ftplugin/logo_snippets.vim +9 -0
- data/lib/dotfiles/vim/after/ftplugin/markdown_snippets.vim +10 -0
- data/lib/dotfiles/vim/after/ftplugin/movable_type_snippets.vim +14 -0
- data/lib/dotfiles/vim/after/ftplugin/objc_snippets.vim +53 -0
- data/lib/dotfiles/vim/after/ftplugin/ocaml_snippets.vim +26 -0
- data/lib/dotfiles/vim/after/ftplugin/perl_snippets.vim +23 -0
- data/lib/dotfiles/vim/after/ftplugin/php_snippets.vim +30 -0
- data/lib/dotfiles/vim/after/ftplugin/phpdoc_snippets.vim +19 -0
- data/lib/dotfiles/vim/after/ftplugin/propel_snippets.vim +14 -0
- data/lib/dotfiles/vim/after/ftplugin/python_snippets.vim +202 -0
- data/lib/dotfiles/vim/after/ftplugin/rails_snippets.vim +54 -0
- data/lib/dotfiles/vim/after/ftplugin/ruby_snippets.vim +32 -0
- data/lib/dotfiles/vim/after/ftplugin/sh_snippets.vim +12 -0
- data/lib/dotfiles/vim/after/ftplugin/slate_snippets.vim +19 -0
- data/lib/dotfiles/vim/after/ftplugin/smarty_snippets.vim +35 -0
- data/lib/dotfiles/vim/after/ftplugin/symfony_snippets.vim +21 -0
- data/lib/dotfiles/vim/after/ftplugin/tcl_snippets.vim +14 -0
- data/lib/dotfiles/vim/after/ftplugin/template_toolkit_snippets.vim +13 -0
- data/lib/dotfiles/vim/after/ftplugin/tex_snippets.vim +13 -0
- data/lib/dotfiles/vim/after/ftplugin/xhtml_snippets.vim +48 -0
- data/lib/dotfiles/vim/autoload/fakeclip.vim +253 -0
- data/lib/dotfiles/vim/autoload/rails.vim +4377 -0
- data/lib/dotfiles/vim/autoload/rubycomplete.vim +802 -0
- data/lib/dotfiles/vim/colors/inkpot.vim +212 -0
- data/lib/dotfiles/vim/colors/ir_black.vim +212 -0
- data/lib/dotfiles/vim/colors/ir_black_mod.vim +213 -0
- data/lib/dotfiles/vim/colors/railscasts.vim +100 -0
- data/lib/dotfiles/vim/colors/rubyblue.vim +74 -0
- data/lib/dotfiles/vim/colors/twilight.vim +75 -0
- data/lib/dotfiles/vim/colors/twilight2.vim +74 -0
- data/lib/dotfiles/vim/colors/wombat256.vim +302 -0
- data/lib/dotfiles/vim/compiler/eruby.vim +41 -0
- data/lib/dotfiles/vim/compiler/ruby.vim +68 -0
- data/lib/dotfiles/vim/compiler/rubyunit.vim +35 -0
- data/lib/dotfiles/vim/doc/NERD_tree.txt +1235 -0
- data/lib/dotfiles/vim/doc/fakeclip.txt +190 -0
- data/lib/dotfiles/vim/doc/matchit.txt +406 -0
- data/lib/dotfiles/vim/doc/project.txt +710 -0
- data/lib/dotfiles/vim/doc/rails.txt +1123 -0
- data/lib/dotfiles/vim/doc/snippets_emu.txt +354 -0
- data/lib/dotfiles/vim/doc/surround.txt +218 -0
- data/lib/dotfiles/vim/doc/tags +433 -0
- data/lib/dotfiles/vim/filetype.vim +13 -0
- data/lib/dotfiles/vim/ftdetect/gist.vim +3 -0
- data/lib/dotfiles/vim/ftdetect/ruby.vim +14 -0
- data/lib/dotfiles/vim/ftplugin/eruby.vim +101 -0
- data/lib/dotfiles/vim/ftplugin/ruby.vim +230 -0
- data/lib/dotfiles/vim/indent/eruby.vim +73 -0
- data/lib/dotfiles/vim/indent/ruby.vim +373 -0
- data/lib/dotfiles/vim/plugin/NERD_tree.vim +3536 -0
- data/lib/dotfiles/vim/plugin/comments.vim +321 -0
- data/lib/dotfiles/vim/plugin/fakeclip.vim +174 -0
- data/lib/dotfiles/vim/plugin/fuzzyfinder.vim +1676 -0
- data/lib/dotfiles/vim/plugin/fuzzyfinder_textmate.vim +150 -0
- data/lib/dotfiles/vim/plugin/gist.vim +241 -0
- data/lib/dotfiles/vim/plugin/gitdiff.vim +141 -0
- data/lib/dotfiles/vim/plugin/matchit.vim +812 -0
- data/lib/dotfiles/vim/plugin/mru.vim +787 -0
- data/lib/dotfiles/vim/plugin/rails.vim +310 -0
- data/lib/dotfiles/vim/plugin/rspec.vim +12 -0
- data/lib/dotfiles/vim/plugin/snippets.vim +17 -0
- data/lib/dotfiles/vim/plugin/snippetsEmu.vim +973 -0
- data/lib/dotfiles/vim/plugin/supertab.vim +531 -0
- data/lib/dotfiles/vim/plugin/surround.vim +632 -0
- data/lib/dotfiles/vim/ref_vimrc +80 -0
- data/lib/dotfiles/vim/ruby/fuzzy_file_finder.rb +353 -0
- data/lib/dotfiles/vim/syntax/eruby.vim +85 -0
- data/lib/dotfiles/vim/syntax/haml.vim +113 -0
- data/lib/dotfiles/vim/syntax/mkd.vim +86 -0
- data/lib/dotfiles/vim/syntax/ruby.vim +324 -0
- data/lib/dotfiles/vim/syntax/sass.vim +93 -0
- data/lib/dotfiles/vimrc +269 -0
- data/lib/vixplode/cli.rb +73 -0
- data/lib/vixploder.rb +6 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/vixplode_cli_spec.rb +15 -0
- data/spec/vixploder_spec.rb +7 -0
- data/tasks/rspec.rake +21 -0
- metadata +202 -8
@@ -0,0 +1,310 @@
|
|
1
|
+
" rails.vim - Detect a rails application
|
2
|
+
" Author: Tim Pope <vimNOSPAM@tpope.info>
|
3
|
+
" GetLatestVimScripts: 1567 1 :AutoInstall: rails.vim
|
4
|
+
" URL: http://rails.vim.tpope.net/
|
5
|
+
|
6
|
+
" Install this file as plugin/rails.vim. See doc/rails.txt for details. (Grab
|
7
|
+
" it from the URL above if you don't have it.) To access it from Vim, see
|
8
|
+
" :help add-local-help (hint: :helptags ~/.vim/doc) Afterwards, you should be
|
9
|
+
" able to do :help rails
|
10
|
+
|
11
|
+
" ============================================================================
|
12
|
+
|
13
|
+
" Exit quickly when:
|
14
|
+
" - this plugin was already loaded (or disabled)
|
15
|
+
" - when 'compatible' is set
|
16
|
+
if &cp || (exists("g:loaded_rails") && g:loaded_rails) && !(exists("g:rails_debug") && g:rails_debug)
|
17
|
+
finish
|
18
|
+
endif
|
19
|
+
let g:loaded_rails = 1
|
20
|
+
|
21
|
+
" Apparently, the nesting level within Vim when the Ruby interface is
|
22
|
+
" initialized determines how much stack space Ruby gets. In previous
|
23
|
+
" versions of rails.vim, sporadic stack overflows occured when omnicomplete
|
24
|
+
" was used. This was apparently due to rails.vim having first initialized
|
25
|
+
" ruby deep in a nested function call.
|
26
|
+
if has("ruby")
|
27
|
+
silent! ruby nil
|
28
|
+
endif
|
29
|
+
|
30
|
+
" Utility Functions {{{1
|
31
|
+
|
32
|
+
function! s:error(str)
|
33
|
+
echohl ErrorMsg
|
34
|
+
echomsg a:str
|
35
|
+
echohl None
|
36
|
+
let v:errmsg = a:str
|
37
|
+
endfunction
|
38
|
+
|
39
|
+
function! s:autoload(...)
|
40
|
+
if !exists("g:autoloaded_rails")
|
41
|
+
runtime! autoload/rails.vim
|
42
|
+
endif
|
43
|
+
if exists("g:autoloaded_rails")
|
44
|
+
if a:0
|
45
|
+
exe a:1
|
46
|
+
endif
|
47
|
+
return 1
|
48
|
+
endif
|
49
|
+
if !exists("g:rails_no_autoload_warning")
|
50
|
+
let g:rails_no_autoload_warning = 1
|
51
|
+
call s:error("Disabling rails.vim: autoload/rails.vim is missing")
|
52
|
+
endif
|
53
|
+
return ""
|
54
|
+
endfunction
|
55
|
+
|
56
|
+
" }}}1
|
57
|
+
" Configuration {{{
|
58
|
+
|
59
|
+
function! s:SetOptDefault(opt,val)
|
60
|
+
if !exists("g:".a:opt)
|
61
|
+
let g:{a:opt} = a:val
|
62
|
+
endif
|
63
|
+
endfunction
|
64
|
+
|
65
|
+
call s:SetOptDefault("rails_level",3)
|
66
|
+
call s:SetOptDefault("rails_statusline",1)
|
67
|
+
call s:SetOptDefault("rails_syntax",1)
|
68
|
+
call s:SetOptDefault("rails_mappings",1)
|
69
|
+
call s:SetOptDefault("rails_abbreviations",1)
|
70
|
+
call s:SetOptDefault("rails_expensive",1+0*(has("win32")||has("win32unix")))
|
71
|
+
call s:SetOptDefault("rails_dbext",g:rails_expensive)
|
72
|
+
call s:SetOptDefault("rails_subversion",0)
|
73
|
+
call s:SetOptDefault("rails_default_file","README")
|
74
|
+
call s:SetOptDefault("rails_default_database","")
|
75
|
+
call s:SetOptDefault("rails_root_url",'http://localhost:3000/')
|
76
|
+
call s:SetOptDefault("rails_modelines",0)
|
77
|
+
call s:SetOptDefault("rails_menu",1)
|
78
|
+
call s:SetOptDefault("rails_gnu_screen",1)
|
79
|
+
call s:SetOptDefault("rails_history_size",5)
|
80
|
+
call s:SetOptDefault("rails_debug",0)
|
81
|
+
call s:SetOptDefault("rails_generators","controller\nintegration_test\nmailer\nmigration\nmodel\nobserver\nplugin\nresource\nscaffold\nsession_migration")
|
82
|
+
call s:SetOptDefault("rails_rake_tasks","db:charset\ndb:collation\ndb:create\ndb:create:all\ndb:drop\ndb:drop:all\ndb:fixtures:identify\ndb:fixtures:load\ndb:migrate\ndb:reset\ndb:rollback\ndb:schema:dump\ndb:schema:load\ndb:sessions:clear\ndb:sessions:create\ndb:structure:dump\ndb:test:clone\ndb:test:clone_structure\ndb:test:prepare\ndb:test:purge\ndb:version\ndoc:app\ndoc:clobber_app\ndoc:clobber_plugins\ndoc:clobber_rails\ndoc:plugins\ndoc:rails\ndoc:reapp\ndoc:rerails\nlog:clear\nnotes\nnotes:fixme\nnotes:optimize\nnotes:todo\nrails:freeze:edge\nrails:freeze:gems\nrails:unfreeze\nrails:update\nrails:update:configs\nrails:update:javascripts\nrails:update:scripts\nroutes\nstats\ntest\ntest:functionals\ntest:integration\ntest:plugins\ntest:recent\ntest:uncommitted\ntest:units\ntmp:cache:clear\ntmp:clear\ntmp:create\ntmp:pids:clear\ntmp:sessions:clear\ntmp:sockets:clear")
|
83
|
+
if g:rails_dbext
|
84
|
+
if exists("g:loaded_dbext") && executable("sqlite3") && ! executable("sqlite")
|
85
|
+
" Since dbext can't find it by itself
|
86
|
+
call s:SetOptDefault("dbext_default_SQLITE_bin","sqlite3")
|
87
|
+
endif
|
88
|
+
endif
|
89
|
+
|
90
|
+
" }}}1
|
91
|
+
" Detection {{{1
|
92
|
+
|
93
|
+
function! s:escvar(r)
|
94
|
+
let r = fnamemodify(a:r,':~')
|
95
|
+
let r = substitute(r,'\W','\="_".char2nr(submatch(0))."_"','g')
|
96
|
+
let r = substitute(r,'^\d','_&','')
|
97
|
+
return r
|
98
|
+
endfunction
|
99
|
+
|
100
|
+
function! s:Detect(filename)
|
101
|
+
let fn = substitute(fnamemodify(a:filename,":p"),'\c^file://','','')
|
102
|
+
if fn =~ '[\/]config[\/]environment\.rb$'
|
103
|
+
return s:BufInit(strpart(fn,0,strlen(fn)-22))
|
104
|
+
endif
|
105
|
+
if isdirectory(fn)
|
106
|
+
let fn = fnamemodify(fn,":s?[\/]$??")
|
107
|
+
else
|
108
|
+
let fn = fnamemodify(fn,':s?\(.*\)[\/][^\/]*$?\1?')
|
109
|
+
endif
|
110
|
+
let ofn = ""
|
111
|
+
let nfn = fn
|
112
|
+
while nfn != ofn && nfn != ""
|
113
|
+
if exists("s:_".s:escvar(nfn))
|
114
|
+
return s:BufInit(nfn)
|
115
|
+
endif
|
116
|
+
let ofn = nfn
|
117
|
+
let nfn = fnamemodify(nfn,':h')
|
118
|
+
endwhile
|
119
|
+
let ofn = ""
|
120
|
+
while fn != ofn
|
121
|
+
if filereadable(fn . "/config/environment.rb")
|
122
|
+
return s:BufInit(fn)
|
123
|
+
endif
|
124
|
+
let ofn = fn
|
125
|
+
let fn = fnamemodify(ofn,':s?\(.*\)[\/]\(app\|config\|db\|doc\|lib\|log\|public\|script\|spec\|test\|tmp\|vendor\)\($\|[\/].*$\)?\1?')
|
126
|
+
endwhile
|
127
|
+
return 0
|
128
|
+
endfunction
|
129
|
+
|
130
|
+
function! s:BufInit(path)
|
131
|
+
let s:_{s:escvar(a:path)} = 1
|
132
|
+
if s:autoload()
|
133
|
+
return RailsBufInit(a:path)
|
134
|
+
endif
|
135
|
+
endfunction
|
136
|
+
|
137
|
+
" }}}1
|
138
|
+
" Initialization {{{1
|
139
|
+
|
140
|
+
augroup railsPluginDetect
|
141
|
+
autocmd!
|
142
|
+
autocmd BufNewFile,BufRead * call s:Detect(expand("<afile>:p"))
|
143
|
+
autocmd VimEnter * if expand("<amatch>") == "" && !exists("b:rails_root") | call s:Detect(getcwd()) | endif | if exists("b:rails_root") | silent doau User BufEnterRails | endif
|
144
|
+
autocmd FileType netrw if !exists("b:rails_root") | call s:Detect(expand("<afile>:p")) | endif | if exists("b:rails_root") | silent doau User BufEnterRails | endif
|
145
|
+
autocmd BufEnter * if exists("b:rails_root")|silent doau User BufEnterRails|endif
|
146
|
+
autocmd BufLeave * if exists("b:rails_root")|silent doau User BufLeaveRails|endif
|
147
|
+
autocmd FileType railslog if s:autoload()|call RailslogSyntax()|endif
|
148
|
+
augroup END
|
149
|
+
|
150
|
+
command! -bar -bang -nargs=* -complete=dir Rails :if s:autoload()|call RailsNewApp(<bang>0,<f-args>)|endif
|
151
|
+
|
152
|
+
" }}}1
|
153
|
+
" Menus {{{1
|
154
|
+
|
155
|
+
if !(g:rails_menu && has("menu"))
|
156
|
+
finish
|
157
|
+
endif
|
158
|
+
|
159
|
+
function! s:sub(str,pat,rep)
|
160
|
+
return substitute(a:str,'\v\C'.a:pat,a:rep,'')
|
161
|
+
endfunction
|
162
|
+
|
163
|
+
function! s:gsub(str,pat,rep)
|
164
|
+
return substitute(a:str,'\v\C'.a:pat,a:rep,'g')
|
165
|
+
endfunction
|
166
|
+
|
167
|
+
function! s:CreateMenus() abort
|
168
|
+
if exists("g:rails_installed_menu") && g:rails_installed_menu != ""
|
169
|
+
exe "aunmenu ".s:gsub(g:rails_installed_menu,'\&','')
|
170
|
+
unlet g:rails_installed_menu
|
171
|
+
endif
|
172
|
+
if has("menu") && (exists("g:did_install_default_menus") || exists("$CREAM")) && g:rails_menu
|
173
|
+
if g:rails_menu > 1
|
174
|
+
let g:rails_installed_menu = '&Rails'
|
175
|
+
else
|
176
|
+
let g:rails_installed_menu = '&Plugin.&Rails'
|
177
|
+
endif
|
178
|
+
if exists("$CREAM")
|
179
|
+
let menucmd = '87anoremenu <script> '
|
180
|
+
exe menucmd.g:rails_installed_menu.'.-PSep- :'
|
181
|
+
exe menucmd.g:rails_installed_menu.'.&Related\ file\ :R\ /\ Alt+] :R<CR>'
|
182
|
+
exe menucmd.g:rails_installed_menu.'.&Alternate\ file\ :A\ /\ Alt+[ :A<CR>'
|
183
|
+
exe menucmd.g:rails_installed_menu.'.&File\ under\ cursor\ Ctrl+Enter :Rfind<CR>'
|
184
|
+
else
|
185
|
+
let menucmd = 'anoremenu <script> '
|
186
|
+
exe menucmd.g:rails_installed_menu.'.-PSep- :'
|
187
|
+
exe menucmd.g:rails_installed_menu.'.&Related\ file\ :R\ /\ ]f :R<CR>'
|
188
|
+
exe menucmd.g:rails_installed_menu.'.&Alternate\ file\ :A\ /\ [f :A<CR>'
|
189
|
+
exe menucmd.g:rails_installed_menu.'.&File\ under\ cursor\ gf :Rfind<CR>'
|
190
|
+
endif
|
191
|
+
exe menucmd.g:rails_installed_menu.'.&Other\ files.Application\ &Controller :find app/controllers/application.rb<CR>'
|
192
|
+
exe menucmd.g:rails_installed_menu.'.&Other\ files.Application\ &Helper :find app/helpers/application_helper.rb<CR>'
|
193
|
+
exe menucmd.g:rails_installed_menu.'.&Other\ files.Application\ &Javascript :find public/javascripts/application.js<CR>'
|
194
|
+
exe menucmd.g:rails_installed_menu.'.&Other\ files.Application\ &Layout :Rlayout application<CR>'
|
195
|
+
exe menucmd.g:rails_installed_menu.'.&Other\ files.Application\ &README :find doc/README_FOR_APP<CR>'
|
196
|
+
exe menucmd.g:rails_installed_menu.'.&Other\ files.&Environment :find config/environment.rb<CR>'
|
197
|
+
exe menucmd.g:rails_installed_menu.'.&Other\ files.&Database\ Configuration :find config/database.yml<CR>'
|
198
|
+
exe menucmd.g:rails_installed_menu.'.&Other\ files.Database\ &Schema :call <SID>findschema()<CR>'
|
199
|
+
exe menucmd.g:rails_installed_menu.'.&Other\ files.R&outes :find config/routes.rb<CR>'
|
200
|
+
exe menucmd.g:rails_installed_menu.'.&Other\ files.&Test\ Helper :find test/test_helper.rb<CR>'
|
201
|
+
exe menucmd.g:rails_installed_menu.'.-FSep- :'
|
202
|
+
exe menucmd.g:rails_installed_menu.'.Ra&ke\ :Rake :Rake<CR>'
|
203
|
+
let tasks = g:rails_rake_tasks
|
204
|
+
while tasks != ''
|
205
|
+
let task = matchstr(tasks,'.\{-\}\ze\%(\n\|$\)')
|
206
|
+
let tasks = s:sub(tasks,'.{-}%(\n|$)','')
|
207
|
+
exe menucmd.g:rails_installed_menu.'.Rake\ &tasks\ :Rake.'.s:sub(s:sub(task,'^[^:]*$','&:all'),':','.').' :Rake '.task.'<CR>'
|
208
|
+
endwhile
|
209
|
+
let tasks = g:rails_generators
|
210
|
+
while tasks != ''
|
211
|
+
let task = matchstr(tasks,'.\{-\}\ze\%(\n\|$\)')
|
212
|
+
let tasks = s:sub(tasks,'.{-}%(\n|$)','')
|
213
|
+
exe menucmd.'<silent> '.g:rails_installed_menu.'.&Generate\ :Rgen.'.s:gsub(task,'_','\\ ').' :call <SID>menuprompt("Rgenerate '.task.'","Arguments for script/generate '.task.': ")<CR>'
|
214
|
+
exe menucmd.'<silent> '.g:rails_installed_menu.'.&Destroy\ :Rdestroy.'.s:gsub(task,'_','\\ ').' :call <SID>menuprompt("Rdestroy '.task.'","Arguments for script/destroy '.task.': ")<CR>'
|
215
|
+
endwhile
|
216
|
+
exe menucmd.g:rails_installed_menu.'.&Server\ :Rserver.&Start\ :Rserver :Rserver<CR>'
|
217
|
+
exe menucmd.g:rails_installed_menu.'.&Server\ :Rserver.&Force\ start\ :Rserver! :Rserver!<CR>'
|
218
|
+
exe menucmd.g:rails_installed_menu.'.&Server\ :Rserver.&Kill\ :Rserver!\ - :Rserver! -<CR>'
|
219
|
+
exe menucmd.'<silent> '.g:rails_installed_menu.'.&Evaluate\ Ruby\.\.\.\ :Rp :call <SID>menuprompt("Rp","Code to execute and output: ")<CR>'
|
220
|
+
exe menucmd.g:rails_installed_menu.'.&Console\ :Rconsole :Rconsole<CR>'
|
221
|
+
exe menucmd.g:rails_installed_menu.'.&Preview\ :Rpreview :Rpreview<CR>'
|
222
|
+
exe menucmd.g:rails_installed_menu.'.&Log\ file\ :Rlog :Rlog<CR>'
|
223
|
+
exe s:sub(menucmd,'anoremenu','vnoremenu').' <silent> '.g:rails_installed_menu.'.E&xtract\ as\ partial\ :Rextract :call <SID>menuprompt("'."'".'<,'."'".'>Rextract","Partial name (e.g., template or /controller/template): ")<CR>'
|
224
|
+
exe menucmd.g:rails_installed_menu.'.&Migration\ writer\ :Rinvert :Rinvert<CR>'
|
225
|
+
exe menucmd.' '.g:rails_installed_menu.'.-HSep- :'
|
226
|
+
exe menucmd.'<silent> '.g:rails_installed_menu.'.&Help\ :help\ rails :if <SID>autoload()<Bar>exe RailsHelpCommand("")<Bar>endif<CR>'
|
227
|
+
exe menucmd.'<silent> '.g:rails_installed_menu.'.Abo&ut\ :if <SID>autoload()<Bar>exe RailsHelpCommand("about")<Bar>endif<CR>'
|
228
|
+
let g:rails_did_menus = 1
|
229
|
+
call s:ProjectMenu()
|
230
|
+
call s:menuBufLeave()
|
231
|
+
if exists("b:rails_root")
|
232
|
+
call s:menuBufEnter()
|
233
|
+
endif
|
234
|
+
endif
|
235
|
+
endfunction
|
236
|
+
|
237
|
+
function! s:ProjectMenu()
|
238
|
+
if exists("g:rails_did_menus") && g:rails_history_size > 0
|
239
|
+
if !exists("g:RAILS_HISTORY")
|
240
|
+
let g:RAILS_HISTORY = ""
|
241
|
+
endif
|
242
|
+
let history = g:RAILS_HISTORY
|
243
|
+
let menu = s:gsub(g:rails_installed_menu,'\&','')
|
244
|
+
silent! exe "aunmenu <script> ".menu.".Projects"
|
245
|
+
let dots = s:gsub(menu,'[^.]','')
|
246
|
+
exe 'anoremenu <script> <silent> '.(exists("$CREAM") ? '87' : '').dots.'.100 '.menu.'.Pro&jects.&New\.\.\.\ :Rails :call <SID>menuprompt("Rails","New application path and additional arguments: ")<CR>'
|
247
|
+
exe 'anoremenu <script> '.menu.'.Pro&jects.-FSep- :'
|
248
|
+
while history =~ '\n'
|
249
|
+
let proj = matchstr(history,'^.\{-\}\ze\n')
|
250
|
+
let history = s:sub(history,'^.{-}\n','')
|
251
|
+
exe 'anoremenu <script> '.menu.'.Pro&jects.'.s:gsub(proj,'[.\\ ]','\\&').' :e '.s:gsub(proj."/".g:rails_default_file,'[ !%#]','\\&')."<CR>"
|
252
|
+
endwhile
|
253
|
+
endif
|
254
|
+
endfunction
|
255
|
+
|
256
|
+
function! s:menuBufEnter()
|
257
|
+
if exists("g:rails_installed_menu") && g:rails_installed_menu != ""
|
258
|
+
let menu = s:gsub(g:rails_installed_menu,'\&','')
|
259
|
+
exe 'amenu enable '.menu.'.*'
|
260
|
+
if RailsFileType() !~ '^view\>'
|
261
|
+
exe 'vmenu disable '.menu.'.Extract\ as\ partial'
|
262
|
+
endif
|
263
|
+
if RailsFileType() !~ '^\%(db-\)\=migration$' || RailsFilePath() =~ '\<db/schema\.rb$'
|
264
|
+
exe 'amenu disable '.menu.'.Migration\ writer'
|
265
|
+
endif
|
266
|
+
call s:ProjectMenu()
|
267
|
+
endif
|
268
|
+
endfunction
|
269
|
+
|
270
|
+
function! s:menuBufLeave()
|
271
|
+
if exists("g:rails_installed_menu") && g:rails_installed_menu != ""
|
272
|
+
let menu = s:gsub(g:rails_installed_menu,'\&','')
|
273
|
+
exe 'amenu disable '.menu.'.*'
|
274
|
+
exe 'amenu enable '.menu.'.Help\ '
|
275
|
+
exe 'amenu enable '.menu.'.About\ '
|
276
|
+
exe 'amenu enable '.menu.'.Projects'
|
277
|
+
endif
|
278
|
+
endfunction
|
279
|
+
|
280
|
+
function! s:menuprompt(vimcmd,prompt)
|
281
|
+
let res = inputdialog(a:prompt,'','!!!')
|
282
|
+
if res == '!!!'
|
283
|
+
return ""
|
284
|
+
endif
|
285
|
+
exe a:vimcmd." ".res
|
286
|
+
endfunction
|
287
|
+
|
288
|
+
function! s:findschema()
|
289
|
+
let env = exists('$RAILS_ENV') ? $RAILS_ENV : "development"
|
290
|
+
if filereadable(b:rails_root."/db/schema.rb")
|
291
|
+
edit `=b:rails_root.'/db/schema.rb'`
|
292
|
+
elseif filereadable(b:rails_root.'/db/'.env.'_structure.sql')
|
293
|
+
edit `=b:rails_root.'/db/'.env.'_structure.sql'`
|
294
|
+
else
|
295
|
+
return s:error("Schema not found: try :Rake db:schema:dump")
|
296
|
+
endif
|
297
|
+
endfunction
|
298
|
+
|
299
|
+
call s:CreateMenus()
|
300
|
+
|
301
|
+
augroup railsPluginMenu
|
302
|
+
autocmd!
|
303
|
+
autocmd User BufEnterRails call s:menuBufEnter()
|
304
|
+
autocmd User BufLeaveRails call s:menuBufLeave()
|
305
|
+
" g:RAILS_HISTORY hasn't been set when s:InitPlugin() is called.
|
306
|
+
autocmd VimEnter * call s:ProjectMenu()
|
307
|
+
augroup END
|
308
|
+
|
309
|
+
" }}}1
|
310
|
+
" vim:set sw=2 sts=2:
|
@@ -0,0 +1,12 @@
|
|
1
|
+
noremap <buffer><silent> <F10> :w<CR>:echo "Running test file..."<CR>:!spec %<CR>
|
2
|
+
|
3
|
+
" Sigh... everybody has their own keystroke for running specs...
|
4
|
+
|
5
|
+
" for VS aficionados...
|
6
|
+
" noremap <buffer><silent> <F5> :w<CR>:echo "Running tests..."<CR>:let spec_response = system("spec -l ".line(".")." ".expand("%"))<CR>:echo spec_response<CR>
|
7
|
+
|
8
|
+
" for Mac/Textmate geeks...
|
9
|
+
noremap <buffer><silent> <M-r> :w<CR>:echo "Running tests..."<CR>:let spec_response = system("spec -l ".line(".")." ".expand("%"))<CR>:echo spec_response<CR>
|
10
|
+
|
11
|
+
" randomly chosen to be near F10...
|
12
|
+
noremap <buffer><silent> <F11> :w<CR>:echo "Running tests..."<CR>:let spec_response = system("spec -l ".line(".")." ".expand("%"))<CR>:echo spec_response<CR>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
func Eatchar(pat)
|
2
|
+
let c = nr2char(getchar(0))
|
3
|
+
return (c =~ a:pat) ? '' : c
|
4
|
+
endfunc
|
5
|
+
|
6
|
+
nmap <silent> <Tab> /!@[^@]*@!/<CR>"_cf!
|
7
|
+
nmap <silent> ; /!@[^@]*@!/<CR>"_cf!
|
8
|
+
|
9
|
+
iab <silent> ea each do \|!@block_variable@!\|<CR>!@block@!<CR>end<CR><Esc>3k0;<C-R>=Eatchar('\s')<CR>
|
10
|
+
iab <silent> eal each { \|!@block_variable@!\| !@block@! }<CR><Esc>3k0;<C-R>=Eatchar('\s')<CR>
|
11
|
+
|
12
|
+
iab <silent> dm def !@method@!<CR>!@method_body@!<CR>end<CR><Esc>3k0;<C-R>=Eatchar('\s')<CR>
|
13
|
+
|
14
|
+
iab <silent> des describe '!@method@!' do<CR>!@its@!<CR>end<Esc>2k0;<C-R>=Eatchar('\s')<CR>
|
15
|
+
iab <silent> iit it "should !@should@!" do<CR>!@something@!<CR>end<CR><Esc>3k0;<C-R>=Eatchar('\s')<CR>
|
16
|
+
iab <silent> desit describe '!@method@!' do<CR>it "should !@should@!" do<CR>!@stuff@!<CR>end<CR>end<CR><Esc>5k<Esc>;<C-R>=Eatchar('\s')<CR>
|
17
|
+
iab <silent> bef before(:each) do<CR>end<CR><Esc>kO<C-R>=Eatchar('\s')<CR>
|
@@ -0,0 +1,973 @@
|
|
1
|
+
" File: snippetsEmu.vim
|
2
|
+
" Author: Felix Ingram
|
3
|
+
" ( f.ingram.lists <AT> gmail.com )
|
4
|
+
" Description: An attempt to implement TextMate style Snippets. Features include
|
5
|
+
" automatic cursor placement and command execution.
|
6
|
+
" $LastChangedDate$
|
7
|
+
" Version: 1.1
|
8
|
+
" $Revision$
|
9
|
+
"
|
10
|
+
" This file contains some simple functions that attempt to emulate some of the
|
11
|
+
" behaviour of 'Snippets' from the OS X editor TextMate, in particular the
|
12
|
+
" variable bouncing and replacement behaviour.
|
13
|
+
"
|
14
|
+
" {{{ USAGE:
|
15
|
+
"
|
16
|
+
" Place the file in your plugin directory.
|
17
|
+
" Define snippets using the Snippet command.
|
18
|
+
" Snippets are best defined in the 'after' subdirectory of your Vim home
|
19
|
+
" directory ('~/.vim/after' on Unix). Filetype specific snippets can be defined
|
20
|
+
" in '~/.vim/after/ftplugin/<filetype>_snippets.vim. Using the <buffer> argument will
|
21
|
+
" By default snippets are buffer specific. To define general snippets available
|
22
|
+
" globally use the 'Iabbr' command.
|
23
|
+
"
|
24
|
+
" Example One:
|
25
|
+
" Snippet fori for <{datum}> in <{data}>:<CR><{datum}>.<{}>
|
26
|
+
"
|
27
|
+
" The above will expand to the following (indenting may differ):
|
28
|
+
"
|
29
|
+
" for <{datum}> in <{data}>:
|
30
|
+
" <{datum}>.<{}>
|
31
|
+
"
|
32
|
+
" The cursor will be placed after the first '<{' in insert mode.
|
33
|
+
" Pressing <Tab> will 'tab' to the next place marker (<{data}>) in
|
34
|
+
" insert mode. Adding text between <{ and }> and then hitting <{Tab}> will
|
35
|
+
" remove the angle brackets and replace all markers with a similar identifier.
|
36
|
+
"
|
37
|
+
" Example Two:
|
38
|
+
" With the cursor at the pipe, hitting <Tab> will replace:
|
39
|
+
" for <{MyVariableName|datum}> in <{data}>:
|
40
|
+
" <{datum}>.<{}>
|
41
|
+
"
|
42
|
+
" with (the pipe shows the cursor placement):
|
43
|
+
"
|
44
|
+
" for MyVariableName in <{data}>:
|
45
|
+
" MyVariableName.<{}>
|
46
|
+
"
|
47
|
+
" Enjoy.
|
48
|
+
"
|
49
|
+
" For more information please see the documentation accompanying this plugin.
|
50
|
+
"
|
51
|
+
" Additional Features:
|
52
|
+
"
|
53
|
+
" Commands in tags. Anything after a ':' in a tag will be run with Vim's
|
54
|
+
" 'execute' command. The value entered by the user (or the tag name if no change
|
55
|
+
" has been made) is passed in the @z register (the original contents of the
|
56
|
+
" register are restored once the command has been run).
|
57
|
+
"
|
58
|
+
" Named Tags. Naming a tag (the <{datum}> tag in the example above) and changing
|
59
|
+
" the value will cause all other tags with the same name to be changed to the
|
60
|
+
" same value (as illustrated in the above example). Not changing the value and
|
61
|
+
" hitting <Tab> will cause the tag's name to be used as the default value.
|
62
|
+
"
|
63
|
+
" Test tags for pattern matching:
|
64
|
+
" The following are examples of valid and invalid tags. Whitespace can only be
|
65
|
+
" used in a tag name if the name is enclosed in quotes.
|
66
|
+
"
|
67
|
+
" Valid tags
|
68
|
+
" <{}>
|
69
|
+
" <{tagName}>
|
70
|
+
" <{tagName:command}>
|
71
|
+
" <{"Tag Name"}>
|
72
|
+
" <{"Tag Name":command}>
|
73
|
+
"
|
74
|
+
" Invalid tags, random text
|
75
|
+
" <{:}>
|
76
|
+
" <{:command}>
|
77
|
+
" <{Tag Name}>
|
78
|
+
" <{Tag Name:command}>
|
79
|
+
" <{"Tag Name":}>
|
80
|
+
" <{Tag }>
|
81
|
+
" <{OpenTag
|
82
|
+
"
|
83
|
+
" Here's our magic search term (assumes '<{',':' and '}>' as our tag delimiters:
|
84
|
+
" <{\([^[:punct:] \t]\{-}\|".\{-}"\)\(:[^}>]\{-1,}\)\?}>
|
85
|
+
" }}}
|
86
|
+
|
87
|
+
if v:version < 700
|
88
|
+
echomsg "snippetsEmu plugin requires Vim version 7 or later"
|
89
|
+
finish
|
90
|
+
endif
|
91
|
+
|
92
|
+
if globpath(&rtp, 'plugin/snippetEmu.vim') != ""
|
93
|
+
call confirm("It looks like you've got an old version of snippetsEmu installed. Please delete the file 'snippetEmu.vim' from the plugin directory. Note lack of 's'")
|
94
|
+
endif
|
95
|
+
|
96
|
+
let s:debug = 0
|
97
|
+
let s:Disable = 0
|
98
|
+
|
99
|
+
function! s:Debug(func, text)
|
100
|
+
if exists('s:debug') && s:debug == 1
|
101
|
+
echom "Snippy: ".a:func.": ".a:text
|
102
|
+
endif
|
103
|
+
endfunction
|
104
|
+
|
105
|
+
if (exists('loaded_snippet') || &cp) && !s:debug
|
106
|
+
finish
|
107
|
+
endif
|
108
|
+
|
109
|
+
"call s:Debug("","Started the plugin")
|
110
|
+
|
111
|
+
let loaded_snippet=1
|
112
|
+
" {{{ Set up variables
|
113
|
+
if !exists("g:snip_start_tag")
|
114
|
+
let g:snip_start_tag = "<{"
|
115
|
+
endif
|
116
|
+
|
117
|
+
if !exists("g:snip_end_tag")
|
118
|
+
let g:snip_end_tag = "}>"
|
119
|
+
endif
|
120
|
+
|
121
|
+
if !exists("g:snip_elem_delim")
|
122
|
+
let g:snip_elem_delim = ":"
|
123
|
+
endif
|
124
|
+
|
125
|
+
if !exists("g:snippetsEmu_key")
|
126
|
+
let g:snippetsEmu_key = "<Tab>"
|
127
|
+
endif
|
128
|
+
|
129
|
+
"call s:Debug("", "Set variables")
|
130
|
+
|
131
|
+
" }}}
|
132
|
+
" {{{ Set up menu
|
133
|
+
for def_file in split(globpath(&rtp, "after/ftplugin/*_snippets.vim"), '\n')
|
134
|
+
"call s:Debug("","Adding ".def_file." definitions to menu")
|
135
|
+
let snip = substitute(def_file, '.*[\\/]\(.*\)_snippets.vim', '\1', '')
|
136
|
+
exec "nmenu <silent> S&nippets.".snip." :source ".def_file."<CR>"
|
137
|
+
endfor
|
138
|
+
" }}}
|
139
|
+
" {{{ Sort out supertab
|
140
|
+
function! s:GetSuperTabSNR()
|
141
|
+
let a_sav = @a
|
142
|
+
redir @a
|
143
|
+
exec "silent function"
|
144
|
+
redir END
|
145
|
+
let funclist = @a
|
146
|
+
let @a = a_sav
|
147
|
+
try
|
148
|
+
let func = split(split(matchstr(funclist,'.SNR.\{-}SuperTab(command)'),'\n')[-1])[1]
|
149
|
+
return matchlist(func, '\(.*\)S')[1]
|
150
|
+
catch /E684/
|
151
|
+
endtry
|
152
|
+
return ""
|
153
|
+
endfunction
|
154
|
+
|
155
|
+
function! s:SetupSupertab()
|
156
|
+
if !exists('s:supInstalled')
|
157
|
+
let s:supInstalled = 0
|
158
|
+
endif
|
159
|
+
if s:supInstalled == 1 || globpath(&rtp, 'plugin/supertab.vim') != ""
|
160
|
+
"call s:Debug("SetupSupertab", "Supertab installed")
|
161
|
+
let s:SupSNR = s:GetSuperTabSNR()
|
162
|
+
let s:supInstalled = 1
|
163
|
+
if s:SupSNR != ""
|
164
|
+
let s:done_remap = 1
|
165
|
+
else
|
166
|
+
let s:done_remap = 0
|
167
|
+
endif
|
168
|
+
endif
|
169
|
+
endfunction
|
170
|
+
|
171
|
+
call s:SetupSupertab()
|
172
|
+
" }}}
|
173
|
+
" {{{ Map Jumper to the default key if not set already
|
174
|
+
function! s:SnipMapKeys()
|
175
|
+
if (!hasmapto('<Plug>Jumper','i'))
|
176
|
+
if s:supInstalled == 1
|
177
|
+
exec 'imap '.g:snippetsEmu_key.' <Plug>Jumper'
|
178
|
+
else
|
179
|
+
exec 'imap <unique> '.g:snippetsEmu_key.' <Plug>Jumper'
|
180
|
+
endif
|
181
|
+
endif
|
182
|
+
|
183
|
+
if (!hasmapto( 'i<BS>'.g:snippetsEmu_key, 's'))
|
184
|
+
exec 'smap <unique> '.g:snippetsEmu_key.' i<BS>'.g:snippetsEmu_key
|
185
|
+
endif
|
186
|
+
imap <silent> <script> <Plug>Jumper <C-R>=<SID>Jumper()<CR>
|
187
|
+
endfunction
|
188
|
+
|
189
|
+
call s:SnipMapKeys()
|
190
|
+
|
191
|
+
"call s:Debug("", "Mapped keys")
|
192
|
+
|
193
|
+
" }}}
|
194
|
+
" {{{ SetLocalTagVars()
|
195
|
+
function! s:SetLocalTagVars()
|
196
|
+
if exists("b:snip_end_tag") && exists("b:snip_start_tag") && exists("b:snip_elem_delim")
|
197
|
+
return [b:snip_start_tag, b:snip_elem_delim, b:snip_end_tag]
|
198
|
+
else
|
199
|
+
return [g:snip_start_tag, g:snip_elem_delim, g:snip_end_tag]
|
200
|
+
endif
|
201
|
+
endfunction
|
202
|
+
" }}}
|
203
|
+
" {{{ SetSearchStrings() - Set the search string. Checks for buffer dependence
|
204
|
+
function! s:SetSearchStrings()
|
205
|
+
let [snip_start_tag, snip_elem_delim, snip_end_tag] = s:SetLocalTagVars()
|
206
|
+
let b:search_str = snip_start_tag.'\([^'.
|
207
|
+
\snip_start_tag.snip_end_tag.
|
208
|
+
\'[:punct:] \t]\{-}\|".\{-}"\)\('.
|
209
|
+
\snip_elem_delim.
|
210
|
+
\'[^'.snip_end_tag.snip_start_tag.']\{-1,}\)\?'.snip_end_tag
|
211
|
+
let b:search_commandVal = "[^".snip_elem_delim."]*"
|
212
|
+
let b:search_endVal = "[^".snip_end_tag."]*"
|
213
|
+
endfunction
|
214
|
+
" }}}
|
215
|
+
" {{{ SetCom(text, scope) - Set command function
|
216
|
+
function! <SID>SetCom(text, scope)
|
217
|
+
let text = substitute(a:text, '\c<CR>\|<Esc>\|<Tab>\|<BS>\|<Space>\|<C-r>\|<Bar>\|\"\|\\','\\&',"g")
|
218
|
+
|
219
|
+
if s:supInstalled == 1
|
220
|
+
call s:SetupSupertab()
|
221
|
+
call s:SnipMapKeys()
|
222
|
+
endif
|
223
|
+
|
224
|
+
let text = substitute(text, "\r$", "","")
|
225
|
+
|
226
|
+
let tokens = split(text, ' ')
|
227
|
+
call filter(tokens, 'v:val != ""')
|
228
|
+
if len(tokens) == 0
|
229
|
+
let output = join(s:ListSnippets("","","",eval(a:scope)) ,"\n")
|
230
|
+
if output == ""
|
231
|
+
echohl Title | echo "No snippets defined" | echohl None
|
232
|
+
else
|
233
|
+
echohl Title | echo "Defined snippets:" | echohl None
|
234
|
+
echo output
|
235
|
+
endif
|
236
|
+
" NOTE - cases such as ":Snippet if " will intentionally(?) be parsed as a
|
237
|
+
" snippet named "if" with contents of " "
|
238
|
+
elseif len(tokens) == 1
|
239
|
+
let snip = s:Hash(tokens[0])
|
240
|
+
if exists(a:scope."trigger_".snip)
|
241
|
+
" FIXME - is there a better approach?
|
242
|
+
" echo doesn't handle ^M correctly
|
243
|
+
let pretty = substitute(eval(a:scope."trigger_".snip), "\r", "\n","g")
|
244
|
+
echo pretty
|
245
|
+
else
|
246
|
+
echohl Error | echo "Undefined snippet: ".snip | echohl None
|
247
|
+
endif
|
248
|
+
else
|
249
|
+
let [lhs, rhs] = [s:Hash(tokens[0]), join(tokens[1:])]
|
250
|
+
call s:SetSearchStrings()
|
251
|
+
let g:search_str = b:search_str
|
252
|
+
exe "let ".a:scope."trigger_".lhs.' = "'.rhs.'"'
|
253
|
+
endif
|
254
|
+
endfunction
|
255
|
+
" }}}
|
256
|
+
" {{{ RestoreSearch()
|
257
|
+
" Checks whether more tags exist and restores hlsearch and @/ if not
|
258
|
+
function! s:RestoreSearch()
|
259
|
+
if !search(b:search_str, "n")
|
260
|
+
if exists("b:hl_on") && b:hl_on == 1
|
261
|
+
setlocal hlsearch
|
262
|
+
endif
|
263
|
+
if exists("b:search_sav")
|
264
|
+
let @/ = b:search_sav
|
265
|
+
endif
|
266
|
+
endif
|
267
|
+
endfunction
|
268
|
+
"}}}
|
269
|
+
" {{{ DeleteEmptyTag
|
270
|
+
function! s:DeleteEmptyTag()
|
271
|
+
let [snip_start_tag, snip_elem_delim, snip_end_tag] = s:SetLocalTagVars()
|
272
|
+
exec "normal zv".(s:StrLen(snip_start_tag) + s:StrLen(snip_end_tag))."x"
|
273
|
+
endfunction
|
274
|
+
" }}}
|
275
|
+
" {{{ SetUpTags()
|
276
|
+
function! s:SetUpTags()
|
277
|
+
let [snip_start_tag, snip_elem_delim, snip_end_tag] = s:SetLocalTagVars()
|
278
|
+
if (strpart(getline("."), col(".")+strlen(snip_start_tag)-1, strlen(snip_end_tag)) == snip_end_tag)
|
279
|
+
"call s:Debug("SetUpTags","Found an empty tag")
|
280
|
+
let b:tag_name = ""
|
281
|
+
if col(".") + s:StrLen(snip_start_tag.snip_end_tag) == s:StrLen(getline("."))
|
282
|
+
" We delete the empty tag here as otherwise we can't determine whether we
|
283
|
+
" need to send 'a' or 'A' as deleting the empty tag will sit us on the
|
284
|
+
" final character either way
|
285
|
+
call s:DeleteEmptyTag()
|
286
|
+
call s:RestoreSearch()
|
287
|
+
if col(".") == s:StrLen(getline("."))
|
288
|
+
return "\<Esc>a"
|
289
|
+
endif
|
290
|
+
else
|
291
|
+
call s:DeleteEmptyTag()
|
292
|
+
call s:RestoreSearch()
|
293
|
+
if col(".") == s:StrLen(getline("."))
|
294
|
+
return "\<Esc>A"
|
295
|
+
endif
|
296
|
+
endif
|
297
|
+
return ''
|
298
|
+
else
|
299
|
+
" Not on an empty tag so it must be a normal tag
|
300
|
+
let b:tag_name = s:ChopTags(matchstr(getline("."),b:search_str,col(".")-1))
|
301
|
+
"call s:Debug("SetUpTags","On a tag called: ".b:tag_name)
|
302
|
+
|
303
|
+
" Check for exclusive selection mode. If exclusive is not set then we need to
|
304
|
+
" move back a character.
|
305
|
+
if &selection == "exclusive"
|
306
|
+
let end_skip = ""
|
307
|
+
else
|
308
|
+
let end_skip = "\<Left>"
|
309
|
+
endif
|
310
|
+
|
311
|
+
let start_skip = repeat("\<Right>",s:StrLen(snip_start_tag)+1)
|
312
|
+
"call s:Debug("SetUpTags","Start skip is: ".start_skip)
|
313
|
+
"call s:Debug("SetUpTags","Col() is: ".col("."))
|
314
|
+
if col(".") == 1
|
315
|
+
"call s:Debug("SetUpTags","We're at the start of the line so don't need to skip the first char of start tag")
|
316
|
+
let start_skip = strpart(start_skip, 0, strlen(start_skip)-strlen("\<Right>"))
|
317
|
+
"call s:Debug("SetUpTags","Start skip is now: ".start_skip)
|
318
|
+
endif
|
319
|
+
"call s:Debug("SetUpTags","Returning: \<Esc>".start_skip."v/".snip_end_tag."\<CR>".end_skip."\<C-g>")
|
320
|
+
return "\<Esc>".start_skip."v/".snip_end_tag."\<CR>".end_skip."\<C-g>"
|
321
|
+
endif
|
322
|
+
endfunction
|
323
|
+
" }}}
|
324
|
+
" {{{ NextHop() - Jump to the next tag if one is available
|
325
|
+
function! <SID>NextHop()
|
326
|
+
let [snip_start_tag, snip_elem_delim, snip_end_tag] = s:SetLocalTagVars()
|
327
|
+
"call s:Debug("NextHop", "Col() is: ".col("."))
|
328
|
+
"call s:Debug("NextHop", "Position of next match = ".match(getline("."), b:search_str))
|
329
|
+
" First check to see if we have any tags on lines above the current one
|
330
|
+
" If the first match is after the current cursor position or not on this
|
331
|
+
" line...
|
332
|
+
if match(getline("."), b:search_str) >= col(".") || match(getline("."), b:search_str) == -1
|
333
|
+
" Perform a search to jump to the next tag
|
334
|
+
"call s:Debug("NextHop", "Seaching for a tag")
|
335
|
+
if search(b:search_str) != 0
|
336
|
+
return s:SetUpTags()
|
337
|
+
else
|
338
|
+
" there are no more matches
|
339
|
+
"call s:Debug("NextHop", "No more tags in the buffer")
|
340
|
+
" Restore hlsarch and @/
|
341
|
+
call s:RestoreSearch()
|
342
|
+
return ''
|
343
|
+
endif
|
344
|
+
else
|
345
|
+
" The match on the current line is on or before the cursor, so we need to
|
346
|
+
" move the cursor back
|
347
|
+
"call s:Debug("NextHop", "Moving the cursor back")
|
348
|
+
"call s:Debug("NextHop", "Col is: ".col("."))
|
349
|
+
"call s:Debug("NextHop", "Moving back to column: ".match(getline("."), b:search_str))
|
350
|
+
while col(".") > match(getline("."), b:search_str) + 1
|
351
|
+
call cursor(0,col('.')-1)
|
352
|
+
endwhile
|
353
|
+
"call s:Debug("NextHop", "Col is now: ".col("."))
|
354
|
+
" Now we just set up the tag as usual
|
355
|
+
return s:SetUpTags()
|
356
|
+
endif
|
357
|
+
endfunction
|
358
|
+
" }}}
|
359
|
+
" {{{ RunCommand() - Execute commands stored in tags
|
360
|
+
function! s:RunCommand(command, z)
|
361
|
+
let [snip_start_tag, snip_elem_delim, snip_end_tag] = s:SetLocalTagVars()
|
362
|
+
"call s:Debug("RunCommand", "RunCommand was passed this command: ".a:command." and this value: ".a:z)
|
363
|
+
if a:command == ''
|
364
|
+
return a:z
|
365
|
+
endif
|
366
|
+
" Save current value of 'z'
|
367
|
+
let snip_save = @z
|
368
|
+
let @z=a:z
|
369
|
+
" Call the command
|
370
|
+
execute 'let ret = '. a:command
|
371
|
+
" Replace the value
|
372
|
+
let @z = snip_save
|
373
|
+
return ret
|
374
|
+
endfunction
|
375
|
+
" }}}
|
376
|
+
" {{{ MakeChanges() - Search the document making all the changes required
|
377
|
+
" This function has been factored out to allow the addition of commands in tags
|
378
|
+
function! s:MakeChanges()
|
379
|
+
" Make all the changes
|
380
|
+
" Change all the tags with the same name and no commands defined
|
381
|
+
let [snip_start_tag, snip_elem_delim, snip_end_tag] = s:SetLocalTagVars()
|
382
|
+
|
383
|
+
if b:tag_name == ""
|
384
|
+
"call s:Debug("MakeChanges", "Nothing to do: tag_name is empty")
|
385
|
+
return
|
386
|
+
endif
|
387
|
+
|
388
|
+
let tagmatch = '\V'.snip_start_tag.b:tag_name.snip_end_tag
|
389
|
+
|
390
|
+
"call s:Debug("MakeChanges", "Matching on this value: ".tagmatch)
|
391
|
+
"call s:Debug("MakeChanges", "Replacing with this value: ".s:replaceVal)
|
392
|
+
|
393
|
+
try
|
394
|
+
"call s:Debug("MakeChanges", "Running these commands: ".join(b:command_dict[b:tag_name], "', '"))
|
395
|
+
catch /E175/
|
396
|
+
"call s:Debug("MakeChanges", "Could not find this key in the dict: ".b:tag_name)
|
397
|
+
endtry
|
398
|
+
|
399
|
+
let ind = 0
|
400
|
+
while search(tagmatch,"w") > 0
|
401
|
+
try
|
402
|
+
let commandResult = s:RunCommand(b:command_dict[b:tag_name][0], s:replaceVal)
|
403
|
+
catch /E175/
|
404
|
+
"call s:Debug("MakeChanges", "Could not find this key in the dict: ".b:tag_name)
|
405
|
+
endtry
|
406
|
+
"call s:Debug("MakeChanges", "Got this result: ".commandResult)
|
407
|
+
let lines = split(substitute(getline("."), tagmatch, commandResult, ''),'\n')
|
408
|
+
if len(lines) > 1
|
409
|
+
call setline(".", lines[0])
|
410
|
+
call append(".", lines[1:])
|
411
|
+
else
|
412
|
+
call setline(".", lines)
|
413
|
+
endif
|
414
|
+
try
|
415
|
+
unlet b:command_dict[b:tag_name][0]
|
416
|
+
catch /E175/
|
417
|
+
"call s:Debug("MakeChanges", "Could not find this key in the dict: ".b:tag_name)
|
418
|
+
endtry
|
419
|
+
endwhile
|
420
|
+
endfunction
|
421
|
+
" }}}
|
422
|
+
" {{{ ChangeVals() - Set up values for MakeChanges()
|
423
|
+
function! s:ChangeVals(changed)
|
424
|
+
let [snip_start_tag, snip_elem_delim, snip_end_tag] = s:SetLocalTagVars()
|
425
|
+
|
426
|
+
if a:changed == 1
|
427
|
+
let s:CHANGED_VAL = 1
|
428
|
+
else
|
429
|
+
let s:CHANGED_VAL = 0
|
430
|
+
endif
|
431
|
+
|
432
|
+
"call s:Debug("ChangeVals", "CHANGED_VAL: ".s:CHANGED_VAL)
|
433
|
+
"call s:Debug("ChangeVals", "b:tag_name: ".b:tag_name)
|
434
|
+
let elem_match = match(s:line, snip_elem_delim, s:curCurs)
|
435
|
+
let tagstart = strridx(getline("."), snip_start_tag,s:curCurs)+strlen(snip_start_tag)
|
436
|
+
|
437
|
+
"call s:Debug("ChangeVals", "About to access b:command_dict")
|
438
|
+
try
|
439
|
+
let commandToRun = b:command_dict[b:tag_name][0]
|
440
|
+
"call s:Debug("ChangeVals", "Accessed command_dict")
|
441
|
+
"call s:Debug("ChangeVals", "Running this command: ".commandToRun)
|
442
|
+
unlet b:command_dict[b:tag_name][0]
|
443
|
+
"call s:Debug("ChangeVals", "Command list is now: ".join(b:command_dict[b:tag_name], "', '"))
|
444
|
+
catch /E175/
|
445
|
+
"call s:Debug("ChangeVals", "Could not find this key in the dict: ".b:tag_name)
|
446
|
+
endtry
|
447
|
+
|
448
|
+
let commandMatch = substitute(commandToRun, '\', '\\\\', 'g')
|
449
|
+
if s:CHANGED_VAL
|
450
|
+
" The value has changed so we need to grab our current position back
|
451
|
+
" to the start of the tag
|
452
|
+
let replaceVal = strpart(getline("."), tagstart,s:curCurs-tagstart)
|
453
|
+
"call s:Debug("ChangeVals", "User entered this value: ".replaceVal)
|
454
|
+
let tagmatch = replaceVal
|
455
|
+
"call s:Debug("ChangeVals", "Col is: ".col("."))
|
456
|
+
call cursor(0,col('.')-s:StrLen(tagmatch))
|
457
|
+
"call s:Debug("ChangeVals", "Col is: ".col("."))
|
458
|
+
else
|
459
|
+
" The value hasn't changed so it's just the tag name
|
460
|
+
" without any quotes that are around it
|
461
|
+
"call s:Debug("ChangeVals", "Tag name is: ".b:tag_name)
|
462
|
+
let replaceVal = substitute(b:tag_name, '^"\(.*\)"$', '\1', '')
|
463
|
+
"call s:Debug("ChangeVals", "User did not enter a value. Replacing with this value: ".replaceVal)
|
464
|
+
let tagmatch = ''
|
465
|
+
"call s:Debug("ChangeVals", "Col is: ".col("."))
|
466
|
+
endif
|
467
|
+
|
468
|
+
let tagmatch = '\V'.snip_start_tag.tagmatch.snip_end_tag
|
469
|
+
"call s:Debug("ChangeVals", "Matching on this string: ".tagmatch)
|
470
|
+
let tagsubstitution = s:RunCommand(commandToRun, replaceVal)
|
471
|
+
let lines = split(substitute(getline("."), tagmatch, tagsubstitution, ""),'\n')
|
472
|
+
if len(lines) > 1
|
473
|
+
call setline(".", lines[0])
|
474
|
+
call append(".", lines[1:])
|
475
|
+
else
|
476
|
+
call setline(".", lines)
|
477
|
+
endif
|
478
|
+
" We use replaceVal instead of tagsubsitution as otherwise the command
|
479
|
+
" result will be passed to subsequent tags
|
480
|
+
let s:replaceVal = replaceVal
|
481
|
+
let line = line('.')
|
482
|
+
let col = col('.')
|
483
|
+
call s:MakeChanges()
|
484
|
+
call cursor(line, col)
|
485
|
+
unlet s:CHANGED_VAL
|
486
|
+
endfunction
|
487
|
+
" }}}
|
488
|
+
"{{{ SID() - Get the SID for the current script
|
489
|
+
function! s:SID()
|
490
|
+
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$')
|
491
|
+
endfun
|
492
|
+
"}}}
|
493
|
+
"{{{ CheckForInTag() - Check whether we're in a tag
|
494
|
+
function! s:CheckForInTag()
|
495
|
+
let [snip_start_tag, snip_elem_delim, snip_end_tag] = s:SetLocalTagVars()
|
496
|
+
if snip_start_tag != snip_end_tag
|
497
|
+
" The tags are different so we can check to see whether the
|
498
|
+
" end tag comes before a start tag
|
499
|
+
let s:startMatch = match(s:line, '\V'.snip_start_tag, s:curCurs)
|
500
|
+
let s:endMatch = match(s:line, '\V'.snip_end_tag, s:curCurs)
|
501
|
+
|
502
|
+
if s:endMatch != -1 && ((s:endMatch < s:startMatch) || s:startMatch == -1)
|
503
|
+
" End has come before start so we're in a tag.
|
504
|
+
return 1
|
505
|
+
else
|
506
|
+
return 0
|
507
|
+
endif
|
508
|
+
else
|
509
|
+
" Start and end tags are the same so we need do tag counting to see
|
510
|
+
" whether we're in a tag.
|
511
|
+
let s:count = 0
|
512
|
+
let s:curSkip = s:curCurs
|
513
|
+
while match(strpart(s:line,s:curSkip),snip_start_tag) != -1
|
514
|
+
if match(strpart(s:line,s:curSkip),snip_start_tag) == 0
|
515
|
+
let s:curSkip = s:curSkip + 1
|
516
|
+
else
|
517
|
+
let s:curSkip = s:curSkip + 1 + match(strpart(s:line,s:curSkip),snip_start_tag)
|
518
|
+
endif
|
519
|
+
let s:count = s:count + 1
|
520
|
+
endwhile
|
521
|
+
if (s:count % 2) == 1
|
522
|
+
" Odd number of tags implies we're inside a tag.
|
523
|
+
return 1
|
524
|
+
else
|
525
|
+
" We're not inside a tag.
|
526
|
+
return 0
|
527
|
+
endif
|
528
|
+
endif
|
529
|
+
endfunction
|
530
|
+
"}}}
|
531
|
+
" {{{ SubSpecialVars(text)
|
532
|
+
function! s:SubSpecialVars(text)
|
533
|
+
let text = a:text
|
534
|
+
let text = substitute(text, 'SNIP_FILE_NAME', expand('%'), 'g')
|
535
|
+
let text = substitute(text, 'SNIP_ISO_DATE', strftime("%Y-%m-%d"), 'g')
|
536
|
+
return text
|
537
|
+
endfunction
|
538
|
+
" }}}
|
539
|
+
" {{{ SubCommandOutput(text)
|
540
|
+
function! s:SubCommandOutput(text)
|
541
|
+
let search = '``.\{-}``'
|
542
|
+
let text = a:text
|
543
|
+
while match(text, search) != -1
|
544
|
+
let command_match = matchstr(text, search)
|
545
|
+
"call s:Debug("SubCommandOutput", "Command found: ".command_match)
|
546
|
+
let command = substitute(command_match, '^..\(.*\)..$', '\1', '')
|
547
|
+
"call s:Debug("SubCommandOutput", "Command being run: ".command)
|
548
|
+
exec 'let output = '.command
|
549
|
+
let output = escape(output, '\')
|
550
|
+
let text = substitute(text, '\V'.escape(command_match, '\'), output, '')
|
551
|
+
endwhile
|
552
|
+
let text = substitute(text, '\\`\\`\(.\{-}\)\\`\\`','``\1``','g')
|
553
|
+
return text
|
554
|
+
endfunction
|
555
|
+
" }}}
|
556
|
+
" {{{ RemoveAndStoreCommands(text)
|
557
|
+
function! s:RemoveAndStoreCommands(text)
|
558
|
+
let [snip_start_tag, snip_elem_delim, snip_end_tag] = s:SetLocalTagVars()
|
559
|
+
|
560
|
+
let text = a:text
|
561
|
+
if !exists("b:command_dict")
|
562
|
+
let b:command_dict = {}
|
563
|
+
endif
|
564
|
+
|
565
|
+
let tmp_command_dict = {}
|
566
|
+
try
|
567
|
+
let ind = match(text, b:search_str)
|
568
|
+
catch /E55: Unmatched \\)/
|
569
|
+
call confirm("SnippetsEmu has caught an error while performing a search. This is most likely caused by setting the start and end tags to special characters. Try setting the 'fileencoding' of the file in which you defined them to 'utf-8'.\n\nThe plugin will be disabled for the remainder of this Vim session.")
|
570
|
+
let s:Disable = 1
|
571
|
+
return ''
|
572
|
+
endtry
|
573
|
+
while ind > -1
|
574
|
+
"call s:Debug("RemoveAndStoreCommands", "Text is: ".text)
|
575
|
+
"call s:Debug("RemoveAndStoreCommands", "index is: ".ind)
|
576
|
+
let tag = matchstr(text, b:search_str, ind)
|
577
|
+
"call s:Debug("RemoveAndStoreCommands", "Tag is: ".tag)
|
578
|
+
let commandToRun = matchstr(tag, snip_elem_delim.".*".snip_end_tag)
|
579
|
+
|
580
|
+
if commandToRun != ''
|
581
|
+
let tag_name = strpart(tag,strlen(snip_start_tag),match(tag,snip_elem_delim)-strlen(snip_start_tag))
|
582
|
+
"call s:Debug("RemoveAndStoreCommands", "Got this tag: ".tag_name)
|
583
|
+
"call s:Debug("RemoveAndStoreCommands", "Adding this command: ".commandToRun)
|
584
|
+
if tag_name != ''
|
585
|
+
if has_key(tmp_command_dict, tag_name)
|
586
|
+
call add(tmp_command_dict[tag_name], strpart(commandToRun, 1, strlen(commandToRun)-strlen(snip_end_tag)-1))
|
587
|
+
else
|
588
|
+
let tmp_command_dict[tag_name] = [strpart(commandToRun, 1, strlen(commandToRun)-strlen(snip_end_tag)-1)]
|
589
|
+
endif
|
590
|
+
endif
|
591
|
+
let text = substitute(text, '\V'.escape(commandToRun,'\'), snip_end_tag,'')
|
592
|
+
else
|
593
|
+
let tag_name = s:ChopTags(tag)
|
594
|
+
if tag_name != ''
|
595
|
+
if has_key(tmp_command_dict, tag_name)
|
596
|
+
call add(tmp_command_dict[tag_name], '')
|
597
|
+
else
|
598
|
+
let tmp_command_dict[tag_name] = ['']
|
599
|
+
endif
|
600
|
+
endif
|
601
|
+
endif
|
602
|
+
"call s:Debug("RemoveAndStoreCommands", "".tag." found at ".ind)
|
603
|
+
let ind = match(text, b:search_str, ind+strlen(snip_end_tag))
|
604
|
+
endwhile
|
605
|
+
|
606
|
+
for key in keys(tmp_command_dict)
|
607
|
+
if has_key(b:command_dict, key)
|
608
|
+
for item in reverse(tmp_command_dict[key])
|
609
|
+
call insert(b:command_dict[key], item)
|
610
|
+
endfor
|
611
|
+
else
|
612
|
+
let b:command_dict[key] = tmp_command_dict[key]
|
613
|
+
endif
|
614
|
+
endfor
|
615
|
+
return text
|
616
|
+
endfunction
|
617
|
+
" }}}
|
618
|
+
" {{{ ReturnKey() - Return our mapped key or Supertab key
|
619
|
+
function! s:ReturnKey()
|
620
|
+
if s:supInstalled
|
621
|
+
"call s:Debug('ReturnKey', 'Snippy: SuperTab installed. Returning <C-n> instead of <Tab>')
|
622
|
+
return "\<C-R>=".s:SupSNR."SuperTab('n')\<CR>"
|
623
|
+
else
|
624
|
+
" We need this hacky line as the one below doesn't seem to work.
|
625
|
+
" Patches welcome
|
626
|
+
exe "return \"".substitute(g:snippetsEmu_key, '^<', "\\\\<","")."\""
|
627
|
+
"return substitute(g:snippetsEmu_key, '^<', "\\<","")
|
628
|
+
endif
|
629
|
+
endfunction
|
630
|
+
" }}}
|
631
|
+
" {{{ Jumper()
|
632
|
+
" We need to rewrite this function to reflect the new behaviour. Every jump
|
633
|
+
" will now delete the markers so we need to allow for the following conditions
|
634
|
+
" 1. Empty tags e.g. "<{}>". When we land inside then we delete the tags.
|
635
|
+
" "<{:}>" is now an invalid tag (use "<{}>" instead) so we don't need to check for
|
636
|
+
" this
|
637
|
+
" 2. Tag with variable name. Save the variable name for the next jump.
|
638
|
+
" 3. Tag with command. Tags no longer have default values. Everything after the
|
639
|
+
" centre delimiter until the end tag is assumed to be a command.
|
640
|
+
"
|
641
|
+
" Jumper is performed when we want to perform a jump. If we've landed in a
|
642
|
+
" 1. style tag then we'll be in free form text and just want to jump to the
|
643
|
+
" next tag. If we're in a 2. or 3. style tag then we need to look for whether
|
644
|
+
" the value has changed and make all the replacements. If we're in a 3.
|
645
|
+
" style tag then we need to replace all the occurrences with their command
|
646
|
+
" modified values.
|
647
|
+
"
|
648
|
+
function! <SID>Jumper()
|
649
|
+
if s:Disable == 1
|
650
|
+
return substitute(g:snippetsEmu_key, '^<', "\\<",'')
|
651
|
+
endif
|
652
|
+
let [snip_start_tag, snip_elem_delim, snip_end_tag] = s:SetLocalTagVars()
|
653
|
+
|
654
|
+
" Set up some mapping in case we got called before Supertab
|
655
|
+
if s:supInstalled == 1 && s:done_remap != 1
|
656
|
+
call s:SetupSupertab()
|
657
|
+
call s:SnipMapKeys()
|
658
|
+
endif
|
659
|
+
|
660
|
+
if !exists('b:search_str') && exists('g:search_str')
|
661
|
+
let b:search_str = g:search_str
|
662
|
+
endif
|
663
|
+
|
664
|
+
if !exists('b:search_str')
|
665
|
+
return s:ReturnKey()
|
666
|
+
endif
|
667
|
+
|
668
|
+
let s:curCurs = col(".") - 1
|
669
|
+
let s:curLine = line(".")
|
670
|
+
let s:line = getline(".")
|
671
|
+
let s:replaceVal = ""
|
672
|
+
|
673
|
+
" First we'll check that the user hasn't just typed a snippet to expand
|
674
|
+
let origword = matchstr(strpart(getline("."), 0, s:curCurs), '\(^\|\s\)\S\{-}$')
|
675
|
+
let origword = substitute(origword, '\s', "", "")
|
676
|
+
"call s:Debug("Jumper", "Original word was: ".origword)
|
677
|
+
let word = s:Hash(origword)
|
678
|
+
" The following code is lifted from the imaps.vim script - Many
|
679
|
+
" thanks for the inspiration to add the TextMate compatibility
|
680
|
+
let rhs = ''
|
681
|
+
let found = 0
|
682
|
+
" Check for buffer specific expansions
|
683
|
+
if exists('b:trigger_'.word)
|
684
|
+
exe 'let rhs = b:trigger_'.word
|
685
|
+
let found = 1
|
686
|
+
elseif exists('g:trigger_'.word)
|
687
|
+
" also check for global definitions
|
688
|
+
exe 'let rhs = g:trigger_'.word
|
689
|
+
let found = 1
|
690
|
+
endif
|
691
|
+
|
692
|
+
if found == 0
|
693
|
+
" Check using keyword boundary
|
694
|
+
let origword = matchstr(strpart(getline("."), 0, s:curCurs), '\k\{-}$')
|
695
|
+
"call s:Debug("Jumper", "Original word was: ".origword)
|
696
|
+
let word = s:Hash(origword)
|
697
|
+
if exists('b:trigger_'.word)
|
698
|
+
exe 'let rhs = b:trigger_'.word
|
699
|
+
elseif exists('g:trigger_'.word)
|
700
|
+
" also check for global definitions
|
701
|
+
exe 'let rhs = g:trigger_'.word
|
702
|
+
endif
|
703
|
+
endif
|
704
|
+
|
705
|
+
if rhs != ''
|
706
|
+
" Save the value of hlsearch
|
707
|
+
if &hls
|
708
|
+
"call s:Debug("Jumper", "Hlsearch set")
|
709
|
+
setlocal nohlsearch
|
710
|
+
let b:hl_on = 1
|
711
|
+
else
|
712
|
+
"call s:Debug("Jumper", "Hlsearch not set")
|
713
|
+
let b:hl_on = 0
|
714
|
+
endif
|
715
|
+
" Save the last search value
|
716
|
+
let b:search_sav = @/
|
717
|
+
" Count the number of lines in the rhs
|
718
|
+
let move_up = ""
|
719
|
+
if len(split(rhs, "\<CR>")) - 1 != 0
|
720
|
+
let move_up = len(split(rhs, "\<CR>")) - 1
|
721
|
+
let move_up = move_up."\<Up>"
|
722
|
+
endif
|
723
|
+
|
724
|
+
" If this is a mapping, then erase the previous part of the map
|
725
|
+
" by returning a number of backspaces.
|
726
|
+
let bkspc = substitute(origword, '.', "\<BS>", "g")
|
727
|
+
"call s:Debug("Jumper", "Backspacing ".s:StrLen(origword)." characters")
|
728
|
+
let delEndTag = ""
|
729
|
+
if s:CheckForInTag()
|
730
|
+
"call s:Debug("Jumper", "We're doing a nested tag")
|
731
|
+
"call s:Debug("Jumper", "B:tag_name: ".b:tag_name)
|
732
|
+
if b:tag_name != ''
|
733
|
+
try
|
734
|
+
"call s:Debug("Jumper", "Commands for this tag are currently: ".join(b:command_dict[b:tag_name],"', '"))
|
735
|
+
"call s:Debug("Jumper", "Removing command for '".b:tag_name."'")
|
736
|
+
unlet b:command_dict[b:tag_name][0]
|
737
|
+
"call s:Debug("Jumper", "Commands for this tag are now: ".join(b:command_dict[b:tag_name],"', '"))
|
738
|
+
catch /E175/
|
739
|
+
"call s:Debug("Jumper", "Could not find this key in the dict: ".b:tag_name)
|
740
|
+
endtry
|
741
|
+
endif
|
742
|
+
"call s:Debug("Jumper", "Deleting start tag")
|
743
|
+
let bkspc = bkspc.substitute(snip_start_tag, '.', "\<BS>", "g")
|
744
|
+
"call s:Debug("Jumper", "Deleting end tag")
|
745
|
+
let delEndTag = substitute(snip_end_tag, '.', "\<Del>", "g")
|
746
|
+
"call s:Debug("Jumper", "Deleting ".s:StrLen(delEndTag)." characters")
|
747
|
+
endif
|
748
|
+
|
749
|
+
" We've found a mapping so we'll substitute special variables
|
750
|
+
let rhs = s:SubSpecialVars(rhs)
|
751
|
+
let rhs = s:SubCommandOutput(rhs)
|
752
|
+
" Now we'll chop out the commands from tags
|
753
|
+
let rhs = s:RemoveAndStoreCommands(rhs)
|
754
|
+
if s:Disable == 1
|
755
|
+
return substitute(g:snippetsEmu_key, '^<', "\\<",'')
|
756
|
+
endif
|
757
|
+
|
758
|
+
" Save the value of 'backspace'
|
759
|
+
let bs_save = &backspace
|
760
|
+
set backspace=indent,eol,start
|
761
|
+
return bkspc.delEndTag.rhs."\<Esc>".move_up."^:set backspace=".bs_save."\<CR>a\<C-r>=<SNR>".s:SID()."_NextHop()\<CR>"
|
762
|
+
else
|
763
|
+
" No definition so let's check to see whether we're in a tag
|
764
|
+
if s:CheckForInTag()
|
765
|
+
"call s:Debug("Jumper", "No mapping and we're in a tag")
|
766
|
+
" We're in a tag so we need to do processing
|
767
|
+
if strpart(s:line, s:curCurs - strlen(snip_start_tag), strlen(snip_start_tag)) == snip_start_tag
|
768
|
+
"call s:Debug("Jumper", "Value not changed")
|
769
|
+
call s:ChangeVals(0)
|
770
|
+
else
|
771
|
+
"call s:Debug("Jumper", "Value changed")
|
772
|
+
call s:ChangeVals(1)
|
773
|
+
endif
|
774
|
+
return "\<C-r>=<SNR>".s:SID()."_NextHop()\<CR>"
|
775
|
+
else
|
776
|
+
" We're not in a tag so we'll see whether there are more tags
|
777
|
+
if search(b:search_str, "n")
|
778
|
+
" More tags so let's perform nexthop
|
779
|
+
let s:replaceVal = ""
|
780
|
+
return "\<C-r>=<SNR>".s:SID()."_NextHop()\<CR>"
|
781
|
+
else
|
782
|
+
" No more tags so let's return a Tab after restoring hlsearch and @/
|
783
|
+
call s:RestoreSearch()
|
784
|
+
if exists("b:command_dict")
|
785
|
+
unlet b:command_dict
|
786
|
+
endif
|
787
|
+
return s:ReturnKey()
|
788
|
+
endif
|
789
|
+
endif
|
790
|
+
endif
|
791
|
+
endfunction
|
792
|
+
" }}}
|
793
|
+
"{{{ ListSnippets() - Return a list of snippets - used for command completion
|
794
|
+
function! s:ListSnippets(ArgLead, CmdLine, CursorPos, scope)
|
795
|
+
" Only allow completion for the second argument
|
796
|
+
" TODO
|
797
|
+
return sort(map(map(filter(keys(a:scope), 'v:val =~ "^trigger_'.a:ArgLead.'"'), 'v:val[8:]'), 's:UnHash(v:val)'))
|
798
|
+
endfunction
|
799
|
+
|
800
|
+
function! s:ListBufferSnippets(ArgLead, CmdLine, CursorPos)
|
801
|
+
return s:ListSnippets(a:ArgLead, a:CmdLine, a:CursorPos, b:)
|
802
|
+
endfunction
|
803
|
+
|
804
|
+
function! s:ListGlobalSnippets(ArgLead, CmdLine, CursorPos)
|
805
|
+
return s:ListSnippets(a:ArgLead, a:CmdLine, a:CursorPos, g:)
|
806
|
+
endfunction
|
807
|
+
" }}}
|
808
|
+
" {{{ DelSnippet() - Delete a snippet
|
809
|
+
function! s:DelSnippet(snippet, scope)
|
810
|
+
if a:snippet != ""
|
811
|
+
try
|
812
|
+
exec "unlet ".a:scope."trigger_".s:Hash(a:snippet)
|
813
|
+
catch /E108: No such variable:/
|
814
|
+
echom "Snippet '".a:snippet."' does not exist."
|
815
|
+
endtry
|
816
|
+
endif
|
817
|
+
endfunction
|
818
|
+
" }}}
|
819
|
+
" {{{ Set up the 'Iabbr' and 'Snippet' commands
|
820
|
+
"command! -nargs=+ Iabbr execute s:SetCom(<q-args>)
|
821
|
+
"command! -nargs=+ Snippet execute s:SetCom("<buffer> ".<q-args>)
|
822
|
+
command! -complete=customlist,s:ListGlobalSnippets -nargs=*
|
823
|
+
\ Iabbr call <SID>SetCom(<q-args>, "g:")
|
824
|
+
command! -complete=customlist,s:ListBufferSnippets -nargs=*
|
825
|
+
\ Snippet call <SID>SetCom(<q-args>, "b:")
|
826
|
+
command! -range CreateSnippet <line1>,<line2>call s:CreateSnippet()
|
827
|
+
command! -range CreateBundleSnippet <line1>,<line2>call s:CreateBundleSnippet()
|
828
|
+
command! -complete=customlist,s:ListBufferSnippets -nargs=*
|
829
|
+
\ DelSnippet call <SID>DelSnippet(<q-args>, "b:")
|
830
|
+
command! -complete=customlist,s:ListGlobalSnippets -nargs=*
|
831
|
+
\ DelIabbr call <SID>DelSnippet(<q-args>, "g:")
|
832
|
+
"}}}
|
833
|
+
" {{{ Utility functions
|
834
|
+
|
835
|
+
" This function will convert the selected range into a snippet
|
836
|
+
function! s:CreateSnippet() range
|
837
|
+
let [snip_start_tag, snip_elem_delim, snip_end_tag] = s:SetLocalTagVars()
|
838
|
+
let snip = ""
|
839
|
+
if &expandtab
|
840
|
+
let tabs = indent(a:firstline)/&shiftwidth
|
841
|
+
let tabstr = repeat(' ',&shiftwidth)
|
842
|
+
else
|
843
|
+
let tabs = indent(a:firstline)/&tabstop
|
844
|
+
let tabstr = '\t'
|
845
|
+
endif
|
846
|
+
let tab_text = repeat(tabstr,tabs)
|
847
|
+
|
848
|
+
for i in range(a:firstline, a:lastline)
|
849
|
+
"First chop off the indent
|
850
|
+
let text = substitute(getline(i),tab_text,'','')
|
851
|
+
"Now replace 'tabs' with <Tab>s
|
852
|
+
let text = substitute(text, tabstr, '<Tab>','g')
|
853
|
+
"And trim the newlines
|
854
|
+
let text = substitute(text, "\r", '','g')
|
855
|
+
let snip = snip.text.'<CR>'
|
856
|
+
endfor
|
857
|
+
let tag = snip_start_tag.snip_end_tag
|
858
|
+
let split_sav = &swb
|
859
|
+
set swb=useopen
|
860
|
+
if bufexists("Snippets")
|
861
|
+
belowright sb Snippets
|
862
|
+
else
|
863
|
+
belowright sp Snippets
|
864
|
+
endif
|
865
|
+
resize 8
|
866
|
+
setlocal buftype=nofile
|
867
|
+
setlocal bufhidden=hide
|
868
|
+
setlocal noswapfile
|
869
|
+
let @"=tag
|
870
|
+
exe 'set swb='.split_sav
|
871
|
+
let trig = inputdialog("Please enter the trigger word for your snippet: ", "My_snippet")
|
872
|
+
if trig == ""
|
873
|
+
let trig = "YOUR_SNIPPET_NAME_HERE"
|
874
|
+
endif
|
875
|
+
call append("$", "Snippet ".trig." ".snip)
|
876
|
+
if getline(1) == ""
|
877
|
+
1 delete _
|
878
|
+
endif
|
879
|
+
call cursor(line('$'),1)
|
880
|
+
endfunction
|
881
|
+
|
882
|
+
" This function will convert the selected range into a snippet suitable for
|
883
|
+
" including in a bundle.
|
884
|
+
function! s:CreateBundleSnippet() range
|
885
|
+
let [snip_start_tag, snip_elem_delim, snip_end_tag] = s:SetLocalTagVars()
|
886
|
+
let snip = ""
|
887
|
+
if &expandtab
|
888
|
+
let tabs = indent(a:firstline)/&shiftwidth
|
889
|
+
let tabstr = repeat(' ',&shiftwidth)
|
890
|
+
else
|
891
|
+
let tabs = indent(a:firstline)/&tabstop
|
892
|
+
let tabstr = '\t'
|
893
|
+
endif
|
894
|
+
let tab_text = repeat(tabstr,tabs)
|
895
|
+
|
896
|
+
for i in range(a:firstline, a:lastline)
|
897
|
+
let text = substitute(getline(i),tab_text,'','')
|
898
|
+
let text = substitute(text, tabstr, '<Tab>','g')
|
899
|
+
let text = substitute(text, "\r$", '','g')
|
900
|
+
let text = substitute(text, '"', '\\"','g')
|
901
|
+
let text = substitute(text, '|', '<Bar>','g')
|
902
|
+
let snip = snip.text.'<CR>'
|
903
|
+
endfor
|
904
|
+
let tag = '".st.et."'
|
905
|
+
let split_sav = &swb
|
906
|
+
set swb=useopen
|
907
|
+
if bufexists("Snippets")
|
908
|
+
belowright sb Snippets
|
909
|
+
else
|
910
|
+
belowright sp Snippets
|
911
|
+
endif
|
912
|
+
resize 8
|
913
|
+
setlocal buftype=nofile
|
914
|
+
setlocal bufhidden=hide
|
915
|
+
setlocal noswapfile
|
916
|
+
let @"=tag
|
917
|
+
exe 'set swb='.split_sav
|
918
|
+
let trig = inputdialog("Please enter the trigger word for your snippet: ", "My_snippet")
|
919
|
+
if trig == ""
|
920
|
+
let trig = "YOUR_SNIPPET_NAME_HERE"
|
921
|
+
endif
|
922
|
+
call append("$", 'exe "Snippet '.trig." ".snip.'"')
|
923
|
+
if getline(1) == ""
|
924
|
+
1 delete _
|
925
|
+
endif
|
926
|
+
call cursor(line('$'),1)
|
927
|
+
endfunction
|
928
|
+
|
929
|
+
" This function will just return what's passed to it unless a change has been
|
930
|
+
" made
|
931
|
+
fun! D(text)
|
932
|
+
if exists('s:CHANGED_VAL') && s:CHANGED_VAL == 1
|
933
|
+
return @z
|
934
|
+
else
|
935
|
+
return a:text
|
936
|
+
endif
|
937
|
+
endfun
|
938
|
+
|
939
|
+
" s:Hash allows the use of special characters in snippets
|
940
|
+
" This function is lifted straight from the imaps.vim plugin. Please let me know
|
941
|
+
" if this is against licensing.
|
942
|
+
function! s:Hash(text)
|
943
|
+
return substitute(a:text, '\([^[:alnum:]]\)',
|
944
|
+
\ '\="_".char2nr(submatch(1))."_"', 'g')
|
945
|
+
endfunction
|
946
|
+
|
947
|
+
" s:UnHash allows the use of special characters in snippets
|
948
|
+
" This function is lifted straight from the imaps.vim plugin. Please let me know
|
949
|
+
" if this is against licensing.
|
950
|
+
function! s:UnHash(text)
|
951
|
+
return substitute(a:text, '_\(\d\+\)_',
|
952
|
+
\ '\=nr2char(submatch(1))', 'g')
|
953
|
+
endfunction
|
954
|
+
|
955
|
+
" This function chops tags from any text passed to it
|
956
|
+
function! s:ChopTags(text)
|
957
|
+
let text = a:text
|
958
|
+
"call s:Debug("ChopTags", "ChopTags was passed this text: ".text)
|
959
|
+
let [snip_start_tag, snip_elem_delim, snip_end_tag] = s:SetLocalTagVars()
|
960
|
+
let text = strpart(text, strlen(snip_start_tag))
|
961
|
+
let text = strpart(text, 0, strlen(text)-strlen(snip_end_tag))
|
962
|
+
"call s:Debug("ChopTags", "ChopTags is returning this text: ".text)
|
963
|
+
return text
|
964
|
+
endfunction
|
965
|
+
|
966
|
+
" This function ensures we measure string lengths correctly
|
967
|
+
function! s:StrLen(str)
|
968
|
+
"call s:Debug("StrLen", "StrLen returned: ".strlen(substitute(a:str, '.', 'x', 'g'))." based on this text: ".a:str)
|
969
|
+
return strlen(substitute(a:str, '.', 'x', 'g'))
|
970
|
+
endfunction
|
971
|
+
|
972
|
+
" }}}
|
973
|
+
" vim: set tw=80 sw=2 sts=2 et foldmethod=marker :
|