vimrc: rewrite functions in ruby

master
an 2019-05-01 00:22:48 -04:00
parent e0efc55671
commit be7bd398ce
1 changed files with 28 additions and 20 deletions

48
vimrc
View File

@ -32,7 +32,7 @@ se stl+=%r
se stl+=%m
"se stl+=\ %{tagbar#currenttag('←\ %s\ ','','f')}
se stl+=\ %=
se stl+=\ %{MabFileSize()}
se stl+=\ %{FileSize()}
se stl+=\ %4l:%-3c
se stl+=\ %4L
se stl+=\ %3p%%
@ -168,31 +168,39 @@ en
" Functions ------------------------------------------------------------------|
" Strip whitespace on buffer write
fu! <SID>StripWhite()
let l=line(".")
let c=col(".")
%s/\s\+$//e
cal cursor(l, c)
endf
" Automatic headers
fu! <SID>FillLine(str)
let tw=&textwidth
if tw == 0 | let tw=80 | en
.s/\s*$//
let rep = ((tw - col("$")) / len(a:str)) - 2
if rep > 0 | .s/$/\=(' '.repeat(a:str, rep))/ | en
fu! <SID>FillLine()
ruby<<
tw = VIM::evaluate("&tw").to_i
tw = 80 if tw == 0
lin = $curbuf.line
rep = tw - lin.length - 3
if rep > 0
$curbuf.line += " " + "-" * rep + "|"
end
.
endf
" File size
fu! MabFileSize()
fu! FileSize()
let fs=line2byte(line('$')+1)-1
if fs < 0 | retu "" | else | retu fs | en
endf
" Strip whitespace on buffer write
fu! s:StripWhite()
ruby<<
for ln in 1..$curbuf.length
rs = $curbuf[ln].rstrip
if $curbuf[ln] != rs
$curbuf[ln] = rs
end
end
.
endf
" Close empty buffers
fu! <SID>CloseEmptyBuffers()
fu! s:CloseEmptyBuffers()
let bufs = filter(range(1, bufnr('$')), 'buflisted(v:val) && empty(bufname(v:val)) && bufwinnr(v:val) < 0 && !getbufvar(v:val, "&mod")')
if !empty(bufs)
exe 'bd' join(bufs, ' ')
@ -202,7 +210,7 @@ endf
" Autocommands ---------------------------------------------------------------|
" Strip whitespace
au FileType c,cpp,cs,java,php,ruby,rust,python,go,zscript,markdown au BufWritePre <buffer> cal <SID>StripWhite()
au FileType c,cpp,cs,java,php,ruby,rust,python,go,zscript,markdown au BufWritePre <buffer> cal s:StripWhite()
" Enable rainbow braces
au FileType c,cpp,cs,java,php,ruby,rust,python,go,zscript,html,scheme,racket,lisp au BufEnter <buffer> RainbowToggleOn
@ -211,7 +219,7 @@ au FileType c,cpp,cs,java,php,ruby,rust,python,go,zscript,html,scheme,racket,lis
au BufNewFile,BufRead *.s,*.inc setl sw=8 ft=asm_ca65
" close empty buffers automatically
au BufEnter * cal <SID>CloseEmptyBuffers()
au BufEnter * cal s:CloseEmptyBuffers()
" EDF → conf
au FileType edif se syn=conf
@ -233,7 +241,7 @@ au BufRead,BufNewFile Cargo.toml if &filetype == "" | set filetype=toml | endif
nm ga <Plug>(EasyAlign)
xm ga <Plug>(EasyAlign)
nn <Leader>e :cal <SID>FillLine("-")<CR>A\|<ESC>
nn <Leader>e :cal <SID>FillLine()<CR>
" TagBar
nm <F5> :TagbarToggle<CR>