Skip to content

Commit a921241

Browse files
committed
Slightly better names for cfile helper functions
1 parent 1f1c9a5 commit a921241

File tree

1 file changed

+55
-55
lines changed

1 file changed

+55
-55
lines changed

autoload/rails.vim

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,7 +2248,7 @@ function! s:Complete_cd(ArgLead, CmdLine, CursorPos) abort
22482248
return filter(all,'s:startswith(v:val,a:ArgLead)')
22492249
endfunction
22502250

2251-
function! s:matchcursor(pat)
2251+
function! s:match_cursor(pat) abort
22522252
let line = getline(".")
22532253
let lastend = 0
22542254
while lastend >= 0
@@ -2262,16 +2262,16 @@ function! s:matchcursor(pat)
22622262
return ""
22632263
endfunction
22642264

2265-
function! s:findit(pat,repl)
2266-
let res = s:matchcursor(a:pat)
2265+
function! s:match_it(pat, repl) abort
2266+
let res = s:match_cursor(a:pat)
22672267
if res != ""
22682268
return substitute(res,'\C'.a:pat,a:repl,'')
22692269
else
22702270
return ""
22712271
endif
22722272
endfunction
22732273

2274-
function! s:findamethod(func, ...) abort
2274+
function! s:match_method(func, ...) abort
22752275
let l = ''
22762276
let r = ''
22772277
if &filetype =~# '\<eruby\>'
@@ -2280,16 +2280,16 @@ function! s:findamethod(func, ...) abort
22802280
elseif &filetype =~# '\<haml\>'
22812281
let l = '\s*[=-]'
22822282
endif
2283-
let result = s:findit(l.'\s*\<\%('.a:func.'\)\s*(\=\s*\(:\=[''"@]\=\f\+\)\>[''"]\='.r, '\1')
2283+
let result = s:match_it(l.'\s*\<\%('.a:func.'\)\s*(\=\s*\(:\=[''"@]\=\f\+\)\>[''"]\='.r, '\1')
22842284
return a:0 ? result : substitute(result, '^:\=[''"@]\=', '', '')
22852285
endfunction
22862286

2287-
function! s:findasymbol(sym) abort
2288-
return s:findit('\s*\%(:\%('.a:sym.'\)\s*=>\|\<'.a:sym.':\)\s*(\=\s*[@:'."'".'"]\(\f\+\)\>.\=', '\1')
2287+
function! s:match_symbol(sym) abort
2288+
return s:match_it('\s*\%(:\%('.a:sym.'\)\s*=>\|\<'.a:sym.':\)\s*(\=\s*[@:'."'".'"]\(\f\+\)\>.\=', '\1')
22892289
endfunction
22902290

2291-
function! s:findapartial(func) abort
2292-
let res = s:findamethod(a:func, '\1', 1)
2291+
function! s:match_partial(func) abort
2292+
let res = s:match_method(a:func, '\1', 1)
22932293
if empty(res)
22942294
return ''
22952295
elseif res =~# '^\w\+\%(\.\w\+\)\=$'
@@ -2403,22 +2403,22 @@ function! s:sprockets_cfile() abort
24032403

24042404
let asset = ''
24052405
let sssuf = s:suffixes('stylesheets')
2406-
let res = s:findit('\%(^\s*[[:alnum:]-]\+:\s\+\)\=\<[[:alnum:]-]\+-\%(path\|url\)(["'']\=\([^"''() ]*\)', '\1')
2406+
let res = s:match_it('\%(^\s*[[:alnum:]-]\+:\s\+\)\=\<[[:alnum:]-]\+-\%(path\|url\)(["'']\=\([^"''() ]*\)', '\1')
24072407
if !empty(res)
24082408
let asset = s:resolve_asset(path, res)
24092409
endif
2410-
let res = s:findit('\%(^\s*[[:alnum:]-]\+:\s\+\)\=\<stylesheet-\%(path\|url\)(["'']\=\([^"''() ]*\)', '\1')
2410+
let res = s:match_it('\%(^\s*[[:alnum:]-]\+:\s\+\)\=\<stylesheet-\%(path\|url\)(["'']\=\([^"''() ]*\)', '\1')
24112411
if !empty(res)
24122412
let asset = s:resolve_asset(path, res, sssuf)
24132413
endif
2414-
let res = s:findit('\%(^\s*[[:alnum:]-]\+:\s\+\)\=\<javascript-\%(path\|url\)(["'']\=\([^"''() ]*\)', '\1')
2414+
let res = s:match_it('\%(^\s*[[:alnum:]-]\+:\s\+\)\=\<javascript-\%(path\|url\)(["'']\=\([^"''() ]*\)', '\1')
24152415
if !empty(res)
24162416
let asset = s:resolve_asset(path, res, s:suffixes('javascripts'))
24172417
endif
24182418
if !empty(asset)
24192419
return asset
24202420
endif
2421-
let res = s:findit('^\s*@import\s*\%(url(\)\=["'']\=\([^"''() ]*\)', '\1')
2421+
let res = s:match_it('^\s*@import\s*\%(url(\)\=["'']\=\([^"''() ]*\)', '\1')
24222422
if !empty(res)
24232423
let base = expand('%:p:h')
24242424
let rel = s:sub(res, '\ze[^/]*$', '_')
@@ -2438,7 +2438,7 @@ function! s:sprockets_cfile() abort
24382438
endif
24392439
endif
24402440

2441-
let res = s:findit('^\s*\%(//\|[*#]\)=\s*\%(link\|require\|depend_on\|stub\)\w*\s*["'']\=\([^"'' ]*\)', '\1')
2441+
let res = s:match_it('^\s*\%(//\|[*#]\)=\s*\%(link\|require\|depend_on\|stub\)\w*\s*["'']\=\([^"'' ]*\)', '\1')
24422442
if !empty(res) && exists('l:dir')
24432443
let asset = s:resolve_asset(path, res, dir)
24442444
return empty(asset) ? res : asset
@@ -2462,143 +2462,143 @@ endfunction
24622462
function! s:ruby_cfile() abort
24632463
let buffer = rails#buffer()
24642464

2465-
let res = s:findit('\v\s*<require\s*\(=\s*File.expand_path\([''"]../(\f+)[''"],\s*__FILE__\s*\)',expand('%:p:h').'/\1')
2465+
let res = s:match_it('\v\s*<require\s*\(=\s*File.expand_path\([''"]../(\f+)[''"],\s*__FILE__\s*\)',expand('%:p:h').'/\1')
24662466
if len(res)|return s:simplify(res.(res !~ '\.[^\/.]\+$' ? '.rb' : ''))|endif
24672467

2468-
let res = s:findit('\v<File.expand_path\([''"]../(\f+)[''"],\s*__FILE__\s*\)',expand('%:p:h').'/\1')
2468+
let res = s:match_it('\v<File.expand_path\([''"]../(\f+)[''"],\s*__FILE__\s*\)',expand('%:p:h').'/\1')
24692469
if len(res)|return s:simplify(res)|endif
24702470

2471-
let res = s:findit('\v\s*<require\s*\(=\s*File.dirname\(__FILE__\)\s*\+\s*[:''"](\f+)>.=',expand('%:p:h').'/\1')
2471+
let res = s:match_it('\v\s*<require\s*\(=\s*File.dirname\(__FILE__\)\s*\+\s*[:''"](\f+)>.=',expand('%:p:h').'/\1')
24722472
if len(res)|return s:simplify(res.(res !~ '\.[^\/.]\+$' ? '.rb' : ''))|endif
24732473

2474-
let res = s:findit('\v<File.dirname\(__FILE__\)\s*\+\s*[:''"](\f+)>[''"]=',expand('%:p:h').'\1')
2474+
let res = s:match_it('\v<File.dirname\(__FILE__\)\s*\+\s*[:''"](\f+)>[''"]=',expand('%:p:h').'\1')
24752475
if len(res)|return s:simplify(res)|endif
24762476

2477-
let res = s:findit('\v\s*<%(include|extend)\(=\s*<([[:alnum:]_:]+)>','\1')
2477+
let res = s:match_it('\v\s*<%(include|extend)\(=\s*<([[:alnum:]_:]+)>','\1')
24782478
if len(res)|return rails#underscore(res, 1).".rb"|endif
24792479

2480-
let res = s:findamethod('require')
2480+
let res = s:match_method('require')
24812481
if len(res)|return res.(res !~ '\.[^\/.]\+$' ? '.rb' : '')|endif
24822482

2483-
if !empty(s:findamethod('\w\+'))
2484-
let class = s:findit('^[^;#]*,\s*\%(:class_name\s*=>\|class_name:\)\s*["'':]\=\([[:alnum:]_:]\+\)','\1')
2483+
if !empty(s:match_method('\w\+'))
2484+
let class = s:match_it('^[^;#]*,\s*\%(:class_name\s*=>\|class_name:\)\s*["'':]\=\([[:alnum:]_:]\+\)','\1')
24852485
if len(class)|return rails#underscore(class, 1).".rb"|endif
24862486
endif
24872487

2488-
let res = s:findamethod('belongs_to\|has_one\|embedded_in\|embeds_one\|composed_of\|validates_associated\|scaffold')
2488+
let res = s:match_method('belongs_to\|has_one\|embedded_in\|embeds_one\|composed_of\|validates_associated\|scaffold')
24892489
if len(res)|return res.'.rb'|endif
24902490

