diff --git a/.gitignore b/.gitignore index 9aff2d6..f85e4cc 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,5 @@ python/build !docker/*/.env .envs !docker/*/deps/whl/** + +!dotfiles/.vim diff --git a/Makefile b/Makefile index 95a6e7b..a47f1ae 100644 --- a/Makefile +++ b/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) diff --git a/dotfiles/.py3.vimrc b/dotfiles/.py3.vimrc index 7721a17..ba11c90 100644 --- a/dotfiles/.py3.vimrc +++ b/dotfiles/.py3.vimrc @@ -1,12 +1,18 @@ py3 < 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() diff --git a/dotfiles/.module.vimrc.py b/dotfiles/.vim/online_fxreader_pr34_vim/main.py similarity index 91% rename from dotfiles/.module.vimrc.py rename to dotfiles/.vim/online_fxreader_pr34_vim/main.py index 3188be7..d64708f 100644 --- a/dotfiles/.module.vimrc.py +++ b/dotfiles/.vim/online_fxreader_pr34_vim/main.py @@ -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() diff --git a/dotfiles/.vim/online_fxreader_pr34_vim/utils.py b/dotfiles/.vim/online_fxreader_pr34_vim/utils.py new file mode 100644 index 0000000..ebe86fb --- /dev/null +++ b/dotfiles/.vim/online_fxreader_pr34_vim/utils.py @@ -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 diff --git a/dotfiles/.vimrc b/dotfiles/.vimrc index c10f2e0..3dc7618 100644 --- a/dotfiles/.vimrc +++ b/dotfiles/.vimrc @@ -88,4 +88,4 @@ set foldmethod=indent set nofoldenable map e :e # -map :python3 FastSelect.singleton().switch_buffer() +map :python3 import online_fxreader_pr34_vim.beta; online_fxreader_pr34_vim.beta.FastSelect.singleton().switch_buffer()