[~] Refactor

This commit is contained in:
Siarhei Siniak 2022-09-30 15:36:03 +03:00
parent 6427bbd071
commit a8616ff090
3 changed files with 53 additions and 3 deletions

@ -5,6 +5,7 @@ cp dotfiles/.local/bin/commands ~/.local/bin/commands
mkdir -p ~/.sway mkdir -p ~/.sway
cp dotfiles/.sway/config ~/.sway/config cp dotfiles/.sway/config ~/.sway/config
cp dotfiles/.zshenv ~/.zshenv cp dotfiles/.zshenv ~/.zshenv
cp dotfiles/.vimrc ~/.vimrc
cp dotfiles/.tmux.conf ~/.tmux.conf cp dotfiles/.tmux.conf ~/.tmux.conf
cp -rp \ cp -rp \
dotfiles/.ipython/profile_default/ipython_config.py \ dotfiles/.ipython/profile_default/ipython_config.py \

@ -4,15 +4,59 @@ c.InteractiveShellApp.exec_lines = [
def ipython_update_shortcuts(): def ipython_update_shortcuts():
import IPython import IPython
import prompt_toolkit.filters import prompt_toolkit.filters
import prompt_toolkit.document
import functools
import tempfile
import io
import subprocess
def ipython_edit_in_vim(*args, pt_app):
content = pt_app.app.current_buffer.document.text
lines_count = lambda text: len(text.splitlines())
with tempfile.NamedTemporaryFile(
suffix='.py',
mode='w',
) as f:
with io.open(f.name, 'w') as f2:
f2.write(content)
f2.flush()
result = subprocess.call([
'vim',
'+%d' % lines_count(content),
f.name,
])
if result != 0:
return
f.seek(0, io.SEEK_SET)
with io.open(f.name, 'r') as f2:
new_content = f2.read()
pt_app.app.current_buffer.document = \
prompt_toolkit.document.Document(
new_content,
cursor_position=len(new_content.rstrip()),
)
t1 = IPython.get_ipython() t1 = IPython.get_ipython()
t2 = t1.pt_app t2 = t1.pt_app
t3 = [o for o in t2.key_bindings.bindings if 'f2' in repr(o).lower()] t3 = [o for o in t2.key_bindings.bindings if 'f2' in repr(o.keys).lower()]
assert len(t3) == 1 assert len(t3) == 1
t4 = t3[0] t4 = t3[0]
t2.key_bindings.remove(t4.handler) t2.key_bindings.remove(t4.handler)
t2.key_bindings.add( t2.key_bindings.add(
'e', filter=~prompt_toolkit.filters.vi_insert_mode, 'e', filter=~prompt_toolkit.filters.vi_insert_mode,
)(t4.handler) )(
functools.partial(
ipython_edit_in_vim,
pt_app=t2,
)
#t4.handler
)
''', ''',
'ipython_update_shortcuts()', 'ipython_update_shortcuts()',
] ]

@ -43,13 +43,18 @@ syntax on
set hls set hls
map <Leader>w <C-w> map <Leader>w <C-w>
map <Leader>r :source ~/.vimrc<CR>:echo 'reloaded'<CR> map <Leader>z :wqa<CR>
map <Leader>m :py3 f1()<CR> map <Leader>m :py3 f1()<CR>
map <Leader>r :redraw!<CR>
map <Leader>cq :cq<CR> map <Leader>cq :cq<CR>
map <Leader>f2 :py3 f2()<CR> map <Leader>f2 :py3 f2()<CR>
map <Leader>f3 :source ~/.vimrc<CR>:echo 'reloaded'<CR>
map <Leader>qy :q!<CR> map <Leader>qy :q!<CR>
map <Leader>cq :cq1<CR> map <Leader>cq :cq1<CR>
map <Leader>dq :cq2<CR> map <Leader>dq :cq2<CR>
map <Leader>i1 :set sw=4 sts=4 ts=4 et ai ci<CR>:retab<CR> map <Leader>i1 :set sw=4 sts=4 ts=4 et ai ci<CR>:retab<CR>
map <Leader>i2 :set sw=2 sts=2 ts=2 et ai ci<CR>:retab<CR> map <Leader>i2 :set sw=2 sts=2 ts=2 et ai ci<CR>:retab<CR>
map <Leader>i3 :set t_Co=0 so=999<CR>
map <Leader>i4 :set t_Co=256 so=0<CR>
set foldmethod=indent set foldmethod=indent
set nofoldenable