2491-
let res = s:findamethod('has_many\|has_and_belongs_to_many\|embeds_many\|accepts_nested_attributes_for\|expose')
2491+
let res = s:match_method('has_many\|has_and_belongs_to_many\|embeds_many\|accepts_nested_attributes_for\|expose')
24922492
if len(res)|return rails#singularize(res).'.rb'|endif
24932493

2494-
let res = s:findamethod('create_table\|change_table\|drop_table\|rename_table\|\%(add\|remove\)_\%(column\|index\|timestamps\|reference\|belongs_to\)\|rename_column\|remove_columns\|rename_index')
2494+
let res = s:match_method('create_table\|change_table\|drop_table\|rename_table\|\%(add\|remove\)_\%(column\|index\|timestamps\|reference\|belongs_to\)\|rename_column\|remove_columns\|rename_index')
24952495
if len(res)|return rails#singularize(res).'.rb'|endif
24962496

2497-
let res = s:findasymbol('through')
2497+
let res = s:match_symbol('through')
24982498
if len(res)|return rails#singularize(res).".rb"|endif
24992499

2500-
let res = s:findamethod('fixtures')
2500+
let res = s:match_method('fixtures')
25012501
if len(res)|return 'fixtures/'.res.'.yml'|endif
25022502

2503-
let res = s:findamethod('fixture_file_upload')
2503+
let res = s:match_method('fixture_file_upload')
25042504
if len(res)|return 'fixtures/'.res|endif
25052505

2506-
let res = s:findamethod('file_fixture')
2506+
let res = s:match_method('file_fixture')
25072507
if len(res)|return 'fixtures/files/'.res|endif
25082508

2509-
let res = s:findamethod('\%(\w\+\.\)\=resources')
2509+
let res = s:match_method('\%(\w\+\.\)\=resources')
25102510
if len(res)|return res.'_controller.rb'|endif
25112511

2512-
let res = s:findamethod('\%(\w\+\.\)\=resource')
2512+
let res = s:match_method('\%(\w\+\.\)\=resource')
25132513
if len(res)|return rails#pluralize(res)."_controller.rb"|endif
25142514

2515-
let res = s:findasymbol('to')
2515+
let res = s:match_symbol('to')
25162516
if res =~ '#'|return s:sub(res,'#','_controller.rb#')|endif
25172517

2518-
let res = s:findamethod('root\s*\%(:to\s*=>\|\<to:\)\s*')
2518+
let res = s:match_method('root\s*\%(:to\s*=>\|\<to:\)\s*')
25192519
if res =~ '#'|return s:sub(res,'#','_controller.rb#')|endif
25202520

2521-
let res = s:findamethod('\%(match\|get\|put\|patch\|post\|delete\|redirect\)\s*(\=\s*[:''"][^''"]*[''"]\=\s*\%(\%(,\s*:to\s*\)\==>\|,\s*to:\)\s*')
2521+
let res = s:match_method('\%(match\|get\|put\|patch\|post\|delete\|redirect\)\s*(\=\s*[:''"][^''"]*[''"]\=\s*\%(\%(,\s*:to\s*\)\==>\|,\s*to:\)\s*')
25222522
if res =~ '#'|return s:sub(res,'#','_controller.rb#')|endif
25232523

25242524
if !buffer.type_name('controller', 'mailer')
2525-
let res = s:sub(s:sub(s:findasymbol('layout'),'^/',''),'[^/]+$','_&')
2525+
let res = s:sub(s:sub(s:match_symbol('layout'),'^/',''),'[^/]+$','_&')
25262526
if len(res)|return s:findview(res)|endif
2527-
let raw = s:sub(s:findamethod('render\s*(\=\s*\%(:layout\s\+=>\|layout:\)\s*',1),'[^/]+$','_&')
2527+
let raw = s:sub(s:match_method('render\s*(\=\s*\%(:layout\s\+=>\|layout:\)\s*',1),'[^/]+$','_&')
25282528
if len(res)|return s:findview(res)|endif
25292529
endif
25302530

2531-
let res = s:findamethod('layout')
2531+
let res = s:match_method('layout')
25322532
if len(res)|return s:findlayout(res)|endif
25332533

2534-
let res = s:findasymbol('layout')
2534+
let res = s:match_symbol('layout')
25352535
if len(res)|return s:findlayout(res)|endif
25362536

2537-
let res = s:findamethod('helper')
2537+
let res = s:match_method('helper')
25382538
if len(res)|return res.'_helper.rb'|endif
25392539

2540-
let res = s:findasymbol('controller')
2540+
let res = s:match_symbol('controller')
25412541
if len(res)|return s:sub(res, '^/', '').'_controller.rb'|endif
25422542

