Aggiunta impostazioni base vim.

This commit is contained in:
Emiliano Vavassori 2023-04-29 16:36:57 +02:00
parent 56f659d5ce
commit 0f56baa132
48 changed files with 10738 additions and 1 deletions

238
vim/plugin/let-modeline.vim Normal file
View file

@ -0,0 +1,238 @@
" example -> VIM: let b:toto="foo" g:tata=4 g:egal="t=y".&tw
" ===========================================================================
" $Id$
" File: let-modeline.vim {{{1
" Author: Luc Hermitte <EMAIL:hermitte {at} free {dot} fr>
" <URL:http://hermitte.free.fr/vim/>
" URL: http://code.google.com/p/lh-vim/source/browse/misc/trunk/plugin/let-modeline.vim
" Version: 1.9
" Last Update: 21st Apr 2011 ($Date$)
"
" Purpose: {{{2
" Defines the function : FirstModeLine() that extends the VIM modeline
" feature to variables. In VIM, it is possible to set options in the
" first and last lines. -> :h modeline
" The function proposed extends it to 'let {var}={val}' affectations.
"
" Exemples Of Useful Aplications: {{{2
" Typical Example: {{{3
" When editing a LaTeX document composed of several files, it is very
" practical to know the name of the main file whichever file is edited --
" TKlatex does this thanks the global variable g:TeXfile. Hence it knows
" that latex should be called on this main file ; aux2tags.vim could also
" be told to compute the associated .aux file.
" Anyway. Defining (through menus or a let command) g:TeXfile each time is
" really boring. It bored me so much that I programmed a first version of
" this script. In every file of one of my projects I added the line :
" % VIM: let g:TeXfile=main.tex
" [main.tex is the name of the main file of the project]
" Thus, I can very simply call LaTeX from within VIM without having to
" wonder which file is the main one nor having to specify g:TeXfile each
" time.
"
" Using Callback Functions: {{{3
" Actually, in order to affect g:TeXfile, I have to call another function.
" Hence, I define a callback function (in my (La)TeX ftplugin) that checks
" whether I want to set g:TeXfile. In that case, the callback function
" calls the right function and return true. Otherwise, it returns false.
" You will find the code of this precise callback function as an example at
" the end of this file.
"
" Tune C Compilations: {{{3
" An easy way to tune the parameters of the compilation of simple programs
" without having to maintain a makefile:
" // VIM: let $CPPFLAGS='-I../../libs':
"
" ---------------------------------------------------------------------------
" Format: {{{2
" On the _first_ line of any file, the extended modeline format is:
" {line} ::= [text]{white}VIM:[white]let{affectations}
" {affectations} ::= {sgl_affect.}
" {affectations} ::= {sgl_affect.}{white}{affectations}
" {sgl_affect.} ::= {variable}[white]=[white]{value}
" {variable} ::= cf. vim variable format ; beware simple
" variables (other than global-, buffer-,
" or window-variables) are not exported.
" Can also be an environment variable -> $VAR.
" {value} ::= string or numeral value : no function
" call allowed.
"
" Options: {{2
" (*) 'modeline' : vim-option that must be set to 1
" (*) 'modelines': vim-option corrsponding to the number of lines
" searched.
" (*) b:ModeLine_CallBack(var,val) : callback function
" Enable to define callback functions when needed. cf. lhlatex.vim
"
" Installation: {{{2
" (*) Drop the file into your {rtp}/plugin/ folder.
"
" Remarks: {{{2
" (*) The only way to call a function is through the callback feature.
" Affectation like 'let g:foo="abc".DEF()' are recognized and
" forbiden.
" (*) The modeline is recognized thanks to "VIM" in that *must* be in
" uppercase letters
"
" Changes: {{{2
" v1.9: @/ is preserved
" v1.8: autocommands moved to the plugin
" v1.7: Optimizations
" v1.6: Support for environment variables.
" vim 6.x only
" Doesn't check into folded lines anymore
" v1.5: Check that the format of the variables and values is correct
" before it tries to set the variables -> no more error messages
" when using 2html.vim.
" v1.4: With Vim 6.x, it doesn't mess anymore with the search history
" v1.3: Parse several lines according to &modelines and &modeline
" v1.2: no-reinclusion mecanism
" v1.1b: extend variable names to accept underscores
"
" Todo: {{{2
" (*) Enforce the patterns and the resulting errors
" (*) Permit to have comments ending characters at the end of the line.
" (*) Simplify the regexps
"
" }}}1
" ===========================================================================
" Definitions: {{{1
if exists("g:loaded_let_modeline") && ! exists('g:force_reload_let_modeline') | finish | endif
let g:loaded_let_modeline = 1
" Internal function dedicated to the recognition of function calls {{{2
function! s:FoundFunctionCall(value_str)
let str = substitute(a:value_str, '"[^"]*"', '', 'g')
let str = substitute(str, "'[^']*'", '', 'g')
return match(str, '(.*)') != -1
endfunction
let s:re_var = '\s\+\([[:alnum:]:_$]\+\)'
" beware the comments ending characters
let s:re_val = '\(\%(' . "'[^']*'" . '\|"[^"]*"\|[-a-zA-Z0-9:_.&$]\)\+\)$'
let s:re_other = '^\(.\{-}\)'
let s:re_sub = s:re_other . s:re_var . '\s*=\s*' . s:re_val
" Internal function dedicated to the parsing of a line {{{2
function! FML_parse_line(mtch)
" call confirm('Find:'.a:mtch, '&ok', 1)
if a:mtch !=""
let mtch = a:mtch
while strlen(mtch) != 0
let vari = substitute( mtch, s:re_sub, '\2', '' )
let valu = substitute( mtch, s:re_sub, '\3', '' )
" call confirm('regex: '.s:re_sub."\nmtch: <<".mtch.">>\nvar: ".vari."\nval: ".valu, '&ok', 1)
if (vari !~ '^[[:alnum:]:_$]\+$') || (valu !~ s:re_val)
return
endif
" Check : no function !
if s:FoundFunctionCall(valu)
echohl ErrorMsg
echo "Find a function call in the affectation : let " . vari . " = " . valu
echohl None
return
endif
let mtch = substitute( mtch, s:re_sub, '\1', '' )
""echo vari . " = " . valu . " --- " . mtch . "\n"
" call confirm('vari: '.vari.' = '.valu." --- " . mtch, '&Ok', 1)
if exists("b:ModeLine_CallBack")
exe 'let res = '. b:ModeLine_CallBack . '("'.vari.'","'.valu.'")'
if res == 1 | return | endif
endif
" Else
execute "let " . vari . " = " . valu
endwhile
endif
endfunction
" Internal function dedicated searching the matching lines {{{2
" let s:modeline_pat = '[vV][iI][mM]\d*:\s*let\s*\zs.*$'
let s:modeline_pat = '[vV][iI][mM]\d*:\s*let\zs.*$'
function! s:Do_it_on_range(first, last)
if &verbose >= 2 " {{{
echo "\n->"a:first.','.a:last. 'g/'.s:modeline_pat.
\ '/:call FML_parse_line(matchstr(getline("."),"'.
\ escape(s:modeline_pat, '\\') .'"))'
endif " }}}
let s:save_fold_enable= &foldenable
set nofoldenable
if exists(':try')
try
let s = @/
silent execute a:first.','.a:last. 'g/'.s:modeline_pat.
\ '/:call FML_parse_line(matchstr(getline("."),"'.
\ escape(s:modeline_pat, '\\') .'"))'
" Purge the history for the search pattern just used.
call histdel('search', -1)
finally
let @/ = s
let &foldenable = s:save_fold_enable
endtry
else " Older versions of Vim
silent execute a:first.','.a:last. 'g/'.s:modeline_pat.
\ '/:call FML_parse_line(matchstr(getline("."),"'.
\ escape(s:modeline_pat, '\\') .'"))'
" Purge the history for the search pattern just used.
call histdel('search', -1)
let &foldenable = s:save_fold_enable
endif
endfunction
" The main function {{{2
function! FirstModeLine()
if !&modeline | return | endif
let pos = line('.') . 'normal! ' . virtcol('.') . '|'
let e1 = 1+&modelines-1
let b2 = line('$') - &modelines+1
" call confirm('e1='.e1."\nb2=".b2, '&ok', 1)
if e1 >= b2
call s:Do_it_on_range(1, line('$'))
else
call s:Do_it_on_range(1, e1)
call s:Do_it_on_range(b2, line('$'))
endif
if !exists('b:this_is_new_buffer')
exe pos
else
unlet b:this_is_new_buffer
endif
" call confirm('fini!', '&ok', 1)
endfunction
" }}}2
" autocommand {{{2
aug LetModeline
au!
au BufReadPost * :call FirstModeLine()
" To not interfere with Templates loaders
" au BufNewFile * :let b:this_is_new_buffer=1
" Modeline interpretation
" au BufEnter * :call FirstModeLine()
aug END
" }}}1
" ===========================================================================
" Example of a callback function {{{1
" Version I use in my (La)TeX ftplugin
if 0
let b:ModeLine_CallBack = "TeXModeLine_CallBack"
function! TeXModeLine_CallBack(var,val)
if match(a:var, "g:TeXfile") != -1
" restore quotes around the file name
"let valu = substitute( valu, '^"\=\([[:alnum:].]\+\)"\=$', '"\1"', '' )
call TKSetTeXfileName( 2, a:val )
return 1
else
return 0
endif
endfunction
endif
" }}}1
" ===========================================================================
" vim600: set fdm=marker:

