Skip to content

Commit

Permalink
Some ruby plugins and macvim specific fullscreen mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
skammer committed Apr 15, 2009
1 parent 447d17d commit 9d1b1fd
Show file tree
Hide file tree
Showing 4 changed files with 288 additions and 2 deletions.
File renamed without changes.
173 changes: 173 additions & 0 deletions plugin/rcodetools.vim
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
63 changes: 63 additions & 0 deletions plugin/vruby.vim
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()

54 changes: 52 additions & 2 deletions vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,56 @@ nnoremap <c-t>t :FuzzyFinderTextMate<CR>
nnoremap <leader>b :BufExplorer<cr>
imap <D-Enter> <Esc>o
imap <D-S-Enter> <Esc>O
" Рубиистические всякие вкусности

" plain annotations
map <silent> <D-r> !xmpfilter -a<cr>
nmap <silent> <D-r> V<D-r>
imap <silent> <D-r> <ESC><D-r>a
" Annotate the full buffer
" I actually prefer ggVG to %; it's a sort of poor man's visual bell
nmap <silent> <D-R> mzggVG!xmpfilter -a<cr>'z
imap <silent> <D-R> <ESC><D-R>
" assertions
nmap <silent> <C-D-r> mzggVG!xmpfilter -u<cr>'z
imap <silent> <C-D-r> <ESC><C-D-r>a
" Add # => markers
vmap <silent> <localleader>a3 !xmpfilter -m<cr>
nmap <silent> <localleader>a3 V<localleader>a3
imap <silent> <localleader>a3 <ESC><localleader>a3a
" Remove # => markers
vmap <silent> <localleader>r3 ms:call RemoveRubyEval()<CR>
nmap <silent> <localleader>r3 V<localleader>r3
imap <silent> <localleader>r3 <ESC><localleader>r3a
function! RemoveRubyEval() range
let begv = a:firstline
let endv = a:lastline
normal Hmt
set lz
execute ":" . begv . "," . endv . 's/\s*# \(=>\|!!\).*$//e'
normal 'tzt`s
set nolz
redraw
endfunction
set invfullsreen
fu! ToggleFullscreen()
if &go == "amge"
exec 'set go='."amg"
exec 'set invfullscreen'
else
exec 'set go='."amge"
exec 'set invfullscreen'
endif
endf

map <D-D> :call ToggleFullscreen()<cr>
"imap <D-Enter> <Esc>A<cr>

" Настройки завершения скобок
Expand Down Expand Up @@ -193,8 +243,8 @@ runtime! macros/matchit.vim


"folding settings
set foldmethod=syntax "fold based on indent
set foldnestmax=5 "deepest fold is 3 levels
set foldmethod=indent "fold based on indent
set foldnestmax=3 "deepest fold is 3 levels
set nofoldenable "dont fold by default

set wildmode=list:longest,full "make cmdline tab completion similar to bash
Expand Down

0 comments on commit 9d1b1fd

Please sign in to comment.