2543-
let res = s:findasymbol('action')
2543+
let res = s:match_symbol('action')
25442544
if len(res)|return s:findview(res)|endif
25452545

2546-
let res = s:findasymbol('template')
2546+
let res = s:match_symbol('template')
25472547
if len(res)|return s:findview(res)|endif
25482548

2549-
let res = s:sub(s:sub(s:findasymbol('partial'),'^/',''),'[^/]+$','_&')
2549+
let res = s:sub(s:sub(s:match_symbol('partial'),'^/',''),'[^/]+$','_&')
25502550
if len(res)|return s:findview(res)|endif
25512551

2552-
let res = s:sub(s:sub(s:findamethod('(\=\s*\%(:partial\s\+=>\|partial:\s*\|json.partial!\)\s*'),'^/',''),'[^/]+$','_&')
2552+
let res = s:sub(s:sub(s:match_method('(\=\s*\%(:partial\s\+=>\|partial:\s*\|json.partial!\)\s*'),'^/',''),'[^/]+$','_&')
25532553
if len(res)|return s:findview(res)|endif
25542554

2555-
let res = s:findapartial('render\%(_to_string\)\=\s*(\=\s*\%(:partial\s\+=>\|partial:\)\s*')
2555+
let res = s:match_partial('render\%(_to_string\)\=\s*(\=\s*\%(:partial\s\+=>\|partial:\)\s*')
25562556
if len(res)|return res|endif
25572557

2558-
let res = s:findamethod('render\>\s*\%(:\%(template\|action\)\s\+=>\|template:\|action:\)\s*')
2558+
let res = s:match_method('render\>\s*\%(:\%(template\|action\)\s\+=>\|template:\|action:\)\s*')
25592559
if len(res)|return s:findview(res)|endif
25602560

25612561
if buffer.type_name('controller', 'mailer')
2562-
let res = s:sub(s:findamethod('render'),'^/','')
2562+
let res = s:sub(s:match_method('render'),'^/','')
25632563
if len(res)|return s:findview(res)|endif
25642564
else
2565-
let res = s:findapartial('render')
2565+
let res = s:match_partial('render')
25662566
if len(res)|return res|endif
25672567
endif
25682568

2569-
let res = s:findamethod('redirect_to\s*(\=\s*\%\(:action\s\+=>\|\<action:\)\s*')
2569+
let res = s:match_method('redirect_to\s*(\=\s*\%\(:action\s\+=>\|\<action:\)\s*')
25702570
if len(res)|return res|endif
25712571

2572-
let res = s:findamethod('image[_-]\%(\|path\|url\)\|\%(path\|url\)_to_image')
2572+
let res = s:match_method('image[_-]\%(\|path\|url\)\|\%(path\|url\)_to_image')
25732573
if len(res)
25742574
return s:findasset(res, 'images')
25752575
endif
25762576

2577-
let res = s:findamethod('stylesheet[_-]\%(link_tag\|path\|url\)\|\%(path\|url\)_to_stylesheet')
2577+
let res = s:match_method('stylesheet[_-]\%(link_tag\|path\|url\)\|\%(path\|url\)_to_stylesheet')
25782578
if len(res)
25792579
return s:findasset(res, 'stylesheets')
25802580
endif
25812581

2582-
let res = s:sub(s:findamethod('javascript_\%(include_tag\|path\|url\)\|\%(path\|url\)_to_javascript'),'/defaults>','/application')
2582+
let res = s:sub(s:match_method('javascript_\%(include_tag\|path\|url\)\|\%(path\|url\)_to_javascript'),'/defaults>','/application')
25832583
if len(res)
25842584
return s:findasset(res, 'javascripts')
25852585
endif
25862586

2587-
let res = s:findamethod('asset_pack_path')
2587+
let res = s:match_method('asset_pack_path')
25882588
if len(res)
25892589
return buffer.app().resolve_pack(res)
25902590
endif
25912591

25922592
for [type, suf] in [['javascript', '.js'], ['stylesheet', '.css']]
2593-
let res = s:findamethod(type.'_pack_tag')
2593+
let res = s:match_method(type.'_pack_tag')
25942594
if len(res)
25952595
return buffer.app().resolve_pack(res . suf)
25962596
endif
25972597
endfor
25982598

25992599
if buffer.type_name('controller', 'mailer')
26002600
let contr = s:controller()
2601-
let view = s:findit('\s*\<def\s\+\(\k\+\)\>(\=','/\1')
2601+
let view = s:match_it('\s*\<def\s\+\(\k\+\)\>(\=','/\1')
26022602
if view !=# ''
26032603
let res = rails#buffer().resolve_view(contr.view)
26042604
if len(res)|return res|endif

0 commit comments

Comments
 (0)