249
vim/plugin/libList.vim Normal file
View file

@ -0,0 +1,249 @@
" File: libList.vim
" Last Change: 2001 Dec 10
" Maintainer: Gontran BAERTS <gbcreation@free.fr>
" Version: 0.1
"
" Please don't hesitate to correct my english :)
" Send corrections to <gbcreation@free.fr>
"
"-----------------------------------------------------------------------------
" Description: libList.vim is a set of functions to work with lists or one
" level arrays.
"
"-----------------------------------------------------------------------------
" To Enable: Normally, this file will reside in your plugins directory and be
" automatically sourced.
"
"-----------------------------------------------------------------------------
" Usage: Lists are strings variable with values separated by g:listSep
" character (comma" by default). You may redefine g:listSep variable as you
" wish.
"
" Here are available functions :
"
" - AddListItem( array, newItem, index ) :
" Add item "newItem" to array "array" at "index" position
" - GetListItem( array, index ) :
" Return item at "index" position in array "array"
" - GetListMatchItem( array, pattern ) :
" Return item matching "pattern" in array "array"
" - GetListCount( array ) :
" Return the number of items in array "array"
" - RemoveListItem( array, index ) :
" Remove item at "index" position from array "array"
" - ReplaceListItem( array, index, item ) :
" Remove item at "index" position by "item" in array "array"
" - ExchangeListItems( array, item1Index, item2Index ) :
" Exchange item "item1Index" with item "item2Index" in array "array"
" - QuickSortList( array, beg, end ) :
" Return array "array" with items between "beg" and "end" sorted
"
" Example:
" let mylist=""
" echo GetListCount( mylist ) " --> 0
" let mylist = AddListItem( mylist, "One", 0 ) " mylist == "One"
" let mylist = AddListItem( mylist, "Three", 1 ) " mylist == "One,Three"
" let mylist = AddListItem( mylist, "Two", 1 ) " mylist == "One,Two,Three"
" echo GetListCount( mylist ) " --> 3
" echo GetListItem( mylist, 2 ) " --> Three
" echo GetListMatchItem( mylist, "w" ) " --> two
" echo GetListMatchItem( mylist, "e" ) " --> One
" let mylist = RemoveListItem( mylist, 2 ) " mylist == "One,Two"
" echo GetListCount( mylist ) " --> 2
" let mylist = ReplaceListItem( mylist, 0, "Three" ) " mylist == "Three,Two"
" let mylist = ExchangeListItems( mylist, 0, 1 ) " mylist == "Two,Three"
" let mylist = AddListItem( mylist, "One", 0 ) " mylist == "One,Two,Three"
" let mylist = QuickSortList( mylist, 0, GetListCount(mylist)-1 )
" " mylist == "One,Three,Two"
"
"-----------------------------------------------------------------------------
" Updates:
" in version 0.1
" - First version
" Has this already been loaded ?
if exists("loaded_libList")
finish
endif
let loaded_libList=1
"**
" Separator:
" You may change the separator character et any time.
"**
let g:listSep = ","
"**
"AddListItem:
" Add new item at given position.
" First item index is 0 (zero).
"Parameters:
" - array : Array/List (string of values) which receives the new item.
" - newItem : String containing the item value to add.
" - index : Integer indicating the position at which the new item is added.
" It must be greater than or equals to 0 (zero).
"Return:
"String containing array values, including newItem.
"**
function AddListItem( array, newItem, index )
if a:index == 0
if a:array == ""
return a:newItem
endif
return a:newItem . g:listSep . a:array
endif
return substitute( a:array, '\(\%(^\|' . g:listSep . '\)[^' . g:listSep . ']\+\)\{' . a:index . '\}', '\0' . g:listSep . a:newItem , "" )
endfunction
"**
"GetListItem:
" Get item at given position.
"Parameters:
" - array : Array/List (string of values).
" - index : Integer indicating the position of item to return.
" It must be greater than or equals to 0 (zero).
"Return:
"String representing the item.
"**
function GetListItem( array, index )
if a:index == 0
return matchstr( a:array, '^[^' . g:listSep . ']\+' )
else
return matchstr( a:array, "[^" . g:listSep . "]\\+", matchend( a:array, '\(\%(^\|' . g:listSep . '\)[^' . g:listSep . ']\+\)\{' . a:index . '\}' . g:listSep ) )
endif
endfunction
"**
"GetListMatchItem:
" Get the first item matching given pattern.
"Parameters:
" - array : Array/List (string of values).
" - pattern : Regular expression to match with items.
" Avoid to use ^, $ and listSep characters in pattern, unless you
" know what you do.
"Return:
"String representing the first item that matches the pattern.
"**
function GetListMatchItem( array, pattern )
return matchstr( a:array, '[^' . g:listSep . ']*' . a:pattern . '[^' . g:listSep . ']*' )
endfunction
"**
"ReplaceListItem:
" Replace item at given position by a new one.
"Parameters:
" - array : Array/List (string of values).
" - index : Integer indicating the position of item to replace.
" It must be greater than or equals to 0 (zero).
" - item : String containing the new value of the replaced item.
"Return:
"String containing array values.
"**
function ReplaceListItem( array, index, item )
if a:index == 0
return substitute( a:array, '^[^' .g:listSep. ']\+', a:item, "" )
else
return substitute( a:array, '\(\%(\%(^\|' . g:listSep . '\)[^' . g:listSep . ']\+\)\{' . a:index . '\}\)' . g:listSep . '[^' . g:listSep . ']\+', '\1' . g:listSep . a:item , "" )
endif
endfunction
"**
"RemoveListItem:
" Remove item at given position.
"Parameters:
" - array : Array/List (string of values) from which remove an item.
" - index : Integer indicating the position of item to remove.
" It must be greater than or equals to 0 (zero).
"Return:
"String containing array values, except the removed one.
"**
function RemoveListItem( array, index )
if a:index == 0
return substitute( a:array, '^[^' .g:listSep. ']\+\(' . g:listSep . '\|$\)', "", "" )
else
return substitute( a:array, '\(\%(\%(^\|' . g:listSep . '\)[^' . g:listSep . ']\+\)\{' . a:index . '\}\)' . g:listSep . '[^' . g:listSep . ']\+', '\1', "" )
endif
endfunction
"**
"ExchangeListItems:
" Exchange item at position item1Index with item at position item2Index.
"Parameters:
" - array : Array/List (string of values).
" - item1index : Integer indicating the position of the first item to exchange.
" It must be greater than or equals to 0 (zero).
" - item2index : Integer indicating the position of the second item to
" exchange. It must be greater than or equals to 0 (zero).
"Return:
"String containing array values.
"**
function ExchangeListItems( array, item1Index, item2Index )
let item1 = GetListItem( a:array, a:item1Index )
let array = ReplaceListItem( a:array, a:item1Index, GetListItem( a:array, a:item2Index ) )
return ReplaceListItem( array, a:item2Index, item1 )
endfunction
"**
"GetListCount:
" Number of items in array.
"Parameters:
" - array : Array/List (string of values).
"Return:
"Integer representing the number of items in array.
"Index of last item is GetListCount(array)-1.
"**
function GetListCount( array )
if a:array == "" | return 0 | endif
let pos = 0
let cnt = 0
while pos != -1
let pos = matchend( a:array, g:listSep, pos )
let cnt = cnt + 1
endwhile
return cnt
endfunction
"**
"QuickSortList:
" Sort array.
"Parameters:
" - array : Array/List (string of values).
" - beg : Min index of the range of items to sort.
" - end : Max index of the range of items to sort.
"Return:
"String containing array values with indicated range of items sorted.
"**
function QuickSortList( array, beg, end )
let array = a:array
let pivot = GetListItem( array, a:beg )
let l = a:beg
let r = a:end
while l < r
while GetListItem( array, r ) > pivot
let r = r - 1
endwhile
if l != r
let array = ReplaceListItem( array, l, GetListItem( array, r ) )
let array = ReplaceListItem( array, r, pivot )
let l = l + 1
endif
while GetListItem( array, l ) < pivot
let l = l + 1
endwhile
if l != r
let array = ReplaceListItem( array, r, GetListItem( array, l ) )
let array = ReplaceListItem( array, l, pivot )
let r = r - 1
endif
endwhile
if a:beg < l-1
let array = QuickSortList( array, a:beg, l-1 )
endif
if a:end > l+1
let array = QuickSortList( array, l+1, a:end )
endif
return array
endfunction

