-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some ruby plugins and macvim specific fullscreen mappings
- Loading branch information
Showing
4 changed files
with
288 additions
and
2 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
" Copyright (C) 2006 Mauricio Fernandez <[email protected]> | ||
" rcodetools support plugin | ||
" | ||
|
||
if exists("loaded_rcodetools") | ||
finish | ||
endif | ||
|
||
let loaded_rcodetools = 1 | ||
let s:save_cpo = &cpo | ||
set cpo&vim | ||
|
||
"{{{ set s:sid | ||
|
||
map <SID>xx <SID>xx | ||
let s:sid = maparg("<SID>xx") | ||
unmap <SID>xx | ||
let s:sid = substitute(s:sid, 'xx', '', '') | ||
|
||
"{{{ function: s:spellgetoption(name, default) | ||
" grab a user-specified option to override the default provided. options are | ||
" searched in the window, buffer, then global spaces. | ||
function! s:GetOption(name, default) | ||
if exists("w:{&filetype}_" . a:name) | ||
execute "return w:{&filetype}_".a:name | ||
elseif exists("w:" . a:name) | ||
execute "return w:".a:name | ||
elseif exists("b:{&filetype}_" . a:name) | ||
execute "return b:{&filetype}_".a:name | ||
elseif exists("b:" . a:name) | ||
execute "return b:".a:name | ||
elseif exists("g:{&filetype}_" . a:name) | ||
execute "return g:{&filetype}_".a:name | ||
elseif exists("g:" . a:name) | ||
execute "return g:".a:name | ||
else | ||
return a:default | ||
endif | ||
endfunction | ||
|
||
"{{{ IsOptionSet | ||
function! s:IsOptionSet(name) | ||
let bogus_val = "df hdsoi3y98 hjsdfhdkj" | ||
return s:GetOption(a:name, bogus_val) == bogus_val ? 0 : 1 | ||
endfunction | ||
|
||
|
||
"{{{ RCT_completion function | ||
|
||
let s:last_test_file = "" | ||
let s:last_test_lineno = 0 | ||
|
||
let s:rct_completion_col = 0 | ||
let s:rct_tmpfile = "" | ||
|
||
function! <SID>RCT_command_with_test_options(cmd) | ||
if s:last_test_file != "" | ||
return a:cmd . | ||
\ "-" . "-filename='" . expand("%:p") . "' " . | ||
\ "-t '" . s:last_test_file . "@" . s:last_test_lineno . "' " | ||
endif | ||
return a:cmd | ||
endfunction | ||
|
||
function! <SID>RCT_completion(findstart, base) | ||
if a:findstart | ||
let s:rct_completion_col = col('.') - 1 | ||
let s:rct_tmpfile = "tmp-rcodetools" . strftime("Y-%m-%d-%H-%M-%S.rb") | ||
silent exec ":w " . s:rct_tmpfile | ||
return strridx(getline('.'), '.', col('.')) + 1 | ||
else | ||
let line = line('.') | ||
let column = s:rct_completion_col | ||
|
||
let command = "rct-complete --completion-class-info --dev --fork --line=" . | ||
\ line . " --column=" . column . " " | ||
let command = <SID>RCT_command_with_test_options(command) . s:rct_tmpfile | ||
|
||
let data = split(system(command), '\n') | ||
|
||
for dline in data | ||
let parts = split(dline, "\t") | ||
let name = get(parts, 0) | ||
let selector = get(parts, 1) | ||
echo name | ||
echo selector | ||
if s:GetOption('rct_completion_use_fri', 0) && s:GetOption('rct_completion_info_max_len', 20) >= len(data) | ||
let fri_data = system('fri -f plain ' . "'" . selector . "'" . ' 2>/dev/null') | ||
call complete_add({'word': name, | ||
\ 'menu': get(split(fri_data), 2, ''), | ||
\ 'info': fri_data } ) | ||
else | ||
call complete_add(name) | ||
endif | ||
if complete_check() | ||
break | ||
endif | ||
endfor | ||
|
||
call delete(s:rct_tmpfile) | ||
return [] | ||
endif | ||
endfunction | ||
|
||
"{{{ ri functions | ||
|
||
function! <SID>RCT_new_ri_window() | ||
execute "new" | ||
execute "set bufhidden=delete buftype=nofile noswapfile nobuflisted" | ||
execute 'nmap <buffer><silent> <C-T> 2u' | ||
execute 'nmap <buffer><silent> <C-]> :call' . s:sid . 'RCT_execute_ri(expand("<cWORD>"))<cr>' | ||
endfunction | ||
|
||
function! <SID>RCT_execute_ri(query_term) | ||
silent %delete _ | ||
let term = matchstr(a:query_term, '\v[^,.;]+') | ||
let cmd = s:GetOption("RCT_ri_cmd", "fri -f plain ") | ||
let text = system(cmd . "'" . term . "'") | ||
call append(0, split(text, "\n")) | ||
normal gg | ||
endfunction | ||
|
||
function! RCT_find_tag_or_ri(fullname) | ||
" rubikitch: modified for rtags-compatible tags | ||
let tagname = '::' . a:fullname | ||
let tagresults = taglist(tagname) | ||
if len(tagresults) != 0 | ||
execute "tjump " . tagname | ||
else | ||
call <SID>RCT_new_ri_window() | ||
call <SID>RCT_execute_ri(a:fullname) | ||
endif | ||
endfunction | ||
|
||
function! <SID>RCT_smart_ri() | ||
let tmpfile = "tmp-rcodetools" . strftime("Y-%m-%d-%H-%M-%S.rb") | ||
silent exec ":w " . tmpfile | ||
|
||
let line = line('.') | ||
let column = col('.') - 1 | ||
let command = "rct-doc --ri-vim --line=" . line . " --column=" . column . " " | ||
let command = <SID>RCT_command_with_test_options(command) . tmpfile | ||
"let term = matchstr(system(command), "\\v[^\n]+") | ||
exec system(command) | ||
call delete(tmpfile) | ||
"call RCT_find_tag_or_ri(term) | ||
endfunction | ||
|
||
function! <SID>RCT_ruby_toggle() | ||
let curr_file = expand("%:p") | ||
let cmd = "ruby -S ruby-toggle-file " . curr_file | ||
if match(curr_file, '\v_test|test_') != -1 | ||
let s:last_test_file = curr_file | ||
let s:last_test_lineno = line(".") | ||
endif | ||
let dest = system(cmd) | ||
silent exec ":w" | ||
exec ("edit " . dest) | ||
silent! normal g; | ||
endfunction | ||
|
||
"{{{ bindings and au | ||
|
||
if v:version >= 700 | ||
execute "au Filetype ruby setlocal completefunc=" . s:sid . "RCT_completion" | ||
endif | ||
execute 'au Filetype ruby nmap <buffer><silent> <C-]> :exec "call ' . | ||
\ 'RCT_find_tag_or_ri(''" . expand("<cword>") . "'')"<cr>' | ||
execute 'au Filetype ruby nmap <buffer><silent>' . s:GetOption("RCT_ri_binding", "<LocalLeader>r") . | ||
\ ' :call ' . s:sid . 'RCT_smart_ri()<cr>' | ||
execute 'au Filetype ruby nmap <buffer><silent>' . s:GetOption("RCT_toggle_binding", "<LocalLeader>t") . | ||
\ ' :call ' . s:sid . 'RCT_ruby_toggle()<cr>' | ||
let &cpo = s:save_cpo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
" | ||
" vruby.vim -- Interactive Ruby inside Vim | ||
" | ||
|
||
" (C) 2009 Bertram Scharpf <[email protected]> | ||
" License: BSD | ||
|
||
" Put this file into some ~/.vim/plugin/ directory. | ||
|
||
|
||
" Examples: | ||
" | ||
" a = 'hello' | ||
" append a.upcase | ||
" ~ | ||
" :%Ruby | ||
" | ||
" 23,45 | ||
" 5.01 | ||
" ~ | ||
" :%RubySum | ||
|
||
|
||
function s:Ruby() range | ||
exec a:lastline | ||
put _ | ||
ruby << | ||
_ = eval(VIM.evaluate("getline(a:firstline,a:lastline)")) | ||
_.nil? or append "# => " + _.inspect | ||
. | ||
endfunc | ||
|
||
function s:RubySum() range | ||
exec a:lastline | ||
ruby << | ||
_ = eval( | ||
VIM.evaluate("getline(a:firstline,a:lastline)").map { |l| | ||
l.chomp! | ||
l.gsub! /(\d+),(\d+)/, "\\1.\\2" | ||
l | ||
}.join " + " | ||
) | ||
append "-"*32, _.inspect | ||
. | ||
endfunc | ||
|
||
ruby << | ||
def append *s | ||
s.any? or s.push nil | ||
c = VIM::Buffer.current | ||
s.each { |l| | ||
n = c.line_number | ||
c.append n, l.to_s.chomp | ||
n += 1 | ||
Vim.command n.to_s | ||
} | ||
nil | ||
end | ||
. | ||
|
||
command -bar -nargs=0 -range=% Ruby <line1>,<line2>call s:Ruby() | ||
command -bar -nargs=0 -range=% RubySum <line1>,<line2>call s:RubySum() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters