Skip to content

Commit 0195ff0

Browse files
committed
Teach buffer().last_format() about views
1 parent b6276ba commit 0195ff0

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

autoload/rails.vim

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,14 @@ function! s:lastmethod(...)
261261
endfunction
262262

263263
function! s:readable_last_format(start) dict abort
264+
if self.type_name('view')
265+
let format = fnamemodify(self.path(),':r:e')
266+
if format == ''
267+
return get({'rhtml': 'html', 'rxml': 'xml', 'rjs': 'js', 'haml': 'html'},fnamemodify(self.path(),':e'),'')
268+
else
269+
return format
270+
endif
271+
endif
264272
let rline = self.last_opening_line(a:start,'\C^\s*\%(mail\>.*\|respond_to\)\s*\%(\<do\|{\)\s*|\zs\h\k*\ze|',self.last_method_line(a:start))
265273
if rline
266274
let variable = matchstr(self.getline(rline),'\C^\s*\%(mail\>.*\|respond_to\)\s*\%(\<do\|{\)\s*|\zs\h\k*\ze|')
@@ -281,15 +289,8 @@ function! s:lastformat(start)
281289
endfunction
282290

283291
function! s:format(...)
284-
if RailsFileType() =~ '^view\>'
285-
let format = fnamemodify(RailsFilePath(),':r:e')
286-
else
287-
let format = rails#buffer().last_format(a:0 > 1 ? a:2 : line("."))
288-
endif
289-
if format == ''
290-
return get({'rhtml': 'html', 'rxml': 'xml', 'rjs': 'js'},fnamemodify(RailsFilePath(),':e'),a:0 ? a:1 : '')
291-
endif
292-
return format
292+
let format = rails#buffer().last_format(a:0 > 1 ? a:2 : line("."))
293+
return format ==# '' && a:0 ? a:1 : format
293294
endfunction
294295

295296
call s:add_methods('readable',['end_of','last_opening_line','last_method_line','last_method','last_format','define_pattern'])

0 commit comments

Comments
 (0)