340
vim/plugin/rails.vim Normal file
View file

@ -0,0 +1,340 @@
" rails.vim - Detect a rails application
" Author: Tim Pope <vimNOSPAM@tpope.org>
" GetLatestVimScripts: 1567 1 :AutoInstall: rails.vim
" URL: http://rails.vim.tpope.net/
" Install this file as plugin/rails.vim. See doc/rails.txt for details. (Grab
" it from the URL above if you don't have it.) To access it from Vim, see
" :help add-local-help (hint: :helptags ~/.vim/doc) Afterwards, you should be
" able to do :help rails
if exists('g:loaded_rails') || &cp || v:version < 700
finish
endif
let g:loaded_rails = 1
" Utility Functions {{{1
function! s:error(str)
echohl ErrorMsg
echomsg a:str
echohl None
let v:errmsg = a:str
endfunction
function! s:autoload(...)
if !exists("g:autoloaded_rails") && v:version >= 700
runtime! autoload/rails.vim
endif
if exists("g:autoloaded_rails")
if a:0
exe a:1
endif
return 1
endif
if !exists("g:rails_no_autoload_warning")
let g:rails_no_autoload_warning = 1
if v:version >= 700
call s:error("Disabling rails.vim: autoload/rails.vim is missing")
else
call s:error("Disabling rails.vim: Vim version 7 or higher required")
endif
endif
return ""
endfunction
" }}}1
" Configuration {{{
function! s:SetOptDefault(opt,val)
if !exists("g:".a:opt)
let g:{a:opt} = a:val
endif
endfunction
call s:SetOptDefault("rails_statusline",1)
call s:SetOptDefault("rails_syntax",1)
call s:SetOptDefault("rails_mappings",1)
call s:SetOptDefault("rails_abbreviations",1)
call s:SetOptDefault("rails_ctags_arguments","--languages=-javascript")
call s:SetOptDefault("rails_default_file","README")
call s:SetOptDefault("rails_root_url",'http://localhost:3000/')
call s:SetOptDefault("rails_modelines",0)
call s:SetOptDefault("rails_menu",!has('mac'))
call s:SetOptDefault("rails_gnu_screen",1)
call s:SetOptDefault("rails_history_size",5)
call s:SetOptDefault("rails_generators","controller\ngenerator\nhelper\nintegration_test\nmailer\nmetal\nmigration\nmodel\nobserver\nperformance_test\nplugin\nresource\nscaffold\nscaffold_controller\nsession_migration\nstylesheets")
if exists("g:loaded_dbext") && executable("sqlite3") && ! executable("sqlite")
" Since dbext can't find it by itself
call s:SetOptDefault("dbext_default_SQLITE_bin","sqlite3")
endif
" }}}1
" Detection {{{1
function! s:escvar(r)
let r = fnamemodify(a:r,':~')
let r = substitute(r,'\W','\="_".char2nr(submatch(0))."_"','g')
let r = substitute(r,'^\d','_&','')
return r
endfunction
function! s:Detect(filename)
let fn = substitute(fnamemodify(a:filename,":p"),'\c^file://','','')
let sep = matchstr(fn,'^[^\\/]\{3,\}\zs[\\/]')
if sep != ""
let fn = getcwd().sep.fn
endif
if fn =~ '[\/]config[\/]environment\.rb$'
return s:BufInit(strpart(fn,0,strlen(fn)-22))
endif
if isdirectory(fn)
let fn = fnamemodify(fn,':s?[\/]$??')
else
let fn = fnamemodify(fn,':s?\(.*\)[\/][^\/]*$?\1?')
endif
let ofn = ""
let nfn = fn
while nfn != ofn && nfn != ""
if exists("s:_".s:escvar(nfn))
return s:BufInit(nfn)
endif
let ofn = nfn
let nfn = fnamemodify(nfn,':h')
endwhile
let ofn = ""
while fn != ofn
if filereadable(fn . "/config/environment.rb")
return s:BufInit(fn)
endif
let ofn = fn
let fn = fnamemodify(ofn,':s?\(.*\)[\/]\(app\|config\|db\|doc\|features\|lib\|log\|public\|script\|spec\|stories\|test\|tmp\|vendor\)\($\|[\/].*$\)?\1?')
endwhile
return 0
endfunction
function! s:BufInit(path)
let s:_{s:escvar(a:path)} = 1
if s:autoload()
return RailsBufInit(a:path)
endif
endfunction
" }}}1
" Initialization {{{1
augroup railsPluginDetect
autocmd!
autocmd BufNewFile,BufRead * call s:Detect(expand("<afile>:p"))
autocmd VimEnter * if expand("<amatch>") == "" && !exists("b:rails_root") | call s:Detect(getcwd()) | endif | if exists("b:rails_root") | silent doau User BufEnterRails | endif
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
autocmd BufEnter * if exists("b:rails_root")|silent doau User BufEnterRails|endif
autocmd BufLeave * if exists("b:rails_root")|silent doau User BufLeaveRails|endif
autocmd Syntax railslog if s:autoload()|call rails#log_syntax()|endif
augroup END
command! -bar -bang -nargs=* -complete=dir Rails :if s:autoload()|call rails#new_app_command(<bang>0,<f-args>)|endif
" }}}1
" abolish.vim support {{{1
function! s:function(name)
return function(substitute(a:name,'^s:',matchstr(expand('<sfile>'), '<SNR>\d\+_'),''))
endfunction
augroup railsPluginAbolish
autocmd!
autocmd VimEnter * call s:abolish_setup()
augroup END
function! s:abolish_setup()
if exists('g:Abolish') && has_key(g:Abolish,'Coercions')
if !has_key(g:Abolish.Coercions,'l')
let g:Abolish.Coercions.l = s:function('s:abolish_l')
endif
if !has_key(g:Abolish.Coercions,'t')
let g:Abolish.Coercions.t = s:function('s:abolish_t')
endif
endif
endfunction
function! s:abolish_l(word)
let singular = rails#singularize(a:word)
return a:word ==? singular ? rails#pluralize(a:word) : singular
endfunction
function! s:abolish_t(word)
if a:word =~# '\u'
return rails#pluralize(rails#underscore(a:word))
else
return rails#singularize(rails#camelize(a:word))
endif
endfunction
" }}}1
" Menus {{{1
if !(g:rails_menu && has("menu"))
finish
endif
function! s:sub(str,pat,rep)
return substitute(a:str,'\v\C'.a:pat,a:rep,'')
endfunction
function! s:gsub(str,pat,rep)
return substitute(a:str,'\v\C'.a:pat,a:rep,'g')
endfunction
function! s:menucmd(priority)
return 'anoremenu <script> '.(exists("$CREAM") ? 87 : '').s:gsub(g:rails_installed_menu,'[^.]','').'.'.a:priority.' '
endfunction
function! s:CreateMenus() abort
if exists("g:rails_installed_menu") && g:rails_installed_menu != ""
exe "aunmenu ".s:gsub(g:rails_installed_menu,'\&','')
unlet g:rails_installed_menu
endif
if has("menu") && (exists("g:did_install_default_menus") || exists("$CREAM")) && g:rails_menu
if g:rails_menu > 1
let g:rails_installed_menu = '&Rails'
else
let g:rails_installed_menu = '&Plugin.&Rails'
endif
let dots = s:gsub(g:rails_installed_menu,'[^.]','')
let menucmd = s:menucmd(200)
if exists("$CREAM")
exe menucmd.g:rails_installed_menu.'.-PSep- :'
exe menucmd.g:rails_installed_menu.'.&Related\ file\ :R\ /\ Alt+] :R<CR>'
exe menucmd.g:rails_installed_menu.'.&Alternate\ file\ :A\ /\ Alt+[ :A<CR>'
exe menucmd.g:rails_installed_menu.'.&File\ under\ cursor\ Ctrl+Enter :Rfind<CR>'
else
exe menucmd.g:rails_installed_menu.'.-PSep- :'
exe menucmd.g:rails_installed_menu.'.&Related\ file\ :R\ /\ ]f :R<CR>'
exe menucmd.g:rails_installed_menu.'.&Alternate\ file\ :A\ /\ [f :A<CR>'
exe menucmd.g:rails_installed_menu.'.&File\ under\ cursor\ gf :Rfind<CR>'
endif
exe menucmd.g:rails_installed_menu.'.&Other\ files.Application\ &Controller :Rcontroller application<CR>'
exe menucmd.g:rails_installed_menu.'.&Other\ files.Application\ &Helper :Rhelper application<CR>'
exe menucmd.g:rails_installed_menu.'.&Other\ files.Application\ &Javascript :Rjavascript application<CR>'
exe menucmd.g:rails_installed_menu.'.&Other\ files.Application\ &Layout :Rlayout application<CR>'
exe menucmd.g:rails_installed_menu.'.&Other\ files.Application\ &README :R doc/README_FOR_APP<CR>'
exe menucmd.g:rails_installed_menu.'.&Other\ files.&Environment :Renvironment<CR>'
exe menucmd.g:rails_installed_menu.'.&Other\ files.&Database\ Configuration :R config/database.yml<CR>'
exe menucmd.g:rails_installed_menu.'.&Other\ files.Database\ &Schema :Rmigration 0<CR>'
exe menucmd.g:rails_installed_menu.'.&Other\ files.R&outes :Rinitializer<CR>'
exe menucmd.g:rails_installed_menu.'.&Other\ files.&Test\ Helper :Rintegrationtest<CR>'
exe menucmd.g:rails_installed_menu.'.-FSep- :'
exe menucmd.g:rails_installed_menu.'.Ra&ke\ :Rake :Rake<CR>'
let menucmd = substitute(menucmd,'200 $','500 ','')
exe menucmd.g:rails_installed_menu.'.&Server\ :Rserver.&Start\ :Rserver :Rserver<CR>'
exe menucmd.g:rails_installed_menu.'.&Server\ :Rserver.&Force\ start\ :Rserver! :Rserver!<CR>'
exe menucmd.g:rails_installed_menu.'.&Server\ :Rserver.&Kill\ :Rserver!\ - :Rserver! -<CR>'
exe substitute(menucmd,'<script>','<script> <silent>','').g:rails_installed_menu.'.&Evaluate\ Ruby\.\.\.\ :Rp :call <SID>menuprompt("Rp","Code to execute and output: ")<CR>'
exe menucmd.g:rails_installed_menu.'.&Console\ :Rscript :Rscript console<CR>'
exe menucmd.g:rails_installed_menu.'.&Preview\ :Rpreview :Rpreview<CR>'
exe menucmd.g:rails_installed_menu.'.&Log\ file\ :Rlog :Rlog<CR>'
exe substitute(s:sub(menucmd,'anoremenu','vnoremenu'),'<script>','<script> <silent>','').g:rails_installed_menu.'.E&xtract\ as\ partial\ :Rextract :call <SID>menuprompt("'."'".'<,'."'".'>Rextract","Partial name (e.g., template or /controller/template): ")<CR>'
exe menucmd.g:rails_installed_menu.'.&Migration\ writer\ :Rinvert :Rinvert<CR>'
exe menucmd.' '.g:rails_installed_menu.'.-HSep- :'
exe substitute(menucmd,'<script>','<script> <silent>','').g:rails_installed_menu.'.&Help\ :help\ rails :if <SID>autoload()<Bar>exe RailsHelpCommand("")<Bar>endif<CR>'
exe substitute(menucmd,'<script>','<script> <silent>','').g:rails_installed_menu.'.Abo&ut\ :if <SID>autoload()<Bar>exe RailsHelpCommand("about")<Bar>endif<CR>'
let g:rails_did_menus = 1
call s:ProjectMenu()
call s:menuBufLeave()
if exists("b:rails_root")
call s:menuBufEnter()
endif
endif
endfunction
function! s:ProjectMenu()
if exists("g:rails_did_menus") && g:rails_history_size > 0
if !exists("g:RAILS_HISTORY")
let g:RAILS_HISTORY = ""
endif
let history = g:RAILS_HISTORY
let menu = s:gsub(g:rails_installed_menu,'\&','')
silent! exe "aunmenu <script> ".menu.".Projects"
let dots = s:gsub(menu,'[^.]','')
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>'
exe 'anoremenu <script> '.menu.'.Pro&jects.-FSep- :'
while history =~ '\n'
let proj = matchstr(history,'^.\{-\}\ze\n')
let history = s:sub(history,'^.{-}\n','')
exe 'anoremenu <script> '.menu.'.Pro&jects.'.s:gsub(proj,'[.\\ ]','\\&').' :e '.s:gsub(proj."/".g:rails_default_file,'[ !%#]','\\&')."<CR>"
endwhile
endif
endfunction
function! s:menuBufEnter()
if exists("g:rails_installed_menu") && g:rails_installed_menu != ""
let menu = s:gsub(g:rails_installed_menu,'\&','')
exe 'amenu enable '.menu.'.*'
if RailsFileType() !~ '^view\>'
exe 'vmenu disable '.menu.'.Extract\ as\ partial'
endif
if RailsFileType() !~ '^\%(db-\)\=migration$' || RailsFilePath() =~ '\<db/schema\.rb$'
exe 'amenu disable '.menu.'.Migration\ writer'
endif
call s:ProjectMenu()
silent! exe 'aunmenu '.menu.'.Rake\ tasks'
silent! exe 'aunmenu '.menu.'.Generate'
silent! exe 'aunmenu '.menu.'.Destroy'
if rails#app().cache.needs('rake_tasks') || empty(rails#app().rake_tasks())
exe substitute(s:menucmd(300),'<script>','<script> <silent>','').g:rails_installed_menu.'.Rake\ &tasks\ :Rake.Fill\ this\ menu :call rails#app().rake_tasks()<Bar>call <SID>menuBufLeave()<Bar>call <SID>menuBufEnter()<CR>'
else
let i = 0
while i < len(rails#app().rake_tasks())
let task = rails#app().rake_tasks()[i]
exe s:menucmd(300).g:rails_installed_menu.'.Rake\ &tasks\ :Rake.'.s:sub(task,':',':.').' :Rake '.task.'<CR>'
let i += 1
endwhile
endif
let i = 0
let menucmd = substitute(s:menucmd(400),'<script>','<script> <silent>','').g:rails_installed_menu
while i < len(rails#app().generators())
let generator = rails#app().generators()[i]
exe menucmd.'.&Generate\ :Rgen.'.s:gsub(generator,'_','\\ ').' :call <SID>menuprompt("Rgenerate '.generator.'","Arguments for script/generate '.generator.': ")<CR>'
exe menucmd.'.&Destroy\ :Rdestroy.'.s:gsub(generator,'_','\\ ').' :call <SID>menuprompt("Rdestroy '.generator.'","Arguments for script/destroy '.generator.': ")<CR>'
let i += 1
endwhile
endif
endfunction
function! s:menuBufLeave()
if exists("g:rails_installed_menu") && g:rails_installed_menu != ""
let menu = s:gsub(g:rails_installed_menu,'\&','')
exe 'amenu disable '.menu.'.*'
exe 'amenu enable '.menu.'.Help\ '
exe 'amenu enable '.menu.'.About\ '
exe 'amenu enable '.menu.'.Projects'
silent! exe 'aunmenu '.menu.'.Rake\ tasks'
silent! exe 'aunmenu '.menu.'.Generate'
silent! exe 'aunmenu '.menu.'.Destroy'
exe s:menucmd(300).g:rails_installed_menu.'.Rake\ tasks\ :Rake.-TSep- :'
exe s:menucmd(400).g:rails_installed_menu.'.&Generate\ :Rgen.-GSep- :'
exe s:menucmd(400).g:rails_installed_menu.'.&Destroy\ :Rdestroy.-DSep- :'
endif
endfunction
function! s:menuprompt(vimcmd,prompt)
let res = inputdialog(a:prompt,'','!!!')
if res == '!!!'
return ""
endif
exe a:vimcmd." ".res
endfunction
call s:CreateMenus()
augroup railsPluginMenu
autocmd!
autocmd User BufEnterRails call s:menuBufEnter()
autocmd User BufLeaveRails call s:menuBufLeave()
" g:RAILS_HISTORY hasn't been set when s:InitPlugin() is called.
autocmd VimEnter * call s:ProjectMenu()
augroup END
" }}}1
" vim:set sw=2 sts=2:

576
vim/plugin/rake.vim Normal file
View file

@ -0,0 +1,576 @@
" rake.vim - It's like rails.vim without the rails
" Maintainer: Tim Pope <http://tpo.pe/>
" Version: 1.0
" GetLatestVimScripts: 3669 1 :AutoInstall: rake.vim
if exists('g:loaded_rake') || &cp || v:version < 700
finish
endif
let g:loaded_rake = 1
" Utility {{{1
function! s:function(name) abort
return function(substitute(a:name,'^s:',matchstr(expand('<sfile>'), '<SNR>\d\+_'),''))
endfunction
function! s:sub(str,pat,rep) abort
return substitute(a:str,'\v\C'.a:pat,a:rep,'')
endfunction
function! s:gsub(str,pat,rep) abort
return substitute(a:str,'\v\C'.a:pat,a:rep,'g')
endfunction
function! s:shellesc(arg) abort
if a:arg =~ '^[A-Za-z0-9_/.-]\+$'
return a:arg
else
return shellescape(a:arg)
endif
endfunction
function! s:fnameescape(file) abort
if exists('*fnameescape')
return fnameescape(a:file)
else
return escape(a:file," \t\n*?[{`$\\%#'\"|!<")
endif
endfunction
function! s:shellslash(path)
if exists('+shellslash') && !&shellslash
return s:gsub(a:path,'\\','/')
else
return a:path
endif
endfunction
function! s:fuzzyglob(arg)
return s:gsub(s:gsub(a:arg,'[^/.]','[&]*'),'%(/|^)\.@!|\.','&*')
endfunction
function! s:completion_filter(results,A)
let results = sort(copy(a:results))
call filter(results,'v:val !~# "\\~$"')
let filtered = filter(copy(results),'v:val[0:strlen(a:A)-1] ==# a:A')
if !empty(filtered) | return filtered | endif
let regex = s:gsub(a:A,'[^/:]','[&].*')
let filtered = filter(copy(results),'v:val =~# "^".regex')
if !empty(filtered) | return filtered | endif
let filtered = filter(copy(results),'"/".v:val =~# "[/:]".regex')
if !empty(filtered) | return filtered | endif
let regex = s:gsub(a:A,'.','[&].*')
let filtered = filter(copy(results),'"/".v:val =~# regex')
return filtered
endfunction
function! s:throw(string) abort
let v:errmsg = 'rake: '.a:string
throw v:errmsg
endfunction
function! s:warn(str)
echohl WarningMsg
echomsg a:str
echohl None
let v:warningmsg = a:str
endfunction
function! s:add_methods(namespace, method_names) abort
for name in a:method_names
let s:{a:namespace}_prototype[name] = s:function('s:'.a:namespace.'_'.name)
endfor
endfunction
let s:commands = []
function! s:command(definition) abort
let s:commands += [a:definition]
endfunction
function! s:define_commands()
for command in s:commands
exe 'command! -buffer '.command
endfor
endfunction
augroup rake_utility
autocmd!
autocmd User Rake call s:define_commands()
augroup END
let s:abstract_prototype = {}
" }}}1
" Initialization {{{1
function! s:FindRakeRoot(path) abort
let path = s:shellslash(a:path)
for p in [$GEM_HOME] + split($GEM_PATH,':')
if p !=# '' && s:shellslash(p.'/gems/') ==# (path)[0 : strlen(p)+5]
return simplify(s:shellslash(p.'/gems/')).matchstr(path[strlen(p)+6:-1],'[^\\/]*')
endif
endfor
let fn = fnamemodify(path,':s?[\/]$??')
let ofn = ""
let nfn = fn
while fn != ofn
if filereadable(fn.'/Rakefile')
if filereadable(fn.'/config/environment.rb')
return ''
else
return s:sub(simplify(fnamemodify(fn,':p')),'[\\/]$','')
endif
endif
let ofn = fn
let fn = fnamemodify(ofn,':h')
endwhile
return ''
endfunction
function! s:Detect(path)
if exists('b:rake_root') && b:rake_root ==# ''
unlet b:rake_root
endif
if !exists('b:rake_root')
let dir = s:FindRakeRoot(a:path)
if dir != ''
let b:rake_root = dir
endif
endif
if exists('b:rake_root')
silent doautocmd User Rake
endif
endfunction
augroup rake
autocmd!
autocmd BufNewFile,BufReadPost * call s:Detect(expand('<amatch>:p'))
autocmd FileType netrw call s:Detect(expand('<afile>:p'))
autocmd VimEnter * if expand('<amatch>')==''|call s:Detect(getcwd())|endif
augroup END
" }}}1
" Project {{{1
let s:project_prototype = {}
let s:projects = {}
function! s:project(...) abort
let dir = a:0 ? a:1 : (exists('b:rake_root') && b:rake_root !=# '' ? b:rake_root : s:FindRakeRoot(expand('%:p')))
if dir !=# ''
if has_key(s:projects,dir)
let project = get(s:projects,dir)
else
let project = {'root': dir}
let s:projects[dir] = project
endif
return extend(extend(project,s:project_prototype,'keep'),s:abstract_prototype,'keep')
endif
call s:throw('not a rake project: '.expand('%:p'))
endfunction
function! s:project_path(...) dict abort
return join([self.root]+a:000,'/')
endfunction
call s:add_methods('project',['path'])
function! s:project_dirglob(base) dict abort
let base = s:sub(a:base,'^/','')
let matches = split(glob(self.path(s:gsub(base,'/','*&').'*/')),"\n")
call map(matches,'v:val[ strlen(self.path())+(a:base !~ "^/") : -1 ]')
return matches
endfunction
function! s:project_has_file(file) dict
return filereadable(self.path(a:file))
endfunction
function! s:project_has_directory(file) dict
return isdirectory(self.path(a:file))
endfunction
function! s:project_first_file(...) dict abort
for file in a:000
if s:project().has_file(file)
return file
endif
endfor
for file in a:000
if s:project().has_directory(matchstr(file,'^[^/]*'))
return file
endif
endfor
return a:000[0]
endfunction
call s:add_methods('project',['dirglob','has_file','has_directory','first_file'])
" }}}1
" Buffer {{{1
let s:buffer_prototype = {}
function! s:buffer(...) abort
let buffer = {'#': bufnr(a:0 ? a:1 : '%')}
call extend(extend(buffer,s:buffer_prototype,'keep'),s:abstract_prototype,'keep')
if buffer.getvar('rake_root') !=# ''
return buffer
endif
call s:throw('not a rake project: '.expand('%:p'))
endfunction
function! rake#buffer(...) abort
return s:buffer(a:0 ? a:1 : '%')
endfunction
function! s:buffer_getvar(var) dict abort
return getbufvar(self['#'],a:var)
endfunction
function! s:buffer_setvar(var,value) dict abort
return setbufvar(self['#'],a:var,a:value)
endfunction
function! s:buffer_getline(lnum) dict abort
return getbufline(self['#'],a:lnum)[0]
endfunction
function! s:buffer_project() dict abort
return s:project(self.getvar('rake_root'))
endfunction
function! s:buffer_name() dict abort
return self.path()[strlen(self.project().path())+1 : -1]
endfunction
function! s:buffer_path() dict abort
let bufname = bufname(self['#'])
return s:shellslash(bufname == '' ? '' : fnamemodify(bufname,':p'))
endfunction
call s:add_methods('buffer',['getvar','setvar','getline','project','name','path'])
" }}}1
" Rake {{{1
function! s:push_chdir(...)
if !exists("s:command_stack") | let s:command_stack = [] | endif
let chdir = exists("*haslocaldir") && haslocaldir() ? "lchdir " : "chdir "
call add(s:command_stack,chdir.s:fnameescape(getcwd()))
exe chdir.'`=s:project().path()`'
endfunction
function! s:pop_command()
if exists("s:command_stack") && len(s:command_stack) > 0
exe remove(s:command_stack,-1)
endif
endfunction
function! s:Rake(bang,arg)
let old_makeprg = &l:makeprg
let old_errorformat = &l:errorformat
call s:push_chdir()
try
if exists('b:bundle_root') && b:bundler_root ==# s:project().path()
let &l:makeprg = 'bundle exec rake'
else
let &l:makeprg = 'rake'
endif
let &l:errorformat = '%D(in\ %f),'
\.'%\\s%#from\ %f:%l:%m,'
\.'%\\s%#from\ %f:%l:,'
\.'%\\s#{RAILS_ROOT}/%f:%l:\ %#%m,'
\.'%\\s%#[%f:%l:\ %#%m,'
\.'%W%m\ (Cucumber::Undefined),'
\.'%E%m\ (%.%#),'
\.'%Z%f:%l,'
\.'%Z%f:%l:%.%#,'
\.'%\\s%#%f:%l:\ %#%m,'
\.'%\\s%#%f:%l:,'
\.'%m\ [%f:%l]:'
execute 'make! '.a:arg
if a:bang !=# '!'
return 'cwindow'
endif
return ''
finally
let &l:errorformat = old_errorformat
let &l:makeprg = old_makeprg
call s:pop_command()
endtry
endfunction
function! s:RakeComplete(A,L,P)
return s:completion_filter(s:project().tasks(),a:A)
endfunction
function! s:project_tasks()
call s:push_chdir()
try
let lines = split(system('rake -T'),"\n")
finally
call s:pop_command()
endtry
if v:shell_error != 0
return []
endif
call map(lines,'matchstr(v:val,"^rake\\s\\+\\zs\\S*")')
call filter(lines,'v:val != ""')
return lines
endfunction
call s:add_methods('project',['tasks'])
call s:command("-bar -bang -nargs=? -complete=customlist,s:RakeComplete Rake :execute s:Rake('<bang>',<q-args>)")
" }}}1
" Rcd, Rlcd {{{1
function! s:DirComplete(A,L,P) abort
return s:project().dirglob(a:A)
endfunction
call s:command("-bar -bang -nargs=? -complete=customlist,s:DirComplete Rcd :cd<bang> `=s:project().path(<q-args>)`")
call s:command("-bar -bang -nargs=? -complete=customlist,s:DirComplete Rlcd :lcd<bang> `=s:project().path(<q-args>)`")
" }}}1
" R {{{1
function! s:buffer_related() dict abort
if self.name() =~# '^lib/'
let bare = s:sub(self.name()[4:-1],'\.rb$','')
return s:project().first_file(
\'test/'.bare.'_test.rb',
\'spec/'.bare.'_spec.rb',
\'test/unit/'.bare.'_test.rb',
\'spec/unit/'.bare.'_spec.rb')
elseif self.name() =~# '^\(test\|spec\)/.*_\1\.rb$'
return 'lib/'.self.name()[5:-9].'.rb'
elseif self.name() ==# 'Gemfile'
return 'Gemfile.lock'
elseif self.name() ==# 'Gemfile.lock'
return 'Gemfile'
endif
return ''
endfunction
call s:add_methods('buffer',['related'])
function! s:project_relglob(path,glob,...) dict
if exists("+shellslash") && ! &shellslash
let old_ss = &shellslash
endif
try
let &shellslash = 1
let path = a:path
if path !~ '^/' && path !~ '^\w:'
let path = self.path(path)
endif
let suffix = a:0 ? a:1 : ''
let full_paths = split(glob(path.a:glob.suffix),"\n")
let relative_paths = []
for entry in full_paths
if suffix == '' && isdirectory(entry) && entry !~ '/$'
let entry .= '/'
endif
let relative_paths += [entry[strlen(path) : -strlen(suffix)-1]]
endfor
return relative_paths
finally
if exists("old_ss")
let &shellslash = old_ss
endif
endtry
endfunction
call s:add_methods('project',['relglob'])
function! s:R(cmd,bang,...) abort
let cmds = {'E': 'edit', 'S': 'split', 'V': 'vsplit', 'T': 'tabedit', 'D': 'read'}
let cmd = cmds[a:cmd] . a:bang
try
if a:0
let goal = s:project().path(a:1)
else
let related = s:buffer().related()
if related == ''
call s:throw('no related file')
else
let goal = s:project().path(related)
endif
endif
if goal =~# '[#:]\d\+$'
let cmd .= ' +'.matchstr(goal,'\d\+$')
let goal = matchstr(goal,'.*\ze[:#].*$')
elseif goal =~ '[#:]\w\+[?!=]\=$'
let cmd .= ' +/^\\s*def\\s\\+'.matchstr(goal,'[:#]\zs.\{-\}$')
let goal = matchstr(goal,'.*\ze[:#].*$')
endif
let parent = fnamemodify(goal,':h')
if !isdirectory(parent)
if a:bang ==# '!' && isdirectory(fnamemodify(parent,':h'))
call mkdir(parent)
endif
call s:throw('No such directory: '.parent)
endif
return cmd.' '.s:fnameescape(goal)
return ''
catch /^rake:/
return 'echoerr v:errmsg'
endtry
endfunction
function! s:RComplete(A,L,P) abort
return s:completion_filter(s:project().relglob('',s:fuzzyglob(a:A).'*'),a:A)
endfunction
call s:command("-bar -bang -nargs=? -complete=customlist,s:RComplete R :execute s:R('E','<bang>',<f-args>)")
call s:command("-bar -bang -nargs=? -complete=customlist,s:RComplete RS :execute s:R('S','<bang>',<f-args>)")
call s:command("-bar -bang -nargs=? -complete=customlist,s:RComplete RV :execute s:R('V','<bang>',<f-args>)")
call s:command("-bar -bang -nargs=? -complete=customlist,s:RComplete RT :execute s:R('T','<bang>',<f-args>)")
call s:command("-bar -bang -nargs=? -complete=customlist,s:RComplete RD :execute s:R('D','<bang>',<f-args>)")
call s:command("-bar -bang -nargs=? -complete=customlist,s:RComplete A :execute s:R('E','<bang>',<f-args>)")
call s:command("-bar -bang -nargs=? -complete=customlist,s:RComplete AS :execute s:R('S','<bang>',<f-args>)")
call s:command("-bar -bang -nargs=? -complete=customlist,s:RComplete AV :execute s:R('V','<bang>',<f-args>)")
call s:command("-bar -bang -nargs=? -complete=customlist,s:RComplete AT :execute s:R('T','<bang>',<f-args>)")
call s:command("-bar -bang -nargs=? -complete=customlist,s:RComplete AD :execute s:R('D','<bang>',<f-args>)")
" }}}1
" Rlib, etc. {{{1
function! s:navcommand(name) abort
for type in ['', 'S', 'V', 'T', 'D']
call s:command("-bar -bang -nargs=? -complete=customlist,s:R".a:name."Complete R".type.a:name." :execute s:Edit('".type."','<bang>',s:R".a:name."(matchstr(<q-args>,'[^:#]*')).matchstr(<q-args>,'[:#].*'))")
endfor
endfunction
function! s:Edit(cmd,bang,file)
return s:R(a:cmd == '' ? 'E' : a:cmd, a:bang, a:file)
endfunction
function! s:Rlib(file)
if a:file ==# ''
return get(s:project().relglob('','*.gemspec'),0,'Gemfile')
elseif a:file =~# '/$'
return 'lib/'.a:file
else
return 'lib/'.a:file.'.rb'
endif
endfunction
function! s:RlibComplete(A,L,P)
return s:completion_filter(s:project().relglob('lib/','**/*','.rb'),a:A)
endfunction
function! s:first_file(choices)
return call(s:project().first_file,a:choices,s:project())
endfunction
function! s:Rtestorspec(order,file)
if a:file ==# ''
return s:first_file(map(copy(a:order),'v:val."/".v:val."_helper.rb"'))
elseif a:file =~# '/$'
return s:first_file(map(copy(a:order),'v:val."/".a:file."/"'))
elseif a:file ==# '.'
return s:first_file(map(copy(a:order),'v:val."/"'))
else
return s:first_file(map(copy(a:order),'v:val."/".a:file."_".v:val.".rb"'))
endif
endfunction
function! s:Rtest(...)
return call('s:Rtestorspec',[['test', 'spec']] + a:000)
endfunction
function! s:RtestComplete(A,L,P)
return s:completion_filter(s:project().relglob('test/','**/*','_test.rb')+s:project().relglob('spec/','**/*','_spec.rb'),a:A)
endfunction
function! s:Rspec(...)
return call('s:Rtestorspec',[['spec', 'test']] + a:000)
endfunction
function! s:RspecComplete(A,L,P)
return s:completion_filter(s:project().relglob('spec/','**/*','_spec.rb')+s:project().relglob('test/','**/*','_test.rb'),a:A)
endfunction
function! s:Rtask(file)
if a:file ==# ''
return 'Rakefile'
elseif a:file =~# '/$'
return 'rakelib/'.a:file
else
return 'rakelib/'.a:file.'.rake'
endif
endfunction
function! s:RtaskComplete(A,L,P)
return s:completion_filter(s:project().relglob('rakelib/','**/*','.rake'),a:A)
endfunction
call s:navcommand('lib')
call s:navcommand('test')
call s:navcommand('spec')
call s:navcommand('task')
" }}}1
" Rtags {{{1
function! s:project_tags_file() dict abort
if filereadable(self.path('tags')) || filewritable(self.path())
return self.path('tags')
else
if !has_key(self,'_tags_file')
let self._tags_file = tempname()
endif
endif
return self._tags_file
endfunction
call s:add_methods('project',['tags_file'])
function! s:Tags(args)
if exists("g:Tlist_Ctags_Cmd")
let cmd = g:Tlist_Ctags_Cmd
elseif executable("exuberant-ctags")
let cmd = "exuberant-ctags"
elseif executable("ctags-exuberant")
let cmd = "ctags-exuberant"
elseif executable("ctags")
let cmd = "ctags"
elseif executable("ctags.exe")
let cmd = "ctags.exe"
else
call s:throw("ctags not found")
endif
return escape('!'.cmd.' -f '.s:shellesc(s:project().tags_file()).' -R '.s:shellesc(s:project().path()),'%#').' '.a:args
endfunction
call s:command("-bar -bang -nargs=? Rtags :execute s:Tags(<q-args>)")
augroup rake_tags
autocmd!
autocmd User Rake
\ if stridx(&tags, escape(s:project().tags_file(),', ')) < 0 |
\ let &l:tags = escape(s:project().tags_file(),', ') . ',' . &tags |
\ endif
augroup END
" }}}1
" Path {{{1
augroup rake_path
autocmd!
autocmd User Rake
\ if &suffixesadd =~# '\.rb\>' && stridx(&path, escape(s:project().path('lib'),', ')) < 0 |
\ let &l:path = escape(s:project().path('lib'),', ')
\ . ',' . escape(s:project().path('ext'),', ') . ',' . &path |
\ endif
augroup END
" }}}1
" vim:set sw=2 sts=2: