Skip to content

Commit f22f4f0

Browse files
committed
Unify buffer setup
1 parent 84ff696 commit f22f4f0

File tree

2 files changed

+18
-35
lines changed

2 files changed

+18
-35
lines changed

autoload/rails.vim

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ endfunction
11331133
function! s:RefreshBuffer()
11341134
if exists("b:rails_refresh") && b:rails_refresh
11351135
let b:rails_refresh = 0
1136-
call rails#buffer_init()
1136+
call rails#buffer_setup()
11371137
let &filetype = &filetype
11381138
unlet! b:rails_refresh
11391139
endif
@@ -1566,7 +1566,7 @@ function! s:Preview(bang, lnum, uri) abort
15661566
setlocal filetype=xhtml
15671567
endif
15681568
endif
1569-
call rails#buffer_init()
1569+
call rails#buffer_setup()
15701570
map <buffer> <silent> q :bwipe<CR>
15711571
wincmd p
15721572
if !a:bang
@@ -4431,24 +4431,6 @@ endfunction
44314431
" }}}1
44324432
" Detection {{{1
44334433

4434-
function! rails#buffer_init()
4435-
let app = rails#app()
4436-
let buffer = rails#buffer()
4437-
" Apparently rails#buffer().calculate_file_type() can be slow if the
4438-
" underlying file system is slow (even though it doesn't really do anything
4439-
" IO related). This caching is a temporary hack; if it doesn't cause
4440-
" problems it should probably be refactored.
4441-
let b:rails_cached_file_type = buffer.calculate_file_type()
4442-
call s:BufCommands()
4443-
if !empty(findfile('macros/rails.vim', escape(&runtimepath, ' ')))
4444-
runtime! macros/rails.vim
4445-
endif
4446-
silent doautocmd User Rails
4447-
call s:BufProjectionCommands()
4448-
call s:BufAbbreviations()
4449-
return b:rails_root
4450-
endfunction
4451-
44524434
function! s:SetBasePath() abort
44534435
let self = rails#buffer()
44544436
if self.app().path() =~ '://'
@@ -4488,13 +4470,21 @@ function! s:SetBasePath() abort
44884470
call self.setvar('&path',(add_dot ? '.,' : '').s:pathjoin(s:uniq(path + [self.app().path()] + old_path + engine_paths)))
44894471
endfunction
44904472

4491-
function! rails#buffer_settings()
4473+
function! rails#buffer_setup() abort
44924474
if !exists('b:rails_root')
44934475
return ''
44944476
endif
44954477
let self = rails#buffer()
4496-
call s:SetBasePath()
4478+
let b:rails_cached_file_type = self.calculate_file_type()
44974479
call s:BufMappings()
4480+
call s:BufCommands()
4481+
if !empty(findfile('macros/rails.vim', escape(&runtimepath, ' ')))
4482+
runtime! macros/rails.vim
4483+
endif
4484+
silent doautocmd User Rails
4485+
call s:BufProjectionCommands()
4486+
call s:BufAbbreviations()
4487+
call s:SetBasePath()
44984488
let rp = s:gsub(self.app().path(),'[ ,]','\\&')
44994489
if stridx(&tags,rp.'/tags') == -1
45004490
let &l:tags = rp . '/tags,' . rp . '/tmp/tags,' . &tags

plugin/rails.vim

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,6 @@ function! RailsDetect(...) abort
5252
return 0
5353
endfunction
5454

55-
function! s:Activate(filename) abort
56-
if RailsDetect(a:filename)
57-
call rails#buffer_init()
58-
return 1
59-
endif
60-
endfunction
61-
6255
" }}}1
6356
" Initialization {{{1
6457

@@ -72,19 +65,19 @@ augroup railsPluginDetect
7265
autocmd BufLeave * if exists("b:rails_root")|silent doau User BufLeaveRails|endif
7366

7467
autocmd BufNewFile,BufReadPost *
75-
\ if s:Activate(expand("<afile>:p")) && empty(&filetype) |
76-
\ call rails#buffer_settings() |
68+
\ if RailsDetect(expand("<afile>:p")) && empty(&filetype) |
69+
\ call rails#buffer_setup() |
7770
\ endif
7871
autocmd VimEnter *
79-
\ if empty(expand("<amatch>")) && s:Activate(getcwd()) |
80-
\ call rails#buffer_settings() |
72+
\ if empty(expand("<amatch>")) && RailsDetect(getcwd()) |
73+
\ call rails#buffer_setup() |
8174
\ silent doau User BufEnterRails |
8275
\ endif
8376
autocmd FileType netrw
84-
\ if s:Activate(expand("%:p")) |
77+
\ if RailsDetect() |
8578
\ silent doau User BufEnterRails |
8679
\ endif
87-
autocmd FileType * if RailsDetect() | call rails#buffer_settings() | endif
80+
autocmd FileType * if RailsDetect() | call rails#buffer_setup() | endif
8881

8982
autocmd BufNewFile,BufReadPost *.yml.example set filetype=yaml
9083
autocmd BufNewFile,BufReadPost *.rjs,*.rxml,*.builder,*.jbuilder,*.ruby

0 commit comments

Comments
 (0)