add conditional and delmarks

master
Totem4 Totem4 4 years ago
parent d94a5ac06d
commit 6fe44cbb93

@ -63,7 +63,7 @@ def isbanana(banana, dictstart = None, shiftend = None, dictionary = None):
return(True) return(True)
def callback(x): def callback(x):
return " %s " % dec2banana(int(x[0], base=10)).upper() return "%s" % dec2banana(int(x[0], base=10)).upper()
def text2banana(text): def text2banana(text):
text = re.sub(r"[0-9][0-9]*",callback,text) text = re.sub(r"[0-9][0-9]*",callback,text)
@ -85,12 +85,14 @@ def get_selected_text():
(lnum1, col1) = buf.mark('<') (lnum1, col1) = buf.mark('<')
(lnum2, col2) = buf.mark('>') (lnum2, col2) = buf.mark('>')
lines = vim.eval('getline({}, {})'.format(lnum1, lnum2)) lines = vim.eval('getline({}, {})'.format(lnum1, lnum2))
if len(lines) > 1:
lines[0] = lines[0][col1:] lines[0] = lines[0][col1:]
lines[-1] = lines[-1][:col2] lines[-1] = lines[-1][:col2]
else:
lines[0] = lines[0][col1:col2+1]
return "\n".join(lines) return "\n".join(lines)
def replace_selected_text(new_str): def replace_selected_text(new_str):
buf = vim.current.buffer buf = vim.current.buffer
(lnum1, col1) = buf.mark('<') (lnum1, col1) = buf.mark('<')
@ -100,8 +102,12 @@ def replace_selected_text(new_str):
new_str_list = new_str.split('\n') new_str_list = new_str.split('\n')
del buf[lnum1-1:lnum2] del buf[lnum1-1:lnum2]
buf.append(new_str_list, lnum1-1) buf.append(new_str_list, lnum1-1)
vim.command("delmarks < >")
return new_str return new_str
def enc_line():
vim.current.line = re.sub(r"[0-9][0-9]*",callback,vim.current.line)
if __name__ == "__main__": def dec_line():
print("Ciao sono la libreria banana") vim.current.line = re.sub(r"[A-Z][A-Z]*",callback_dec,vim.current.line)

Loading…
Cancel
Save