[+] update vim modules
1. use python modules for separate logic; 2. update popup_menu parameters for fast select;
This commit is contained in:
parent
3a76eab761
commit
ecab00f4aa
2
.gitignore
vendored
2
.gitignore
vendored
@ -19,3 +19,5 @@ python/build
|
||||
!docker/*/.env
|
||||
.envs
|
||||
!docker/*/deps/whl/**
|
||||
|
||||
!dotfiles/.vim
|
||||
|
4
Makefile
4
Makefile
@ -83,11 +83,11 @@ dotfiles_put:
|
||||
|
||||
dotfiles_vim_put:
|
||||
mkdir -p $(INSTALL_ROOT)
|
||||
mkdir -p $(INSTALL_ROOT)/.vim
|
||||
|
||||
cp dotfiles/.vimrc ~/.vimrc
|
||||
cp dotfiles/.py3.vimrc ~/.py3.vimrc
|
||||
cp dotfiles/.module.vimrc.py ~/.module.vimrc.py
|
||||
cp dotfiles/.beta.vimrc.py ~/.beta.vimrc.py
|
||||
cp -rp dotfiles/.vim/online_fxreader_pr34_vim ~/.vim/
|
||||
|
||||
PLATFORM ?= macbook_air_2012
|
||||
PLATFORM_TMP ?= tmp/platform_dotfiles/$(PLATFORM)
|
||||
|
@ -1,12 +1,18 @@
|
||||
py3 <<EOF
|
||||
|
||||
def load():
|
||||
import logging
|
||||
import logging.handlers
|
||||
|
||||
import importlib
|
||||
|
||||
import json
|
||||
import pathlib
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.append(
|
||||
str(pathlib.Path('~/.vim').expanduser())
|
||||
)
|
||||
|
||||
logging.basicConfig(
|
||||
level=getattr(
|
||||
@ -24,24 +30,22 @@ def load():
|
||||
)
|
||||
|
||||
modules = [
|
||||
pathlib.Path(o).expanduser()
|
||||
for o in json.loads(os.environ.get('VIM_PY3_MODULES', '["~/.module.vimrc.py"]'))
|
||||
str(o)
|
||||
for o in json.loads(os.environ.get('VIM_PY3_MODULES', '["online_fxreader_pr34_vim.main"]'))
|
||||
]
|
||||
for o in modules:
|
||||
if not o.exists():
|
||||
raise RuntimeError('not found %s' % str(o))
|
||||
|
||||
vim.command('py3file {}'.format(str(o)))
|
||||
for o in modules:
|
||||
# if not o.exists():
|
||||
# raise RuntimeError('not found %s' % str(o))
|
||||
|
||||
m = importlib.import_module(o)
|
||||
getattr(m, 'init')()
|
||||
# vim.command('py3file {}'.format(str(o)))
|
||||
EOF
|
||||
|
||||
" py3file ~/.module.vimrc.py
|
||||
python3 load()
|
||||
|
||||
augroup EditorConfigModeline
|
||||
autocmd!
|
||||
autocmd BufEnter * python3 EditorConfigModeline.singleton().on_buffer()
|
||||
augroup END
|
||||
|
||||
function! F5(pattern, flags, info)
|
||||
let res = py3eval(
|
||||
\'f5_1(
|
||||
|
0
dotfiles/.vim/online_fxreader_pr34_vim/__init__.py
Normal file
0
dotfiles/.vim/online_fxreader_pr34_vim/__init__.py
Normal file
@ -19,6 +19,8 @@ from typing import (
|
||||
Callable,
|
||||
)
|
||||
|
||||
from .utils import Vim
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
MODULE_NAME = 'online_fxreader_pr34_vim'
|
||||
@ -241,21 +243,6 @@ class EditorConfigModeline:
|
||||
# raise NotImplementedError
|
||||
|
||||
|
||||
class _Vim:
|
||||
@classmethod
|
||||
def run_command(cls, cmd) -> list[str]:
|
||||
# logger.info(dict(cmd=cmd))
|
||||
|
||||
output: list[str] = []
|
||||
for line in cmd.splitlines():
|
||||
if line.strip() == '':
|
||||
continue
|
||||
output.append(
|
||||
vim.command(line)
|
||||
)
|
||||
|
||||
return output
|
||||
|
||||
def future_dump_exception(future: Any) -> None:
|
||||
try:
|
||||
future.result()
|
||||
@ -287,16 +274,16 @@ class FastSelect:
|
||||
|
||||
vim.command(r'''
|
||||
func! UIThread(timer_id)
|
||||
python3 FastSelect.singleton().ui_thread()
|
||||
python3 online_fxreader_pr34_vim.beta.FastSelect.singleton().ui_thread()
|
||||
endfunc
|
||||
''')
|
||||
_Vim.run_command(r'''
|
||||
Vim.run_command(r'''
|
||||
call timer_start(100, 'UIThread', {'repeat': -1})
|
||||
''')
|
||||
_Vim.run_command(r'''
|
||||
Vim.run_command(r'''
|
||||
augroup {auto_group}
|
||||
autocmd!
|
||||
autocmd VimLeavePre * python3 FastSelect.singleton().close()
|
||||
autocmd VimLeavePre * python3 online_fxreader_pr34_vim.beta.FastSelect.singleton().close()
|
||||
augroup END
|
||||
'''.format(
|
||||
auto_group=auto_group,
|
||||
@ -357,7 +344,7 @@ augroup END
|
||||
|
||||
logger.warning(dict(buffers=list(vim.buffers), id=selected_id))
|
||||
# print(vim.buffers, selected_id)
|
||||
if selected_id:
|
||||
if not selected_id is None:
|
||||
vim.current.buffer = vim.buffers[buffers[selected_id][1]]
|
||||
|
||||
with self._lock:
|
||||
@ -375,28 +362,6 @@ augroup END
|
||||
logger.info(dict(msg='after switch_buffer started'))
|
||||
|
||||
|
||||
def pick_file_from_popup(
|
||||
self,
|
||||
paths: list[pathlib.Path],
|
||||
) -> None:
|
||||
|
||||
_Vim.run_command(r'''
|
||||
call popup_menu(['asdasdfasdfasdfasdfasdfasdfasdff', 'adfadf'], {'title': '!!!!sdfasdf'})
|
||||
''')
|
||||
return
|
||||
|
||||
logger.info(dict(msg='before pick started'))
|
||||
result = asyncio.run_coroutine_threadsafe(
|
||||
self._pick_option_from_popup(
|
||||
options=[str(o) for o in paths]
|
||||
),
|
||||
self.loop
|
||||
)
|
||||
|
||||
result.add_done_callback(future_dump_exception)
|
||||
|
||||
logger.info(dict(msg='after pick started'))
|
||||
|
||||
async def _pick_option_from_popup(
|
||||
self,
|
||||
options: list[str],
|
||||
@ -425,7 +390,7 @@ augroup END
|
||||
|
||||
def ui_thread(self):
|
||||
with self._lock:
|
||||
#_Vim.run_command(r'''
|
||||
#Vim.run_command(r'''
|
||||
# set laststatus=2
|
||||
# set statusline={}
|
||||
#'''.format(datetime.datetime.now().isoformat()))
|
||||
@ -456,9 +421,9 @@ augroup END
|
||||
vim.command(r"""
|
||||
function! {callback_name}(id, result)
|
||||
if a:result > 0
|
||||
call py3eval('FastSelect.singleton().pick_option_put_id(' . (a:result - 1). ')')
|
||||
call py3eval('online_fxreader_pr34_vim.beta.FastSelect.singleton().pick_option_put_id(' . (a:result - 1). ')')
|
||||
else
|
||||
call py3eval('FastSelect.singleton().pick_option_put_id(-1)')
|
||||
call py3eval('online_fxreader_pr34_vim.beta.FastSelect.singleton().pick_option_put_id(-1)')
|
||||
endif
|
||||
endfunction
|
||||
""".format(
|
||||
@ -475,7 +440,13 @@ augroup END
|
||||
self._options,
|
||||
{
|
||||
'title': 'Select a file',
|
||||
'callback': callback_name
|
||||
'callback': callback_name,
|
||||
'wrap': 1,
|
||||
'maxwidth': 80,
|
||||
'close': 'button',
|
||||
'resize': 1,
|
||||
'drag': 1,
|
||||
'maxheight': '16',
|
||||
}
|
||||
)
|
||||
#lambda : vim.command(
|
||||
@ -496,3 +467,6 @@ augroup END
|
||||
# logger.info(dict(popup_id=popup_id))
|
||||
|
||||
# logger.info(dict(msg='after popup'))
|
||||
|
||||
def init():
|
||||
EditorConfigModeline.singleton()
|
@ -20,6 +20,8 @@ from typing import (
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
from .utils import Vim
|
||||
|
||||
# logging.basicConfig(level=logging.WARNING)
|
||||
|
||||
|
||||
@ -161,6 +163,13 @@ class EditorConfigModeline:
|
||||
dict[str, str],
|
||||
] = dict()
|
||||
|
||||
Vim.run_command(r'''
|
||||
augroup EditorConfigModeline
|
||||
autocmd!
|
||||
autocmd BufEnter * python3 import online_fxreader_pr34_vim.main; online_fxreader_pr34_vim.main.EditorConfigModeline.singleton().on_buffer()
|
||||
augroup END
|
||||
''')
|
||||
|
||||
@classmethod
|
||||
def singleton(cls) -> Self:
|
||||
if cls._instance is None:
|
||||
@ -179,7 +188,11 @@ class EditorConfigModeline:
|
||||
|
||||
parser = configparser.ConfigParser()
|
||||
parser.optionxform = str # keep case
|
||||
parser.read(str(config_path))
|
||||
try:
|
||||
parser.read(str(config_path))
|
||||
except:
|
||||
logger.exception('')
|
||||
return None
|
||||
|
||||
config: dict[str, str] = dict()
|
||||
|
||||
@ -241,3 +254,8 @@ class EditorConfigModeline:
|
||||
# vim.command("echo '{}'".format('applied %s' % entry))
|
||||
|
||||
# raise NotImplementedError
|
||||
|
||||
# EditorConfigModeline.singleton()
|
||||
|
||||
def init():
|
||||
EditorConfigModeline.singleton()
|
16
dotfiles/.vim/online_fxreader_pr34_vim/utils.py
Normal file
16
dotfiles/.vim/online_fxreader_pr34_vim/utils.py
Normal file
@ -0,0 +1,16 @@
|
||||
import vim
|
||||
|
||||
class Vim:
|
||||
@classmethod
|
||||
def run_command(cls, cmd) -> list[str]:
|
||||
# logger.info(dict(cmd=cmd))
|
||||
|
||||
output: list[str] = []
|
||||
for line in cmd.splitlines():
|
||||
if line.strip() == '':
|
||||
continue
|
||||
output.append(
|
||||
vim.command(line)
|
||||
)
|
||||
|
||||
return output
|
@ -88,4 +88,4 @@ set foldmethod=indent
|
||||
set nofoldenable
|
||||
map <Leader>e :e #<cR>
|
||||
|
||||
map <C-p> :python3 FastSelect.singleton().switch_buffer()<CR>
|
||||
map <C-p> :python3 import online_fxreader_pr34_vim.beta; online_fxreader_pr34_vim.beta.FastSelect.singleton().switch_buffer()<CR>
|
||||
|
Loading…
Reference in New Issue
Block a user