diff options
author | Teddy Wing | 2018-03-05 21:01:11 +0100 |
---|---|---|
committer | Teddy Wing | 2018-03-05 21:01:11 +0100 |
commit | dc9a0e2b3c39f1287cf8aae6eea098629778f370 (patch) | |
tree | 63ac1fc8cf5a0e4859c9a81e021ffc856b3cbad9 | |
parent | 1bb1fe8927ad8df734adaf89cee0c95b04a396eb (diff) | |
download | vim-rails-locale-alternate-dc9a0e2b3c39f1287cf8aae6eea098629778f370.tar.bz2 |
Move functions to `autoload`
Improve startup performance and be a good Vim plugin citizen.
-rw-r--r-- | autoload/rails_locale_alternate.vim | 18 | ||||
-rw-r--r-- | plugin/rails_locale_alternate.vim | 21 |
2 files changed, 19 insertions, 20 deletions
diff --git a/autoload/rails_locale_alternate.vim b/autoload/rails_locale_alternate.vim new file mode 100644 index 0000000..bf33b89 --- /dev/null +++ b/autoload/rails_locale_alternate.vim @@ -0,0 +1,18 @@ +function! s:AlternateLocale(key) + let filename = expand('%') + let alternate = substitute(filename, '\a\{2}\.yml', a:key . '.yml', '') + return alternate +endfunction + + +function! s:SplitAlternate(key, modifiers) + execute a:modifiers . ' split ' . s:AlternateLocale(a:key) +endfunction + + +function! rails_locale_alternate#CreateCommands() + command! -buffer -nargs=1 RailsLocaleAlternate :call s:SplitAlternate(<q-args>, <q-mods>) + command! -buffer -nargs=1 ERailsLocaleAlternate :execute 'edit ' . s:AlternateLocale(<q-args>) + command! -buffer -nargs=1 SRailsLocaleAlternate :call s:SplitAlternate(<q-args>, '') + command! -buffer -nargs=1 VRailsLocaleAlternate :call s:SplitAlternate(<q-args>, 'vertical') +endfunction diff --git a/plugin/rails_locale_alternate.vim b/plugin/rails_locale_alternate.vim index b0a82f0..4d161e3 100644 --- a/plugin/rails_locale_alternate.vim +++ b/plugin/rails_locale_alternate.vim @@ -1,24 +1,5 @@ -function! s:AlternateLocale(key) - let filename = expand('%') - let alternate = substitute(filename, '\a\{2}\.yml', a:key . '.yml', '') - return alternate -endfunction - - -function! s:SplitAlternate(key, modifiers) - execute a:modifiers . ' split ' . s:AlternateLocale(a:key) -endfunction - - -function! s:CreateCommands() - command! -buffer -nargs=1 RailsLocaleAlternate :call s:SplitAlternate(<q-args>, <q-mods>) - command! -buffer -nargs=1 ERailsLocaleAlternate :execute 'edit ' . s:AlternateLocale(<q-args>) - command! -buffer -nargs=1 SRailsLocaleAlternate :call s:SplitAlternate(<q-args>, '') - command! -buffer -nargs=1 VRailsLocaleAlternate :call s:SplitAlternate(<q-args>, 'vertical') -endfunction - augroup rails_locale_alternate autocmd! - autocmd BufNewFile,BufRead config/locales/*.\a\a.yml call s:CreateCommands() + autocmd BufNewFile,BufRead config/locales/*.\a\a.yml call rails_locale_alternate#CreateCommands() augroup END |