working vim plugin

master
Totem4 Totem4 1 year ago
parent dc37224a9f
commit 265eb2a2d3

@ -1,130 +0,0 @@
if exists("g:loaded_Banananew") || &cp
finish
endif
let g:loaded_Banananew= 1 " your version number
let s:keepcpo = &cpo
set cpo&vim
if !hasmapto('<Plug>BananaEncnew')
map <unique> <Leader>c <Plug>BananaEncNew
endif
if !hasmapto('<Plug>BananaDecnew')
map <unique> <Leader>t <Plug>BananaDecNew
endif
noremap <silent> <unique> <script> <Plug>BananaEncNew
\ :call <SID>Enc()<CR>
noremap <silent> <unique> <script> <Plug>BananaDecNew
\ :call <SID>Dec()<CR>
fun! s:Enc() range
if line("'<") > 0
call s:ReplSel(s:Dec2Ban(s:GetSel()))
else
call s:EncLine()
endif
endfun!
fun! s:EncLine()
call setline('.', substitute(getline('.'), '\d\d*', '\=toupper(s:Doban(submatch(0)))','g'))
endfun!
fun! s:Dec() range
if line("'<") > 0
call s:ReplSel(s:Ban2Dec(s:GetSel()))
else
call s:DecLine()
endif
endfun!
fun! s:DecLine()
call setline('.', substitute(getline('.'), '\C\u\u*', '\=s:Unban(tolower(submatch(0)))','g'))
endfun!
let s:dictionary = [['b', 'c', 'd', 'f', 'g', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v', 'z'], ['a', 'e', 'i', 'o', 'u']]
let s:numdict = len(s:dictionary)
fun! s:Doban(num)
let l:v = a:num
let l:st = ''
let l:l = 0
let l:i = (s:numdict - 1) % s:numdict
while ! (l:v == 0 && l:i == (s:numdict -1) % s:numdict && l:l >= 0)
let l:r = l:v % len(s:dictionary[l:i])
let l:v = l:v / len(s:dictionary[l:i])
let l:st = s:dictionary[l:i][l:r] . l:st
let l:i = abs((l:i - 1) % s:numdict)
let l:l = l:l + 1
endwhile
return l:st
endfun!
fun! s:Unban(ban)
if ! s:IsBanana(a:ban)
return toupper(a:ban)
endif
let l:v = 0
for l:i in range(len(a:ban))
let l:r = (s:numdict + l:i) % s:numdict
let l:p = index(s:dictionary[l:r],a:ban[l:i])
let l:v = l:v * len(s:dictionary[l:r]) + l:p
endfor
return l:v
endfun!
fun! s:IsBanana(ban)
if (len(a:ban) % s:numdict) != 0
return 0
endif
for l:i in range(len(a:ban))
let l:r = (s:numdict + l:i) % s:numdict
if index(s:dictionary[l:r],a:ban[l:i]) == -1
return 0
endif
endfor
return 1
endfun!
fun! s:GetSel()
let [l:lstart, l:cstart] = getcharpos("'<")[1:2]
let [l:lend, l:cend] = getcharpos("'>")[1:2]
let l:lines = getline(l:lstart, l:lend)
if len(l:lines) == 0
return ''
endif
let l:lines[-1] = l:lines[-1][: l:cend - (&selection == 'inclusive' ? 1 : 2)]
let l:lines[0] = l:lines[0][l:cstart - 1:]
return join(l:lines, "\n")
endfun!
fun! s:ReplSel(str)
let [l:lstart, l:cstart] = getcharpos("'<")[1:2]
let [l:lend, l:cend] = getcharpos("'>")[1:2]
let l:lines = getline(l:lstart, l:lend)
let l:new_str = slice(l:lines[0],0,l:cstart - 1) . a:str . l:lines[-1][l:cend:]
let l:new_str_lst = split(l:new_str,'\n')
call setline(l:lstart ,l:new_str_lst)
delmarks < >
endfun!
fun! s:Dec2Ban(text)
return substitute(a:text, '\d\d*', '\=toupper(s:Doban(submatch(0)))', 'g')
endfun!
fun! s:Ban2Dec(text)
return substitute(a:text, '\C\u\u*', '\=s:Unban(tolower(submatch(0)))', 'g')
endfun!
let &cpo= s:keepcpo
unlet s:keepcpo

@ -1,121 +1,93 @@
if exists("g:loaded_Banana") || &cp
if exists("g:loaded_Banananew") || &cp
finish
endif
let g:loaded_Banana= 1 " your version number
let g:loaded_Banananew= 1 " your version number
let s:keepcpo = &cpo
set cpo&vim
if !hasmapto('<Plug>BananaEnc')
map <unique> <Leader>b <Plug>BananaEnc
if !hasmapto('<Plug>BananaEncnew')
map <unique> <Leader>c <Plug>BananaEncNew
endif
if !hasmapto('<Plug>BananaDec')
map <unique> <Leader>t <Plug>BananaDec
if !hasmapto('<Plug>BananaDecnew')
map <unique> <Leader>t <Plug>BananaDecNew
endif
noremap <silent> <unique> <script> <Plug>BananaEnc
\ :call <SID>EncLine()<CR>
noremap <silent> <unique> <script> <Plug>BananaDec
\ :call <SID>DecLine()<CR>
noremap <silent> <unique> <script> <Plug>BananaEncNew
\ :call <SID>Enc()<CR>
noremap <silent> <unique> <script> <Plug>BananaDecNew
\ :call <SID>Dec()<CR>
fun! s:Enc()
:call s:ReplaceSelectedText(s:GetSelectedText())
fun! s:Enc() range
if line("'<") > 0
call s:ReplSel(s:Dec2Ban(s:GetSel()))
else
call s:EncLine()
endif
endfun!
fun! s:EncLine()
:call setline('.', substitute(getline('.'), '[0-9][0-9]*', s:Doban(getline('.')),""))
endfun!
fun! s:DecLine()
":call setline('.', substitute(getline('.'), '([A-Z][A-Z])*', s:Unban(getline('.')),""))
:call setline('.', substitute(getline('.'), '[a-z][a-z]*', s:Unban(getline('.')),""))
call setline('.', substitute(getline('.'), '\d\d*', '\=toupper(s:Doban(submatch(0)))','g'))
endfun!
fun! s:GetSelectedText()
let [line_start, column_start] = getpos("'<")[1:2]
let [line_end, column_end] = getpos("'>")[1:2]
let lines = getline(line_start, line_end)
if len(lines) == 0
return ''
fun! s:Dec() range
if line("'<") > 0
call s:ReplSel(s:Ban2Dec(s:GetSel()))
else
call s:DecLine()
endif
let lines[-1] = lines[-1][: column_end - (&selection == 'inclusive' ? 1 : 2)]
let lines[0] = lines[0][column_start - 1:]
return join(lines, "\n")
endfun!
fun! s:ReplaceSelectedText(new_str)
let [line_start, column_start] = getpos("'<")[1:2]
let [line_end, column_end] = getpos("'>")[1:2]
let lines = getline(line_start, line_end)
let new_str = lines[0][:column_start] . new_str . lines[-1][column_end + 1:]
let new_str_lst = split(new_str,"\n")
'<,'>s/.*/join(new_str_lst,"\n")/ge
delmarks < >
return new_str
fun! s:DecLine()
call setline('.', substitute(getline('.'), '\C\u\u*', '\=s:Unban(tolower(submatch(0)))','g'))
endfun!
fun! s:Doban(num)
let s:dictionary = [['b', 'c', 'd', 'f', 'g', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v', 'z'], ['a', 'e', 'i', 'o', 'u']]
let s:numdict = len(s:dictionary)
let s:v = a:num
let s:st = ''
let s:l = 0
let s:i = (s:numdict - 1) % s:numdict
let s:dictionary = [['b', 'c', 'd', 'f', 'g', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v', 'z'], ['a', 'e', 'i', 'o', 'u']]
let s:numdict = len(s:dictionary)
while ! (s:v == 0 && s:i == (s:numdict -1) % s:numdict && s:l >= 0)
let s:r = s:v % len(s:dictionary[s:i])
let s:v = s:v / len(s:dictionary[s:i])
let s:st = s:dictionary[s:i][s:r] . s:st
let s:i = abs((s:i - 1) % s:numdict)
let s:l = s:l + 1
fun! s:Doban(num)
let l:v = a:num
let l:st = ''
let l:l = 0
let l:i = (s:numdict - 1) % s:numdict
while ! (l:v == 0 && l:i == (s:numdict -1) % s:numdict && l:l >= 0)
let l:r = l:v % len(s:dictionary[l:i])
let l:v = l:v / len(s:dictionary[l:i])
let l:st = s:dictionary[l:i][l:r] . l:st
let l:i = abs((l:i - 1) % s:numdict)
let l:l = l:l + 1
endwhile
return s:st
return l:st
endfun!
fun! s:Unban(ban)
let s:dictionary = [['b', 'c', 'd', 'f', 'g', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v', 'z'], ['a', 'e', 'i', 'o', 'u']]
let s:numdict = len(s:dictionary)
" if (len(a:ban) % s:numdict) != 0
" echo "Banana non valida"
" return a:ban
" endif
if ! s:IsBanana(a:ban)
echo "Banana non valida"
return a:ban
return toupper(a:ban)
endif
let s:v = 0
for i in range(len(a:ban))
let l:v = 0
for l:i in range(len(a:ban))
let s:r = (s:numdict + i) % s:numdict
let s:p = index(s:dictionary[s:r],a:ban[i])
let l:r = (s:numdict + l:i) % s:numdict
let l:p = index(s:dictionary[l:r],a:ban[l:i])
" if s:p < 0
" echo "Carattere non valido in posizione" . i + 1
" return a:ban
" endif
let s:v = s:v * len(s:dictionary[s:r]) + s:p
let l:v = l:v * len(s:dictionary[l:r]) + l:p
endfor
return s:v
return l:v
endfun!
fun! s:IsBanana(ban)
let s:dictionary = [['b', 'c', 'd', 'f', 'g', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v', 'z'], ['a', 'e', 'i', 'o', 'u']]
let s:numdict = len(s:dictionary)
if (len(a:ban) % s:numdict) != 0
return 0
endif
for i in range(len(a:ban))
let s:r = (s:numdict + i) % s:numdict
if index(s:dictionary[s:r],a:ban[i]) == -1
for l:i in range(len(a:ban))
let l:r = (s:numdict + l:i) % s:numdict
if index(s:dictionary[l:r],a:ban[l:i]) == -1
return 0
endif
endfor
@ -123,5 +95,36 @@ fun! s:IsBanana(ban)
return 1
endfun!
fun! s:GetSel()
let [l:lstart, l:cstart] = getcharpos("'<")[1:2]
let [l:lend, l:cend] = getcharpos("'>")[1:2]
let l:lines = getline(l:lstart, l:lend)
if len(l:lines) == 0
return ''
endif
let l:lines[-1] = l:lines[-1][: l:cend - (&selection == 'inclusive' ? 1 : 2)]
let l:lines[0] = l:lines[0][l:cstart - 1:]
return join(l:lines, "\n")
endfun!
fun! s:ReplSel(str)
let [l:lstart, l:cstart] = getcharpos("'<")[1:2]
let [l:lend, l:cend] = getcharpos("'>")[1:2]
let l:lines = getline(l:lstart, l:lend)
let l:new_str = slice(l:lines[0],0,l:cstart - 1) . a:str . l:lines[-1][l:cend:]
let l:new_str_lst = split(l:new_str,'\n')
call setline(l:lstart ,l:new_str_lst)
delmarks < >
endfun!
fun! s:Dec2Ban(text)
return substitute(a:text, '\d\d*', '\=toupper(s:Doban(submatch(0)))', 'g')
endfun!
fun! s:Ban2Dec(text)
return substitute(a:text, '\C\u\u*', '\=s:Unban(tolower(submatch(0)))', 'g')
endfun!
let &cpo= s:keepcpo
unlet s:keepcpo

Loading…
Cancel
Save