From c4cc14ea2681f475c5db7e0ae9d66a2add1d2d86 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Fri, 10 Jun 2022 16:31:14 +0800 Subject: [PATCH] feat(incsearch): update incsearch layer --- autoload/SpaceVim/layers/edit.vim | 2 +- autoload/SpaceVim/layers/incsearch.vim | 18 +- bundle/README.md | 9 + bundle/incsearch-easymotion.vim/README.md | 67 ++ .../autoload/incsearch/config/easymotion.vim | 26 + .../incsearch/over/modules/EasyMotion.vim | 60 ++ .../plugin/incsearch/easymotion.vim | 29 + bundle/incsearch-fuzzy.vim/README.md | 81 +++ .../autoload/incsearch/config/fuzzy.vim | 25 + .../autoload/incsearch/config/fuzzyspell.vim | 25 + .../autoload/incsearch/config/fuzzyword.vim | 26 + bundle/incsearch-fuzzy.vim/autoload/vital.vim | 12 + .../autoload/vital/_incsearch_fuzzy.vim | 5 + .../Data/String/Converter.vim | 138 ++++ .../autoload/vital/incsearch_fuzzy.vim | 339 ++++++++++ .../autoload/vital/incsearch_fuzzy.vital | 4 + .../plugin/incsearch/fuzzy.vim | 44 ++ bundle/incsearch.vim/README.md | 10 + .../.github/workflows/reviewdog.yml | 12 + bundle/vim-asterisk/.travis.yml | 10 + bundle/vim-asterisk/LICENSE | 20 + bundle/vim-asterisk/README.md | 92 +++ bundle/vim-asterisk/autoload/asterisk.vim | 365 +++++++++++ bundle/vim-asterisk/doc/asterisk.txt | 165 +++++ bundle/vim-asterisk/plugin/asterisk.vim | 57 ++ bundle/vim-asterisk/test/.themisrc | 47 ++ .../vim-asterisk/test/basic_asterisk.vimspec | 169 +++++ bundle/vim-asterisk/test/keeppos.vimspec | 106 ++++ bundle/vim-asterisk/test/visual.vimspec | 131 ++++ bundle/vim-asterisk/test/zstar.vimspec | 62 ++ bundle/vim-over/.gitignore | 1 + bundle/vim-over/README.md | 46 ++ bundle/vim-over/autoload/over.vim | 173 +++++ .../vim-over/autoload/over/command_line.vim | 252 ++++++++ .../over/command_line/command_history.vim | 45 ++ .../autoload/over/command_line/complete.vim | 152 +++++ .../autoload/over/command_line/global.vim | 56 ++ .../over/command_line/insert_register.vim | 84 +++ .../autoload/over/command_line/search.vim | 60 ++ .../autoload/over/command_line/substitute.vim | 253 ++++++++ bundle/vim-over/autoload/vital/_over.vim | 9 + .../autoload/vital/_over/Coaster/Buffer.vim | 361 +++++++++++ .../vital/_over/Coaster/Buffer/Object.vim | 314 +++++++++ .../vital/_over/Coaster/Highlight.vim | 246 +++++++ .../autoload/vital/_over/Coaster/Search.vim | 147 +++++ .../autoload/vital/_over/Coaster/Window.vim | 62 ++ .../autoload/vital/_over/Data/Dict.vim | 151 +++++ .../autoload/vital/_over/Data/List.vim | 464 ++++++++++++++ bundle/vim-over/autoload/vital/_over/Gift.vim | 159 +++++ .../autoload/vital/_over/Gift/Tabpage.vim | 47 ++ .../autoload/vital/_over/Gift/Window.vim | 153 +++++ bundle/vim-over/autoload/vital/_over/Over.vim | 23 + .../autoload/vital/_over/Over/Commandline.vim | 61 ++ .../vital/_over/Over/Commandline/Base.vim | 600 ++++++++++++++++++ .../vital/_over/Over/Commandline/Maker.vim | 97 +++ .../vital/_over/Over/Commandline/Modules.vim | 36 ++ .../_over/Over/Commandline/Modules/All.vim | 24 + .../Over/Commandline/Modules/AsyncUpdate.vim | 47 ++ .../Commandline/Modules/BufferComplete.vim | 173 +++++ .../_over/Over/Commandline/Modules/Cancel.vim | 34 + .../Over/Commandline/Modules/CursorMove.vim | 52 ++ .../_over/Over/Commandline/Modules/Delete.vim | 50 ++ .../Over/Commandline/Modules/Digraphs.vim | 110 ++++ .../Over/Commandline/Modules/Doautocmd.vim | 115 ++++ .../Commandline/Modules/DrawCommandline.vim | 149 +++++ .../Commandline/Modules/ExceptionExit.vim | 31 + .../Commandline/Modules/ExceptionMessage.vim | 60 ++ .../Over/Commandline/Modules/Execute.vim | 100 +++ .../Modules/ExecuteFailedMessage.vim | 17 + .../_over/Over/Commandline/Modules/Exit.vim | 34 + .../Modules/HighlightBufferCursor.vim | 9 + .../Over/Commandline/Modules/HistAdd.vim | 32 + .../Over/Commandline/Modules/History.vim | 69 ++ .../Modules/IgnoreRegexpBackwardWord.vim | 48 ++ .../Over/Commandline/Modules/Incsearch.vim | 83 +++ .../Commandline/Modules/InsertRegister.vim | 158 +++++ .../Over/Commandline/Modules/KeyMapping.vim | 149 +++++ .../Commandline/Modules/LiteralInsert.vim | 39 ++ .../Over/Commandline/Modules/NoInsert.vim | 49 ++ .../_over/Over/Commandline/Modules/Paste.vim | 34 + .../_over/Over/Commandline/Modules/Redraw.vim | 66 ++ .../_over/Over/Commandline/Modules/Scroll.vim | 46 ++ .../autoload/vital/_over/Over/Exception.vim | 40 ++ .../autoload/vital/_over/Over/Input.vim | 34 + .../autoload/vital/_over/Over/Keymapping.vim | 89 +++ .../autoload/vital/_over/Over/Signals.vim | 113 ++++ .../autoload/vital/_over/Over/String.vim | 158 +++++ .../autoload/vital/_over/Palette/Capture.vim | 79 +++ .../vital/_over/Palette/Highlight.vim | 127 ++++ .../vital/_over/Palette/Keymapping.vim | 115 ++++ .../vim-over/autoload/vital/_over/Prelude.vim | 424 +++++++++++++ .../autoload/vital/_over/Unlocker/Holder.vim | 108 ++++ .../vital/_over/Unlocker/Holder/Any.vim | 82 +++ .../_over/Unlocker/Holder/Buffer/Text.vim | 60 ++ .../_over/Unlocker/Holder/Buffer/Undofile.vim | 45 ++ .../vital/_over/Unlocker/Holder/File.vim | 40 ++ .../vital/_over/Unlocker/Holder/Multi.vim | 43 ++ .../vital/_over/Unlocker/Holder/Option.vim | 42 ++ .../vital/_over/Unlocker/Holder/Position.vim | 40 ++ .../vital/_over/Unlocker/Holder/Register.vim | 45 ++ .../vital/_over/Unlocker/Holder/Value.vim | 67 ++ .../vital/_over/Unlocker/Holder/Variable.vim | 42 ++ .../vital/_over/Unlocker/Holder/Winview.vim | 39 ++ .../autoload/vital/_over/Unlocker/Rocker.vim | 100 +++ .../_over/Unlocker/Rocker/HolderBase.vim | 55 ++ .../vital/_over/Unlocker/Rocker/Multi.vim | 45 ++ .../vital/_over/Unlocker/Rocker/Undotree.vim | 68 ++ .../autoload/vital/_over/Vim/Buffer.vim | 207 ++++++ .../autoload/vital/_over/Vim/Guard.vim | 234 +++++++ .../autoload/vital/_over/Vim/Message.vim | 74 +++ .../autoload/vital/_over/Vim/Type.vim | 92 +++ bundle/vim-over/autoload/vital/over.vim | 328 ++++++++++ bundle/vim-over/autoload/vital/over.vital | 43 ++ bundle/vim-over/doc/over.jax | 297 +++++++++ bundle/vim-over/doc/over.txt | 236 +++++++ bundle/vim-over/plugin/over.vim | 63 ++ bundle/vim-over/test/autoload/over.vim | 13 + .../autoload/over/command_line/complete.vim | 10 + .../autoload/over/command_line/substitute.vim | 20 + 119 files changed, 11698 insertions(+), 5 deletions(-) create mode 100644 bundle/incsearch-easymotion.vim/README.md create mode 100644 bundle/incsearch-easymotion.vim/autoload/incsearch/config/easymotion.vim create mode 100644 bundle/incsearch-easymotion.vim/autoload/incsearch/over/modules/EasyMotion.vim create mode 100644 bundle/incsearch-easymotion.vim/plugin/incsearch/easymotion.vim create mode 100644 bundle/incsearch-fuzzy.vim/README.md create mode 100644 bundle/incsearch-fuzzy.vim/autoload/incsearch/config/fuzzy.vim create mode 100644 bundle/incsearch-fuzzy.vim/autoload/incsearch/config/fuzzyspell.vim create mode 100644 bundle/incsearch-fuzzy.vim/autoload/incsearch/config/fuzzyword.vim create mode 100644 bundle/incsearch-fuzzy.vim/autoload/vital.vim create mode 100644 bundle/incsearch-fuzzy.vim/autoload/vital/_incsearch_fuzzy.vim create mode 100644 bundle/incsearch-fuzzy.vim/autoload/vital/_incsearch_fuzzy/Data/String/Converter.vim create mode 100644 bundle/incsearch-fuzzy.vim/autoload/vital/incsearch_fuzzy.vim create mode 100644 bundle/incsearch-fuzzy.vim/autoload/vital/incsearch_fuzzy.vital create mode 100644 bundle/incsearch-fuzzy.vim/plugin/incsearch/fuzzy.vim create mode 100644 bundle/vim-asterisk/.github/workflows/reviewdog.yml create mode 100644 bundle/vim-asterisk/.travis.yml create mode 100644 bundle/vim-asterisk/LICENSE create mode 100644 bundle/vim-asterisk/README.md create mode 100644 bundle/vim-asterisk/autoload/asterisk.vim create mode 100644 bundle/vim-asterisk/doc/asterisk.txt create mode 100644 bundle/vim-asterisk/plugin/asterisk.vim create mode 100644 bundle/vim-asterisk/test/.themisrc create mode 100644 bundle/vim-asterisk/test/basic_asterisk.vimspec create mode 100644 bundle/vim-asterisk/test/keeppos.vimspec create mode 100644 bundle/vim-asterisk/test/visual.vimspec create mode 100644 bundle/vim-asterisk/test/zstar.vimspec create mode 100644 bundle/vim-over/.gitignore create mode 100644 bundle/vim-over/README.md create mode 100644 bundle/vim-over/autoload/over.vim create mode 100644 bundle/vim-over/autoload/over/command_line.vim create mode 100644 bundle/vim-over/autoload/over/command_line/command_history.vim create mode 100644 bundle/vim-over/autoload/over/command_line/complete.vim create mode 100644 bundle/vim-over/autoload/over/command_line/global.vim create mode 100644 bundle/vim-over/autoload/over/command_line/insert_register.vim create mode 100644 bundle/vim-over/autoload/over/command_line/search.vim create mode 100644 bundle/vim-over/autoload/over/command_line/substitute.vim create mode 100644 bundle/vim-over/autoload/vital/_over.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Coaster/Buffer.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Coaster/Buffer/Object.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Coaster/Highlight.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Coaster/Search.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Coaster/Window.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Data/Dict.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Data/List.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Gift.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Gift/Tabpage.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Gift/Window.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Base.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Maker.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/All.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/AsyncUpdate.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/BufferComplete.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Cancel.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/CursorMove.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Delete.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Digraphs.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Doautocmd.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/DrawCommandline.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/ExceptionExit.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/ExceptionMessage.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Execute.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/ExecuteFailedMessage.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Exit.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/HighlightBufferCursor.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/HistAdd.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/History.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/IgnoreRegexpBackwardWord.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Incsearch.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/InsertRegister.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/KeyMapping.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/LiteralInsert.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/NoInsert.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Paste.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Redraw.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Scroll.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Exception.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Input.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Keymapping.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/Signals.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Over/String.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Palette/Capture.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Palette/Highlight.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Palette/Keymapping.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Prelude.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Unlocker/Holder.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Any.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Buffer/Text.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Buffer/Undofile.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Unlocker/Holder/File.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Multi.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Option.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Position.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Register.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Value.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Variable.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Winview.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Unlocker/Rocker.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Unlocker/Rocker/HolderBase.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Unlocker/Rocker/Multi.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Unlocker/Rocker/Undotree.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Vim/Buffer.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Vim/Guard.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Vim/Message.vim create mode 100644 bundle/vim-over/autoload/vital/_over/Vim/Type.vim create mode 100644 bundle/vim-over/autoload/vital/over.vim create mode 100644 bundle/vim-over/autoload/vital/over.vital create mode 100644 bundle/vim-over/doc/over.jax create mode 100644 bundle/vim-over/doc/over.txt create mode 100644 bundle/vim-over/plugin/over.vim create mode 100644 bundle/vim-over/test/autoload/over.vim create mode 100644 bundle/vim-over/test/autoload/over/command_line/complete.vim create mode 100644 bundle/vim-over/test/autoload/over/command_line/substitute.vim diff --git a/autoload/SpaceVim/layers/edit.vim b/autoload/SpaceVim/layers/edit.vim index 2f0303c82..b16b1e653 100644 --- a/autoload/SpaceVim/layers/edit.vim +++ b/autoload/SpaceVim/layers/edit.vim @@ -114,7 +114,7 @@ function! SpaceVim#layers#edit#plugins() abort \ [g:_spacevim_root_dir . 'bundle/tabular', { 'merged' : 0}], \ ['andrewradev/splitjoin.vim',{ 'on_cmd':['SplitjoinJoin', 'SplitjoinSplit'],'merged' : 0, 'loadconf' : 1}], \ ] - if has('nvim-0.6.0') + if has('nvim-0.6.0') && s:enable_hop call add(plugins,[g:_spacevim_root_dir . 'bundle/hop.nvim', { 'merged' : 0, 'loadconf' : 1}]) else call add(plugins,[g:_spacevim_root_dir . 'bundle/vim-easymotion', { 'merged' : 0}]) diff --git a/autoload/SpaceVim/layers/incsearch.vim b/autoload/SpaceVim/layers/incsearch.vim index 1b59f690a..6f4d0b9a5 100644 --- a/autoload/SpaceVim/layers/incsearch.vim +++ b/autoload/SpaceVim/layers/incsearch.vim @@ -34,10 +34,10 @@ let s:filename = expand(':~') function! SpaceVim#layers#incsearch#plugins() abort let plugins = [] call add(plugins, [g:_spacevim_root_dir . 'bundle/incsearch.vim', {'merged' : 0}]) - call add(plugins, ['haya14busa/incsearch-fuzzy.vim', {'merged' : 0}]) - call add(plugins, ['haya14busa/vim-asterisk', {'merged' : 0}]) - call add(plugins, ['osyo-manga/vim-over', {'merged' : 0}]) - call add(plugins, ['haya14busa/incsearch-easymotion.vim', {'merged' : 0}]) + call add(plugins, [g:_spacevim_root_dir . 'bundle/incsearch-fuzzy.vim', {'merged' : 0}]) + call add(plugins, [g:_spacevim_root_dir . 'bundle/vim-asterisk', {'merged' : 0}]) + call add(plugins, [g:_spacevim_root_dir . 'bundle/vim-over', {'merged' : 0}]) + call add(plugins, [g:_spacevim_root_dir . 'bundle/incsearch-easymotion.vim', {'merged' : 0}]) return plugins endfunction @@ -82,6 +82,7 @@ function! SpaceVim#layers#incsearch#config() abort \ 'is_stay': 1 \ }), get(a:, 1, {})) endfunction + noremap (incsearch-fuzzymotion) incsearch#go(config_easyfuzzymotion()) let lnum = expand('') + s:lnum - 1 call SpaceVim#mapping#space#def('nmap', ['b', '/'], '(incsearch-fuzzyword-/)', ['fuzzy-find-word', \ [ @@ -91,6 +92,15 @@ function! SpaceVim#layers#incsearch#config() abort \ ] \ ] \ , 0) + let lnum = expand('') + s:lnum - 1 + call SpaceVim#mapping#space#def('nmap', ['/'], '(incsearch-fuzzymotion)', ['fuzzy-easymotion', + \ [ + \ '[SPC /] is to run fuzzy easymotion', + \ '', + \ 'Definition: ' . s:filename . ':' . lnum, + \ ] + \ ] + \ , 0) endfunction diff --git a/bundle/README.md b/bundle/README.md index 9480aa4b3..4a8c637f0 100644 --- a/bundle/README.md +++ b/bundle/README.md @@ -10,6 +10,7 @@ In `bundle/` directory, there are two kinds of plugins: forked plugins without c - [`lang#python` layer](#langpython-layer) - [`lang#liquid` layer](#langliquid-layer) - [`tmux` layer](#tmux-layer) + - [`incsearch` layer](#incsearch-layer) @@ -62,3 +63,11 @@ In `bundle/` directory, there are two kinds of plugins: forked plugins without c #### `tmux` layer - [christoomey/vim-tmux-navigator@9ca5bfe5b](https://github.com/christoomey/vim-tmux-navigator/tree/9ca5bfe5bd274051b5dd796cc150348afc993b80) + +#### `incsearch` layer + +- [incsearch.vim@c83de6d1](https://github.com/haya14busa/incsearch.vim/tree/c83de6d1ac31d173d7c3ffee0ad61dc643ee4f08) +- [incsearch-fuzzy.vim@b08fa8fb](https://github.com/haya14busa/incsearch-fuzzy.vim/tree/b08fa8fbfd633e2f756fde42bfb5251d655f5403) +- [vim-asterisk@77e9706](https://github.com/haya14busa/vim-asterisk/tree/77e97061d6691637a034258cc415d98670698459) +- [vim-over@878f83b](https://github.com/osyo-manga/vim-over/tree/878f83bdac0cda308f599d319f45c7877d5274a9) +- [incsearch-easymotion.vim@fcdd3ae](https://github.com/haya14busa/incsearch-easymotion.vim/tree/fcdd3aee6f4c0eef1a515727199ece8d6c6041b5) diff --git a/bundle/incsearch-easymotion.vim/README.md b/bundle/incsearch-easymotion.vim/README.md new file mode 100644 index 000000000..1cb9b882d --- /dev/null +++ b/bundle/incsearch-easymotion.vim/README.md @@ -0,0 +1,67 @@ +incsearch-easymotion.vim +======================== + +Integration between [haya14busa/incsearch.vim](https://github.com/haya14busa/incsearch.vim) and [easymotion/vim-easymotion](https://github.com/easymotion/vim-easymotion) + +![incsearch-easymotion.gif](https://raw.githubusercontent.com/haya14busa/i/master/incsearch.vim/extensions/incsearch-easymotion.gif) + +### Dependencies +- https://github.com/haya14busa/incsearch.vim +- https://github.com/easymotion/vim-easymotion + +### Installtaion + +[Neobundle](https://github.com/Shougo/neobundle.vim) / [Vundle](https://github.com/gmarik/Vundle.vim) / [vim-plug](https://github.com/junegunn/vim-plug) + +```vim +NeoBundle 'haya14busa/incsearch.vim' +Plugin 'haya14busa/incsearch.vim' +Plug 'haya14busa/incsearch.vim' + +NeoBundle 'haya14busa/incsearch-easymotion.vim' +Plugin 'haya14busa/incsearch-easymotion.vim' +Plug 'haya14busa/incsearch-easymotion.vim' +``` + +[pathogen](https://github.com/tpope/vim-pathogen) + +``` +git clone https://github.com/haya14busa/incsearch.vim ~/.vim/bundle/incsearch.vim +git clone https://github.com/haya14busa/incsearch-easymotion.vim ~/.vim/bundle/incsearch-easymotion.vim +``` + +### Usage + +**Give it a shot!** :gun: `:call incsearch#call(incsearch#config#easymotion#make()) ` + +```vim +map z/ (incsearch-easymotion-/) +map z? (incsearch-easymotion-?) +map zg/ (incsearch-easymotion-stay) +``` + +### Advanced usage + +#### incremental fuzzymotion +![incsearch-fuzzy-easymotion.gif](https://raw.githubusercontent.com/haya14busa/i/master/incsearch.vim/extensions/incsearch-fuzzy-easymotion.gif) + +```vim +" incsearch.vim x fuzzy x vim-easymotion + +function! s:config_easyfuzzymotion(...) abort + return extend(copy({ + \ 'converters': [incsearch#config#fuzzy#converter()], + \ 'modules': [incsearch#config#easymotion#module()], + \ 'keymap': {"\": '(easymotion)'}, + \ 'is_expr': 0, + \ 'is_stay': 1 + \ }), get(a:, 1, {})) +endfunction + +noremap / incsearch#go(config_easyfuzzymotion()) +``` + +### API +- `incsearch#config#easymotion#module()`: return easymotion module for incsearch.vim + - It provide `(easymotion)` key to invoke easymotion feature from incsearch.vim +- `incsearch#config#easymotion#make`: return default config diff --git a/bundle/incsearch-easymotion.vim/autoload/incsearch/config/easymotion.vim b/bundle/incsearch-easymotion.vim/autoload/incsearch/config/easymotion.vim new file mode 100644 index 000000000..51ffd1f3c --- /dev/null +++ b/bundle/incsearch-easymotion.vim/autoload/incsearch/config/easymotion.vim @@ -0,0 +1,26 @@ +"============================================================================= +" FILE: autoload/incsearch/config/easymotion.vim +" AUTHOR: haya14busa +" License: MIT license +"============================================================================= +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +function! incsearch#config#easymotion#module(...) abort + return call('incsearch#over#modules#EasyMotion#make', a:000, {}) +endfunction + +function! incsearch#config#easymotion#make(...) abort + return incsearch#util#deepextend(deepcopy({ + \ 'modules': [incsearch#config#easymotion#module()], + \ 'keymap': {"\": '(easymotion)'}, + \ 'is_expr': 0 + \ }), get(a:, 1, {})) +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo +" __END__ +" vim: expandtab softtabstop=2 shiftwidth=2 foldmethod=marker diff --git a/bundle/incsearch-easymotion.vim/autoload/incsearch/over/modules/EasyMotion.vim b/bundle/incsearch-easymotion.vim/autoload/incsearch/over/modules/EasyMotion.vim new file mode 100644 index 000000000..66446915c --- /dev/null +++ b/bundle/incsearch-easymotion.vim/autoload/incsearch/over/modules/EasyMotion.vim @@ -0,0 +1,60 @@ +"============================================================================= +" FILE: autoload/incsearch/over/modules/EasyMotion.vim +" AUTHOR: haya14busa +" License: MIT license +"============================================================================= +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +let s:module = { +\ 'name' : 'EasyMotion', +\ 'config': { +\ 'overwin': 0 +\ }, +\ } + +function! s:module._easymotion(cmdline) abort + let [raw_pattern, _] = a:cmdline._parse_pattern() + if raw_pattern is# '' + let pattern = @/ + else + let pattern = a:cmdline._convert(raw_pattern) + call histadd('/', a:cmdline.getline()) + let @/ = pattern + endif + let config = { + \ 'pattern': pattern, + \ 'visualmode': s:is_visual(a:cmdline._mode), + \ 'direction': 2, + \ 'accept_cursor_pos': 1, + \ 'overwin': self.config.overwin && a:cmdline._mode is# 'n' + \ } + call incsearch#highlight#off() + call EasyMotion#go(config) + call incsearch#autocmd#auto_nohlsearch(1) + call feedkeys("\(_incsearch-hlsearch)", 'm') +endfunction + +function! s:module.on_char_pre(cmdline) + if a:cmdline.is_input('(easymotion)') + call a:cmdline.setchar('') + call self._easymotion(a:cmdline) + call a:cmdline._exit_incsearch() + endif +endfunction + +function! incsearch#over#modules#EasyMotion#make(...) abort + let m = deepcopy(s:module) + let m.config = extend(m.config, get(a:, 1, {})) + return m +endfunction + +function! s:is_visual(mode) abort + return a:mode =~# "[vV\]" +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo +" __END__ +" vim: expandtab softtabstop=2 shiftwidth=2 foldmethod=marker diff --git a/bundle/incsearch-easymotion.vim/plugin/incsearch/easymotion.vim b/bundle/incsearch-easymotion.vim/plugin/incsearch/easymotion.vim new file mode 100644 index 000000000..0eec03fde --- /dev/null +++ b/bundle/incsearch-easymotion.vim/plugin/incsearch/easymotion.vim @@ -0,0 +1,29 @@ +"============================================================================= +" FILE: plugin/incsearch/easymotion.vim +" AUTHOR: haya14busa +" License: MIT license +"============================================================================= +scriptencoding utf-8 +if expand('%:p') ==# expand(':p') + unlet! g:loaded_incsearch_easymotion +endif +if exists('g:loaded_incsearch_easymotion') + finish +endif +let g:loaded_incsearch_easymotion = 1 +let s:save_cpo = &cpo +set cpo&vim + +function! s:config(...) abort + return incsearch#config#easymotion#make(get(a:, 1, {})) +endfunction + +noremap (incsearch-easymotion-/) incsearch#go(config()) +noremap (incsearch-easymotion-?) incsearch#go(config({'command': '?'})) +noremap (incsearch-easymotion-stay) incsearch#go(config({'is_stay': 1})) + + +let &cpo = s:save_cpo +unlet s:save_cpo +" __END__ +" vim: expandtab softtabstop=2 shiftwidth=2 foldmethod=marker diff --git a/bundle/incsearch-fuzzy.vim/README.md b/bundle/incsearch-fuzzy.vim/README.md new file mode 100644 index 000000000..2c30e0853 --- /dev/null +++ b/bundle/incsearch-fuzzy.vim/README.md @@ -0,0 +1,81 @@ +incsearch-fuzzy.vim +=================== + +incremantal fuzzy search extension for [incsearch.vim](https://github.com/haya14busa/incsearch.vim) + +![incsearch-fuzzy.gif](https://raw.githubusercontent.com/haya14busa/i/master/incsearch.vim/extensions/incsearch-fuzzy.gif) + +### Dependencies +- https://github.com/haya14busa/incsearch.vim + +### Installtaion + +[Neobundle](https://github.com/Shougo/neobundle.vim) / [Vundle](https://github.com/gmarik/Vundle.vim) / [vim-plug](https://github.com/junegunn/vim-plug) + +```vim +NeoBundle 'haya14busa/incsearch.vim' +Plugin 'haya14busa/incsearch.vim' +Plug 'haya14busa/incsearch.vim' + +NeoBundle 'haya14busa/incsearch-fuzzy.vim' +Plugin 'haya14busa/incsearch-fuzzy.vim' +Plug 'haya14busa/incsearch-fuzzy.vim' +``` + +[pathogen](https://github.com/tpope/vim-pathogen) + +``` +git clone https://github.com/haya14busa/incsearch.vim ~/.vim/bundle/incsearch.vim +git clone https://github.com/haya14busa/incsearch-fuzzy.vim ~/.vim/bundle/incsearch-fuzzy.vim +``` + +### Usage + +#### fuzzy search + +**Give it a shot!** :gun: `:call incsearch#call(incsearch#config#fuzzy#make()) ` + +```vim +map z/ (incsearch-fuzzy-/) +map z? (incsearch-fuzzy-?) +map zg/ (incsearch-fuzzy-stay) +``` + +#### fuzzyspell search + +It use `spell` feature in Vim + +![incsearch-fuzzyspell.gif](https://raw.githubusercontent.com/haya14busa/i/master/incsearch.vim/extensions/incsearch-fuzzyspell.gif) + +```vim +map z/ (incsearch-fuzzyspell-/) +map z? (incsearch-fuzzyspell-?) +map zg/ (incsearch-fuzzyspell-stay) +``` + +### API + +#### fuzzy +- `incsearch#config#fuzzy#converter()`: return fuzzy converter function +- `incsearch#config#fuzzy#make()`: return default config for fuzzy command + +#### fuzzyspell +- `incsearch#config#fuzzyspell#converter()`: return fuzzyspell converter function +- `incsearch#config#fuzzyspell#make`: return default config for fuzzyspell command + +#### Example: Use both fuzzy & fuzzyspell feature + +```vim +function! s:config_fuzzyall(...) abort + return extend(copy({ + \ 'converters': [ + \ incsearch#config#fuzzy#converter(), + \ incsearch#config#fuzzyspell#converter() + \ ], + \ }), get(a:, 1, {})) +endfunction + +noremap z/ incsearch#go(config_fuzzyall()) +noremap z? incsearch#go(config_fuzzyall({'command': '?'})) +noremap zg? incsearch#go(config_fuzzyall({'is_stay': 1})) +``` diff --git a/bundle/incsearch-fuzzy.vim/autoload/incsearch/config/fuzzy.vim b/bundle/incsearch-fuzzy.vim/autoload/incsearch/config/fuzzy.vim new file mode 100644 index 000000000..b3d35700f --- /dev/null +++ b/bundle/incsearch-fuzzy.vim/autoload/incsearch/config/fuzzy.vim @@ -0,0 +1,25 @@ +"============================================================================= +" FILE: autoload/incsearch/config/fuzzy.vim +" AUTHOR: haya14busa +" License: MIT license +"============================================================================= +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +let s:C = vital#incsearch_fuzzy#import('Data.String.Converter') + +function! incsearch#config#fuzzy#converter() abort + return s:C.fuzzy +endfunction + +function! incsearch#config#fuzzy#make(...) abort + return incsearch#util#deepextend(deepcopy({ + \ 'converters': [incsearch#config#fuzzy#converter()] + \ }), get(a:, 1, {})) +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo +" __END__ +" vim: expandtab softtabstop=2 shiftwidth=2 foldmethod=marker diff --git a/bundle/incsearch-fuzzy.vim/autoload/incsearch/config/fuzzyspell.vim b/bundle/incsearch-fuzzy.vim/autoload/incsearch/config/fuzzyspell.vim new file mode 100644 index 000000000..0a96e4e11 --- /dev/null +++ b/bundle/incsearch-fuzzy.vim/autoload/incsearch/config/fuzzyspell.vim @@ -0,0 +1,25 @@ +"============================================================================= +" FILE: autoload/incsearch/config/fuzzyspell.vim +" AUTHOR: haya14busa +" License: MIT license +"============================================================================= +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +let s:C = vital#incsearch_fuzzy#import('Data.String.Converter') + +function! incsearch#config#fuzzyspell#converter() abort + return s:C.fuzzyspell +endfunction + +function! incsearch#config#fuzzyspell#make(...) abort + return incsearch#util#deepextend(deepcopy({ + \ 'converters': [incsearch#config#fuzzyspell#converter()] + \ }), get(a:, 1, {})) +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo +" __END__ +" vim: expandtab softtabstop=2 shiftwidth=2 foldmethod=marker diff --git a/bundle/incsearch-fuzzy.vim/autoload/incsearch/config/fuzzyword.vim b/bundle/incsearch-fuzzy.vim/autoload/incsearch/config/fuzzyword.vim new file mode 100644 index 000000000..ca45ddbe3 --- /dev/null +++ b/bundle/incsearch-fuzzy.vim/autoload/incsearch/config/fuzzyword.vim @@ -0,0 +1,26 @@ +"============================================================================= +" FILE: autoload/incsearch/config/fuzzy.vim +" AUTHOR: haya14busa +" License: MIT license +"============================================================================= +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +let s:C = vital#incsearch_fuzzy#import('Data.String.Converter') + +function! incsearch#config#fuzzyword#converter() abort + return s:C.fuzzyword +endfunction + +function! incsearch#config#fuzzyword#make(...) abort + return incsearch#util#deepextend(deepcopy({ + \ 'converters': [incsearch#config#fuzzyword#converter()] + \ }), get(a:, 1, {})) +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo +" __END__ +" vim: expandtab softtabstop=2 shiftwidth=2 foldmethod=marker + diff --git a/bundle/incsearch-fuzzy.vim/autoload/vital.vim b/bundle/incsearch-fuzzy.vim/autoload/vital.vim new file mode 100644 index 000000000..f1ba849a0 --- /dev/null +++ b/bundle/incsearch-fuzzy.vim/autoload/vital.vim @@ -0,0 +1,12 @@ +function! vital#of(name) abort + let files = globpath(&runtimepath, 'autoload/vital/' . a:name . '.vital', 1) + let file = split(files, "\n") + if empty(file) + throw 'vital: version file not found: ' . a:name + endif + let ver = readfile(file[0], 'b') + if empty(ver) + throw 'vital: invalid version file: ' . a:name + endif + return vital#_{substitute(ver[0], '\W', '', 'g')}#new() +endfunction diff --git a/bundle/incsearch-fuzzy.vim/autoload/vital/_incsearch_fuzzy.vim b/bundle/incsearch-fuzzy.vim/autoload/vital/_incsearch_fuzzy.vim new file mode 100644 index 000000000..9eba17768 --- /dev/null +++ b/bundle/incsearch-fuzzy.vim/autoload/vital/_incsearch_fuzzy.vim @@ -0,0 +1,5 @@ +let s:_plugin_name = expand(':t:r') + +function! vital#{s:_plugin_name}#new() abort + return vital#{s:_plugin_name[1:]}#new() +endfunction diff --git a/bundle/incsearch-fuzzy.vim/autoload/vital/_incsearch_fuzzy/Data/String/Converter.vim b/bundle/incsearch-fuzzy.vim/autoload/vital/_incsearch_fuzzy/Data/String/Converter.vim new file mode 100644 index 000000000..be40466bd --- /dev/null +++ b/bundle/incsearch-fuzzy.vim/autoload/vital/_incsearch_fuzzy/Data/String/Converter.vim @@ -0,0 +1,138 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +if v:version > 703 || v:version == 703 && has('patch1170') + function! vital#_incsearch_fuzzy#Data#String#Converter#import() abort + return map({'smartsign_char': '', 'fuzzyspell': '', 'fuzzyword': '', 'get_smartsign_table': '', 'fuzzy': '', 'smartsign': ''}, 'function("s:" . v:key)') + endfunction +else + function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') + endfunction + execute join(['function! vital#_incsearch_fuzzy#Data#String#Converter#import() abort', printf("return map({'smartsign_char': '', 'fuzzyspell': '', 'fuzzyword': '', 'get_smartsign_table': '', 'fuzzy': '', 'smartsign': ''}, \"function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") + delfunction s:_SID +endif +" ___vital___ +"============================================================================= +" FILE: autoload/vital/__latest__/Data/String/Converter.vim +" AUTHOR: haya14busa +" License: MIT license +"============================================================================= +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +let s:TRUE = !0 +let s:FALSE = 0 +let s:escaped_backslash = '\m\%(^\|[^\\]\)\%(\\\\\)*' +let s:non_escaped_backslash = '\m\%(\%(^\|[^\\]\)\%(\\\\\)*\)\@1<=\\' + +function! s:_throw(message) abort + throw printf('vital: Data.String.Converter: %s', a:message) +endfunction + +" fuzzy -- +function! s:fuzzy(pattern) abort + if a:pattern is# '' | return '' | endif + let pattern = substitute(a:pattern, s:non_escaped_backslash . '[mMvV]', '', 'g') + let pattern = substitute(pattern, s:escaped_backslash . '\([mMvV]\)', '\1', 'g') + let chars = map(split(pattern, '\zs'), "escape(v:val, '\\')") + let p = '\c\V' . + \ join(map(chars[0:-2], " + \ printf('%s\\[^%s]\\{-}', v:val, v:val) + \ "), '') . chars[-1] + return p +endfunction + +let s:nonwords = join([ +\ '[:space:]', +\ ], '') + +" fuzzy word -- +function! s:fuzzyword(pattern) abort + if a:pattern is# '' | return '' | endif + let pattern = substitute(a:pattern, s:non_escaped_backslash . '[mMvV]', '', 'g') + let pattern = substitute(pattern, s:escaped_backslash . '\([mMvV]\)', '\1', 'g') + let chars = map(split(pattern, '\zs'), "escape(v:val, '\\')") + let p = '\c\V\<\=' . + \ join(map(chars[0:-2], " + \ printf('%s\\[^%s%s]\\{-}', v:val, s:nonwords, v:val) + \ "), '') . chars[-1] + return p +endfunction + +" smartsign -- +let s:sign_table = {} +let s:sign_table.us = { +\ ',' : '<', '.' : '>', '/' : '?', +\ '1' : '!', '2' : '@', '3' : '#', '4' : '$', '5' : '%', +\ '6' : '^', '7' : '&', '8' : '*', '9' : '(', '0' : ')', '-' : '_', '=' : '+', +\ ';' : ':', '[' : '{', ']' : '}', '`' : '~', "'" : "\"", '\' : '|', +\ } + +let s:sign_table.ja = { +\ ',' : '<', '.' : '>', '/' : '?', +\ '1' : '!', '2' : '"', '3' : '#', '4' : '$', '5' : '%', +\ '6' : '&', '7' : "'", '8' : '(', '9' : ')', '0' : '_', '-' : '=', '^' : '~', +\ ';' : '+', ':' : '*', '[' : '{', ']' : '}', '@' : '`', '\' : '|', +\ } + +" characters which should be escaped in rectangle ([]) of regular expressions +let s:escape_in_rec = '\]^-/?' + +function! s:get_smartsign_table(...) abort + let table = get(a:, 1, s:sign_table.us) + if type(table) is# type('') + if !has_key(s:sign_table, table) + call s:_throw(printf('table named %s does not exist', table)) + else + let tmp = s:sign_table[table] + unlet table + let table = tmp + endif + endif + return table +endfunction + +" assume '\V' +function! s:smartsign_char(sign, ...) abort + let table = call(function('s:get_smartsign_table'), a:000) + return has_key(table, a:sign) ? + \ printf('\[%s%s]', + \ escape(a:sign, s:escape_in_rec), + \ escape(table[a:sign], s:escape_in_rec)) + \ : a:sign +endfunction + +function! s:smartsign(pattern, ...) abort + let table = call(function('s:get_smartsign_table'), a:000) + let signs = '\m[' . escape(join(keys(table), ''), s:escape_in_rec) . ']' + return '\V' . substitute(a:pattern, signs, '\= + \ s:smartsign_char(submatch(0), table)', 'g') +endfunction + +" fuzzyspell -- +function! s:fuzzyspell(pattern) abort + let spell_save = &spell + let &spell = s:TRUE + try + return substitute(a:pattern, '\k\+', '\=s:_make_fuzzy_spell(submatch(0))', 'g') + finally + let &spell = spell_save + endtry +endfunction + +function! s:_spellsuggest(word, ...) abort + let max = get(a:, 1, 25) + return [a:word] + spellsuggest(a:word, max) +endfunction + +function! s:_make_fuzzy_spell(word) abort + return printf('\m\(%s\)', join(s:_spellsuggest(a:word), '\|')) +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo +" __END__ +" vim: expandtab softtabstop=2 shiftwidth=2 foldmethod=marker diff --git a/bundle/incsearch-fuzzy.vim/autoload/vital/incsearch_fuzzy.vim b/bundle/incsearch-fuzzy.vim/autoload/vital/incsearch_fuzzy.vim new file mode 100644 index 000000000..d428cc261 --- /dev/null +++ b/bundle/incsearch-fuzzy.vim/autoload/vital/incsearch_fuzzy.vim @@ -0,0 +1,339 @@ +let s:plugin_name = expand(':t:r') +let s:vital_base_dir = expand(':h') +let s:project_root = expand(':h:h:h') +let s:is_vital_vim = s:plugin_name is# 'vital' + +let s:loaded = {} +let s:cache_sid = {} + +" function() wrapper +if v:version > 703 || v:version == 703 && has('patch1170') + function! s:_function(fstr) abort + return function(a:fstr) + endfunction +else + function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') + endfunction + let s:_s = '' . s:_SID() . '_' + function! s:_function(fstr) abort + return function(substitute(a:fstr, 's:', s:_s, 'g')) + endfunction +endif + +function! vital#{s:plugin_name}#new() abort + return s:new(s:plugin_name) +endfunction + +function! vital#{s:plugin_name}#import(...) abort + if !exists('s:V') + let s:V = s:new(s:plugin_name) + endif + return call(s:V.import, a:000, s:V) +endfunction + +let s:Vital = {} + +function! s:new(plugin_name) abort + let base = deepcopy(s:Vital) + let base._plugin_name = a:plugin_name + return base +endfunction + +function! s:vital_files() abort + if !exists('s:vital_files') + let s:vital_files = map( + \ s:is_vital_vim ? s:_global_vital_files() : s:_self_vital_files(), + \ 'fnamemodify(v:val, ":p:gs?[\\\\/]?/?")') + endif + return copy(s:vital_files) +endfunction +let s:Vital.vital_files = s:_function('s:vital_files') + +function! s:import(name, ...) abort dict + let target = {} + let functions = [] + for a in a:000 + if type(a) == type({}) + let target = a + elseif type(a) == type([]) + let functions = a + endif + unlet a + endfor + let module = self._import(a:name) + if empty(functions) + call extend(target, module, 'keep') + else + for f in functions + if has_key(module, f) && !has_key(target, f) + let target[f] = module[f] + endif + endfor + endif + return target +endfunction +let s:Vital.import = s:_function('s:import') + +function! s:load(...) abort dict + for arg in a:000 + let [name; as] = type(arg) == type([]) ? arg[: 1] : [arg, arg] + let target = split(join(as, ''), '\W\+') + let dict = self + let dict_type = type({}) + while !empty(target) + let ns = remove(target, 0) + if !has_key(dict, ns) + let dict[ns] = {} + endif + if type(dict[ns]) == dict_type + let dict = dict[ns] + else + unlet dict + break + endif + endwhile + if exists('dict') + call extend(dict, self._import(name)) + endif + unlet arg + endfor + return self +endfunction +let s:Vital.load = s:_function('s:load') + +function! s:unload() abort dict + let s:loaded = {} + let s:cache_sid = {} + unlet! s:vital_files +endfunction +let s:Vital.unload = s:_function('s:unload') + +function! s:exists(name) abort dict + if a:name !~# '\v^\u\w*%(\.\u\w*)*$' + throw 'vital: Invalid module name: ' . a:name + endif + return s:_module_path(a:name) isnot# '' +endfunction +let s:Vital.exists = s:_function('s:exists') + +function! s:search(pattern) abort dict + let paths = s:_extract_files(a:pattern, self.vital_files()) + let modules = sort(map(paths, 's:_file2module(v:val)')) + return s:_uniq(modules) +endfunction +let s:Vital.search = s:_function('s:search') + +function! s:plugin_name() abort dict + return self._plugin_name +endfunction +let s:Vital.plugin_name = s:_function('s:plugin_name') + +function! s:_self_vital_files() abort + let builtin = printf('%s/__%s__/', s:vital_base_dir, s:plugin_name) + let installed = printf('%s/_%s/', s:vital_base_dir, s:plugin_name) + let base = builtin . ',' . installed + return split(globpath(base, '**/*.vim', 1), "\n") +endfunction + +function! s:_global_vital_files() abort + let pattern = 'autoload/vital/__*__/**/*.vim' + return split(globpath(&runtimepath, pattern, 1), "\n") +endfunction + +function! s:_extract_files(pattern, files) abort + let tr = {'.': '/', '*': '[^/]*', '**': '.*'} + let target = substitute(a:pattern, '\.\|\*\*\?', '\=tr[submatch(0)]', 'g') + let regexp = printf('autoload/vital/[^/]\+/%s.vim$', target) + return filter(a:files, 'v:val =~# regexp') +endfunction + +function! s:_file2module(file) abort + let filename = fnamemodify(a:file, ':p:gs?[\\/]?/?') + let tail = matchstr(filename, 'autoload/vital/_\w\+/\zs.*\ze\.vim$') + return join(split(tail, '[\\/]\+'), '.') +endfunction + +" @param {string} name e.g. Data.List +function! s:_import(name) abort dict + if has_key(s:loaded, a:name) + return copy(s:loaded[a:name]) + endif + let module = self._get_module(a:name) + if has_key(module, '_vital_created') + call module._vital_created(module) + endif + let export_module = filter(copy(module), 'v:key =~# "^\\a"') + " Cache module before calling module.vital_loaded() to avoid cyclic + " dependences but remove the cache if module._vital_loaded() fails. + " let s:loaded[a:name] = export_module + let s:loaded[a:name] = export_module + if has_key(module, '_vital_loaded') + try + call module._vital_loaded(vital#{s:plugin_name}#new()) + catch + unlet s:loaded[a:name] + throw 'vital: fail to call ._vital_loaded(): ' . v:exception + endtry + endif + return copy(s:loaded[a:name]) +endfunction +let s:Vital._import = s:_function('s:_import') + +" s:_get_module() returns module object wihch has all script local functions. +function! s:_get_module(name) abort dict + let funcname = s:_import_func_name(self.plugin_name(), a:name) + if s:_exists_autoload_func_with_source(funcname) + return call(funcname, []) + else + return s:_get_builtin_module(a:name) + endif +endfunction + +function! s:_get_builtin_module(name) abort + return s:sid2sfuncs(s:_module_sid(a:name)) +endfunction + +if s:is_vital_vim + " For vital.vim, we can use s:_get_builtin_module directly + let s:Vital._get_module = s:_function('s:_get_builtin_module') +else + let s:Vital._get_module = s:_function('s:_get_module') +endif + +function! s:_import_func_name(plugin_name, module_name) abort + return printf('vital#_%s#%s#import', a:plugin_name, s:_dot_to_sharp(a:module_name)) +endfunction + +function! s:_module_sid(name) abort + let path = s:_module_path(a:name) + if !filereadable(path) + throw 'vital: module not found: ' . a:name + endif + let vital_dir = s:is_vital_vim ? '__\w\+__' : printf('_\{1,2}%s\%%(__\)\?', s:plugin_name) + let base = join([vital_dir, ''], '[/\\]\+') + let p = base . substitute('' . a:name, '\.', '[/\\\\]\\+', 'g') + let sid = s:_sid(path, p) + if !sid + call s:_source(path) + let sid = s:_sid(path, p) + if !sid + throw printf('vital: cannot get from path: %s', path) + endif + endif + return sid +endfunction + +function! s:_module_path(name) abort + return get(s:_extract_files(a:name, s:vital_files()), 0, '') +endfunction + +function! s:_module_sid_base_dir() abort + return s:is_vital_vim ? &rtp : s:project_root +endfunction + +function! s:_dot_to_sharp(name) abort + return substitute(a:name, '\.', '#', 'g') +endfunction + +" It will sources autoload file if a given func is not already defined. +function! s:_exists_autoload_func_with_source(funcname) abort + if exists('*' . a:funcname) + " Return true if a given func is already defined + return 1 + endif + " source a file which may include a given func definition and try again. + let path = 'autoload/' . substitute(substitute(a:funcname, '#[^#]*$', '.vim', ''), '#', '/', 'g') + call s:_runtime(path) + return exists('*' . a:funcname) +endfunction + +function! s:_runtime(path) abort + execute 'runtime' fnameescape(a:path) +endfunction + +function! s:_source(path) abort + execute 'source' fnameescape(a:path) +endfunction + +" @vimlint(EVL102, 1, l:_) +" @vimlint(EVL102, 1, l:__) +function! s:_sid(path, filter_pattern) abort + let unified_path = s:_unify_path(a:path) + if has_key(s:cache_sid, unified_path) + return s:cache_sid[unified_path] + endif + for line in filter(split(s:_redir(':scriptnames'), "\n"), 'v:val =~# a:filter_pattern') + let [_, sid, path; __] = matchlist(line, '^\s*\(\d\+\):\s\+\(.\+\)\s*$') + if s:_unify_path(path) is# unified_path + let s:cache_sid[unified_path] = sid + return s:cache_sid[unified_path] + endif + endfor + return 0 +endfunction + +function! s:_redir(cmd) abort + let [save_verbose, save_verbosefile] = [&verbose, &verbosefile] + set verbose=0 verbosefile= + redir => res + silent! execute a:cmd + redir END + let [&verbose, &verbosefile] = [save_verbose, save_verbosefile] + return res +endfunction + +if filereadable(expand(':r') . '.VIM') " is case-insensitive or not + let s:_unify_path_cache = {} + " resolve() is slow, so we cache results. + " Note: On windows, vim can't expand path names from 8.3 formats. + " So if getting full path via and $HOME was set as 8.3 format, + " vital load duplicated scripts. Below's :~ avoid this issue. + function! s:_unify_path(path) abort + if has_key(s:_unify_path_cache, a:path) + return s:_unify_path_cache[a:path] + endif + let value = tolower(fnamemodify(resolve(fnamemodify( + \ a:path, ':p')), ':~:gs?[\\/]?/?')) + let s:_unify_path_cache[a:path] = value + return value + endfunction +else + function! s:_unify_path(path) abort + return resolve(fnamemodify(a:path, ':p:gs?[\\/]?/?')) + endfunction +endif + +" copied and modified from Vim.ScriptLocal +let s:SNR = join(map(range(len("\")), '"[\\x" . printf("%0x", char2nr("\"[v:val])) . "]"'), '') +function! s:sid2sfuncs(sid) abort + let fs = split(s:_redir(printf(':function /^%s%s_', s:SNR, a:sid)), "\n") + let r = {} + let pattern = printf('\m^function\s%d_\zs\w\{-}\ze(', a:sid) + for fname in map(fs, 'matchstr(v:val, pattern)') + let r[fname] = function(s:_sfuncname(a:sid, fname)) + endfor + return r +endfunction + +"" Return funcname of script local functions with SID +function! s:_sfuncname(sid, funcname) abort + return printf('%s_%s', a:sid, a:funcname) +endfunction + +if exists('*uniq') + function! s:_uniq(list) abort + return uniq(a:list) + endfunction +else + function! s:_uniq(list) abort + let i = len(a:list) - 1 + while 0 < i + if a:list[i] ==# a:list[i - 1] + call remove(a:list, i) + endif + let i -= 1 + endwhile + return a:list + endfunction +endif diff --git a/bundle/incsearch-fuzzy.vim/autoload/vital/incsearch_fuzzy.vital b/bundle/incsearch-fuzzy.vim/autoload/vital/incsearch_fuzzy.vital new file mode 100644 index 000000000..787b5420d --- /dev/null +++ b/bundle/incsearch-fuzzy.vim/autoload/vital/incsearch_fuzzy.vital @@ -0,0 +1,4 @@ +incsearch_fuzzy +6e682fce672da9da08aee5db517d227be5ef663f + +Data.String.Converter diff --git a/bundle/incsearch-fuzzy.vim/plugin/incsearch/fuzzy.vim b/bundle/incsearch-fuzzy.vim/plugin/incsearch/fuzzy.vim new file mode 100644 index 000000000..ce81099be --- /dev/null +++ b/bundle/incsearch-fuzzy.vim/plugin/incsearch/fuzzy.vim @@ -0,0 +1,44 @@ +"============================================================================= +" FILE: plugin/incsearch/fuzzy.vim +" AUTHOR: haya14busa +" License: MIT license +"============================================================================= +scriptencoding utf-8 +if expand('%:p') ==# expand(':p') + unlet! g:loaded_incsearch_fuzzy +endif +if exists('g:loaded_incsearch_fuzzy') + finish +endif +let g:loaded_incsearch_fuzzy = 1 +let s:save_cpo = &cpo +set cpo&vim + +function! s:config_fuzzy(...) abort + return incsearch#config#fuzzy#make(get(a:, 1, {})) +endfunction + +function! s:config_fuzzyword(...) abort + return incsearch#config#fuzzyword#make(get(a:, 1, {})) +endfunction + +function! s:config_fuzzyspell(...) abort + return incsearch#config#fuzzyspell#make(get(a:, 1, {})) +endfunction + +noremap (incsearch-fuzzy-/) incsearch#go(config_fuzzy()) +noremap (incsearch-fuzzy-?) incsearch#go(config_fuzzy({'command': '?'})) +noremap (incsearch-fuzzy-stay) incsearch#go(config_fuzzy({'is_stay': 1})) + +noremap (incsearch-fuzzyword-/) incsearch#go(config_fuzzyword()) +noremap (incsearch-fuzzyword-?) incsearch#go(config_fuzzyword({'command': '?'})) +noremap (incsearch-fuzzyword-stay) incsearch#go(config_fuzzyword({'is_stay': 1})) + +noremap (incsearch-fuzzyspell-/) incsearch#go(config_fuzzyspell()) +noremap (incsearch-fuzzyspell-?) incsearch#go(config_fuzzyspell({'command': '?'})) +noremap (incsearch-fuzzyspell-stay) incsearch#go(config_fuzzyspell({'is_stay': 1})) + +let &cpo = s:save_cpo +unlet s:save_cpo +" __END__ +" vim: expandtab softtabstop=2 shiftwidth=2 foldmethod=marker diff --git a/bundle/incsearch.vim/README.md b/bundle/incsearch.vim/README.md index 529282a04..d5ecd25d8 100644 --- a/bundle/incsearch.vim/README.md +++ b/bundle/incsearch.vim/README.md @@ -1,3 +1,13 @@ + +> ⚠️ **Deprecated** +> This plugin is no longer necessary since the main functionality is now built into vim/neovim +> +> See: +> - https://medium.com/@haya14busa/incsearch-vim-is-dead-long-live-incsearch-2b7070d55250 +> - https://github.com/vim/vim/pull/2198 +> - Successor plugin: https://github.com/haya14busa/is.vim + + ![incsearch.vim](https://raw.githubusercontent.com/haya14busa/i/master/incsearch.vim/incsearch_logo.png) [![Build Status](https://travis-ci.org/haya14busa/incsearch.vim.svg?branch=master)](https://travis-ci.org/haya14busa/incsearch.vim) diff --git a/bundle/vim-asterisk/.github/workflows/reviewdog.yml b/bundle/vim-asterisk/.github/workflows/reviewdog.yml new file mode 100644 index 000000000..3e78529f9 --- /dev/null +++ b/bundle/vim-asterisk/.github/workflows/reviewdog.yml @@ -0,0 +1,12 @@ +name: reviewdog +on: [pull_request] +jobs: + vint: + name: runner / vint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: vint + uses: reviewdog/action-vint@v1 + with: + github_token: ${{ secrets.github_token }} diff --git a/bundle/vim-asterisk/.travis.yml b/bundle/vim-asterisk/.travis.yml new file mode 100644 index 000000000..d44220fd0 --- /dev/null +++ b/bundle/vim-asterisk/.travis.yml @@ -0,0 +1,10 @@ +language: viml +install: + - git clone https://github.com/thinca/vim-themis --branch v1.5 --single-branch --depth 1 /tmp/vim-themis + - git clone https://github.com/syngan/vim-vimlint /tmp/vim-vimlint + - git clone https://github.com/ynkdir/vim-vimlparser /tmp/vim-vimlparser +before_script: + - vim --version +script: + - /tmp/vim-themis/bin/themis --reporter spec + - sh /tmp/vim-vimlint/bin/vimlint.sh -l /tmp/vim-vimlint -p /tmp/vim-vimlparser -e EVL102.l:_=1 -c func_abort=1 plugin autoload diff --git a/bundle/vim-asterisk/LICENSE b/bundle/vim-asterisk/LICENSE new file mode 100644 index 000000000..2f3a1b871 --- /dev/null +++ b/bundle/vim-asterisk/LICENSE @@ -0,0 +1,20 @@ +MIT License + +Copyright (c) 2014-2016 haya14busa + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR +THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/bundle/vim-asterisk/README.md b/bundle/vim-asterisk/README.md new file mode 100644 index 000000000..c9547312c --- /dev/null +++ b/bundle/vim-asterisk/README.md @@ -0,0 +1,92 @@ +vim-asterisk: * -Improved +======================== +[![](https://travis-ci.org/haya14busa/vim-asterisk.svg?branch=master)](https://travis-ci.org/haya14busa/vim-asterisk) +[![](https://ci.appveyor.com/api/projects/status/uurxg9ips6h2cyd3/branch/master?svg=true)](https://ci.appveyor.com/project/haya14busa/vim-asterisk/branch/master) +[![](https://drone.io/github.com/haya14busa/vim-asterisk/status.png)](https://drone.io/github.com/haya14busa/vim-asterisk/latest) +[![](https://img.shields.io/github/release/haya14busa/vim-asterisk.svg)](https://github.com/haya14busa/vim-asterisk/releases) +[![](http://img.shields.io/github/issues/haya14busa/vim-asterisk.svg)](https://github.com/haya14busa/vim-asterisk/issues) +[![](http://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) +[![](http://img.shields.io/badge/doc-%3Ah%20asterisk.txt-red.svg)](doc/asterisk.txt) + +Introduction +------------ + +asterisk.vim provides improved * motions. + +### 1. stay star motions (z prefixed mappings) +z star motions doesn't move your cursor. + +![](https://raw.githubusercontent.com/haya14busa/i/master/vim-asterisk/asterisk_z_star.gif) + +### 2. visual star motions +Search selected text. + +![](https://raw.githubusercontent.com/haya14busa/i/master/vim-asterisk/asterisk_visual_star.gif) + +### 3. Use smartcase unlike default one +Default behavior, which sees ignorecase and not smartcase, is not intuitive. + +### 4. Keep cursor position across matches +It is handy for refactoring to keep cursor position while iterating over matches. + +Add following line in your vimrc to enable this feature. `let g:asterisk#keeppos = 1` Default: 0 + +![](https://raw.githubusercontent.com/haya14busa/i/master/vim-asterisk/asterisk_keeppos.gif) + + +Installation +------------ + +[Neobundle](https://github.com/Shougo/neobundle.vim) / [Vundle](https://github.com/gmarik/Vundle.vim) / [vim-plug](https://github.com/junegunn/vim-plug) + +```vim +NeoBundle 'haya14busa/vim-asterisk' +Plugin 'haya14busa/vim-asterisk' +Plug 'haya14busa/vim-asterisk' +``` + +[pathogen](https://github.com/tpope/vim-pathogen) + +``` +git clone https://github.com/haya14busa/vim-asterisk ~/.vim/bundle/vim-asterisk +``` + +Usage +----- + +```vim +map * (asterisk-*) +map # (asterisk-#) +map g* (asterisk-g*) +map g# (asterisk-g#) +map z* (asterisk-z*) +map gz* (asterisk-gz*) +map z# (asterisk-z#) +map gz# (asterisk-gz#) +``` + +If you want to set "z" (stay) behavior as default + +```vim +map * (asterisk-z*) +map # (asterisk-z#) +map g* (asterisk-gz*) +map g# (asterisk-gz#) +``` + +To enable keepCursor feature: +```vim +let g:asterisk#keeppos = 1 +``` + +Special thanks +-------------- +|vim-asterisk| uses the code from vim-visualstar for visual star feature. + +- Author: thinca (https://github.com/thinca) +- Plugin: https://github.com/thinca/vim-visualstar + +Author +------ +haya14busa (https://github.com/haya14busa) + diff --git a/bundle/vim-asterisk/autoload/asterisk.vim b/bundle/vim-asterisk/autoload/asterisk.vim new file mode 100644 index 000000000..a036a0ae4 --- /dev/null +++ b/bundle/vim-asterisk/autoload/asterisk.vim @@ -0,0 +1,365 @@ +"============================================================================= +" FILE: autoload/asterisk.vim +" AUTHOR: haya14busa +" License: MIT license {{{ +" Permission is hereby granted, free of charge, to any person obtaining +" a copy of this software and associated documentation files (the +" "Software"), to deal in the Software without restriction, including +" without limitation the rights to use, copy, modify, merge, publish, +" distribute, sublicense, and/or sell copies of the Software, and to +" permit persons to whom the Software is furnished to do so, subject to +" the following conditions: +" +" The above copyright notice and this permission notice shall be included +" in all copies or substantial portions of the Software. +" +" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +" }}} +"============================================================================= +scriptencoding utf-8 +" Saving 'cpoptions' {{{ +let s:save_cpo = &cpo +set cpo&vim +" }}} + +let s:TRUE = !0 +let s:FALSE = 0 +let s:INT = { 'MAX': 2147483647 } +let s:DIRECTION = { 'forward': 1, 'backward': 0 } " see :h v:searchforward + +let g:asterisk#keeppos = get(g:, 'asterisk#keeppos', s:FALSE) + +" do_jump: do not move cursor if false +" is_whole: is_whole word. false if `g` flag given (e.g. * -> true, g* -> false) +let s:_config = { +\ 'direction' : s:DIRECTION.forward, +\ 'do_jump' : s:TRUE, +\ 'is_whole' : s:TRUE, +\ 'keeppos': s:FALSE +\ } + +function! s:default_config() abort + return extend(deepcopy(s:_config), {'keeppos': g:asterisk#keeppos}) +endfunction + +" @return command: String +function! asterisk#do(mode, config) abort + let config = extend(s:default_config(), a:config) + let is_visual = s:is_visual(a:mode) + " Raw cword without \<\> + let cword = (is_visual ? s:get_selected_text() : s:escape_pattern(expand(''))) + if cword is# '' + return s:generate_error_cmd(is_visual) + endif + " v:count handling + let should_plus_one_count = s:should_plus_one_count(cword, config, a:mode) + let maybe_count = (should_plus_one_count ? string(v:count1 + 1) : '') + let pre = (is_visual || should_plus_one_count ? "\" . maybe_count : '') + " Including \<\> if necessary + let pattern = (is_visual ? + \ s:convert_2_word_pattern_4_visual(cword, config) : s:cword_pattern(cword, config)) + let key = (config.direction is s:DIRECTION.forward ? '/' : '?') + " Get offset in current word + let offset = config.keeppos ? s:get_pos_in_cword(cword, a:mode) : 0 + let pattern_offseted = pattern . (offset is 0 ? '' : key . 's+' . offset) + let search_cmd = pre . key . pattern_offseted + if config.do_jump + return search_cmd . "\" + elseif config.keeppos && offset isnot 0 + "" Do not jump with keeppos feature + " NOTE: It doesn't move cursor, so we can assume it works with + " operator pending mode even if it returns command to execute. + let echo = s:generate_echo_cmd(pattern_offseted) + let restore = s:generate_restore_cmd() + "" *premove* & *aftermove* : not to cause flickr as mush as possible + " flick corner case: `#` with under cursor word at the top of window + " and the cursor is at the end of the word. + let premove = + \ (a:mode isnot# 'n' ? "\" : '') + \ . 'm`' + \ . (config.direction is s:DIRECTION.forward ? '0' : '$') + " NOTE: Neovim doesn't stack pos to jumplist after "m`". + " https://github.com/haya14busa/vim-asterisk/issues/34 + if has('nvim') + let aftermove = '``' + else + let aftermove = "\" + endif + " NOTE: To avoid hit-enter prompt, it execute `restore` and `echo` + " command separately. I can also implement one function and call it + " once instead of separately, should I do this? + return printf("%s%s\%s:%s\:%s\", premove, search_cmd, aftermove, restore, echo) + else " Do not jump: Just handle search related + call s:set_search(pattern) + return s:generate_set_search_cmd(pattern, a:mode, config) + endif +endfunction + +"" For keeppos feature +" NOTE: To avoid hit-enter prompt, this function name should be as short as +" possible. `r` is short for restore. Should I use more short function using +" basic global function instead of autoload one. +function! asterisk#r() abort + call winrestview(s:w) + call s:restore_event_ignore() +endfunction + +function! s:set_view(view) abort + let s:w = a:view +endfunction + +"" For keeppos feature +" NOTE: vim-asterisk moves cursor temporarily for keeppos feature with search +" commands. It should not trigger the event related to this cursor move, so +" set eventignore and restore it afterwards. +function! s:set_event_ignore() abort + let s:ei = &ei + let events = ['CursorMoved'] + if exists('##CmdlineEnter') + let events += ['CmdlineEnter', 'CmdlineLeave'] + endif + let &ei = join(events, ',') +endfunction + +function! s:restore_event_ignore() abort + let &ei = s:ei +endfunction + +" @return restore_command: String +function! s:generate_restore_cmd() abort + call s:set_view(winsaveview()) + call s:set_event_ignore() + return 'call asterisk#r()' +endfunction + +" @return \ if needed: String +function! s:cword_pattern(cword, config) abort + return printf((a:config.is_whole && a:cword =~# '\k' ? '\<%s\>' : '%s'), a:cword) +endfunction + +" This function is based on https://github.com/thinca/vim-visualstar +" Author : thinca +" License : zlib License +" @return \: String +function! s:convert_2_word_pattern_4_visual(pattern, config) abort + let text = a:pattern + let type = (a:config.direction is# s:DIRECTION.forward ? '/' : '?') + let [pre, post] = ['', ''] + if a:config.is_whole + let [head_pos, tail_pos] = s:sort_pos([s:getcoord('.'), s:getcoord('v')]) + let head = matchstr(text, '^.') + let is_head_multibyte = 1 < len(head) + let [l, col] = head_pos + let line = getline(l) + let before = line[: col - 2] + let outer = matchstr(before, '.$') + if text =~# '^\k' && ((!empty(outer) && len(outer) != len(head)) || + \ (!is_head_multibyte && (col == 1 || before !~# '\k$'))) + let pre = '\<' + endif + let tail = matchstr(text, '.$') + let is_tail_multibyte = 1 < len(tail) + let [l, col] = tail_pos + let col += s:is_exclusive() && head_pos[1] !=# tail_pos[1] ? - 1 : len(tail) - 1 + let line = getline(l) + let after = line[col :] + let outer = matchstr(after, '^.') + if text =~# '\k$' && ((!empty(outer) && len(outer) != len(tail)) || + \ (!is_tail_multibyte && (col == len(line) || after !~# '^\k'))) + let post = '\>' + endif + endif + let text = substitute(escape(text, '\' . type), "\n", '\\n', 'g') + let text = substitute(text, "\r", '\\r', 'g') + return '\V' . pre . text . post +endfunction + +"" Set pattern and history for search +" @return nothing +function! s:set_search(pattern) abort + let @/ = a:pattern + call histadd('/', @/) +endfunction + +"" Generate command to turn on search related option like hlsearch to work +" with :h function-search-undo +" @return command: String +function! s:generate_set_search_cmd(pattern, mode, config) abort + " :h function-search-undo + " :h v:hlsearch + " :h v:searchforward + let hlsearch = 'let &hlsearch=&hlsearch' + let searchforward = printf('let v:searchforward = %d', a:config.direction) + let echo = s:generate_echo_cmd(a:pattern) + let esc = (a:mode isnot# 'n' ? "\" : '') + return printf("%s:\%s\:%s\:%s\", esc, hlsearch, searchforward, echo) +endfunction + +" @return echo_command: String +function! s:generate_echo_cmd(message) abort + return printf('echo "%s"', escape(a:message, '\"')) +endfunction + +"" Generate command to show error with empty pattern +" @return error_command: String +function! s:generate_error_cmd(is_visual) abort + " 'E348: No string under cursor' + let m = 'asterisk.vim: No selected string' + return (a:is_visual + \ ? printf("\:echohl ErrorMsg | echom '%s' | echohl None\", m) + \ : '*') +endfunction + +" @return boolean +function! s:should_plus_one_count(cword, config, mode) abort + " For backward, because count isn't needed with but it requires + " +1 for backward and for the case that cursor is not at the head of + " cword + if s:is_visual(a:mode) + return a:config.direction is# s:DIRECTION.backward ? s:TRUE : s:FALSE + else + return a:config.direction is# s:DIRECTION.backward + \ ? s:get_pos_char() =~# '\k' && ! s:is_head_of_cword(a:cword) && ! a:config.keeppos + \ : s:get_pos_char() !~# '\k' + endif +endfunction + +" @return boolean +function! s:is_head_of_cword(cword) abort + return 0 == s:get_pos_in_cword(a:cword) +endfunction + +" Assume the current mode is middle of visual mode. +" @return selected text +function! s:get_selected_text(...) abort + let mode = get(a:, 1, mode(1)) + let end_col = s:curswant() is s:INT.MAX ? s:INT.MAX : s:get_col_in_visual('.') + let current_pos = [line('.'), end_col] + let other_end_pos = [line('v'), s:get_col_in_visual('v')] + let [begin, end] = s:sort_pos([current_pos, other_end_pos]) + if s:is_exclusive() && begin[1] !=# end[1] + " Decrement column number for :set selection=exclusive + let end[1] -= 1 + endif + if mode !=# 'V' && begin ==# end + let lines = [s:get_pos_char(begin)] + elseif mode ==# "\" + let [min_c, max_c] = s:sort_num([begin[1], end[1]]) + let lines = map(range(begin[0], end[0]), ' + \ getline(v:val)[min_c - 1 : max_c - 1] + \ ') + elseif mode ==# 'V' + let lines = getline(begin[0], end[0]) + else + if begin[0] ==# end[0] + let lines = [getline(begin[0])[begin[1]-1 : end[1]-1]] + else + let lines = [getline(begin[0])[begin[1]-1 :]] + \ + (end[0] - begin[0] < 2 ? [] : getline(begin[0]+1, end[0]-1)) + \ + [getline(end[0])[: end[1]-1]] + endif + endif + return join(lines, "\n") . (mode ==# 'V' ? "\n" : '') +endfunction + +" @return Number: return multibyte aware column number in Visual mode to +" select +function! s:get_col_in_visual(pos) abort + let [pos, other] = [a:pos, a:pos is# '.' ? 'v' : '.'] + let c = col(pos) + let d = s:compare_pos(s:getcoord(pos), s:getcoord(other)) > 0 + \ ? len(s:get_pos_char([line(pos), c - (s:is_exclusive() ? 1 : 0)])) - 1 + \ : 0 + return c + d +endfunction + +function! s:get_multi_col(pos) abort + let c = col(a:pos) + return c + len(s:get_pos_char([line(a:pos), c])) - 1 +endfunction + +" Helper: + +function! s:is_visual(mode) abort + return a:mode =~# "[vV\]" +endfunction + +" @return Boolean +function! s:is_exclusive() abort + return &selection is# 'exclusive' +endfunction + +function! s:curswant() abort + return winsaveview().curswant +endfunction + +" @return coordinate: [Number, Number] +function! s:getcoord(expr) abort + return getpos(a:expr)[1:2] +endfunction + +"" Return character at given position with multibyte handling +" @arg [Number, Number] as coordinate or expression for position :h line() +" @return String +function! s:get_pos_char(...) abort + let pos = get(a:, 1, '.') + let [line, col] = type(pos) is# type('') ? s:getcoord(pos) : pos + return matchstr(getline(line), '.', col - 1) +endfunction + +" @return int index of cursor in cword +function! s:get_pos_in_cword(cword, ...) abort + return (s:is_visual(get(a:, 1, mode(1))) || s:get_pos_char() !~# '\k') ? 0 + \ : s:count_char(searchpos(a:cword, 'bcn')[1], s:get_multi_col('.')) +endfunction + +" multibyte aware +function! s:count_char(from, to) abort + let chars = getline('.')[a:from-1:a:to-1] + return len(split(chars, '\zs')) - 1 +endfunction + +" 7.4.341 +" http://ftp.vim.org/vim/patches/7.4/7.4.341 +if v:version > 704 || v:version == 704 && has('patch341') + function! s:sort_num(xs) abort + return sort(a:xs, 'n') + endfunction +else + function! s:_sort_num_func(x, y) abort + return a:x - a:y + endfunction + function! s:sort_num(xs) abort + return sort(a:xs, 's:_sort_num_func') + endfunction +endif + +function! s:sort_pos(pos_list) abort + " pos_list: [ [x1, y1], [x2, y2] ] + return sort(a:pos_list, 's:compare_pos') +endfunction + +function! s:compare_pos(x, y) abort + return max([-1, min([1,(a:x[0] == a:y[0]) ? a:x[1] - a:y[1] : a:x[0] - a:y[0]])]) +endfunction + +" taken from :h Vital.Prelude.escape_pattern() +function! s:escape_pattern(str) abort + return escape(a:str, '~"\.^$[]*') +endfunction + +" Restore 'cpoptions' {{{ +let &cpo = s:save_cpo +unlet s:save_cpo +" }}} +" __END__ {{{ +" vim: expandtab softtabstop=4 shiftwidth=4 +" vim: foldmethod=marker +" }}} + diff --git a/bundle/vim-asterisk/doc/asterisk.txt b/bundle/vim-asterisk/doc/asterisk.txt new file mode 100644 index 000000000..e69399b88 --- /dev/null +++ b/bundle/vim-asterisk/doc/asterisk.txt @@ -0,0 +1,165 @@ +*asterisk.txt* *-improved + +Author : haya14busa +Version : 1.0.0 +License : MIT license {{{ + + Copyright (c) 2014-2015 haya14busa + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +}}} + +CONTENTS *asterisk-contents* + + Introduction |asterisk-introduction| + Install |asterisk-install| + Usage |asterisk-usage| + Key Mappings |asterisk-key-mappings| + Variables |asterisk-variables| + Known Issues |asterisk-known-issues| + ChangeLog |asterisk-changelog| + +============================================================================== +INTRODUCTION *asterisk-introduction* + + *asterisk.vim* provides improved |star| motions. It works in visual + mode and provide stay star motions which don't move cursor. + +============================================================================== +INSTALL *asterisk-install* + + Install with |NeoBundle|: + + 1. Add the following configuration to your vimrc. +> + NeoBundle 'haya14busa/vim-asterisk' +< + 2. Install with |:NeoBundleInstall|. + + Install with |NeoBundleLazy|: + + 1. Add the following configuration sample to your vimrc. +> + NeoBundleLazy 'haya14busa/vim-asterisk', { + \ 'autoload' : { + \ 'mappings' : ['(asterisk-'] + \ } + \ } +< + 2. Install with |:NeoBundleInstall|. + + +============================================================================== +USAGE *asterisk-usage* + +------------------------------------------------------------------------------ +KEY MAPPINGS *asterisk-key-mappings* + +(asterisk-*) *(asterisk-star)* +(asterisk-#) *(asterisk-#)* +(asterisk-g*) *(asterisk-gstar)* +(asterisk-g#) *(asterisk-g#)* +(asterisk-z*) *(asterisk-zstar)* +(asterisk-z#) *(asterisk-z#)* +(asterisk-gz*) *(asterisk-gzstar)* +(asterisk-gz#) *(asterisk-gz#)* + + Basic behavior is almost same with default one. + See: |star|, |#|, |gstar|, |g#| + + Improvement: + - It uses not only 'ignorecase' but also 'smartcase' unlike + default |star|. + - It works in visual mode in addition to |Normal| & |Visual|. + Search selected text. + - "z" prefixed mappings doesn't move the cursor. + + Example: Write following lines to your vimrc: +> + map * (asterisk-*) + map # (asterisk-#) + map g* (asterisk-g*) + map g# (asterisk-g#) + map z* (asterisk-z*) + map gz* (asterisk-gz*) + map z# (asterisk-z#) + map gz# (asterisk-gz#) +< + If you want to set "z" (stay) behavior as default +> + map * (asterisk-z*) + map # (asterisk-z#) + map g* (asterisk-gz*) + map g# (asterisk-gz#) +< +------------------------------------------------------------------------------ +VARIABLES *asterisk-variables* + +g:asterisk#keeppos *g:asterisk#keeppos* + You can keep cursor position while moving across matches. + By default this feature is disabled but you can activate + it by adding to your vimrc: +> + let g:asterisk#keeppos = 1 +< + Default: 0 + +============================================================================== +KNOWN ISSUES *asterisk-issues* + + Issues + https://github.com/haya14busa/vim-asterisk/issues + + +============================================================================== +CREDITS *asterisk-credits* + +|asterisk.vim| uses the code from vim-visualstar for visual star feature. + +- Plugin: https://github.com/thinca/vim-visualstar +- Author: thinca (https://github.com/thinca) + +============================================================================== +CHANGELOG *asterisk-changelog* + + +1.0.0 2015-04-04 + - Add keepCursor feature. |g:asterisk#keeppos|. This feature is based + on @pelodelfuego's work! https://github.com/pelodelfuego + - Add test + - Fix minor bug and now it's stable + +0.9.3 2014-12-10 + - Fix multybite handling for visual-star feature. This fix is made by + @presuku! https://github.com/presuku + - Fix |v| selection over multi lines. + +0.9.2 2014-12-01 + - Fix count handling for |#| motions with pattern including |\<| and |\>|. + - Refactoring. + +0.9.1 2014-11-28 + - Show error with empty selected string. + +0.9.0 2014-11-28 + - Init. + + +vim:tw=78:ts=8:ft=help:norl:noet:fen:fdl=0:fdm=marker: diff --git a/bundle/vim-asterisk/plugin/asterisk.vim b/bundle/vim-asterisk/plugin/asterisk.vim new file mode 100644 index 000000000..8e02110e5 --- /dev/null +++ b/bundle/vim-asterisk/plugin/asterisk.vim @@ -0,0 +1,57 @@ +"============================================================================= +" FILE: plugin/asterisk.vim +" AUTHOR: haya14busa +" License: MIT license {{{ +" Permission is hereby granted, free of charge, to any person obtaining +" a copy of this software and associated documentation files (the +" "Software"), to deal in the Software without restriction, including +" without limitation the rights to use, copy, modify, merge, publish, +" distribute, sublicense, and/or sell copies of the Software, and to +" permit persons to whom the Software is furnished to do so, subject to +" the following conditions: +" +" The above copyright notice and this permission notice shall be included +" in all copies or substantial portions of the Software. +" +" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +" }}} +"============================================================================= +scriptencoding utf-8 +" Load Once {{{ +if expand('%:p') ==# expand(':p') + unlet! g:loaded_asterisk +endif +if exists('g:loaded_asterisk') + finish +endif +let g:loaded_asterisk = 1 +" }}} + +" Saving 'cpoptions' {{{ +let s:save_cpo = &cpo +set cpo&vim +" }}} + +noremap (asterisk-*) asterisk#do(mode(1), {'direction' : 1, 'do_jump' : 1, 'is_whole' : 1}) +noremap (asterisk-g*) asterisk#do(mode(1), {'direction' : 1, 'do_jump' : 1, 'is_whole' : 0}) +noremap (asterisk-z*) asterisk#do(mode(1), {'direction' : 1, 'do_jump' : 0, 'is_whole' : 1}) +noremap (asterisk-gz*) asterisk#do(mode(1), {'direction' : 1, 'do_jump' : 0, 'is_whole' : 0}) +noremap (asterisk-#) asterisk#do(mode(1), {'direction' : 0, 'do_jump' : 1, 'is_whole' : 1}) +noremap (asterisk-g#) asterisk#do(mode(1), {'direction' : 0, 'do_jump' : 1, 'is_whole' : 0}) +noremap (asterisk-z#) asterisk#do(mode(1), {'direction' : 0, 'do_jump' : 0, 'is_whole' : 1}) +noremap (asterisk-gz#) asterisk#do(mode(1), {'direction' : 0, 'do_jump' : 0, 'is_whole' : 0}) + +" Restore 'cpoptions' {{{ +let &cpo = s:save_cpo +unlet s:save_cpo +" }}} +" __END__ {{{ +" vim: expandtab softtabstop=4 shiftwidth=4 +" vim: foldmethod=marker +" }}} diff --git a/bundle/vim-asterisk/test/.themisrc b/bundle/vim-asterisk/test/.themisrc new file mode 100644 index 000000000..984e7497a --- /dev/null +++ b/bundle/vim-asterisk/test/.themisrc @@ -0,0 +1,47 @@ +call themis#option('recursive', 1) + +let g:Expect = themis#helper('expect') +call themis#helper('command').with(themis#helper('assert')).with({'Expect': g:Expect}) + + +" NOTE: basic specs should pass regardless &selection value except selection +" specific specs +" TODO: Automate testing with other values +set selection=exclusive + +language C +set encoding=utf-8 "Sets the character encoding used inside Vim +set termencoding=utf-8 +set fileencoding=utf-8 +set fileencodings=utf-8,cp932,euc-jp "A list of character encodings +set fileformats=unix,dos,mac "This gives the end-of-line () formats + +" Mapping: +map * (asterisk-*) +map # (asterisk-#) +map g* (asterisk-g*) +map g# (asterisk-g#) +map z* (asterisk-z*) +map gz* (asterisk-gz*) +map z# (asterisk-z#) +map gz# (asterisk-gz#) + +" Default: +noremap * * +noremap # # +noremap g g +noremap g# g# +noremap z z +noremap gz gz +noremap z# z# +noremap gz# gz# + +" Helper Functions: +function! g:Add_lines(lines) + for line in reverse(a:lines) + put! =line + endfor +endfunction +function! g:Get_pos_char() + return matchstr(getline('.'), '.', col('.') - 1) +endfunction diff --git a/bundle/vim-asterisk/test/basic_asterisk.vimspec b/bundle/vim-asterisk/test/basic_asterisk.vimspec new file mode 100644 index 000000000..171ebefa5 --- /dev/null +++ b/bundle/vim-asterisk/test/basic_asterisk.vimspec @@ -0,0 +1,169 @@ +scriptencoding utf-8 +Describe basic_asterisk + + Before all + let lines = [ + \ '1.asterisk 2.asterisk 3.asterisk' + \ , '4.Asterisk 5.AsteRisK 6.Asterisk' + \ , '' + \ , '7.アスタリスク 8.アスタリスクです 9.アスタリスク?' + \ , '.* .* .*' + \ , '.* asterisk asterisk' + \ ] + call g:Add_lines(lines) + End + + Before each + call cursor([1, 1]) + normal! 2l + End + + After all + :1,$ delete + End + + Context * + It search forward with \<\> + let @/ = '' + normal * + Assert Equals(@/, '\') + End + It search forward the 1th occurrence of the word + normal * + normal! 2h + Assert Equals(g:Get_pos_char(), '2') + End + It search forward the 2th occurrence of the word + normal 2* + normal! 2h + Assert Equals(g:Get_pos_char(), '3') + End + It search forward in the middle of word + normal! l + normal * + normal! 2h + Assert Equals(g:Get_pos_char(), '2') + End + It search forward multibyte word + normal! 3j + normal * + normal! B + Assert Equals(g:Get_pos_char(), '8') + End + It throws the error if there are no + normal! 2j + Throws /E348: No string under cursor/ :normal * + End + + Context regular expression handling + It use regular expression characters under cursor if there are no keyword word after them + normal! 4j0 + normal * + Assert Equals(@/, '\.\*') + End + It do not use regular expression characters under cursor if there are keyword words after them + normal! 5j0 + normal * + Assert Equals(@/, '\') + End + End + + End + + Context g* + It search forward without \<\> + let @/ = '' + normal g* + Assert Equals(@/, 'asterisk') + End + It search forward the 1th occurrence of the word + normal g* + normal! 2h + Assert Equals(g:Get_pos_char(), '2') + End + It search forward the 2th occurrence of the word + normal 2* + normal! 2h + Assert Equals(g:Get_pos_char(), '3') + End + It search forward in the middle of word + normal! l + normal g* + normal! 2h + Assert Equals(g:Get_pos_char(), '2') + End + It throws the error if there are no + normal! 2j + Throws /E348: No string under cursor/ :normal g* + End + It search forward with the first keyword after the cursor + normal! h + normal * + normal! 2h + Assert Equals(g:Get_pos_char(), '2') + End + It search forward with ignorecase + set ignorecase nosmartcase + normal! j + normal * + normal! 2h + Assert Equals(g:Get_pos_char(), '5') + set ignorecase& smartcase& + End + It search forward with smartcase + set ignorecase smartcase + normal! j + normal * + normal! 2h + Assert Equals(g:Get_pos_char(), '6') + set ignorecase& smartcase& + End + End + + Context # + It search backward with \<\> + let @/ = '' + normal # + Assert Equals(@/, '\') + End + It search backward the 1th occurrence of the word + normal! $b + normal # + normal! 2h + Assert Equals(g:Get_pos_char(), '2') + End + It search backward the 2th occurrence of the word + normal! $b + normal 2# + normal! 2h + Assert Equals(g:Get_pos_char(), '1') + End + It search backward at the end of word + normal! $ + normal # + normal! 2h + Assert Equals(g:Get_pos_char(), '2') + End + It search backward in the middle of word + normal! $h + normal # + normal! 2h + Assert Equals(g:Get_pos_char(), '2') + End + It search backward with the first keyword after the cursor + normal! $bh + normal # + normal! 2h + Assert Equals(g:Get_pos_char(), '2') + End + End + + Context g# + It search backward with \<\> + let @/ = '' + normal g# + Assert Equals(@/, 'asterisk') + End + End + +End diff --git a/bundle/vim-asterisk/test/keeppos.vimspec b/bundle/vim-asterisk/test/keeppos.vimspec new file mode 100644 index 000000000..c004a1f97 --- /dev/null +++ b/bundle/vim-asterisk/test/keeppos.vimspec @@ -0,0 +1,106 @@ +scriptencoding utf-8 +Describe basic_asterisk + + Before all + let lines = [ + \ '1.asterisk 2.asterisk 3.asterisk' + \ , '4.Asterisk 5.AsteRisK 6.Asterisk' + \ , '' + \ , '7.アスタリスク 8.アスタリスクです 9.アスタリスク?' + \ ] + call g:Add_lines(lines) + let g:asterisk#keeppos = 1 + End + + Before each + call cursor([1, 1]) + normal! 2l + End + + After all + :1,$ delete + let g:asterisk#keeppos = 0 + End + + Describe keeppos * + It search forward with \<\> keeping cursor position + normal! 3l + normal * + Assert Equals(histget('/', -1), '\/s+3') + End + It keep cursor position without offset + normal * + Assert Equals(histget('/', -1), '\') + End + It doesn't keep cursor position if the char under cursor is not keyword + normal 1h + normal * + Assert Equals(histget('/', -1), '\') + End + It handles multibyte + normal! 3j2l + normal * + Assert Equals(histget('/', -1), '\<アスタリスク\>/s+2') + End + End + + Describe keeppos g* + It search forward keeping cursor position + normal! 3l + normal g* + Assert Equals(histget('/', -1), 'asterisk/s+3') + End + It keep cursor position without offset + normal g* + Assert Equals(histget('/', -1), 'asterisk') + End + It doesn't keep cursor position if the char under cursor is not keyword + normal 1h + normal g* + Assert Equals(histget('/', -1), 'asterisk') + End + End + + Describe keeppos # + It search backward with \<\> keeping cursor position + normal! 3l + normal # + Assert Equals(histget('/', -1), '\?s+3') + End + It search backward and correct count at the end of word + normal! $ + normal # + Assert Equals(histget('/', -1), '\?s+7') + normal! 9h + Assert Equals(g:Get_pos_char(), '2') + End + It keep cursor position without offset + normal # + Assert Equals(histget('/', -1), '\') + End + It doesn't keep cursor position if the char under cursor is not keyword + normal 1h + normal # + Assert Equals(histget('/', -1), '\') + End + End + + Describe keeppos g# + It search forward keeping cursor position + normal! 3l + normal g# + Assert Equals(histget('/', -1), 'asterisk?s+3') + End + It keep cursor position without offset + normal g# + Assert Equals(histget('/', -1), 'asterisk') + End + It doesn't keep cursor position if the char under cursor is not keyword + normal 1h + normal g# + Assert Equals(histget('/', -1), 'asterisk') + End + End + + +End diff --git a/bundle/vim-asterisk/test/visual.vimspec b/bundle/vim-asterisk/test/visual.vimspec new file mode 100644 index 000000000..d59808d2c --- /dev/null +++ b/bundle/vim-asterisk/test/visual.vimspec @@ -0,0 +1,131 @@ +scriptencoding utf-8 +Describe visual + + Before all + let lines = [ + \ '1.asterisk 2.asterisk 3.asterisk' + \ , '4.Asterisk 5.AsteRisK 6.Asterisk' + \ , '' + \ , '7.アスタリスク 8.アスタリスクです 9.アスタリスク?' + \ , '.* .* .*' + \ , '.* asterisk asterisk' + \ , '".*" ".*" ''asterisk'' ''asterisk''' + \ , '"''.*" "''.*" "aste"risk" "aste"risk"' + \ , "asterisk\r" + \ ] + call g:Add_lines(lines) + End + + Before each + call cursor([1, 1]) + normal! 2l + let @/ = '' + End + + After all + :1,$ delete + End + + Context * + It search forward with \<\> + normal viw* + Assert Equals(@/, '\V\') + End + It search forward only with \< + normal ve5h* + Assert Equals(@/, '\V\ + normal 2lve* + Assert Equals(@/, '\Vterisk\>') + End + End + + Context # + It search backward and jump to next matchecd pattern + normal $viw2# + Assert Equals(@/, '\V\') + Assert Equals(col('.'), 3) + End + End + + Context multibyte * + It handle left keyword + normal 3jve3h* + Assert Equals(@/, '\V\<アスタ') + End + It handle right keyword + normal 3j3lve* + Assert Equals(@/, '\Vリスク\>') + End + It handle left and right keyword + normal 3jve* + Assert Equals(@/, '\V\<アスタリスク\>') + End + It is irrelabant with keyword + normal 3j1lve2h* + Assert Equals(@/, '\Vスタリ') + End + It handle one character selection + normal 3jve5h* + Assert Equals(@/, '\V\<ア') + End + End + + Context regular expression handling + It correctly escape regex + normal! 4j0 + normal viW* + Assert Equals(@/, '\V.*') + End + End + + Context handling quotes + It correctly handle double quotes with z* + normal! 6j0 + normal viWz* + Assert Equals(@/, '\V".*"') + End + It correctly handle double quotes with * + normal! 6j0 + normal viW* + Assert Equals(@/, '\V".*"') + End + It correctly handle single quotes with z* + normal! 6j02W + normal viWz* + Assert Equals(@/, '\V''asterisk''') + End + End + + Context no cursor movement + It get character under cursor with v + normal v* + Assert Equals(@/, '\V\ + silent! execute 'normal' "\*" + Assert Equals(@/, '\V\ + normal V* + Assert Equals(@/, '\V\<1.asterisk 2.asterisk 3.asterisk\n') + End + End + + Context * + It search forward with \<\> + silent! execute 'normal' "\ej*" + Assert Equals(@/, '\V\') + End + End + + Context contains \r + It handles correctly + normal 8j$v* + Assert Equals(@/, '\V\r') + End + End + + +End diff --git a/bundle/vim-asterisk/test/zstar.vimspec b/bundle/vim-asterisk/test/zstar.vimspec new file mode 100644 index 000000000..0fce21424 --- /dev/null +++ b/bundle/vim-asterisk/test/zstar.vimspec @@ -0,0 +1,62 @@ +scriptencoding utf-8 +Describe zstar + + Before all + let lines = [ + \ '1.asterisk 2.asterisk 3.asterisk' + \ , '4.Asterisk 5.AsteRisK 6.Asterisk' + \ , '' + \ , '7.アスタリスク 8.アスタリスクです 9.アスタリスク?' + \ ] + call g:Add_lines(lines) + End + + Before each + call cursor([1, 1]) + normal! 2l + let @/ = '' + End + + After all + :1,$ delete + End + + Context z* + It set search registar with \<\> + normal z* + Assert Equals(@/, '\') + End + It add search history with \<\> + call histadd('/', ' ') + Assert Equals(histget('/', -1), ' ') + normal z* + Assert Equals(histget('/', -1), '\') + End + It set v:searchforward to 1 + let v:searchforward = 0 + normal z* + Assert Equals(v:searchforward, 1) + End + It doesn't move cursor + Assert Equals(g:Get_pos_char(), 'a') + normal z* + Assert Equals(g:Get_pos_char(), 'a') + normal! 2h + Assert Equals(g:Get_pos_char(), '1') + End + It handle 'selection' value + :1,$ delete + call g:Add_lines(['NeoBundle "kannokanno/previm"']) + let save = &selection + for v in ['inclusive', 'old', 'exclusive'] + call cursor([1, 1]) + Assert Equals(g:Get_pos_char(), 'N') + let &selection=v + normal ve6ho* + Assert Equals(histget('/', -1), '\V\` + * Import cmap/cnoremap setting + * `` by regexp + * Multi lhs by keymapping + * Support `` keymapping + * Refactoring + +* 2.0 + * Refactoring + * Change cursor highlight + * Add highlighting `:/` and `:%g/` + * No input specital keys(e.g. ``, ``) + +## Special Thanks + +* [@haya14busa](https://github.com/haya14busa) + + diff --git a/bundle/vim-over/autoload/over.vim b/bundle/vim-over/autoload/over.vim new file mode 100644 index 000000000..12706ddbe --- /dev/null +++ b/bundle/vim-over/autoload/over.vim @@ -0,0 +1,173 @@ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +let g:over#debug_vital_over = get(g:, "over#debug_vital_over", 0) + + +function! over#load() + call over#command_line#load() +endfunction + + +function! over#vital() + if exists("s:V") + return s:V + endif + if g:over#debug_vital_over + let s:V = vital#of("vital") + else + let s:V = vital#over#new() + endif + return s:V +endfunction + +function! over#revital() + call s:V.unload() + unlet! s:V + call over#vital() +endfunction + + +function! s:silent_feedkeys(expr, name, ...) + let mode = get(a:, 1, "m") + let name = "over-" . a:name + let map = printf("(%s)", name) + if mode == "n" + let command = "nnoremap" + else + let command = "nmap" + endif + execute command "" map printf("%s:nunmap %s", a:expr, map) + call feedkeys(printf("\(%s)", name)) +endfunction + + +" http://d.hatena.ne.jp/thinca/20131104/1383498883 +" {range}s/{pattern}/{string}/{flags} +function! s:parse_substitute(word) + let very_magic = '\v' + let range = '(.{-})' + let command = 's%[ubstitute]' + let first_slash = '([\x00-\xff]&[^\\"|[:alnum:][:blank:]])' + let pattern = '(%(\\.|.){-})' + let second_slash = '\2' + let string = '(%(\\.|.){-})' + let flags = '%(\2([&cegiInp#lr]*))?' + let parse_pattern +\ = very_magic +\ . '^:*' +\ . range +\ . command +\ . first_slash +\ . pattern +\ . '%(' +\ . second_slash +\ . string +\ . flags +\ . ')?$' + let result = matchlist(a:word, parse_pattern)[1:5] + if type(result) == type(0) || empty(result) + return [] + endif + unlet result[1] + return result +endfunction + + + + +" base code +" https://github.com/thinca/vim-ambicmd/blob/78fa88c5647071e73a3d21e5f575ed408f68aaaf/autoload/ambicmd.vim#L26 +function! over#parse_range(string) + let search_pattern = '\v/[^/]*\\@:set hlsearch | set incsearch\", 'n') + endif + let @/ = text +endfunction + + +function! s:set_options() + if s:search_highlighted + let s:search_highlighted = 0 + return + endif + + let s:old_incsearch = &incsearch + let s:old_hlsearch = &hlsearch + let s:old_search_pattern = @/ +endfunction + + + +nnoremap (over-restore-search-pattern) +\ (mode() =~ '[iR]' ? "\" : "") . ":let @/ = " . string(s:old_search_pattern) . "\" + +nnoremap (over-restore-nohlsearch) +\ (mode() =~ '[iR]' ? "\" : "") . ":nohlsearch\" + +function! s:restore_options() + if s:search_highlighted || s:set_flag == 0 + return + endif + + let s:set_flag = 0 + let &incsearch = s:old_incsearch + let &hlsearch = s:old_hlsearch + if g:over_enable_auto_nohlsearch + call s:silent_feedkeys(":nohlsearch\", "nohlsearch", 'n') + call feedkeys("\(over-restore-nohlsearch)") + endif + execute "normal \(over-restore-search-pattern)" +" call s:silent_feedkeys(":let @/ = " . string(s:old_search_pattern) . "\", "restore-search-pattern", 'n') +endfunction + + +function! over#setup() + let s:set_flag = 0 + let s:search_highlighted = 0 + augroup over-cmdwindow + autocmd! + autocmd InsertCharPre * call s:search_highlight(getline(".") . v:char) + autocmd InsertEnter * call s:set_options() + autocmd InsertLeave * call s:restore_options() + augroup END +endfunction + + +function! over#unsetup() + augroup over-cmdwindow + autocmd! + augroup END +endfunction + + +function! over#command_line(prompt, input, ...) + let context = get(a:, 1, {}) + return over#command_line#start(a:prompt, a:input, context) +endfunction + + +function! over#parse_substitute(word) + return s:parse_substitute(a:word) +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/over/command_line.vim b/bundle/vim-over/autoload/over/command_line.vim new file mode 100644 index 000000000..59503ed40 --- /dev/null +++ b/bundle/vim-over/autoload/over/command_line.vim @@ -0,0 +1,252 @@ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +let g:over#command_line#enable_import_commandline_map = get(g:, "over#command_line#enable_import_commandline_map", 1) +let g:over#command_line#substitute#replace_pattern_visually = get(g:, "over#command_line#substitute#replace_pattern_visually", 0) + +function! over#command_line#load() + " dummy +endfunction + +let s:V = over#vital() +let s:Highlight = s:V.import("Coaster.Highlight") +let s:Modules = s:V.import("Over.Commandline.Modules") + + +unlet! s:_cmdline +function! s:cmdline() + if exists("s:_cmdline") + return s:_cmdline + endif + let s:_cmdline = over#vital().import("Over.Commandline") + return s:_cmdline +endfunction + + +let s:main = s:cmdline().make_standard("") +call s:main.connect(s:cmdline().get_module("Doautocmd").make("OverCmdLine")) +call s:main.connect(s:cmdline().get_module("KeyMapping").make_emacs()) +call s:main.connect("BufferComplete") +call s:main.connect("ExceptionMessage") +" call s:main.connect("Paste") + + + +let g:over#command_line#paste_escape_chars = get(g:, "over#command_line#paste_escape_chars", '') + + +let s:default_filters = { +\ "\n" : '\\n', +\ "\r" : '\\r', +\} + +let g:over#command_line#paste_filters = get(g:, "over#command_line#paste_filters", s:default_filters) + + +let s:module = { +\ "name" : "Paste" +\} + +function! s:module.on_char_pre(cmdline) + if a:cmdline.is_input("(paste)") + let register = v:register == "" ? '"' : v:register + let text = escape(getreg(register), g:over#command_line#paste_escape_chars) + for [pat, rep] in items(g:over#command_line#paste_filters) + let text = substitute(text, pat, rep, "g") + endfor + call a:cmdline.insert(text) + call a:cmdline.setchar('') + endif +endfunction +call s:main.connect(s:module) +unlet s:module + + +" call s:main.cnoremap("\", "(buffer-complete)") + +let s:base_keymapping = { +\ "\" : { +\ "key" : "(buffer-complete)", +\ "lock" : 1, +\ "noremap" : 1, +\ }, +\ "\" : { +\ "key" : "(paste)", +\ "lock" : 1, +\ "noremap" : 1, +\ } +\} + +function! s:main.keymapping() + return extend( +\ deepcopy(s:base_keymapping), +\ g:over_command_line_key_mappings, +\ ) +endfunction + + + +let s:module = { +\ "name" : "Scroll" +\} +function! s:module.on_char_pre(cmdline) + if a:cmdline.is_input("\(over-cmdline-scroll-y)") + execute "normal! \" + call a:cmdline.setchar('') + elseif a:cmdline.is_input("\(over-cmdline-scroll-u)") + execute "normal! \" + call a:cmdline.setchar('') + elseif a:cmdline.is_input("\(over-cmdline-scroll-f)") + execute "normal! \" + call a:cmdline.setchar('') + elseif a:cmdline.is_input("\(over-cmdline-scroll-e)") + execute "normal! \" + call a:cmdline.setchar('') + elseif a:cmdline.is_input("\(over-cmdline-scroll-d)") + execute "normal! \" + call a:cmdline.setchar('') + elseif a:cmdline.is_input("\(over-cmdline-scroll-b)") + execute "normal! \" + call a:cmdline.setchar('') + endif +endfunction +call s:main.connect(s:module) + + +let g:over#command_line#enable_Digraphs = get(g:, "over#command_line#enable_Digraphs", 1) + +function! over#command_line#start(prompt, input, ...) + let context = get(a:, 1, {}) + + if g:over#command_line#enable_Digraphs +\ && empty(over#command_line#get().get_module("Digraphs")) + call over#command_line#get().connect("Digraphs") + else + call over#command_line#get().disconnect("Digraphs") + endif + + if g:over#command_line#enable_import_commandline_map == 0 + call s:main.disconnect("KeyMapping_vim_cmdline_mapping") + else + call s:main.connect(s:Modules.get("KeyMapping").make_vim_cmdline_mapping()) + endif + + if get(context, "line1", 1) != get(context, "line2", 1) + call s:main.connect(s:hl_visualmode) + else + call s:main.disconnect("HighlightVisualMode") + endif + + if exists("*strchars") && has("conceal") + call s:main.set_prompt(a:prompt) + let exit_code = s:main.start(a:input) + if exit_code == 1 + doautocmd User OverCmdLineCancel + endif + else + echohl ErrorMsg + echo "Vim 7.3 or above and +conceal." + echo "Need strchars()." + echohl NONE + endif +endfunction + + +function! over#command_line#getline() + return s:main.getline() +endfunction + +function! over#command_line#setline(line) + return s:main.set(a:line) +endfunction + +function! over#command_line#char() + return s:main.char() +endfunction + +function! over#command_line#setchar(char) + call s:main.setchar(a:char) +endfunction + +function! over#command_line#getpos() + return s:main.getpos() +endfunction + +function! over#command_line#setpos(pos) + return s:main.setpos(a:pos) +endfunction + + +function! over#command_line#wait_keyinput_on(key) + return s:main.tap_keyinput(a:key) +endfunction + +function! over#command_line#wait_keyinput_off(key) + return s:main.untap_keyinput(a:key) +endfunction + +function! over#command_line#get_wait_keyinput() + return s:main.get_tap_key() +endfunction + + +function! over#command_line#is_input(...) + return call(s:main.is_input, a:000, s:main) +endfunction + + +function! over#command_line#insert(...) + return call(s:main.insert, a:000, s:main) +endfunction + +function! over#command_line#forward() + return s:main.forward() +endfunction + +function! over#command_line#backward() + return s:main.backward() +endfunction + + +call over#command_line#substitute#load() +call over#command_line#search#load() +call over#command_line#global#load() + + +function! over#command_line#do(input) + call s:main.start(a:input) + return s:main.getline() +endfunction + + +function! over#command_line#get() + return s:main +endfunction + + + +let s:hl_visualmode = { +\ "name" : "HighlightVisualMode" +\} + +function! s:hl_visualmode.on_enter(...) + if &selection == "exclusive" + let pat = '\%''<\|\%>''<.*\%<''>' + else + let pat = '\%''<\|\%>''<.*\%<''>\|\%''>' + endif + + call s:Highlight.highlight("visualmode", "Visual", pat, 0) +endfunction + + +function! s:hl_visualmode.on_leave(...) + call s:Highlight.clear("visualmode") +endfunction + + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/over/command_line/command_history.vim b/bundle/vim-over/autoload/over/command_line/command_history.vim new file mode 100644 index 000000000..2d5958c61 --- /dev/null +++ b/bundle/vim-over/autoload/over/command_line/command_history.vim @@ -0,0 +1,45 @@ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +function! over#command_line#command_history#load() + " load +endfunction + + +function! s:command_histories() + return map(range(1, &history), 'histget(":", v:val * -1)') +endfunction + + +let s:cmdhist = [] +let s:count = 0 + +function! s:main() + if !over#command_line#is_input("\") && !over#command_line#is_input("\") + let s:cmdhist = [] + let s:count = 0 + return + else + if s:count == 0 && empty(s:cmdhist) + let cmdline = '^' . over#command_line#getline() + let s:cmdhist = filter(s:command_histories(), 'v:val =~ cmdline') + endif + endif + call over#command_line#setchar("") + if over#command_line#is_input("\") + let s:count = max([s:count - 1, 0]) + endif + if over#command_line#is_input("\") + let s:count = min([s:count + 1, len(s:cmdhist)]) + endif + call over#command_line#setline(get(s:cmdhist, s:count, over#command_line#getline())) +endfunction + +augroup over-cmdline-command_history + autocmd! + autocmd User OverCmdLineCharPre call s:main() +augroup END + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/over/command_line/complete.vim b/bundle/vim-over/autoload/over/command_line/complete.vim new file mode 100644 index 000000000..3547fb284 --- /dev/null +++ b/bundle/vim-over/autoload/over/command_line/complete.vim @@ -0,0 +1,152 @@ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +function! over#command_line#complete#load() + " load +endfunction + + +function! s:uniq(list) + let dict = {} + for _ in a:list + let dict[_] = 0 + endfor + return keys(dict) +endfunction + + +function! s:buffer_complete() + return sort(s:uniq(filter(split(join(getline(1, '$')), '\W'), '!empty(v:val)')), 1) +endfunction + + +function! s:parse_line(line) + let keyword = matchstr(a:line, '\zs\w\+\ze$') + let pos = strchars(a:line) - strchars(keyword) + return [pos, keyword] +endfunction + + +function! s:make_context(...) + let base = get(a:, 1, {}) + return extend(base, { +\ "backward" : over#command_line#backward() +\ "forward" : over#command_line#forward() +\ }) +endfunction + + +function! s:get_complete_words() + return s:buffer_complete() +endfunction + + +function! s:as_statusline(list, count) + if empty(a:list) + return + endif + let hl_none = "%#StatusLine#" + let hl_select = "%#StatusLineNC#" + let tail = " > " + let result = a:list[0] + let pos = 0 + for i in range(1, len(a:list)-1) + if strdisplaywidth(result . " " . a:list[i]) > &columns - len(tail) + if a:count < i + break + else + let pos = -i + endif + let result = a:list[i] + else + let result .= (" " . a:list[i]) + endif + if a:count == i + let pos = pos + i + endif + endfor + return join(map(split(result, " "), 'v:key == pos ? hl_select . v:val . hl_none : v:val')) +endfunction + + +function! s:start() + let s:old_statusline = &statusline + + let backward = over#command_line#backward() + let [pos, keyword] = s:parse_line(backward) + + if !exists("s:complete") + let s:complete = s:get_complete_words() + endif + let s:complete_list = filter(copy(s:complete), 'v:val =~ ''^''.keyword') + if empty(s:complete_list) + return -1 + endif + + if pos == 0 + let backward = "" + else + let backward = join(split(backward, '\zs')[ : pos-1 ], "") + endif + let s:line = backward . over#command_line#forward() + let s:pos = pos + call over#command_line#setline(s:line) + + let s:count = 0 +endfunction + + +function! s:finish() + if exists("s:old_statusline") + let &statusline = s:old_statusline + unlet s:old_statusline + endif +endfunction + + + +function! s:main() + if over#command_line#is_input("\") + if s:start() == -1 + call s:finish() + call over#command_line#setchar('') + return + endif + call over#command_line#setchar('') + call over#command_line#wait_keyinput_on("Completion") + elseif over#command_line#is_input("\", "Completion") +\ || over#command_line#is_input("\", "Completion") + call over#command_line#setchar('') + let s:count += 1 + if s:count >= len(s:complete_list) + let s:count = 0 + endif + elseif over#command_line#is_input("\", "Completion") + call over#command_line#setchar('') + let s:count -= 1 + if s:count < 0 + let s:count = len(s:complete_list) - 1 + endif + else + call over#command_line#wait_keyinput_off("Completion") + call s:finish() + return + endif + call over#command_line#setline(s:line) + call over#command_line#insert(s:complete_list[s:count], s:pos) + if len(s:complete_list) > 1 + let &statusline = s:as_statusline(s:complete_list, s:count) + endif +endfunction + + +augroup over-cmdwindow-complete + autocmd! + autocmd User OverCmdLineCharPre call s:main() + autocmd User OverCmdLineLeave unlet! s:complete +augroup END + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/over/command_line/global.vim b/bundle/vim-over/autoload/over/command_line/global.vim new file mode 100644 index 000000000..cd49484fe --- /dev/null +++ b/bundle/vim-over/autoload/over/command_line/global.vim @@ -0,0 +1,56 @@ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +" 0 = match just the pattern +" 1 = match whole line +let g:over#command_line#global#highlight_line = get(g:, "over#command_line#global#highlight_line", 0) + +" 0 = do nothing +" 1 = highlight all lines not matching pattern +let g:over#command_bang#global#highlight_bang = get(g:, "over#command_bang#global#highlight_bang", 1) + +function! over#command_line#global#load() + " load +endfunction + + +function! s:search_hl_off() + if exists("s:search_id") && s:search_id != -1 + call matchdelete(s:search_id) + unlet s:search_id + endif +endfunction + + +function! s:search_hl_on(pattern, bang) + let pattern = g:over#command_line#global#highlight_line ? + \ '.*' . a:pattern . '.*' : a:pattern + let pattern = a:bang && g:over#command_bang#global#highlight_bang ? + \ '^\%(\%(' . pattern . '\)\@!.\)*$' : pattern + silent! let s:search_id = matchadd("IncSearch", a:pattern) +endfunction + + +function! s:main() + call s:search_hl_off() + let line = over#command_line#backward() + if line =~ '\v^\%g!?\/.' + let bang = line =~ 'g!\/' + let pattern = matchstr(line, '\v\%g!?\/\zs%(\\\/|[^/])+') + call s:search_hl_on((&ignorecase ? '\c' : '') . pattern, bang) + endif +endfunction + + +augroup over-cmdline-global + autocmd! + autocmd User OverCmdLineChar call s:main() + autocmd User OverCmdLineLeave call s:search_hl_off() + autocmd User OverCmdLineEnter let s:old_pos = getpos(".") + autocmd User OverCmdLineExecutePre call setpos(".", s:old_pos) +augroup END + +let &cpo = s:save_cpo +unlet s:save_cpo + diff --git a/bundle/vim-over/autoload/over/command_line/insert_register.vim b/bundle/vim-over/autoload/over/command_line/insert_register.vim new file mode 100644 index 000000000..737d977ac --- /dev/null +++ b/bundle/vim-over/autoload/over/command_line/insert_register.vim @@ -0,0 +1,84 @@ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +function! over#command_line#insert_register#load() + " load +endfunction + + +function! s:to_string(expr) + return type(a:expr) == type("") ? a:expr : string(a:expr) +endfunction + + +function! s:input() + call over#command_line#hl_cursor_on() + try + call over#command_line#redraw() + let input = input("=", "", "expression") + if !empty(input) + let input = s:to_string(eval(input)) + endif + catch + return "" + finally + call over#command_line#hl_cursor_off() + endtry + return input +endfunction + + +function! s:main() + if over#command_line#is_input("\") + call over#command_line#setchar('"') + call over#command_line#wait_keyinput_on("InsertRegister") + let s:old_line = over#command_line#getline() + let s:old_pos = over#command_line#getpos() + return + elseif over#command_line#get_wait_keyinput() == "InsertRegister" + call over#command_line#setline(s:old_line) + call over#command_line#setpos(s:old_pos) + let key = over#command_line#keymap(over#command_line#char()) + if key =~ '^[0-9a-zA-z.%#:/"\-*]$' + execute "let regist = @" . key + call over#command_line#setchar(regist) + elseif key == '=' + call over#command_line#setchar(s:input()) + elseif key == "\" + call over#command_line#setchar(s:cword) + elseif key == "\" + call over#command_line#setchar(s:cWORD) + elseif key == "\" + call over#command_line#setchar(s:cfile) + elseif key == "\" + call over#command_line#setchar('"') + endif + endif +endfunction + + +function! s:on_OverCmdLineChar() + if over#command_line#is_input("\", "InsertRegister") + call over#command_line#setpos(over#command_line#getpos()-1) + else + call over#command_line#wait_keyinput_off("InsertRegister") + endif +endfunction + + +function! s:save_op() + let s:cword = expand("") + let s:cWORD = expand("cWORD") + let s:cfile = expand("") +endfunction + +augroup over-cmdline-insert_register + autocmd! + autocmd User OverCmdLineEnter call s:save_op() + autocmd User OverCmdLineCharPre call s:main() + autocmd User OverCmdLineChar call s:on_OverCmdLineChar() +augroup END + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/over/command_line/search.vim b/bundle/vim-over/autoload/over/command_line/search.vim new file mode 100644 index 000000000..abce866ba --- /dev/null +++ b/bundle/vim-over/autoload/over/command_line/search.vim @@ -0,0 +1,60 @@ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +let g:over#command_line#search#enable_incsearch = get(g:, "over#command_line#search#enable_incsearch", 1) +let g:over#command_line#search#enable_move_cursor = get(g:, "over#command_line#search#enable_move_cursor", 0) + + +function! over#command_line#search#load() + " load +endfunction + + +function! s:search_hl_off() + if exists("s:search_id") && s:search_id != -1 + call matchdelete(s:search_id) + unlet s:search_id + endif +endfunction + + +function! s:search_hl_on(pattern) + call s:search_hl_off() + silent! let s:search_id = matchadd("IncSearch", a:pattern) +endfunction + + +function! s:main() + call s:search_hl_off() + let line = over#command_line#backward() + if line =~ '^/.\+' +\ || line =~ '^?.\+' + let pattern = matchstr(line, '^\(/\|?\)\zs.\+') + if g:over#command_line#search#enable_incsearch + call s:search_hl_on((&ignorecase ? '\c' : "") . pattern) + endif + if g:over#command_line#search#enable_move_cursor + if line =~ '^/.\+' + silent! call search(pattern, "c") + else + silent! call search(pattern, "cb") + endif + endif + endif +endfunction + + +augroup over-cmdline-search + autocmd! + autocmd User OverCmdLineChar call s:main() + autocmd User OverCmdLineLeave call s:search_hl_off() + autocmd User OverCmdLineEnter let s:old_pos = getpos(".") + autocmd User OverCmdLineExecutePre call setpos(".", s:old_pos) +augroup END + + + +let &cpo = s:save_cpo +unlet s:save_cpo + diff --git a/bundle/vim-over/autoload/over/command_line/substitute.vim b/bundle/vim-over/autoload/over/command_line/substitute.vim new file mode 100644 index 000000000..25e985753 --- /dev/null +++ b/bundle/vim-over/autoload/over/command_line/substitute.vim @@ -0,0 +1,253 @@ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +function! over#command_line#substitute#load() + " load +endfunction + + +let s:V = over#vital() +let s:Rocker = s:V.import("Unlocker.Rocker") +let s:Undo = s:V.import("Unlocker.Rocker.Undotree") + + +let s:hl_mark_begin = '' +let s:hl_mark_center = '' +let s:hl_mark_end = '' + + +let g:over#command_line#substitute#highlight_pattern = get(g:, "over#command_line#substitute#highlight_pattern", "Search") + +if hlexists("Error") + let g:over#command_line#substitute#highlight_string = get(g:, "over#command_line#substitute#highlight_string", "Error") +else + let g:over#command_line#substitute#highlight_string = get(g:, "over#command_line#substitute#highlight_string", "ErrorMsg") +endif + + +function! s:init() + if &modifiable == 0 + return + endif + let s:undo_flag = 0 + + let hl_f = "syntax match %s '%s' conceal containedin=.*" + execute printf(hl_f, "OverCmdLineSubstituteHiddenBegin", s:hl_mark_begin) + execute printf(hl_f, "OverCmdLineSubstituteHiddenCenter", s:hl_mark_center) + execute printf(hl_f, "OverCmdLineSubstituteHiddenEnd", s:hl_mark_end) +" syntax match OverCmdLineSubstituteHiddenBegin '`os`' conceal containedin=ALL +" syntax match OverCmdLineSubstituteHiddenMiddle '`om`' conceal containedin=ALL +" syntax match OverCmdLineSubstituteHiddenEnd '`oe`' conceal containedin=ALL + +" let s:undo_file = tempname() +" execute "wundo" s:undo_file + +" let s:old_pos = getpos(".") + + let s:locker = s:Rocker.lock( +\ "&scrolloff", +\ "&l:conceallevel", +\ "&l:concealcursor", +\ "&l:modified", +\ "&l:undolevels", +\ ) + let &scrolloff = 0 + let s:old_modified = &l:modified + + let s:undo_locker = s:Undo.make().lock() + + " Workaround https://github.com/osyo-manga/vim-over/issues/43 + " substitute use undo + setlocal undolevels=0 + + let s:finished = 0 +" let s:buffer_text = getline(1, "$") +endfunction + + +function! s:finish() + if &modifiable == 0 || s:finished + return + endif + call s:reset_match() + let s:finished = 1 +" call setpos(".", s:old_pos) + call s:locker.unlock() + +" highlight link OverCmdLineSubstitute NONE +" highlight link OverCmdLineSubstitutePattern NONE +" highlight link OverCmdLineSubstituteString NONE +endfunction + + +function! s:undojoin() + if exists("s:undo_locker") + call s:undo() +" call setline(1, s:buffer_text) + call s:undo_locker.unlock() +" if filereadable(s:undo_file) +" silent execute "rundo" s:undo_file +" endif + unlet s:undo_locker +" unlet s:undo_file + endif +endfunction + + +function! s:silent_undo() + let pos = getpos(".") + redir => _ + silent undo + redir END + call setpos(".", pos) +endfunction + + +function! s:undo() + if s:undo_flag + call s:silent_undo() + let s:undo_flag = 0 + endif +endfunction + + +function! s:matchadd(group, pat) + if hlID(a:group) + try + let id = matchadd(a:group, a:pat, 1) + catch + return + endtry + call add(s:matchlist, id) + endif +endfunction + + +let s:matchlist = [] +function! s:reset_match() + for id in s:matchlist + if id != -1 + silent! call matchdelete(id) + endif + endfor + let s:matchlist = [] +endfunction + + +function! s:silent_substitute(range, pattern, string, flags) + try + let flags = substitute(a:flags, 'c', '', "g") + let old_pos = getpos(".") + let old_search = @/ + let check = b:changedtick + silent execute printf('%ss/%s/%s/%s', a:range, a:pattern, a:string, flags) + call histdel("search", -1) + let &l:modified = s:old_modified + catch /\v^Vim%(\(\a+\))=:(E121)|(E117)|(E110)|(E112)|(E113)|(E731)|(E475)|(E15)/ + if check != b:changedtick + call s:silent_undo() + endif + return 0 + catch + finally + call setpos(".", old_pos) + let @/ = old_search + endtry + return check != b:changedtick +endfunction + + +function! s:substitute_preview(line) + if &modifiable == 0 + return + endif + + if over#command_line#is_input("\") + return + endif + + call s:undo() + + call s:reset_match() + + let result = over#parse_substitute(a:line) + if empty(result) + return + endif + nohlsearch + + let [range, pattern, string, flags] = result + if empty(pattern) + let pattern = @/ + endif + + if empty(string) + call s:matchadd(g:over#command_line#substitute#highlight_pattern, (&ignorecase ? '\c' : '') . pattern) + return + endif + + let range = (range ==# "%") ? printf("%d,%d", line("w0"), line("w$")) : range + if string =~ '^\\=.\+' + + " \="`os`" . submatch(0) . "`om`" . (submatch(0)) . "`oe`" + let hl_submatch = printf('\\="%s" . submatch(0) . "%s" . (', s:hl_mark_begin, s:hl_mark_center) + let string = substitute(string, '^\\=\ze.\+', hl_submatch, "") . ') . "' . s:hl_mark_end . '"' + else + if g:over#command_line#substitute#replace_pattern_visually + let string = s:hl_mark_begin . s:hl_mark_center . string . s:hl_mark_end + else + let string = s:hl_mark_begin . '\0' . s:hl_mark_center . string . s:hl_mark_end + endif + endif + let s:undo_flag = s:silent_substitute(range, pattern, string, flags) + + let &l:concealcursor = "nvic" + let &l:conceallevel = 3 + + let pattern = s:hl_mark_begin . '\zs\_.\{-}\ze' . s:hl_mark_center + let string = s:hl_mark_center . '\zs\_.\{-}\ze' . s:hl_mark_end + call s:matchadd(g:over#command_line#substitute#highlight_pattern, pattern) + call s:matchadd(g:over#command_line#substitute#highlight_string, string) +endfunction + + +function! s:on_charpre() + if over#command_line#is_input("\(over-cmdline-substitute-jump-string)") + let result = over#parse_substitute(over#command_line#getline()) + if empty(result) + return + endif + let [range, pattern, string, flags] = result + call over#command_line#setpos(strchars(range . pattern) + 3) + call over#command_line#setchar("") + endif + if over#command_line#is_input("\(over-cmdline-substitute-jump-pattern)") + let result = over#parse_substitute(over#command_line#getline()) + if empty(result) + return + endif + let [range, pattern, string, flags] = result + call over#command_line#setpos(strchars(range ) + 2) + call over#command_line#setchar("") + endif +endfunction + + +augroup over-cmdline-substitute + autocmd! + autocmd User OverCmdLineEnter call s:init() + autocmd User OverCmdLineExecutePre call s:undojoin() + autocmd User OverCmdLineExecutePre call s:finish() + autocmd User OverCmdLineLeave call s:finish() + autocmd User OverCmdLineException call s:finish() + autocmd User OverCmdLineException call s:undojoin() + autocmd User OverCmdLineCancel call s:undojoin() + autocmd User OverCmdLineChar call s:substitute_preview(over#command_line#getline()) + autocmd user OverCmdLineCharPre call s:on_charpre() +augroup END + + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over.vim b/bundle/vim-over/autoload/vital/_over.vim new file mode 100644 index 000000000..55104952e --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over.vim @@ -0,0 +1,9 @@ +let s:_plugin_name = expand(':t:r') + +function! vital#{s:_plugin_name}#new() abort + return vital#{s:_plugin_name[1:]}#new() +endfunction + +function! vital#{s:_plugin_name}#function(funcname) abort + silent! return function(a:funcname) +endfunction diff --git a/bundle/vim-over/autoload/vital/_over/Coaster/Buffer.vim b/bundle/vim-over/autoload/vital/_over/Coaster/Buffer.vim new file mode 100644 index 000000000..440b8aa91 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Coaster/Buffer.vim @@ -0,0 +1,361 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Coaster#Buffer#import() abort', printf("return map({'get_text_line_from_lnum': '', 'setbufline': '', 'pos_less_equal': '', 'execute': '', 'get_line_from_region': '', 'new_temp': '', 'delete': '', 'get_block_from_region': '', 'new': '', 'paste': '', '_vital_depends': '', 'setbufline_if_python': '', 'get_text_from_latest_yank': '', 'get': '', 'get_text_from_region': '', 'as_wise_key': '', 'yank': '', 'get_line_from_pos': '', 'current': '', 'get_region_from_textobj': '', 'get_text_from_pattern': '', 'get_char_from_region': '', 'paste_for_text': '', 'open': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + + +function! s:_vital_loaded(V) + let s:V = a:V + let s:Search = a:V.import("Coaster.Search") + let s:Object = a:V.import("Coaster.Buffer.Object") +endfunction + + +function! s:_vital_depends() + return [ +\ "Coaster.Search", +\ "Coaster.Buffer.Object" +\ ] +endfunction + + +" a <= b +function! s:pos_less_equal(a, b) + return a:a[0] == a:b[0] ? a:a[1] <= a:b[1] : a:a[0] <= a:b[0] +endfunction + + +function! s:as_wise_key(name) + return a:name ==# "char" ? "v" +\ : a:name ==# "line" ? "V" +\ : a:name ==# "block" ? "\" +\ : a:name +endfunction + + +function! s:get_text_from_latest_yank(...) + if mode() != "n" + return + endif + + let wise = get(a:, 1, "v") + let register = v:register == "" ? '"' : v:register + + let old_selection = &selection + let &selection = 'inclusive' + let old_pos = getpos(".") + let old_reg = getreg(register) + try + execute printf('silent normal! `[%s`]y', wise) + return getreg(register) + finally + let &selection = old_selection + call setreg(register, old_reg) + call cursor(old_pos[1], old_pos[2]) + endtry +endfunction + + +function! s:get_line_from_pos(pos) + return a:pos[0] == 0 ? getline(a:pos[1]) : getbufline(a:pos[0], a:pos[1]) +endfunction + + +function! s:get_line_from_region(first, last) + if type(a:first) == type(0) + return s:get_line_from_region([0, a:first, 0, 0], a:last) + elseif type(a:last) == type(0) + return s:get_line_from_region(a:first, [0, a:last, 0, 0]) + endif + if a:first[0] != 0 && a:first[0] == a:last[0] + return join(getbufline(a:first[0], a:first[1], a:last[1]), "\n") + endif + return join(getline(a:first[1], a:last[1]), "\n") +endfunction + + +function! s:yank(wise, first, last) + let old_view = winsaveview() + let old_selection = &selection + let &selection = 'inclusive' + let old_first = getpos("'[") + let old_last = getpos("']") + let old_pos = getpos(".") + try + call s:_setpos("'[", a:first) + call s:_setpos("']", a:last) + execute "normal! `[" . a:wise . "`]y" + finally + call s:_setpos("'[", old_first) + call s:_setpos("']", old_last) + let &selection = old_selection + call winrestview(old_view) + call s:_setpos(".", old_pos) + endtry +endfunction + + +function! s:delete(wise, first, last) + let old_view = winsaveview() + let old_selection = &selection + let &selection = 'inclusive' + let old_first = getpos("'[") + let old_last = getpos("']") + let old_pos = getpos(".") + try + call s:_setpos("'[", a:first) + call s:_setpos("']", a:last) + execute printf('normal! `[%s`]"_d', a:wise) + finally + call s:_setpos("'[", old_first) + call s:_setpos("']", old_last) + let &selection = old_selection + call winrestview(old_view) + call s:_setpos(".", old_pos) + endtry +endfunction + + +function! s:_as_pos(pos) + return len(a:list) == 2 ? [0] + a:pos + [0] : a:pos +endfunction + + +function! s:_setpos(expr, list) + if len(a:list) == 2 + return s:_setpos(a:expr, [0] + a:list + [0]) + endif + return setpos(a:expr, a:list) +endfunction + + +function! s:paste(wise, first, last, register) + let old_view = winsaveview() + let old_selection = &selection + let &selection = 'inclusive' + let old_first = getpos("'[") + let old_last = getpos("']") + let old_pos = getpos(".") + try + call s:_setpos("'[", a:first) + call s:_setpos("']", a:last) + execute printf('normal! `[%s`]"%sp', a:wise, a:register) + finally + call s:_setpos("'[", old_first) + call s:_setpos("']", old_last) + let &selection = old_selection + call winrestview(old_view) + call s:_setpos(".", old_pos) + endtry +endfunction + + +function! s:paste_for_text(wise, first, last, text) + let old = @a + try + let @a = a:text + return s:paste(a:wise, a:first, a:last, "a") + finally + let @a = old + endtry +endfunction + + + +function! s:get_text_line_from_lnum(first, last) + return join(getline(a:first, a:last), "\n") +endfunction + + +" function! s:get_text_line_from_region(first, last) +" " if type(a:first) == type([]) +" " return s:get_text_line_from_region(a:first[1], a:last) +" " elseif type(a:last) == type([]) +" " return s:get_text_line_from_region(a:first, a:last[1]) +" " endif +" " return join(getline(a:first, a:last), "\n") +" +" return s:get_text_line_from_lnum(a:first[1], a:last[1]) +" endfunction + + +function! s:get_char_from_region(first, last) + if a:first[1] == a:last[1] + return getline(a:first[1])[a:first[2] - 1 : a:last[2] - 1] + elseif (a:last[1] - a:first[1]) == 1 + return getline(a:first[1])[ a:first[2] - 1 : ] . "\n" +\ . getline(a:last[1])[ : a:last[2] - 1] + else + return getline(a:first[1])[ a:first[2] - 1 : ] . "\n" +\ . s:get_text_line_from_lnum(a:first[1] + 1, a:last[1] - 1) . "\n" +\ . getline(a:last[1])[ : a:last[2] - 1] + endif +endfunction + + +function! s:get_block_from_region(first, last) + let first = a:first + let last = a:last + return join(map(range(a:first[1], a:last[1]), "s:get_char_from_region([first[0], v:val, first[2], first[3]], [last[0], v:val, last[2], last[3]])"), "\n") +endfunction + + +function! s:get_text_from_region(first, last, ...) + let wise = get(a:, 1, "v") + if wise ==# "v" + return s:get_char_from_region(a:first, a:last) + elseif wise ==# "V" + return s:get_line_from_region(a:first, a:last) + elseif wise ==# "\" + return s:get_block_from_region(a:first, a:last) + endif +endfunction + + +function! s:get_text_from_pattern(pattern) + let [first, last] = s:Search.region(a:pattern, "Wncb", "Wnce") + if first == [0, 0] + return "" + endif + if last == [0, 0] + return "" + endif + let result = s:get_text_from_region([0] + first + [0], [0] + last + [0], "v") + if result !~ '^' . a:pattern . '$' + return "" + endif + return result +endfunction + + +function! s:_as_config(config) + let default = { +\ "textobj" : "", +\ "is_cursor_in" : 0, +\ "noremap" : 0, +\ } + let config +\ = type(a:config) == type("") ? { "textobj" : a:config } +\ : type(a:config) == type({}) ? a:config +\ : {} + return extend(default, config) +endfunction + + +let s:region = [] +let s:wise = "" +function! s:_buffer_region_operator(wise) + let reg_save = @@ + let s:wise = a:wise + let s:region = [getpos("'[")[1:], getpos("']")[1:]] + let @@ = reg_save +endfunction + +nnoremap (vital-coaster_buffer_region) +\ :set operatorfunc=_buffer_region_operatorg@ + + +function! s:get_region_from_textobj(textobj) + let s:region = [] + let config = s:_as_config(a:textobj) + + let winview = winsaveview() + let pos = getpos(".") + try + silent execute (config.noremap ? 'onoremap' : 'omap') '' +\ '(vital-coaster_buffer_region-target)' string(config.textobj) + + let tmp = &operatorfunc + silent execute "normal \(vital-coaster_buffer_region)\(vital-coaster_buffer_region-target)" + let &operatorfunc = tmp + + if !empty(s:region) && !s:pos_less_equal(s:region[0], s:region[1]) + return ["", []] + endif + if !empty(s:region) && config.is_cursor_in && (s:pos_less(pos[1:], s:region[0]) || s:pos_less(s:region[1], pos[1:])) + return ["", []] + endif + return deepcopy([s:wise, s:region]) + finally + call winrestview(winview) + call cursor(pos[1], pos[2]) + endtry +endfunction + + +function! s:get(bufnr) + return s:Object.make(a:bufnr) +endfunction + + +" function! s:make(expr) +" let buffer = s:get(a:expr) +" if buffer.is_exists() +" return buffer +" endif +" return s:new("", type(a:expr) == type("") ? a:expr : "") +" endfunction + + +function! s:current() + return s:get(bufnr("%")) +endfunction + + +function! s:new(...) + let name = get(a:, 1, "") + execute "new" name + let buffer = s:current() + quit + return buffer +endfunction + + +function! s:new_temp(...) + let name = get(a:, 1, "") + execute "new" name + let buffer = s:current() + setlocal bufhidden=hide buftype=nofile noswapfile nobuflisted + quit + return buffer +endfunction + + +function! s:open(cmd) + let buffer = s:new() + call buffer.open(a:cmd) + return buffer +endfunction + + +function! s:execute(expr, cmd) + return s:get(a:expr).execute(a:cmd) +endfunction + + +function! s:setbufline_if_python(expr, lnum, text) + if len(getbufline(a:expr, 1, "$")) < a:lnum - 1 + return + endif + let list = type(a:text) == type([]) ? a:text : [a:text] + python import vim + py vim.buffers[int(vim.eval('a:expr'))][int(vim.eval("a:lnum")) - 1 : int(vim.eval("a:lnum")) - 1 + len(vim.eval("list"))] = vim.eval("list") +endfunction + + +function! s:setbufline(expr, lnum, text) + return s:get(a:expr).setline(a:lnum, a:text) +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Coaster/Buffer/Object.vim b/bundle/vim-over/autoload/vital/_over/Coaster/Buffer/Object.vim new file mode 100644 index 000000000..98a4e460a --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Coaster/Buffer/Object.vim @@ -0,0 +1,314 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Coaster#Buffer#Object#import() abort', printf("return map({'setbufline_if_python': '', 'setbufline_if_python3': '', 'setbufline_if_ruby': '', 'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +let s:obj = { +\ "__variable" : {} +\} + + +function! s:obj.number() + return self.__variable.bufnr +endfunction + + +function! s:obj.invoke(func, ...) + let args = get(a:, 1, []) + return call(a:func, [self.number()] + args) +endfunction + + +function! s:obj.name() + return self.invoke("bufname") +endfunction + + +function! s:obj.get_variable(...) + return self.invoke("getbufvar", a:000) +endfunction + + +function! s:obj.set_variable(...) + return self.invoke("setbufvar", a:000) +endfunction + + +function! s:obj.get_option(name) + return self.get_variable("&" . a:name) +endfunction + + +function! s:obj.set_option(name, var) + return self.set_variable("&" . a:name, a:var) +endfunction + + +function! s:obj.winnr() + return self.invoke("bufwinnr") +endfunction + + +function! s:obj.is_exists() + return bufexists(self.number()) +endfunction + + +function! s:obj.is_listed() + return self.invoke("buflisted") +endfunction + + +function! s:obj.is_loaded() + return self.invoke("bufloaded") +endfunction + + +function! s:obj.is_current() + return self.number() == bufnr("%") +endfunction + + +function! s:obj.is_modifiable() + return self.get_option("modifiable") +endfunction + + +function! s:obj.is_opened_in_current_tabpage() + return self.winnr() != -1 +endfunction + + +function! s:obj.tap() + if !self.is_exists() || self.is_tapped() + return + endif + let self.__variable.tap_bufnr = bufnr("%") + split + execute "b" self.number() + return self.number() +endfunction + + +function! s:obj.untap() + if !self.is_tapped() + return + endif + quit + silent! execute "buffer" self.__variable.tap_bufnr + unlet self.__variable.tap_bufnr + return self.number() +endfunction + + +function! s:obj.tap_modifiable(...) + let force = get(a:, 1, 1) + if !(self.is_modifiable() || force) + return + endif + let result = self.tap() + if result + let self.__variable.modifiable = &modifiable + set modifiable + endif + return result +endfunction + + +function! s:obj.untap_modifiable() + if has_key(self.__variable, "modifiable") + let &modifiable = self.__variable.modifiable + unlet self.__variable.modifiable + call self.untap() + endif +endfunction + + +function! s:obj.is_tapped() + return has_key(self.__variable, "tap_bufnr") +endfunction + + +function! s:obj.execute(cmd) + if self.is_current() + execute a:cmd + return + endif + if self.tap() + try + execute a:cmd + finally + call self.untap() + endtry + endif + +" let view = winsaveview() +" try +" noautocmd silent! execute "bufdo if bufnr('%') == " a:expr . ' | ' . string(a:cmd) . ' | endif' +" finally +" noautocmd silent! execute "buffer" bufnr +" call winrestview(view) +" endtry +endfunction + + +function! s:setbufline_if_python(expr, lnum, text) + if len(getbufline(a:expr, 1, "$")) < a:lnum - 1 + return + endif + let list = type(a:text) == type([]) ? a:text : [a:text] + python import vim + py vim.buffers[int(vim.eval('a:expr'))][int(vim.eval("a:lnum")) - 1 : int(vim.eval("a:lnum")) - 1 + len(vim.eval("list"))] = vim.eval("list") +endfunction + + +function! s:setbufline_if_python3(expr, lnum, text) + if len(getbufline(a:expr, 1, "$")) < a:lnum - 1 + return + endif + let list = type(a:text) == type([]) ? a:text : [a:text] + python3 import vim + py3 vim.buffers[int(vim.eval('a:expr'))][int(vim.eval("a:lnum")) - 1 : int(vim.eval("a:lnum")) - 1 + len(vim.eval("list"))] = vim.eval("list") +endfunction + + +function! s:setbufline_if_ruby(expr, lnum, text) + if len(getbufline(a:expr, 1, "$")) < a:lnum - 1 + return + endif + let save_op = getbufvar(a:expr, "&buflisted") + call setbufvar(a:expr, "&buflisted", 1) + try + let list = type(a:text) == type([]) ? a:text : [a:text] + let bufnr = index(filter(range(1, bufnr("$")), "buflisted(v:val)"), bufnr(a:expr)) +ruby << EOR + bufnr = Vim::evaluate("bufnr") + text = Vim::evaluate("list") + lnum = Vim::evaluate("a:lnum") + b = Vim::Buffer[bufnr] + text.each_with_index {|it, i| + if b.count < lnum + i + b.append lnum + i - 1, it.to_s + else + b[lnum + i] = it.to_s + end + } +EOR + finally + let save_op = setbufvar(a:expr, "&buflisted", save_op) + endtry +endfunction + + +function! s:obj.setline(lnum, text, ...) +" if has("ruby") +" return s:setbufline_if_ruby(self.number(), a:lnum, a:text) +" endif + let force = get(a:, 1, 0) + if self.tap_modifiable(force) + try + if exists("*setbufline") + return setbufline(self.number(), a:lnum, a:text) + endif + + if has("python") + return s:setbufline_if_python(self.number(), a:lnum, a:text) + endif + + if has("python3") + return s:setbufline_if_python3(self.number(), a:lnum, a:text) + endif + + call setline(a:lnum, a:text) + finally + call self.untap_modifiable() + endtry + endif +" return self.execute("call setline(" . a:lnum . "," . string(a:text) . ")") +endfunction + + +function! s:obj.append(lnum, text, ...) + let force = get(a:, 1, 0) + if self.tap_modifiable(force) + try + call append(a:lnum, a:text) + finally + call self.untap_modifiable() + endtry + endif +endfunction + + +function! s:obj.clear(...) + let force = get(a:, 1, 0) + if self.tap_modifiable(force) + try + silent % delete _ + finally + call self.untap_modifiable() + endtry + endif +endfunction + + +function! s:obj.getline(...) + return self.invoke("getbufline", a:000) +endfunction + + +function! s:obj.line_length() + return len(getbufline(self.number(), 1, "$")) +endfunction + + +function! s:obj.open(...) + let open_cmd = get(a:, 1, "") + execute open_cmd + execute "buffer" self.number() +endfunction + + +function! s:obj.close() + call self.execute("close") + call self.delete() +endfunction + + +function! s:obj.delete(...) + let force = get(a:, 1, 0) + if self.is_exists() + try + execute "bdelete" . (force ? "! " : " ") . self.number() + return 0 + catch + return -1 + endtry + endif +endfunction + + +function! s:obj.set_name(name) + return self.execute(":file " . string(a:name)) +endfunction + + +function! s:make(expr) + let obj = deepcopy(s:obj) + let obj.__variable.bufnr = bufnr(a:expr) + return obj +endfunction + + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Coaster/Highlight.vim b/bundle/vim-over/autoload/vital/_over/Coaster/Highlight.vim new file mode 100644 index 000000000..7e201a96f --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Coaster/Highlight.vim @@ -0,0 +1,246 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Coaster#Highlight#import() abort', printf("return map({'highlight': '', 'clear': '', 'delete': '', 'add': '', 'as_windo': '', '_vital_depends': '', 'get_hl_id': '', 'to_list': '', 'clear_all': '', 'delete_all': '', 'to_list_by': '', 'update': '', 'enable': '', 'delete_by': '', 'hl_list': '', 'make': '', 'enable_list': '', 'update_all': '', 'disable': '', 'disable_all': '', 'is_enabled': '', 'enable_all': '', 'is_added': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:_vital_loaded(V) + let s:V = a:V + let s:Window = a:V.import("Coaster.Window") + let s:Gift = a:V.import("Gift") + call s:_init() +endfunction + + +function! s:_vital_depends() + return [ +\ "Coaster.Window", +\ "Gift", +\ ] +endfunction + + + +let s:base = { +\ "variables" : { +\ "hl_list" : {}, +\ "id_list" : {}, +\ "id_count" : 0 +\ } +\} + + +function! s:base.add(name, group, pattern, ...) + if a:name == "" + let self.variables.id_count += 1 + return self.add(self.variables.id_count, a:group, a:pattern, get(a:, 1, 10)) + endif + call self.delete(a:name) + let priority = get(a:, 1, 10) + let self.variables.hl_list[a:name] = { +\ "group" : a:group, +\ "pattern" : a:pattern, +\ "priority" : priority, +\ "name" : a:name, +\ } + return self.variables.hl_list[a:name] +endfunction + + +function! s:base.is_added(name) + return has_key(self.variables.hl_list, a:name) +endfunction + + +function! s:base.hl_list() + return keys(self.variables.hl_list) +endfunction + + +function! s:base.to_list() + return values(self.variables.hl_list) +endfunction + + +function! s:_is_equal(__expr, __hl) + let name = a:__hl.name + let group = a:__hl.group + let pattern = a:__hl.pattern + let priority = a:__hl.priority + return eval(a:__expr) +endfunction + + +function! s:base.to_list_by(expr) + return filter(values(self.variables.hl_list), "s:_is_equal(a:expr, v:val)") +endfunction + + +function! s:base.enable_list(...) + let window = get(a:, 1, s:Gift.uniq_winnr()) + return keys(get(self.variables.id_list, window, {})) +endfunction + + +function! s:base.delete(name) + if !self.is_added(a:name) + return -1 + endif + unlet! self.variables.hl_list[a:name] +endfunction + + +function! s:base.delete_by(expr) + return map(self.to_list_by(a:expr), "self.delete(v:val.name)") +endfunction + + +function! s:base.delete_all() + for name in self.hl_list() + call self.delete(name) + endfor +endfunction + + +function! s:base.get_hl_id(name, ...) + let window = get(a:, 1, s:Gift.uniq_winnr()) + return get(get(self.variables.id_list, window, {}), a:name, "") +endfunction + + +function! s:base.is_enabled(name, ...) + let window = get(a:, 1, s:Gift.uniq_winnr()) + return self.get_hl_id(a:name, window) != "" +endfunction + + +function! s:base.enable(name) + let hl = get(self.variables.hl_list, a:name, {}) + if empty(hl) + return -1 + endif + if self.is_enabled(a:name) + call self.disable(a:name) + endif + let winnr = s:Gift.uniq_winnr() + if !has_key(self.variables.id_list, winnr) + let self.variables.id_list[winnr] = {} + endif + let self.variables.id_list[winnr][a:name] = matchadd(hl.group, hl.pattern, hl.priority) +endfunction + + +function! s:base.enable_all() + for name in self.hl_list() + call self.enable(name) + endfor +endfunction + + +function! s:base.disable(name) + if !self.is_enabled(a:name) + return -1 + endif + let id = -1 + silent! let id = matchdelete(self.get_hl_id(a:name)) + if id == -1 + return -1 + endif + let winnr = get(a:, 1, s:Gift.uniq_winnr()) + unlet! self.variables.id_list[winnr][a:name] +endfunction + + +function! s:base.disable_all() + for name in self.enable_list() + call self.disable(name) + endfor +endfunction + + +function! s:base.update(name) + call self.disable(a:name) + call self.enable(a:name) +endfunction + + +function! s:base.update_all() + call self.disable_all() + call self.enable_all() +endfunction + + +function! s:base.highlight(name, group, pattern, ...) + let priority = get(a:, 1, 10) + let result = self.add(a:name, a:group, a:pattern, priority) + call self.enable(result.name) + return result +endfunction + + +function! s:base.clear(name) + call self.disable(a:name) + call self.delete(a:name) +endfunction + + +function! s:base.clear_all() + call self.disable_all() + call self.delete_all() +endfunction + + +function! s:base.as_windo() + return self.windo +endfunction + + +function! s:make() + let result = deepcopy(s:base) + let result.windo = s:Window.as_windo(result) + return result +endfunction + + +let s:global = deepcopy(s:base) +let s:funcs = keys(filter(copy(s:global), "type(v:val) == type(function('tr'))")) + +for s:name in s:funcs + execute +\ "function! s:" . s:name . "(...) \n" +\ "return call(s:global." . s:name . ", a:000, s:global) \n" +\ "endfunction" +endfor +unlet s:name + + +function! s:_init() + let s:global.windo = s:Window.as_windo(s:global) +endfunction + +" function! s:matchadd(...) +" return { +" \ "id" : call("matchadd", a:000), +" \ "bufnr" : bufnr("%"), +" \ } +" endfunction +" +" +" function! s:matchdelete(id) +" if empty(a:id) +" return -1 +" endif +" return s:Buffer.execute(a:id.bufnr, "call matchdelete(" . a:id.id . ")") +" endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Coaster/Search.vim b/bundle/vim-over/autoload/vital/_over/Coaster/Search.vim new file mode 100644 index 000000000..4df838a61 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Coaster/Search.vim @@ -0,0 +1,147 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Coaster#Search#import() abort', printf("return map({'region': '', '_vital_depends': '', 'pos_ignore_syntaxes': '', 'pattern_by_range': '', 'pattern_in_region': '', 'pattern_in_region_char': '', 'pattern_in_region_block': '', 'pattern_in_region_line': '', 'region_pair': '', 'pattern_in_range': '', 'count': '', 'text_by_pattern': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + + +function! s:_vital_loaded(V) + let s:V = a:V + let s:Buffer = s:V.import("Coaster.Buffer") +endfunction + + +function! s:_vital_depends() + return [ +\ ] +endfunction + + +function! s:region(pattern, ...) + let flag_first = get(a:, 1, "") + let flag_last = get(a:, 2, "") + return [searchpos(a:pattern, flag_first), searchpos(a:pattern, flag_last)] +endfunction + + +function! s:region_pair(fist, last, ...) + " todo +endfunction + + +function! s:pattern_in_region_char(first, last, pattern) + if a:first == a:last + return printf('\%%%dl\%%%dc', a:first[0], a:first[1]) + elseif a:first[0] == a:last[0] + return printf('\%%%dl\%%>%dc\%%(%s\M\)\%%<%dc', a:first[0], a:first[1]-1, a:pattern, a:last[1]+1) + elseif a:last[0] - a:first[0] == 1 + return printf('\%%%dl\%%(%s\M\)\%%>%dc', a:first[0], a:pattern, a:first[1]-1) +\ . "\\|" . printf('\%%%dl\%%(%s\M\)\%%<%dc', a:last[0], a:pattern, a:last[1]+1) + else + return printf('\%%%dl\%%(%s\M\)\%%>%dc', a:first[0], a:pattern, a:first[1]-1) +\ . "\\|" . printf('\%%>%dl\%%(%s\M\)\%%<%dl', a:first[0], a:pattern, a:last[0]) +\ . "\\|" . printf('\%%%dl\%%(%s\M\)\%%<%dc', a:last[0], a:pattern, a:last[1]+1) + endif +endfunction + + +" function! s:pattern_in_region_char(first, last, pattern) +" if a:first == a:last +" return printf('\%%%dl\%%%dv', a:first[0], a:first[1]) +" elseif a:first[0] == a:last[0] +" return printf('\%%%dl\%%>%dv\%%(%s\M\)\%%<%dv', a:first[0], a:first[1]-1, a:pattern, a:last[1]+1) +" elseif a:last[0] - a:first[0] == 1 +" return printf('\%%%dl\%%(%s\M\)\%%>%dv', a:first[0], a:pattern, a:first[1]-1) +" \ . "\\|" . printf('\%%%dl\%%(%s\M\)\%%<%dv', a:last[0], a:pattern, a:last[1]+1) +" else +" return printf('\%%%dl\%%(%s\M\)\%%>%dv', a:first[0], a:pattern, a:first[1]-1) +" \ . "\\|" . printf('\%%>%dl\%%(%s\M\)\%%<%dl', a:first[0], a:pattern, a:last[0]) +" \ . "\\|" . printf('\%%%dl\%%(%s\M\)\%%<%dv', a:last[0], a:pattern, a:last[1]+1) +" endif +" endfunction + + + + +function! s:pattern_in_region_line(first, last, pattern) + return printf('\%%>%dl\%%(%s\M\)\%%<%dl', a:first[0]-1, a:pattern, a:last[0]+1) +endfunction + + +function! s:pattern_in_region_block(first, last, pattern) + return join(map(range(a:first[0], a:last[0]), "s:pattern_in_region_char([v:val, a:first[1]], [v:val, a:last[1]], a:pattern)"), '\|') +endfunction + + +function! s:pattern_in_region(wise, first, last, ...) + let pattern = get(a:, 1, "") + if a:wise ==# "v" + return s:pattern_in_region_char(a:first, a:last, pattern) + elseif a:wise ==# "V" + return s:pattern_in_region_line(a:first, a:last, pattern) + elseif a:wise ==# "\" + return s:pattern_in_region_block(a:first, a:last, pattern) + endif +endfunction + +function! s:pattern_in_range(...) + return call("s:pattern_in_region", a:000) +endfunction + + +function! s:pattern_by_range(wise, first, last) + return s:pattern_in_range(a:wise, a:first, a:last, '.\{-}') +endfunction + + +function! s:text_by_pattern(pattern, ...) + let flag = get(a:, 1, "") + let [first, last] = s:region(a:pattern, "c" . flag, "ce" . flag) + if first == [0, 0] || last == [0, 0] + endif + let result = s:Buffer.get_text_from_region([0] + first + [0], [0] + last + [0], "v") + return result +endfunction + + +function! s:_syntax_name(pos) + return synIDattr(synIDtrans(synID(a:pos[0], a:pos[1], 1)), 'name') +endfunction + + +" log : http://lingr.com/room/vim/archives/2014/08/15#message-19938628 +function! s:pos_ignore_syntaxes(pattern, syntaxes, ...) + let old_pos = getpos(".") + let old_view = winsaveview() + let flag = substitute(get(a:, 1, ""), 'n', "", "g") + try + while 1 + let pos = searchpos(a:pattern, flag . "W") + if pos == [0, 0] || index(a:syntaxes, s:_syntax_name(pos)) == -1 + return pos + endif + endwhile + finally + if get(a:, 1, "") =~# "n" + call setpos(".", old_pos) + call winrestview(old_view) + endif + endtry +endfunction + + +function! s:count(pattern) + return matchstr(s:M.capture('%s/' . a:pattern . '//n'), '\d\+\ze') +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Coaster/Window.vim b/bundle/vim-over/autoload/vital/_over/Coaster/Window.vim new file mode 100644 index 000000000..df61c54e8 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Coaster/Window.vim @@ -0,0 +1,62 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Coaster#Window#import() abort', printf("return map({'as_windo': '', '_vital_depends': '', 'windo': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:_vital_loaded(V) + let s:V = a:V + let s:Buffer = a:V.import("Vim.Buffer") +endfunction + + +function! s:_vital_depends() + return [ +\ "Vim.Buffer", +\ ] +endfunction + + +function! s:windo(func, args, ...) + let dict = get(a:, 1, {}) + if len(tabpagebuflist()) <= 1 || s:Buffer.is_cmdwin() + return call(a:func, a:args, dict) + endif + let pre_winnr = winnr() + + noautocmd windo call call(a:func, a:args, dict) + + if pre_winnr == winnr() + return + endif + noautocmd execute pre_winnr . "wincmd w" +endfunction + + +function! s:as_windo(base) + let windo = {} + let windo.obj = a:base + for [key, Value] in items(a:base) + if type(function("tr")) == type(Value) + execute +\ "function! windo.". key. "(...)\n" +\ " return s:windo(self.obj." . key . ", a:000, self.obj)\n" +\ "endfunction" + endif + unlet Value + endfor + return windo +endfunction + + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Data/Dict.vim b/bundle/vim-over/autoload/vital/_over/Data/Dict.vim new file mode 100644 index 000000000..6f1f63cff --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Data/Dict.vim @@ -0,0 +1,151 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Data#Dict#import() abort', printf("return map({'_vital_depends': '', 'clear': '', 'max_by': '', 'foldl': '', 'pick': '', 'from_list': '', 'swap': '', 'omit': '', 'min_by': '', 'foldr': '', 'make_index': '', 'make': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +" Utilities for dictionary. + +let s:save_cpo = &cpo +set cpo&vim + +function! s:_vital_loaded(V) abort + let s:t = a:V.import('Vim.Type').types +endfunction + +function! s:_vital_depends() abort + return ['Vim.Type'] +endfunction + + +function! s:_ensure_key(key) abort + let t = type(a:key) + if t != s:t.string && t != s:t.number + throw 'vital: Data.Dict: Invalid key: ' . string(a:key) + endif +endfunction + +function! s:from_list(list) abort + let dict = {} + let i = 0 + let len = len(a:list) + while i < len + if type(a:list[i]) == s:t.list + let key_value = a:list[i] + if len(key_value) != 2 + throw 'vital: Data.Dict: Invalid key-value pair index at ' . i + endif + call s:_ensure_key(key_value[0]) + let dict[key_value[0]] = key_value[1] + let i += 1 + else + if len <= i + 1 + throw 'vital: Data.Dict: Invalid key-value pair index at ' . i + endif + call s:_ensure_key(a:list[i]) + let dict[a:list[i]] = a:list[i + 1] + let i += 2 + endif + endwhile + return dict +endfunction + +" Makes a dict from keys and values +function! s:make(keys, values, ...) abort + let dict = {} + let fill = a:0 ? a:1 : 0 + for i in range(len(a:keys)) + let key = type(a:keys[i]) == s:t.string ? a:keys[i] : string(a:keys[i]) + if key ==# '' + throw "vital: Data.Dict: Can't use an empty string for key." + endif + let dict[key] = get(a:values, i, fill) + endfor + return dict +endfunction + +" Swaps keys and values +function! s:swap(dict) abort + return s:make(values(a:dict), keys(a:dict)) +endfunction + +" Makes a index dict from a list +function! s:make_index(list, ...) abort + let value = a:0 ? a:1 : 1 + return s:make(a:list, [], value) +endfunction + +function! s:pick(dict, keys) abort + let new_dict = {} + for key in a:keys + if has_key(a:dict, key) + let new_dict[key] = a:dict[key] + endif + endfor + return new_dict +endfunction + +function! s:omit(dict, keys) abort + let new_dict = copy(a:dict) + for key in a:keys + if has_key(a:dict, key) + call remove(new_dict, key) + endif + endfor + return new_dict +endfunction + +function! s:clear(dict) abort + for key in keys(a:dict) + call remove(a:dict, key) + endfor + return a:dict +endfunction + +function! s:_max_by(dict, expr) abort + let dict = s:swap(map(copy(a:dict), a:expr)) + let key = dict[max(keys(dict))] + return [key, a:dict[key]] +endfunction + +function! s:max_by(dict, expr) abort + if empty(a:dict) + throw 'vital: Data.Dict: Empty dictionary' + endif + return s:_max_by(a:dict, a:expr) +endfunction + +function! s:min_by(dict, expr) abort + if empty(a:dict) + throw 'vital: Data.Dict: Empty dictionary' + endif + return s:_max_by(a:dict, '-(' . a:expr . ')') +endfunction + +function! s:_foldl(f, init, xs) abort + let memo = a:init + for [k, v] in a:xs + let expr = substitute(a:f, 'v:key', string(k), 'g') + let expr = substitute(expr, 'v:val', string(v), 'g') + let expr = substitute(expr, 'v:memo', string(memo), 'g') + unlet memo + let memo = eval(expr) + endfor + return memo +endfunction + +function! s:foldl(f, init, dict) abort + return s:_foldl(a:f, a:init, items(a:dict)) +endfunction + +function! s:foldr(f, init, dict) abort + return s:_foldl(a:f, a:init, reverse(items(a:dict))) +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo + +" vim:set et ts=2 sts=2 sw=2 tw=0: diff --git a/bundle/vim-over/autoload/vital/_over/Data/List.vim b/bundle/vim-over/autoload/vital/_over/Data/List.vim new file mode 100644 index 000000000..121a70962 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Data/List.vim @@ -0,0 +1,464 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Data#List#import() abort', printf("return map({'combinations': '', 'and': '', 'sort_by': '', 'foldr1': '', 'sort': '', 'flatten': '', 'has_index': '', 'find_indices': '', 'any': '', 'unshift': '', 'span': '', 'pop': '', 'binary_search': '', 'uniq_by': '', 'or': '', 'all': '', 'zip': '', 'find_last_index': '', 'find': '', 'partition': '', 'shift': '', 'permutations': '', 'break': '', 'max_by': '', 'foldl': '', 'foldr': '', 'find_index': '', 'drop_while': '', 'group_by': '', 'take_while': '', 'conj': '', 'push': '', 'char_range': '', 'cons': '', 'foldl1': '', 'intersect': '', 'concat': '', 'map_accum': '', 'clear': '', 'has_common_items': '', 'product': '', 'zip_fill': '', 'uniq': '', 'has': '', 'min_by': '', 'with_index': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +" Utilities for list. + +let s:save_cpo = &cpo +set cpo&vim + +function! s:pop(list) abort + return remove(a:list, -1) +endfunction + +function! s:push(list, val) abort + call add(a:list, a:val) + return a:list +endfunction + +function! s:shift(list) abort + return remove(a:list, 0) +endfunction + +function! s:unshift(list, val) abort + return insert(a:list, a:val) +endfunction + +function! s:cons(x, xs) abort + return [a:x] + a:xs +endfunction + +function! s:conj(xs, x) abort + return a:xs + [a:x] +endfunction + +" Removes duplicates from a list. +function! s:uniq(list) abort + return s:uniq_by(a:list, 'v:val') +endfunction + +" Removes duplicates from a list. +function! s:uniq_by(list, f) abort + let list = map(copy(a:list), printf('[v:val, %s]', a:f)) + let i = 0 + let seen = {} + while i < len(list) + let key = string(list[i][1]) + if has_key(seen, key) + call remove(list, i) + else + let seen[key] = 1 + let i += 1 + endif + endwhile + return map(list, 'v:val[0]') +endfunction + +function! s:clear(list) abort + if !empty(a:list) + unlet! a:list[0 : len(a:list) - 1] + endif + return a:list +endfunction + +" Concatenates a list of lists. +" XXX: Should we verify the input? +function! s:concat(list) abort + let memo = [] + for Value in a:list + let memo += Value + endfor + return memo +endfunction + +" Take each elements from lists to a new list. +function! s:flatten(list, ...) abort + let limit = a:0 > 0 ? a:1 : -1 + let memo = [] + if limit == 0 + return a:list + endif + let limit -= 1 + for Value in a:list + let memo += + \ type(Value) == type([]) ? + \ s:flatten(Value, limit) : + \ [Value] + unlet! Value + endfor + return memo +endfunction + +" Sorts a list with expression to compare each two values. +" a:a and a:b can be used in {expr}. +function! s:sort(list, expr) abort + if type(a:expr) == type(function('function')) + return sort(a:list, a:expr) + endif + let s:expr = a:expr + return sort(a:list, 's:_compare') +endfunction + +function! s:_compare(a, b) abort + return eval(s:expr) +endfunction + +" Sorts a list using a set of keys generated by mapping the values in the list +" through the given expr. +" v:val is used in {expr} +function! s:sort_by(list, expr) abort + let pairs = map(a:list, printf('[v:val, %s]', a:expr)) + return map(s:sort(pairs, + \ 'a:a[1] ==# a:b[1] ? 0 : a:a[1] ># a:b[1] ? 1 : -1'), 'v:val[0]') +endfunction + +" Returns a maximum value in {list} through given {expr}. +" Returns 0 if {list} is empty. +" v:val is used in {expr} +function! s:max_by(list, expr) abort + if empty(a:list) + return 0 + endif + let list = map(copy(a:list), a:expr) + return a:list[index(list, max(list))] +endfunction + +" Returns a minimum value in {list} through given {expr}. +" Returns 0 if {list} is empty. +" v:val is used in {expr} +" FIXME: -0x80000000 == 0x80000000 +function! s:min_by(list, expr) abort + return s:max_by(a:list, '-(' . a:expr . ')') +endfunction + +" Returns List of character sequence between [a:from, a:to] +" e.g.: s:char_range('a', 'c') returns ['a', 'b', 'c'] +function! s:char_range(from, to) abort + return map( + \ range(char2nr(a:from), char2nr(a:to)), + \ 'nr2char(v:val)' + \) +endfunction + +" Returns true if a:list has a:value. +" Returns false otherwise. +function! s:has(list, value) abort + return index(a:list, a:value) isnot -1 +endfunction + +" Returns true if a:list[a:index] exists. +" Returns false otherwise. +" NOTE: Returns false when a:index is negative number. +function! s:has_index(list, index) abort + " Return true when negative index? + " let index = a:index >= 0 ? a:index : len(a:list) + a:index + return 0 <= a:index && a:index < len(a:list) +endfunction + +" similar to Haskell's Data.List.span +function! s:span(f, xs) abort + let border = len(a:xs) + for i in range(len(a:xs)) + if !eval(substitute(a:f, 'v:val', string(a:xs[i]), 'g')) + let border = i + break + endif + endfor + return border == 0 ? [[], copy(a:xs)] : [a:xs[: border - 1], a:xs[border :]] +endfunction + +" similar to Haskell's Data.List.break +function! s:break(f, xs) abort + return s:span(printf('!(%s)', a:f), a:xs) +endfunction + +" similar to Haskell's Data.List.takeWhile +function! s:take_while(f, xs) abort + return s:span(a:f, a:xs)[0] +endfunction + +" similar to Haskell's Data.List.dropWhile +function! s:drop_while(f, xs) abort + return s:span(a:f, a:xs)[1] +endfunction + +" similar to Haskell's Data.List.partition +function! s:partition(f, xs) abort + return [filter(copy(a:xs), a:f), filter(copy(a:xs), '!(' . a:f . ')')] +endfunction + +" similar to Haskell's Prelude.all +function! s:all(f, xs) abort + return !s:any(printf('!(%s)', a:f), a:xs) +endfunction + +" similar to Haskell's Prelude.any +function! s:any(f, xs) abort + return !empty(filter(map(copy(a:xs), a:f), 'v:val')) +endfunction + +" similar to Haskell's Prelude.and +function! s:and(xs) abort + return s:all('v:val', a:xs) +endfunction + +" similar to Haskell's Prelude.or +function! s:or(xs) abort + return s:any('v:val', a:xs) +endfunction + +function! s:map_accum(expr, xs, init) abort + let memo = [] + let init = a:init + for x in a:xs + let expr = substitute(a:expr, 'v:memo', init, 'g') + let expr = substitute(expr, 'v:val', x, 'g') + let [tmp, init] = eval(expr) + call add(memo, tmp) + endfor + return memo +endfunction + +" similar to Haskell's Prelude.foldl +function! s:foldl(f, init, xs) abort + let memo = a:init + for x in a:xs + let expr = substitute(a:f, 'v:val', string(x), 'g') + let expr = substitute(expr, 'v:memo', string(memo), 'g') + unlet memo + let memo = eval(expr) + endfor + return memo +endfunction + +" similar to Haskell's Prelude.foldl1 +function! s:foldl1(f, xs) abort + if len(a:xs) == 0 + throw 'vital: Data.List: foldl1' + endif + return s:foldl(a:f, a:xs[0], a:xs[1:]) +endfunction + +" similar to Haskell's Prelude.foldr +function! s:foldr(f, init, xs) abort + return s:foldl(a:f, a:init, reverse(copy(a:xs))) +endfunction + +" similar to Haskell's Prelude.fold11 +function! s:foldr1(f, xs) abort + if len(a:xs) == 0 + throw 'vital: Data.List: foldr1' + endif + return s:foldr(a:f, a:xs[-1], a:xs[0:-2]) +endfunction + +" similar to python's zip() +function! s:zip(...) abort + return map(range(min(map(copy(a:000), 'len(v:val)'))), "map(copy(a:000), 'v:val['.v:val.']')") +endfunction + +" similar to zip(), but goes until the longer one. +function! s:zip_fill(xs, ys, filler) abort + if empty(a:xs) && empty(a:ys) + return [] + elseif empty(a:ys) + return s:cons([a:xs[0], a:filler], s:zip_fill(a:xs[1 :], [], a:filler)) + elseif empty(a:xs) + return s:cons([a:filler, a:ys[0]], s:zip_fill([], a:ys[1 :], a:filler)) + else + return s:cons([a:xs[0], a:ys[0]], s:zip_fill(a:xs[1 :], a:ys[1: ], a:filler)) + endif +endfunction + +" Inspired by Ruby's with_index method. +function! s:with_index(list, ...) abort + let base = a:0 > 0 ? a:1 : 0 + return map(copy(a:list), '[v:val, v:key + base]') +endfunction + +" similar to Ruby's detect or Haskell's find. +function! s:find(list, default, f) abort + let l:Call = type(a:f) is type(function('function')) + \ ? function('call') + \ : function('s:_call_string_expr') + + for x in a:list + if l:Call(a:f, [x]) + return x + endif + endfor + return a:default +endfunction + +function! s:_call_string_expr(expr, args) abort + return map([a:args[0]], a:expr)[0] +endfunction + +" Returns the index of the first element which satisfies the given expr. +function! s:find_index(xs, f, ...) abort + let len = len(a:xs) + let start = a:0 > 0 ? (a:1 < 0 ? len + a:1 : a:1) : 0 + let default = a:0 > 1 ? a:2 : -1 + if start >=# len || start < 0 + return default + endif + for i in range(start, len - 1) + if eval(substitute(a:f, 'v:val', string(a:xs[i]), 'g')) + return i + endif + endfor + return default +endfunction + +" Returns the index of the last element which satisfies the given expr. +function! s:find_last_index(xs, f, ...) abort + let len = len(a:xs) + let start = a:0 > 0 ? (a:1 < 0 ? len + a:1 : a:1) : len - 1 + let default = a:0 > 1 ? a:2 : -1 + if start >=# len || start < 0 + return default + endif + for i in range(start, 0, -1) + if eval(substitute(a:f, 'v:val', string(a:xs[i]), 'g')) + return i + endif + endfor + return default +endfunction + +" Similar to find_index but returns the list of indices satisfying the given expr. +function! s:find_indices(xs, f, ...) abort + let len = len(a:xs) + let start = a:0 > 0 ? (a:1 < 0 ? len + a:1 : a:1) : 0 + let result = [] + if start >=# len || start < 0 + return result + endif + for i in range(start, len - 1) + if eval(substitute(a:f, 'v:val', string(a:xs[i]), 'g')) + call add(result, i) + endif + endfor + return result +endfunction + +" Return non-zero if a:list1 and a:list2 have any common item(s). +" Return zero otherwise. +function! s:has_common_items(list1, list2) abort + return !empty(filter(copy(a:list1), 'index(a:list2, v:val) isnot -1')) +endfunction + +function! s:intersect(list1, list2) abort + let items = [] + " for funcref + for X in a:list1 + if index(a:list2, X) != -1 && index(items, X) == -1 + let items += [X] + endif + endfor + return items +endfunction + +" similar to Ruby's group_by. +function! s:group_by(xs, f) abort + let result = {} + let list = map(copy(a:xs), printf('[v:val, %s]', a:f)) + for x in list + let Val = x[0] + let key = type(x[1]) !=# type('') ? string(x[1]) : x[1] + if has_key(result, key) + call add(result[key], Val) + else + let result[key] = [Val] + endif + unlet Val + endfor + return result +endfunction + +function! s:_default_compare(a, b) abort + return a:a <# a:b ? -1 : a:a ># a:b ? 1 : 0 +endfunction + +function! s:binary_search(list, value, ...) abort + let Predicate = a:0 >= 1 ? a:1 : 's:_default_compare' + let dic = a:0 >= 2 ? a:2 : {} + let start = 0 + let end = len(a:list) - 1 + + while 1 + if start > end + return -1 + endif + + let middle = (start + end) / 2 + + let compared = call(Predicate, [a:value, a:list[middle]], dic) + + if compared < 0 + let end = middle - 1 + elseif compared > 0 + let start = middle + 1 + else + return middle + endif + endwhile +endfunction + +function! s:product(lists) abort + let result = [[]] + for pool in a:lists + let tmp = [] + for x in result + let tmp += map(copy(pool), 'x + [v:val]') + endfor + let result = tmp + endfor + return result +endfunction + +function! s:permutations(list, ...) abort + if a:0 > 1 + throw 'vital: Data.List: too many arguments' + endif + let r = a:0 == 1 ? a:1 : len(a:list) + if r > len(a:list) + return [] + elseif r < 0 + throw 'vital: Data.List: {r} must be non-negative integer' + endif + let n = len(a:list) + let result = [] + for indices in s:product(map(range(r), 'range(n)')) + if len(s:uniq(indices)) == r + call add(result, map(indices, 'a:list[v:val]')) + endif + endfor + return result +endfunction + +function! s:combinations(list, r) abort + if a:r > len(a:list) + return [] + elseif a:r < 0 + throw 'vital: Data.List: {r} must be non-negative integer' + endif + let n = len(a:list) + let result = [] + for indices in s:permutations(range(n), a:r) + if s:sort(copy(indices), 'a:a - a:b') == indices + call add(result, map(indices, 'a:list[v:val]')) + endif + endfor + return result +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo + +" vim:set et ts=2 sts=2 sw=2 tw=0: diff --git a/bundle/vim-over/autoload/vital/_over/Gift.vim b/bundle/vim-over/autoload/vital/_over/Gift.vim new file mode 100644 index 000000000..e6a86f26a --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Gift.vim @@ -0,0 +1,159 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Gift#import() abort', printf("return map({'flatten': '', 'uniq_tabpagenr': '', 'tabpagewinnr_list': '', 'execute': '', 'getwinvar': '', 'winnr': '', 'jump_window': '', '_vital_depends': '', 'uniq_winnr': '', 'setwinvar': '', 'find': '', 'openable_bufnr_list': '', 'to_fullpath': '', 'bufnr': '', 'set_current_window': '', 'tabpagewinnr': '', 'close_window': '', 'close_window_by': '', 'uniq_winnr_list': '', '_vital_loaded': '', 'find_by': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:_vital_loaded(V) + let s:V = a:V + let s:Window = s:V.import("Gift.Window") + let s:Tabpage = s:V.import("Gift.Tabpage") +endfunction + + +function! s:_vital_depends() + return [ +\ "Gift.Window", +\ "Gift.Tabpage", +\ ] +endfunction + + +function! s:to_fullpath(filename) + let name = substitute(fnamemodify(a:filename, ":p"), '\', '/', "g") + if filereadable(name) + return name + else + return a:filename + endif +endfunction + + +function! s:flatten(list) + return eval(join(a:list, "+")) +endfunction + + +function! s:bufnr(expr) + return type(a:expr) == type([]) +\ ? s:bufnr(s:uniq_winnr(a:expr[1], a:expr[0])) +\ : s:Window.bufnr(a:expr) +endfunction + + +function! s:openable_bufnr_list() + return map(s:tabpagewinnr_list(), "s:bufnr([v:val[0], v:val[1]])") +endfunction + + +function! s:tabpagewinnr(...) + return a:0 == 0 ? s:tabpagewinnr(s:uniq_winnr()) +\ : s:Window.tabpagewinnr(a:1) +endfunction + + +function! s:tabpagewinnr_list() + return s:Window.tabpagewinnr_list() +" return s:flatten(map(range(1, tabpagenr("$")), "map(range(1, tabpagewinnr(v:val, '$')), '['.v:val.', v:val]')")) +endfunction + + + +function! s:uniq_winnr(...) + return call(s:Window.uniq_nr, a:000, s:Window) +endfunction + + +function! s:winnr(uniqnr) + let [tabnr, winnr] = s:Window.tabpagewinnr(a:uniqnr) + return winnr +endfunction + + +function! s:uniq_winnr_list(...) + return map(s:tabpagewinnr_list(), "s:uniq_winnr(v:val[1], v:val[0])") +endfunction + + + +function! s:find(expr) + let gift_find_result = [] + for [tabnr, winnr] in s:tabpagewinnr_list() + let bufnr = s:bufnr([tabnr, winnr]) + if eval(a:expr) + call add(gift_find_result, [tabnr, winnr]) + endif + endfor + return gift_find_result +endfunction + + +function! s:find_by(expr) + if type(a:expr) == type(function("tr")) + return filter(s:tabpagewinnr_list(), "a:expr(s:bufnr([v:val[0], v:val[1]]), v:val[0], v:val[1])") + else + return s:find(a:expr) + endif +endfunction + + +function! s:jump_window(expr) + return type(a:expr) == type([]) +\ ? s:jump_window(s:uniq_winnr(a:expr[1], a:expr[0])) +\ : s:Window.jump(a:expr) +endfunction + + +function! s:set_current_window(expr) + return s:jump_window(a:expr) +endfunction + + +function! s:close_window(expr, ...) + let close_cmd = get(a:, 1, "close") + return type(a:expr) == type([]) +\ ? s:close_window(s:uniq_winnr(a:expr[1], a:expr[0]), close_cmd) +\ : s:Window.close(a:expr, close_cmd) +endfunction + + +function! s:close_window_by(expr, ...) + let close_cmd = get(a:, 1, "close") + return map(map(s:find(a:expr), "s:uniq_winnr(v:val[1], v:val[0])"), 's:close_window(v:val, close_cmd)') +endfunction + + +function! s:execute(expr, execute) + return type(a:expr) == type([]) +\ ? s:execute(s:uniq_winnr(a:expr[1], a:expr[0]), a:execute) +\ : s:Window.execute(a:expr, a:execute) +endfunction + + +function! s:getwinvar(uniq_winnr, varname, ...) + let def = get(a:, 1, "") + return s:Window.getvar(a:uniq_winnr, a:varname, def) +endfunction + + +function! s:setwinvar(uniq_winnr, varname, val) + return s:Window.setvar(a:uniq_winnr, a:varname, a:val) +endfunction + + +function! s:uniq_tabpagenr(...) + return call(s:Tabpage.uniq_nr, a:000, s:Tabpage) +endfunction + + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Gift/Tabpage.vim b/bundle/vim-over/autoload/vital/_over/Gift/Tabpage.vim new file mode 100644 index 000000000..7960003e1 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Gift/Tabpage.vim @@ -0,0 +1,47 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Gift#Tabpage#import() abort', printf("return map({'uniq_nr': '', 'make_uniq_nr': '', 'numbering': '', 'set_prefix': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +let s:prefix = expand(":p:h:h:t") +function! s:set_prefix(prefix) + let s:prefix = a:prefix +endfunction + + +let s:uniq_counter = 0 +function! s:make_uniq_nr() + let s:uniq_counter += 1 + return s:uniq_counter +endfunction + + +function! s:numbering(...) + let tabnr = get(a:, 1, tabpagenr()) + let uniq_nr = s:make_uniq_nr() + call settabvar(tabnr, s:prefix . "_gift_uniq_tabpagenr", uniq_nr) + return uniq_nr +endfunction + + +function! s:uniq_nr(...) + let tabnr = get(a:, 1, tabpagenr()) + let uniq_nr = get(gettabvar(tabnr, ""), s:prefix . "_gift_uniq_tabpagenr", -1) + if uniq_nr == -1 + let uniq_nr = s:numbering(tabnr) + endif + return uniq_nr +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Gift/Window.vim b/bundle/vim-over/autoload/vital/_over/Gift/Window.vim new file mode 100644 index 000000000..a8c4d90e9 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Gift/Window.vim @@ -0,0 +1,153 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Gift#Window#import() abort', printf("return map({'flatten': '', 'tabpagewinnr_list': '', 'execute': '', 'close': '', 'numbering': '', 'set_prefix': '', '_vital_depends': '', 'exists': '', 'jump': '', 'setvar': '', 'bufnr': '', 'uniq_nr': '', 'make_uniq_nr': '', 'tabpagewinnr': '', 'getvar': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:_vital_loaded(V) + let s:V = a:V + let s:Tabpage = s:V.import("Gift.Tabpage") +endfunction + + +function! s:_vital_depends() + return [ +\ "Gift.Tabpage", +\ ] +endfunction + + +let s:prefix = expand(":p:h:h:t") +function! s:set_prefix(prefix) + let s:prefix = a:prefix +endfunction + +function! s:flatten(list) + return eval(join(a:list, "+")) +endfunction + + +function! s:tabpagewinnr_list() + return s:flatten(map(range(1, tabpagenr("$")), "map(range(1, tabpagewinnr(v:val, '$')), '['.v:val.', v:val]')")) +endfunction + + +if !exists("s:uniq_counter") + let s:uniq_counter = 0 +endif +function! s:make_uniq_nr() + let s:uniq_counter += 1 + return s:uniq_counter +endfunction + + +function! s:numbering(...) + let winnr = get(a:, 1, winnr()) + let tabnr = get(a:, 2, tabpagenr()) + let uniq_nr = s:make_uniq_nr() + call settabwinvar(tabnr, winnr, s:prefix . "_gift_uniq_winnr", uniq_nr) + return uniq_nr +endfunction + + +function! s:uniq_nr(...) + let winnr = get(a:, 1, winnr()) + let tabnr = get(a:, 2, tabpagenr()) + let uniq_nr = get(gettabwinvar(tabnr, winnr, ""), s:prefix . "_gift_uniq_winnr", -1) + if uniq_nr == -1 + let uniq_nr = s:numbering(winnr, tabnr) + endif + return uniq_nr +endfunction + + +function! s:exists(nr) + let [tabnr, winnr] = s:tabpagewinnr(a:nr) + return tabnr != 0 && winnr != 0 +endfunction + + +function! s:tabpagewinnr(nr) + if a:nr == 0 + return s:tabpagewinnr(s:uniq_nr()) + endif + let tabwinnrs = s:tabpagewinnr_list() + for [tabnr, winnr] in tabwinnrs + if s:uniq_nr(winnr, tabnr) == a:nr + return [tabnr, winnr] + endif + endfor + return [0, 0] +endfunction + + +function! s:getvar(nr, varname, ...) + let def = get(a:, 1, "") + let [tabnr, winnr] = s:tabpagewinnr(a:nr) + return get(gettabwinvar(tabnr, winnr, ""), a:varname, def) +endfunction + + +function! s:setvar(nr, varname, val) + let [tabnr, winnr] = s:tabpagewinnr(a:nr) + if tabnr == 0 || winnr == 0 + return + endif + return settabwinvar(tabnr, winnr, a:varname, a:val) +endfunction + + +function! s:bufnr(nr) + let [tabnr, winnr] = s:tabpagewinnr(a:nr) + return winnr >= 1 ? get(tabpagebuflist(tabnr), winnr-1, -1) : -1 +endfunction + + + +function! s:jump(nr) + let [tabnr, winnr] = s:tabpagewinnr(a:nr) + if tabnr == 0 || winnr == 0 + return -1 + endif + + execute "tabnext" tabnr + execute winnr . "wincmd w" +endfunction + + +function! s:close(nr, close_cmd) + call s:execute(a:nr, a:close_cmd) +" let current = gift#uniq_winnr() +" let result = s:jump(a:nr) +" if result == -1 +" return -1 +" endif +" execute a:close_cmd +" return s:jump(current) +endfunction + + +function! s:execute(nr, expr) + let current = s:uniq_nr() + let result = s:jump(a:nr) + if result == -1 + return -1 + endif + execute a:expr + return s:jump(current) +endfunction + + + + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over.vim b/bundle/vim-over/autoload/vital/_over/Over.vim new file mode 100644 index 000000000..41a7fc6b4 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over.vim @@ -0,0 +1,23 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#import() abort', printf("return map({'error': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:error(text) + echohl ErrorMsg + echom "vital-over:" . a:text + echohl None +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline.vim new file mode 100644 index 000000000..cf4ceb4b6 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline.vim @@ -0,0 +1,61 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#import() abort', printf("return map({'_vital_depends': '', 'make_standard_search_back': '', 'get_module': '', 'make_standard_search': '', 'make_standard': '', 'make_module': '', 'make_default': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:_vital_loaded(V) + let s:V = a:V + let s:Maker = s:V.import("Over.Commandline.Maker") + let s:Modules = s:V.import("Over.Commandline.Modules") +endfunction + + +function! s:_vital_depends() + return [ +\ "Over.Commandline.Maker", +\ "Over.Commandline.Modules", +\ "Over.Commandline.Modules.All", +\ ] +endfunction + + +function! s:make_module(...) + return call(s:Modules.make, a:000, s:Modules) +endfunction + + +function! s:get_module(...) + return call(s:Modules.get, a:000, s:Modules) +endfunction + + +function! s:make_default(...) + return call(s:Maker.default, a:000, s:Maker) +endfunction + + +function! s:make_standard(...) + return call(s:Maker.standard, a:000, s:Maker) +endfunction + + +function! s:make_standard_search(...) + return call(s:Maker.standard_search, a:000, s:Maker) +endfunction + + +function! s:make_standard_search_back(...) + return call(s:Maker.standard_search_back, a:000, s:Maker) +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Base.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Base.vim new file mode 100644 index 000000000..5c1f02695 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Base.vim @@ -0,0 +1,600 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Base#import() abort', printf("return map({'_vital_depends': '', 'make_plain': '', 'is_input_waiting': '', 'make': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:_vital_loaded(V) + let s:V = a:V + let s:String = s:V.import("Over.String") + let s:Signals = s:V.import("Over.Signals") + let s:Input = s:V.import("Over.Input") + let s:Keymapping = s:V.import("Over.Keymapping") + let s:Module = s:V.import("Over.Commandline.Modules") + let s:base.variables.modules = s:Signals.make() + function! s:base.variables.modules.get_slot(val) + return a:val.slot.module + endfunction + + let s:Highlight = s:V.import("Palette.Highlight") +endfunction + + +function! s:_vital_depends() + return [ +\ "Over.String", +\ "Over.Signals", +\ "Over.Input", +\ "Over.Keymapping", +\ "Over.Commandline.Modules", +\ "Palette.Highlight", +\ ] +endfunction + + +function! s:make(...) + let result = deepcopy(s:base) + call result.set_prompt(get(a:, 1, ":")) + call result.connect(result, "_") + return result +endfunction + + +function! s:make_plain() + return deepcopy(s:base) +endfunction + + +let s:base = { +\ "line" : {}, +\ "variables" : { +\ "prompt" : "", +\ "char" : "", +\ "input" : "", +\ "tap_key" : "", +\ "exit" : 0, +\ "keymapping" : {}, +\ "suffix" : "", +\ "is_setted" : 0, +\ }, +\ "highlights" : { +\ "prompt" : "NONE", +\ "cursor" : "VitalOverCommandLineCursor", +\ "cursor_on" : "VitalOverCommandLineCursorOn", +\ "cursor_insert" : "VitalOverCommandLineOnCursor", +\ }, +\} + +if exists("s:Signals") + let s:base.variables.modules = s:Signals.make() + function! s:base.variables.modules.get_slot(val) + return a:val.slot.module + endfunction +endif + + +function! s:base.getline() + return self.line.str() +endfunction + + +function! s:base.setline(line) + return self.line.set(a:line) +endfunction + + +function! s:base.char() + return self.variables.char +endfunction + + +function! s:base.setchar(char, ...) + " 1 の場合は既に設定されていても上書きする + " 0 の場合は既に設定されていれば上書きしない + let overwrite = get(a:, 1, 1) + if overwrite || self.variables.is_setted == 0 + let self.variables.input = a:char + let self.variables.is_setted = 1 + endif +endfunction + + +function! s:base.getpos() + return self.line.pos() +endfunction + + +function! s:base.setpos(pos) + return self.line.set_pos(a:pos) +endfunction + + +function! s:base.tap_keyinput(key) + let self.variables.tap_key = a:key +endfunction + + +function! s:base.untap_keyinput(key) + if self.variables.tap_key == a:key + let self.variables.tap_key = "" + return 1 + endif +endfunction + + +function! s:base.get_tap_key() + return self.variables.tap_key +endfunction + + +function! s:base.is_input(key, ...) + let prekey = get(a:, 1, "") + return self.get_tap_key() ==# prekey +\ && self.char() ==# a:key +" \ && self.char() == (prekey . a:key) +endfunction + + +function! s:base.input_key() + return self.variables.input_key +endfunction + + +function! s:base.set_prompt(prompt) + let self.variables.prompt = a:prompt +endfunction + + +function! s:base.get_prompt() + return self.variables.prompt +endfunction + + +function! s:base.set_suffix(str) + let self.variables.suffix = a:str +endfunction + + +function! s:base.get_suffix() + return self.variables.suffix +endfunction + + +function! s:base.insert(word, ...) + if a:0 + call self.line.set(a:1) + endif + call self.line.input(a:word) +endfunction + +function! s:base.forward() + return self.line.forward() +endfunction + +function! s:base.backward() + return self.line.backward() +endfunction + + +function! s:base.backward_word(...) + let pat = get(a:, 1, '\k\+\s*\|.') + return matchstr(self.backward(), '\%(' . pat . '\)$') +endfunction + + +function! s:base.connect(module, ...) + if type(a:module) == type("") + return call(self.connect, [s:Module.make(a:module)] + a:000, self) + endif + if empty(a:module) + return + endif + let name = a:0 > 0 ? a:1 : a:module.name + let slot = self.variables.modules.find_first_by("get(v:val.slot, 'name', '') == " . string(name)) + if empty(slot) + call self.variables.modules.connect({ "name" : name, "module" : a:module }) + else + let slot.slot.module = a:module + endif +" let self.variables.modules[name] = a:module +endfunction + + +function! s:base.disconnect(name) + return self.variables.modules.disconnect_by( +\ "get(v:val.slot, 'name', '') == " . string(a:name) +\ ) +" unlet self.variables.modules[a:name] +endfunction + + +function! s:base.get_module(name) + let slot = self.variables.modules.find_first_by("get(v:val.slot, 'name', '') == " . string(a:name)) + return empty(slot) ? {} : slot.slot.module +endfunction + + +function! s:base.callevent(event) + call self.variables.modules.sort_by("has_key(v:val.slot.module, 'priority') ? v:val.slot.module.priority('" . a:event . "') : 0") + return self.variables.modules.call(a:event, [self]) +" call map(filter(copy(self.variables.modules), "has_key(v:val, a:event)"), "v:val." . a:event . "(self)") +endfunction + + +function! s:base.cmap(lhs, rhs) + let self.variables.keymapping[a:lhs] = a:rhs +endfunction + + +function! s:base.cnoremap(lhs, rhs) + let key = s:Keymapping.as_key_config(a:rhs) + let key.noremap = 1 + let self.variables.keymapping[a:lhs] = key +endfunction + + +function! s:base.cunmap(lhs) + unlet self.variables.keymapping[a:lhs] +endfunction + + +function! s:base.keymapping() + return self.__keymapping__() +endfunction + + +function! s:base.__keymapping__() + return {} +endfunction + + +function! s:base.execute(...) + let command = get(a:, 1, self.getline()) + call self.__execute(command) +endfunction + + +function! s:base.draw() + call self.callevent("on_draw_pre") + call self.callevent("on_draw") +endfunction + + +function! s:base.exit(...) + let self.variables.exit = 1 + let self.variables.exit_code = get(a:, 1, 0) +endfunction + + +function! s:base.enable_keymapping() + let self.variables.enable_keymapping = 1 +endfunction + + +function! s:base.disable_keymapping() + let self.variables.enable_keymapping = 0 +endfunction + + +function! s:base.is_enable_keymapping() + return self.variables.enable_keymapping +endfunction + +" function! s:base.cancel() +" call self.exit(1) +" call self.__on_cancel() +" endfunction + + +function! s:base.exit_code() + return self.variables.exit_code +endfunction + + +function! s:base.hl_cursor_on() + if exists("self.variables.old_guicursor") + set guicursor& + let &guicursor = self.variables.old_guicursor + unlet self.variables.old_guicursor + endif + + if exists("self.variables.old_t_ve") + let &t_ve = self.variables.old_t_ve + unlet self.variables.old_t_ve + endif +endfunction + + +function! s:base.hl_cursor_off() + if exists("self.variables.old_t_ve") + return + endif + + let self.variables.old_guicursor = &guicursor + set guicursor=n:block-NONE + let self.variables.old_t_ve = &t_ve + set t_ve= +endfunction + + +function! s:base.start(...) + let exit_code = call(self.__main, a:000, self) + return exit_code +endfunction + + +function! s:base.__empty(...) +endfunction + + +function! s:base.get(...) + let Old_execute = self.execute + let self.execute = self.__empty + try + let exit_code = call(self.start, a:000, self) + if exit_code == 0 + return self.getline() + endif + finally + let self.execute = Old_execute + endtry + return "" +endfunction + + +function! s:base.input_key_stack() + return self.variables.input_key_stack +endfunction + + +function! s:base.input_key_stack_string() + return join(self.variables.input_key_stack, "") +endfunction + + +function! s:base.set_input_key_stack(stack) + let self.variables.input_key_stack = a:stack + return self.variables.input_key_stack +endfunction + + +function! s:base.input_key_stack_pop() + return remove(self.input_key_stack(), 0) +endfunction + + +function! s:base.getchar(...) + if empty(self.input_key_stack()) + return call(s:Input.getchar, a:000, s:Input) + endif + return self.input_key_stack_pop() +endfunction + + +function! s:base.__init_variables() + let self.variables.tap_key = "" + let self.variables.char = "" + let self.variables.input = "" + let self.variables.exit = 0 + let self.variables.exit_code = 1 + let self.variables.enable_keymapping = 1 + let self.variables.input_key_stack = [] + let self.line = deepcopy(s:String.make()) +endfunction + + +function! s:_is_valid_highlight(name) + let highlight = s:Highlight.get(a:name) + if empty(highlight) + return 0 + endif + + if has("gui_running") +\ && (has_key(highlight, "guifg") || has_key(highlight, "guibg")) + return 1 + elseif (has_key(highlight, "ctermfg") || has_key(highlight, "ctermbg")) + return 1 + endif + return 0 +endfunction + + +function! s:base.__init() + call self.__init_variables() + call self.hl_cursor_off() + if !hlexists(self.highlights.cursor) + if s:_is_valid_highlight("Cursor") + execute "highlight link " . self.highlights.cursor . " Cursor" + else + " Workaround by CUI Vim Cursor Highlight + " issues #92 + " https://github.com/osyo-manga/vital-over/issues/92 + execute "highlight " . self.highlights.cursor . " term=reverse cterm=reverse gui=reverse" + endif + endif + if !hlexists(self.highlights.cursor_on) + execute "highlight link " . self.highlights.cursor_on . " " . self.highlights.cursor + endif + if !hlexists(self.highlights.cursor_insert) + execute "highlight " . self.highlights.cursor_insert . " cterm=underline term=underline gui=underline" + endif +endfunction + + +function! s:base.__execute(command) + call self.callevent("on_execute_pre") + try + call self.__execute__(a:command) + catch + echohl ErrorMsg + echom matchstr(v:exception, 'Vim\((\w*)\)\?:\zs.*\ze') + echohl None + call self.callevent("on_execute_failed") + finally + call self.callevent("on_execute") + endtry +endfunction + + +function! s:base.__execute__(cmd) + execute a:cmd +endfunction + + +function! s:base.__input_char(char) + let char = a:char + let self.variables.input_key = char + let self.variables.char = char + call self.setchar(self.variables.char) + let self.variables.is_setted = 0 + call self.callevent("on_char_pre") + call self.insert(self.variables.input) + call self.callevent("on_char") +endfunction + + +function! s:base.__input(input, ...) + if a:input == "" + return + endif + + let self.variables.input_key = a:input + if a:0 == 0 + let keymapping = self.__get_keymapping() + else + let keymapping = a:1 + endif + if self.is_enable_keymapping() + let key = s:Keymapping.unmapping(keymapping, a:input) + else + let key = a:input + endif + if key == "" + return + endif + + call self.set_input_key_stack(s:String.split_by_keys(key)) + while !(empty(self.input_key_stack()) || self.is_exit()) + call self.__input_char(self.input_key_stack_pop()) + endwhile +endfunction + + +function! s:is_input_waiting(keymapping, input) + let num = len(filter(copy(a:keymapping), 'stridx(v:key, a:input) == 0')) + return num > 1 || (num == 1 && !has_key(a:keymapping, a:input)) +endfunction + + +function! s:base.__inputting() + if !self.is_enable_keymapping() + return self.__input(s:Input.getchar()) + endif + + let input = s:Input.getchar() + let old_line = self.getline() + let old_pos = self.getpos() + let keymapping = self.__get_keymapping() + try + let t = reltime() + while s:is_input_waiting(keymapping, input) +\ && str2nr(reltimestr(reltime(t))) * 1000 < &timeoutlen + call self.setline(old_line) + call self.insert(input) + call self.setpos(old_pos) + call self.draw() + let input .= s:Input.getchar(0) + endwhile + finally + call self.setline(old_line) + call self.setpos(old_pos) + endtry + call self.__input(input, keymapping) +endfunction + + +function! s:base.__update() +" call self.callevent("on_update") +" if !getchar(1) +" continue +" endif +" +" call self.__input(s:getchar(0)) +" call self.draw() + + call self.callevent("on_update") + call self.__inputting() +" call self.__input(s:Input.getchar()) + if self.is_exit() + return -1 + endif + call self.draw() +endfunction + + +function! s:base.__main(...) + try + call self.__init() + call self.callevent("on_enter") + + call self.__input(get(a:, 1, "")) + call self.draw() + while !self.is_exit() + try + if self.__update() + break + endif + catch + call self.callevent("on_exception") + endtry + endwhile + catch + echohl ErrorMsg | echom v:throwpoint . " " . v:exception | echohl None + let self.variables.exit_code = -1 + finally + call self.__finish() + call self.callevent("on_leave") + endtry + return self.exit_code() +endfunction + + +function! s:base.__finish() + call self.hl_cursor_on() +endfunction + + +function! s:base.__is_exit() + return self.is_exit() +endfunction + + +function! s:base.is_exit() + return self.variables.exit +endfunction + + +function! s:base.__get_keymapping() + let result = {} +" for module in values(self.variables.modules) + for module in self.variables.modules.slots() + if has_key(module, "keymapping") + if module isnot self + call extend(result, module.keymapping(self)) + endif + endif + endfor + return extend(extend(result, self.variables.keymapping), self.keymapping()) +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Maker.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Maker.vim new file mode 100644 index 000000000..20d1358bb --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Maker.vim @@ -0,0 +1,97 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Maker#import() abort', printf("return map({'plain': '', '_vital_depends': '', 'standard_search': '', 'standard': '', 'standard_search_back': '', 'default': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +let s:modules = [ +\ "Scroll", +\ "CursorMove", +\ "Delete", +\ "HistAdd", +\ "History", +\ "Cancel", +\ "Execute", +\ "NoInsert", +\ "InsertRegister", +\ "Redraw", +\ "DrawCommandline", +\ "ExceptionExit", +\ "ExceptionMessage", +\] + + +function! s:_vital_loaded(V) + let s:V = a:V + let s:Cmdline = s:V.import("Over.Commandline.Base") + let s:Modules = s:V.import("Over.Commandline.Modules") +endfunction + + +function! s:_vital_depends() + return [ +\ "Over.Commandline.Base", +\ "Over.Commandline.Modules", +\ ] + map(copy(s:modules), "'Over.Commandline.Modules.' . v:val") +endfunction + + +function! s:default(...) + return call(s:Cmdline.make, a:000, s:Cmdline) +endfunction + + +function! s:plain() + return s:Cmdline.plain() +endfunction + + +function! s:standard(...) + let result = call(s:Cmdline.make, a:000, s:Cmdline) + call result.connect("Execute") + call result.connect("Cancel") + call result.connect("Delete") + call result.connect("CursorMove") + call result.connect("HistAdd") + call result.connect("History") + call result.connect("InsertRegister") + call result.connect(s:Modules.get("NoInsert").make_special_chars()) + call result.connect("Redraw") + call result.connect("DrawCommandline") + call result.connect("ExceptionExit") + call result.connect("ExceptionMessage") + call result.connect(s:Modules.get("KeyMapping").make_vim_cmdline_mapping()) + call result.connect("Digraphs") + call result.connect("LiteralInsert") + + return result +endfunction + + +function! s:standard_search(...) + let result = s:standard(get(a:, 1, "/")) + call result.connect(s:Modules.get("Execute").make_search("/")) + call result.connect(s:Modules.make("HistAdd", "/")) + call result.connect(s:Modules.make("History", "/")) + return result +endfunction + + +function! s:standard_search_back(...) + let result = s:standard(get(a:, 1, "?")) + call result.connect(s:Modules.get("Execute").make_search("?")) + call result.connect(s:Modules.make("HistAdd", "/")) + call result.connect(s:Modules.make("History", "/")) + return result +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules.vim new file mode 100644 index 000000000..4b686399e --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules.vim @@ -0,0 +1,36 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#import() abort', printf("return map({'get': '', 'make': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:_vital_loaded(V) + let s:V = a:V +endfunction + + +function! s:get(name) + if exists("s:" . a:name) + return s:{a:name} + endif + let s:{a:name} = s:V.import('Over.Commandline.Modules.' . a:name) + return s:{a:name} +endfunction + + +function! s:make(name, ...) + let module = s:get(a:name) + return call(module.make, a:000, module) +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/All.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/All.vim new file mode 100644 index 000000000..46f4725f8 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/All.vim @@ -0,0 +1,24 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#All#import() abort', printf("return map({'_vital_depends': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +let s:modules = map(split(globpath(expand(":p:h"), "/*.vim"), "\n"), "fnamemodify(v:val, ':t:r')") + + +function! s:_vital_depends() + return map(copy(s:modules), "'Over.Commandline.Modules.' . v:val") +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/AsyncUpdate.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/AsyncUpdate.vim new file mode 100644 index 000000000..22d97bcdc --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/AsyncUpdate.vim @@ -0,0 +1,47 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#AsyncUpdate#import() abort', printf("return map({'make': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +function! s:_vital_loaded(V) + let s:V = a:V + let s:Base = s:V.import("Over.Commandline.Base") +endfunction + + +let s:module = { +\ "name" : "AsyncUpdate" +\} + +function! s:module.on_enter(cmdline) + function! a:cmdline.__update() + call self.callevent("on_update") + try + if !getchar(1) + return + endif + call self.__inputting() + catch /^Vim:Interrupt$/ + call self.__input("\") + endtry + + call self.draw() + endfunction +endfunction + + +function! s:make() + return deepcopy(s:module) +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/BufferComplete.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/BufferComplete.vim new file mode 100644 index 000000000..de92e323c --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/BufferComplete.vim @@ -0,0 +1,173 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#BufferComplete#import() abort', printf("return map({'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:_uniq(list) + let dict = {} + for _ in a:list + let dict[_] = 0 + endfor + return keys(dict) +endfunction + + +let s:module = { +\ "name" : "BufferComplete", +\} + + +function! s:_buffer_complete() + return sort(s:_uniq(filter(split(join(getline(1, '$')), '\W'), '!empty(v:val)')), 1) +endfunction + + +function! s:_parse_line(line) + let keyword = matchstr(a:line, '\zs\w\+\ze$') + let pos = strchars(a:line) - strchars(keyword) + return [pos, keyword] +endfunction + + +function! s:_as_statusline(list, count) + if empty(a:list) + return + endif + let hl_none = "%#StatusLine#" + let hl_select = "%#StatusLineNC#" + let tail = " > " + let result = a:list[0] + let pos = 0 + for i in range(1, len(a:list)-1) + if strdisplaywidth(result . " " . a:list[i]) > &columns - len(tail) + if a:count < i + break + else + let pos = -i + endif + let result = a:list[i] + else + let result .= (" " . a:list[i]) + endif + if a:count == i + let pos = pos + i + endif + endfor + return join(map(split(result, " "), 'v:key == pos ? hl_select . v:val . hl_none : v:val')) +endfunction + + +function! s:module.get_complete_words() + return s:_buffer_complete() +endfunction + + +function! s:module.complete(cmdline) + call s:_finish() + let s:old_statusline = &statusline + + let backward = a:cmdline.backward() + let [pos, keyword] = s:_parse_line(backward) + + if !exists("s:complete") + let s:complete = self.get_complete_words() + endif + let s:complete_list = filter(copy(s:complete), 'v:val =~ ''^''.keyword') + if empty(s:complete_list) + return -1 + endif + + if pos == 0 + let backward = "" + else + let backward = join(split(backward, '\zs')[ : pos-1 ], "") + endif + let s:line = backward . a:cmdline.forward() + let s:pos = pos + call a:cmdline.setline(s:line) + + let s:count = 0 +endfunction + + +function! s:_finish() + if exists("s:old_statusline") + let &statusline = s:old_statusline + unlet s:old_statusline + redrawstatus + endif +endfunction + + +function! s:module.on_char_pre(cmdline) + if a:cmdline.is_input("(buffer-complete)") +\ || a:cmdline.is_input("(buffer-complete-prev)") + if self.complete(a:cmdline) == -1 + call s:_finish() + call a:cmdline.setchar('') + return + endif + if a:cmdline.is_input("(buffer-complete-prev)") + let s:count = len(s:complete_list) - 1 + endif + call a:cmdline.setchar('') + call a:cmdline.tap_keyinput("Completion") +" elseif a:cmdline.is_input("\", "Completion") + elseif a:cmdline.is_input("(buffer-complete)", "Completion") +\ || a:cmdline.is_input("\", "Completion") + call a:cmdline.setchar('') + let s:count += 1 + if s:count >= len(s:complete_list) + let s:count = 0 + endif + elseif a:cmdline.is_input("(buffer-complete-prev)", "Completion") +\ || a:cmdline.is_input("\", "Completion") + call a:cmdline.setchar('') + let s:count -= 1 + if s:count < 0 + let s:count = len(s:complete_list) - 1 + endif + else + if a:cmdline.untap_keyinput("Completion") + call a:cmdline.callevent("on_char_pre") + endif + call s:_finish() + return + endif + call a:cmdline.setline(s:line) + call a:cmdline.insert(s:complete_list[s:count], s:pos) + if len(s:complete_list) > 1 + let &statusline = s:_as_statusline(s:complete_list, s:count) + redrawstatus + endif + if len(s:complete_list) == 1 + call a:cmdline.untap_keyinput("Completion") + endif +endfunction + + +function! s:module.on_draw_pre(...) +" redrawstatus +endfunction + + +function! s:module.on_leave(cmdline) + call s:_finish() + unlet! s:complete +endfunction + +function! s:make() + return deepcopy(s:module) +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Cancel.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Cancel.vim new file mode 100644 index 000000000..2b87be88a --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Cancel.vim @@ -0,0 +1,34 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#Cancel#import() abort', printf("return map({'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +let s:module = { +\ "name" : "Cancel" +\} + +function! s:module.on_char_pre(cmdline) + if a:cmdline.is_input("\") +\ || a:cmdline.is_input("\") +" call a:cmdline.cancel() + call a:cmdline.exit(1) + call a:cmdline.setchar("") + endif +endfunction + + +function! s:make() + return deepcopy(s:module) +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/CursorMove.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/CursorMove.vim new file mode 100644 index 000000000..59dcdb00b --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/CursorMove.vim @@ -0,0 +1,52 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#CursorMove#import() abort', printf("return map({'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +let s:module = { +\ "name" : "CursorMove" +\} +function! s:module.on_char_pre(cmdline) + if a:cmdline.is_input("\") + call a:cmdline.line.next() + call a:cmdline.setchar('') + elseif a:cmdline.is_input("\") + call a:cmdline.line.prev() + call a:cmdline.setchar('') + elseif a:cmdline.is_input("\") +\ || a:cmdline.is_input("\") + call a:cmdline.setline(0) + call a:cmdline.setchar('') + elseif a:cmdline.is_input("\") +\ || a:cmdline.is_input("\") + call a:cmdline.setline(a:cmdline.line.length()) + call a:cmdline.setchar('') + elseif a:cmdline.is_input("\") +\ || a:cmdline.is_input("\") + call a:cmdline.setline(strridx(a:cmdline.backward()[:-2], ' ') + 1) + call a:cmdline.setchar('') + elseif a:cmdline.is_input("\") +\ || a:cmdline.is_input("\") + let p = stridx(a:cmdline.forward()[1:], ' ') + call a:cmdline.setline(p != -1 ? a:cmdline.line.pos() + p + 2 : a:cmdline.line.length()) + call a:cmdline.setchar('') + endif +endfunction + + +function! s:make() + return deepcopy(s:module) +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Delete.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Delete.vim new file mode 100644 index 000000000..578714d22 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Delete.vim @@ -0,0 +1,50 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#Delete#import() abort', printf("return map({'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +let s:module = { +\ "name" : "Delete", +\} +function! s:module.on_char_pre(cmdline) + if a:cmdline.is_input("\") +\ || a:cmdline.is_input("\") + if a:cmdline.line.length() == 0 + return a:cmdline.exit(1) + else + call a:cmdline.line.remove_prev() + call a:cmdline.setchar('') + endif + elseif a:cmdline.is_input("\") + call a:cmdline.line.remove_pos() + call a:cmdline.setchar('') + elseif a:cmdline.is_input("\") + let word = a:cmdline.backward_word() + let backward = a:cmdline.backward()[ : -strlen(word)-1 ] + call a:cmdline.setline(backward . a:cmdline.line.pos_char() . a:cmdline.forward()) + call a:cmdline.setline(strchars(backward)) + call a:cmdline.setchar('') + elseif a:cmdline.is_input("\") + call a:cmdline.setline(a:cmdline.line.pos_char() . a:cmdline.forward()) + call a:cmdline.setline(0) + call a:cmdline.setchar('') + endif +endfunction + + +function! s:make() + return deepcopy(s:module) +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Digraphs.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Digraphs.vim new file mode 100644 index 000000000..7868938af --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Digraphs.vim @@ -0,0 +1,110 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#Digraphs#import() abort', printf("return map({'capture': '', '_vital_depends': '', 'digraph': '', 'make': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +function! s:_vital_loaded(V) + let s:Input = a:V.import("Over.Input") +endfunction + + +function! s:_vital_depends() + return [ +\ "Over.Input", +\ ] +endfunction + + +let s:module = { +\ "name" : "Digraphs", +\ "digraphs" : {} +\} + +function! s:capture(cmd) + let verbose_save = &verbose + let &verbose = 0 + try + redir => result + execute "silent!" a:cmd + redir END + finally + let &verbose = verbose_save + endtry + return result +endfunction + +function! s:digraph() abort + let x = split(substitute(s:capture(':digraph'), "\n", ' ', 'g'), + \ '[[:graph:]]\{2}\s.\{1,4}\s\+\d\+\s*\zs') + let digraphs = map(x, "split(v:val, ' \\+')") + let r = {} + for d in digraphs + let r[d[0]] = len(d) is 3 && d[2] =~# '\d\+' ? nr2char(str2nr(d[2],10)) + \ : len(d) is 2 && d[1] =~# '32' ? nr2char(str2nr(d[1],10)) + \ : '' + endfor + return r +endfunction + + +function! s:module.on_leave(cmdline) + " Delete cache to handle additional digraphs definition + let self.digraphs = {} +endfunction + +function! s:module.on_char_pre(cmdline) + if a:cmdline.is_input("\") + if empty(self.digraphs) + " Get digraphs when inputting instead of on_enter because it cause + " flicker in some environments #107 + let self.digraphs = s:digraph() + endif + call a:cmdline.setchar('?') + let self.prefix_key = a:cmdline.input_key() + let self.old_line = a:cmdline.getline() + let self.old_pos = a:cmdline.getpos() + return + elseif exists("self.prefix_key") +\ && a:cmdline.get_tap_key() == self.prefix_key + call a:cmdline.setline(self.old_line) + call a:cmdline.setpos(self.old_pos) + let x = a:cmdline.input_key() + let y = s:Input.getchar() + " For CTRL-K, there is one general digraph: CTRL-K {char} will + " enter {char} with the highest bit set. You can use this to enter + " meta-characters. + let char = x ==# "\" ? + \ nr2char(char2nr(y) + 128) : get(self.digraphs, x . y, y) + call a:cmdline.setchar(char) + endif +endfunction + +function! s:module.on_char(cmdline) + if a:cmdline.is_input("\") + call a:cmdline.tap_keyinput(self.prefix_key) + call a:cmdline.disable_keymapping() + call a:cmdline.setpos(a:cmdline.getpos()-1) + else + if exists("self.prefix_key") + call a:cmdline.untap_keyinput(self.prefix_key) + call a:cmdline.enable_keymapping() + unlet! self.prefix_key + endif + endif +endfunction + + +function! s:make() + return deepcopy(s:module) +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Doautocmd.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Doautocmd.vim new file mode 100644 index 000000000..a56960f95 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Doautocmd.vim @@ -0,0 +1,115 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#Doautocmd#import() abort', printf("return map({'_vital_depends': '', 'doautocmd_user': '', 'get_cmdline': '', 'make': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:_vital_loaded(V) + let s:V = a:V + let s:E = s:V.import("Over.Exception") +endfunction + + +function! s:_vital_depends() + return [ +\ "Over.Exception", +\ ] +endfunction + + +let s:cache_command = {} +function! s:doautocmd_user(prefix, command) + let group = a:prefix . "-vital-over-commandline-doautocmd-dummy" + if !has_key(s:cache_command, a:prefix) + let s:cache_command[a:prefix] = {} + endif + + if !has_key(s:cache_command[a:prefix], a:command) + execute "autocmd " . group +\ . " User " . a:command." silent! execute ''" + + if v:version > 703 || v:version == 703 && has("patch438") + let s:cache_command[a:prefix][a:command] = "doautocmd User " . a:command + else + let s:cache_command[a:prefix][a:command] = "doautocmd User " . a:command + endif + endif + + execute s:cache_command[a:prefix][a:command] +endfunction + + +let s:hooks = [ +\ "enter", +\ "leave", +\ "char", +\ "char_pre", +\ "draw", +\ "draw_pre", +\ "execute_pre", +\ "execute_failed", +\ "execute", +\ "exception", +\] + +let s:hooks_camel = [ +\ "Enter", +\ "Leave", +\ "Char", +\ "CharPre", +\ "Draw", +\ "DrawPre", +\ "ExecutePre", +\ "ExecuteFailed", +\ "Execute", +\ "Exception", +\] + + +let s:module = { +\ "name" : "Doautocmd", +\} + + +for s:i in range(len(s:hooks)) + execute join([ +\ "function! s:module.on_" . s:hooks[s:i] . "(cmdline, ...)", +\ " let s:cmdline = a:cmdline", +\ " call s:doautocmd_user(self.prefix, self.prefix . " . string(s:hooks_camel[s:i]) . ")", +\ "endfunction", +\ ], "\n") +endfor + + +function! s:get_cmdline() + if !exists("s:cmdline") + execute s:E.throw_cmd("Undefined cmdline object.", "Over.Commandline.Modules.Doautocmd") + endif + return s:cmdline +endfunction + + +function! s:make(prefix) + if has_key(s:cache_command, a:prefix) + unlet! s:cache_command[a:prefix] + endif + execute "augroup " a:prefix . "-vital-over-commandline-doautocmd-dummy" + autocmd! + augroup END + + let module = deepcopy(s:module) + let module.prefix = a:prefix + return module +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/DrawCommandline.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/DrawCommandline.vim new file mode 100644 index 000000000..3854b6547 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/DrawCommandline.vim @@ -0,0 +1,149 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#DrawCommandline#import() abort', printf("return map({'suffix': '', 'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +let s:module = { +\ "name" : "DrawCommandline" +\} + +let s:cmdheight = {} + +function! s:cmdheight.save() + if has_key(self, "value") + return + endif + let self.value = &cmdheight +endfunction + +function! s:cmdheight.restore() + if has_key(self, "value") + let &cmdheight = self.value + unlet self.value + endif +endfunction + + +function! s:cmdheight.get() + return self.value +endfunction + + +function! s:suffix(left, suffix) + let left_len = strdisplaywidth(a:left) + let len = &columns - left_len % &columns + let len = len + (&columns * (strdisplaywidth(a:suffix) > (len - 1))) - 1 + return repeat(" ", len - strdisplaywidth(a:suffix)) . a:suffix +" return printf("%" . len . "S", a:suffix) +endfunction + + +let s:old_width = 0 +function! s:_redraw(cmdline) + let left = a:cmdline.get_prompt() . a:cmdline.getline() . (empty(a:cmdline.line.pos_char()) ? " " : "") + let width = len(left) + 1 + + if a:cmdline.get_suffix() != "" + let width += len(s:suffix(left, a:cmdline.get_suffix())) - 1 + endif + + if &columns >= width && &columns <= s:old_width && s:old_width >= width + redraw + normal! : + elseif &columns <= width + normal! : + else + redraw + endif + let s:old_width = width + + call s:cmdheight.save() + let height = max([(width - 1) / (&columns) + 1, s:cmdheight.get()]) + if height > &cmdheight || &cmdheight > height + let &cmdheight = height + redraw + endif +endfunction + + +function! s:_as_echon(str) + return "echon " . strtrans(string(a:str)) +endfunction + + +function! s:module.on_draw_pre(cmdline) + if empty(a:cmdline.line.pos_char()) + let cursor = "echohl " . a:cmdline.highlights.cursor . " | echon ' '" + else + let cursor = "echohl " . a:cmdline.highlights.cursor_on . " | " . s:_as_echon(a:cmdline.line.pos_char()) + endif + let suffix = "" + if a:cmdline.get_suffix() != "" + let suffix = s:_as_echon(s:suffix(a:cmdline.get_prompt() . a:cmdline.getline() . repeat(" ", empty(a:cmdline.line.pos_char())), a:cmdline.get_suffix())) + endif + let self.draw_command = join([ +\ "echohl " . a:cmdline.highlights.prompt, +\ s:_as_echon(a:cmdline.get_prompt()), +\ "echohl NONE", +\ s:_as_echon(a:cmdline.backward()), +\ cursor, +\ "echohl NONE", +\ s:_as_echon(a:cmdline.forward()), +\ suffix, +\ ], " | ") + + call s:_redraw(a:cmdline) +endfunction + + +function! s:_echon(expr) + echon strtrans(a:expr) +endfunction + + +function! s:module.on_draw(cmdline) + execute self.draw_command +" execute "echohl" a:cmdline.highlights.prompt +" call s:echon(a:cmdline.get_prompt()) +" echohl NONE +" call s:echon(a:cmdline.backward()) +" if empty(a:cmdline.line.pos_char()) +" execute "echohl" a:cmdline.highlights.cursor +" call s:echon(' ') +" else +" execute "echohl" a:cmdline.highlights.cursor_on +" call s:echon(a:cmdline.line.pos_char()) +" endif +" echohl NONE +" call s:echon(a:cmdline.forward()) +" if a:cmdline.get_suffix() != "" +" call s:echon(s:suffix(a:cmdline.get_prompt() . a:cmdline.getline() . repeat(" ", empty(a:cmdline.line.pos_char())), a:cmdline.get_suffix())) +" endif +endfunction + + +function! s:module.on_execute_pre(...) + call s:cmdheight.restore() +endfunction + + +function! s:module.on_leave(...) + call s:cmdheight.restore() +endfunction + + +function! s:make() + return deepcopy(s:module) +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/ExceptionExit.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/ExceptionExit.vim new file mode 100644 index 000000000..b2db9e495 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/ExceptionExit.vim @@ -0,0 +1,31 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#ExceptionExit#import() abort', printf("return map({'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +let s:module = { +\ "name" : "ExceptionExit", +\} + + +function! s:module.on_exception(cmdline) + call a:cmdline.exit(-1) +endfunction + + +function! s:make(...) + let result = deepcopy(s:module) + let result.exit_code = get(a:, 1, 0) + return result +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/ExceptionMessage.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/ExceptionMessage.vim new file mode 100644 index 000000000..53e039463 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/ExceptionMessage.vim @@ -0,0 +1,60 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#ExceptionMessage#import() abort', printf("return map({'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +let s:vname = expand(":h:h:h:h:t") + + +let s:module = { +\ "name" : "ExceptionMessage", +\} + + +function! s:module.on_exception(cmdline) + let self.exception = v:exception + let self.throwpoint = v:throwpoint +endfunction + + +function! s:module.on_draw_pre(cmdline) + if has_key(self, "exception") + call self.message(a:cmdline) + unlet self.exception + endif +endfunction + +function! s:module.message(...) + echohl ErrorMsg + execute self.command string(self.prefix . " : " . self.throwpoint . " " . self.exception) + echohl None +endfunction + + +function! s:module.on_leave(cmdline) + if has_key(self, "exception") + call self.message(a:cmdline) + unlet self.exception + endif +endfunction + + +function! s:make(...) + let result = deepcopy(s:module) + let result.prefix = get(a:, 1, "vital-over(".s:vname.") Exception") + let result.command = get(a:, 2, "echom") + return result +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Execute.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Execute.vim new file mode 100644 index 000000000..709f62d10 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Execute.vim @@ -0,0 +1,100 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#Execute#import() abort', printf("return map({'make_search': '', 'silent_feedkeys': '', 'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:silent_feedkeys(expr, name, ...) + let mode = get(a:, 1, "m") + let map = printf("(%s)", a:name) + if mode == "n" + let command = "nnoremap" + else + let command = "nmap" + endif + execute command "" map printf("%s:nunmap %s", a:expr, map) + call feedkeys(printf("\(%s)", a:name)) +endfunction + + +function! s:_is_input_enter(cmdline) + return a:cmdline.is_input("\") +\ || a:cmdline.is_input("\") +\ || a:cmdline.is_input("\") +endfunction + + +let s:module = { +\ "name" : "Execute" +\} + +function! s:module.on_char_pre(cmdline) + if s:_is_input_enter(a:cmdline) + call self.execute(a:cmdline) + call a:cmdline.setchar("") + call a:cmdline.exit(0) + endif + if a:cmdline.is_input("(execute-no-exit)") + call self.execute(a:cmdline) + call a:cmdline.setchar("") + endif +endfunction + +function! s:module.execute(cmdline) + return a:cmdline.execute() +endfunction + + +function! s:make() + return deepcopy(s:module) +endfunction + + +let s:search = deepcopy(s:module) +let s:search.prefix = "/" + + +function! s:search.execute(cmdline) + call a:cmdline.callevent("on_execute_pre") + let input = a:cmdline.getline() + if input == "" + return + endif + call s:silent_feedkeys(":call histdel('/', -1)\", "remove_hist", "n") + let cmd = printf("call s:silent_feedkeys(\"%s%s\\", 'search', 'n')", self.prefix, input) + try + execute cmd + catch + echohl ErrorMsg + echom matchstr(v:exception, 'Vim\((\w*)\)\?:\zs.*\ze') + echohl None + call a:cmdline.callevent("on_execute_failed") + finally + call a:cmdline.callevent("on_execute") + endtry + +" let cmd = printf("call search('%s')", a:cmdline.getline()) +" call a:cmdline.execute(cmd) +" let @/ = a:cmdline.getline() +" call s:silent_feedkeys(":let &hlsearch = &hlsearch\", "hlsearch", "n") +endfunction + + + +function! s:make_search(...) + let result = deepcopy(s:search) + let result.prefix = get(a:, 1, "/") + return result +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/ExecuteFailedMessage.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/ExecuteFailedMessage.vim new file mode 100644 index 000000000..614116df7 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/ExecuteFailedMessage.vim @@ -0,0 +1,17 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#ExecuteFailedMessage#import() abort', printf("return map({}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Exit.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Exit.vim new file mode 100644 index 000000000..28752c94d --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Exit.vim @@ -0,0 +1,34 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#Exit#import() abort', printf("return map({'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +let s:module = { +\ "name" : "Exit", +\ "exit_code" : 0 +\} + + +function! s:module.on_char_pre(cmdline) + if a:cmdline.is_input("(exit)") + call a:cmdline.setchar("") + call a:cmdline.exit(self.exit_code) + endif +endfunction + + +function! s:make() + return deepcopy(s:module) +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/HighlightBufferCursor.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/HighlightBufferCursor.vim new file mode 100644 index 000000000..a6d473317 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/HighlightBufferCursor.vim @@ -0,0 +1,9 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#HighlightBufferCursor#import() abort', printf("return map({}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/HistAdd.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/HistAdd.vim new file mode 100644 index 000000000..e2e656828 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/HistAdd.vim @@ -0,0 +1,32 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#HistAdd#import() abort', printf("return map({'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +let s:module = { +\ "name" : "HistAdd", +\ "mode" : "cmd" +\} + +function! s:module.on_leave(cmdline) + call histadd(self.mode, a:cmdline.getline()) +endfunction + + +function! s:make(...) + let module = deepcopy(s:module) + let module.mode = get(a:, 1, "cmd") + return module +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/History.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/History.vim new file mode 100644 index 000000000..2eb8ca192 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/History.vim @@ -0,0 +1,69 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#History#import() abort', printf("return map({'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +let s:module = { +\ "name" : "History", +\ "mode" : "cmd", +\} + +function! s:module.histories() + return map(range(1, &history), 'histget(self.mode, v:val * -1)') +endfunction + +function! s:_should_match_cmdline(cmdline) + return a:cmdline.is_input("\") +\ || a:cmdline.is_input("\") +endfunction + +function! s:_reset() + let s:cmdhist = [] + let s:count = 0 + let s:is_match_mode = 0 " /: true, /: false +endfunction + +function! s:module.on_enter(...) + call s:_reset() +endfunction + +function! s:module.on_char_pre(cmdline) + if !a:cmdline.is_input("\") && !a:cmdline.is_input("\") + \ && !a:cmdline.is_input("\") && !a:cmdline.is_input("\") + call s:_reset() + return + else + if s:count == 0 && empty(s:cmdhist) + \ || s:is_match_mode != s:_should_match_cmdline(a:cmdline) + let cmdline = '^' . a:cmdline.getline() + let s:is_match_mode = s:_should_match_cmdline(a:cmdline) + let s:cmdhist = [a:cmdline.getline()] + (s:is_match_mode ? + \ filter(self.histories(), 'v:val =~ cmdline') : self.histories()) + endif + endif + call a:cmdline.setchar("") + if a:cmdline.is_input("\") || a:cmdline.is_input("\") + let s:count = max([s:count - 1, 0]) + endif + if a:cmdline.is_input("\") || a:cmdline.is_input("\") + let s:count = min([s:count + 1, len(s:cmdhist)]) + endif + call a:cmdline.setline(get(s:cmdhist, s:count, a:cmdline.getline())) +endfunction + +function! s:make(...) + let module = deepcopy(s:module) + let module.mode = get(a:, 1, "cmd") + return module +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/IgnoreRegexpBackwardWord.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/IgnoreRegexpBackwardWord.vim new file mode 100644 index 000000000..a4c62db80 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/IgnoreRegexpBackwardWord.vim @@ -0,0 +1,48 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#IgnoreRegexpBackwardWord#import() abort', printf("return map({'backward_word': '', 'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +" Improved backward word detection which ignore regular expression +let s:module = { +\ "name" : "IgnoreRegexpBackwardWord" +\} + +function! s:backward_word(str, ...) + let pat = get(a:, 1, '\k\+\s*\|.') + let flags = s:non_escaped_backslash . + \ '\%(' . 'z[se]' . + \ '\|' . '[iIkKfFpPsSdDxXoOwWhHaAlLuUetrbncCZmMvV]' . + \ '\|' . '%[dxouUCVlcv]' . + \ '\|' . "%'[a-zA-Z]" . + \ '\|' . '%#=\d' . + \ '\|' . 'z\=\d' . + \ '\)' + return matchstr(get(split(a:str, flags . '\s*\zs'), -1, ""), + \ '\%(' . flags . '\s*\|' . pat . '\)$') +endfunction + + +let s:non_escaped_backslash = '\m\%(\%(^\|[^\\]\)\%(\\\\\)*\)\@<=\\' + +function! s:module.on_enter(cmdline) + function! a:cmdline.backward_word(...) + return call("s:backward_word", [self.backward()] + a:000) + endfunction +endfunction + +function! s:make() + return deepcopy(s:module) +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Incsearch.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Incsearch.vim new file mode 100644 index 000000000..c46e209fa --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Incsearch.vim @@ -0,0 +1,83 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#Incsearch#import() abort', printf("return map({'escape_regex': '', 'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:escape_regex(pattern) + return substitute(a:pattern, '^\^', '\\_^', "") +endfunction + + + +let s:module = { +\ "name" : "Incsearch", +\ "highlights" : { +\ "incsearch" : "IncSearch" +\ }, +\ "pattern" : "", +\ "search_flag" : "", +\ "mode" : "", +\} + + +function! s:module.search_hl_off() + if exists("self.search_hl_id") + call matchdelete(self.search_hl_id) + unlet self.search_hl_id + endif +endfunction + + +function! s:module.search_hl_on(pattern) + call self.search_hl_off() + let self.search_hl_id = matchadd(self.highlights.incsearch, a:pattern) +endfunction + + +function! s:module.on_enter(...) + let self.old_pos = getpos(".") +endfunction + + +function! s:module.on_leave(...) + call setpos(".", self.old_pos) + call self.search_hl_off() +endfunction + + +function! s:module.on_char(cmdline) + call self.search_hl_off() + let line = a:cmdline.getline() + let result = get(matchlist(line, self.pattern), 1, "") + if result != "" + let pos = searchpos(result, self.search_flag) + if pos == [0, 0] + return + endif + call self.search_hl_on('\%' . pos[0] . 'l' . (&ignorecase ? '\c' : "") . s:escape_regex(result)) + redraw + endif +endfunction + + +function! s:make(...) + let module = deepcopy(s:module) + let module.mode = get(a:, 1, "/") + let module.pattern = get(a:, 2, '^\(.\+\)') + let module.search_flag = get(a:, 3, 'c') + return module +endfunction + + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/InsertRegister.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/InsertRegister.vim new file mode 100644 index 000000000..d22f209fc --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/InsertRegister.vim @@ -0,0 +1,158 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#InsertRegister#import() abort', printf("return map({'_vital_depends': '', 'to_string': '', 'input': '', 'get_cmdline_cword': '', 'make': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:_vital_loaded(V) + let s:V = a:V + let s:String = s:V.import("Over.String") +endfunction + + +function! s:_vital_depends() + return [ +\ "Over.String", +\ ] +endfunction + + +function! s:to_string(expr) + return type(a:expr) == type("") ? a:expr : string(a:expr) +endfunction + + +function! s:input(cmdline) + let CR_index = index(a:cmdline.input_key_stack(), "\") + if CR_index != -1 + let input = a:cmdline.input_key_stack_string() + let input = input[ : CR_index-1] + call a:cmdline.set_input_key_stack(a:cmdline.input_key_stack()[CR_index+1 : ]) + return eval(input) + endif + + let input_text = "" + if !empty(a:cmdline.input_key_stack()) + let input_text = a:cmdline.input_key_stack_string() + call a:cmdline.set_input_key_stack([]) + endif + + call a:cmdline.hl_cursor_on() + try + redraw + let input = input("=", input_text, "expression") + if !empty(input) + let input = s:to_string(eval(input)) + endif + catch + return "" + finally + call a:cmdline.hl_cursor_off() + endtry + return input +endfunction + + +let s:module = { +\ "name" : "InsertRegister" +\} + + + +function! s:module.reset() + let self.cword = expand("") + let self.cWORD = expand("") + let self.cfile = expand("") +endfunction + +function! s:module.on_enter(...) + call self.reset() +" let self.prefix_key = "" +endfunction + + +function! s:get_cmdline_cword(backward, cword) +" let backward = matchstr(a:backward, '.\{-}\zs\k\+$') + let backward = a:backward + if &incsearch == 0 || a:cword == "" || a:backward == "" || s:String.index(a:cword, backward) != 0 + return a:cword + endif + return a:cword[len(backward) : ] +endfunction + + +function! s:module.on_char_pre(cmdline) + if a:cmdline.is_input("\") + call a:cmdline.setchar('"') + let self.prefix_key = a:cmdline.input_key() + let self.old_line = a:cmdline.getline() + let self.old_pos = a:cmdline.getpos() + return + elseif exists("self.prefix_key") +\ && a:cmdline.get_tap_key() == self.prefix_key + call a:cmdline.setline(self.old_line) + call a:cmdline.setpos(self.old_pos) + let char = a:cmdline.input_key() + if char =~ '^[0-9a-zA-z.%#:/"\-*+]$' + let register = tr(getreg(char), "\n", "\r") + call a:cmdline.setchar(register) + elseif char == "=" + call a:cmdline.setchar(s:input(a:cmdline)) + elseif char == "\" + call a:cmdline.setchar(s:get_cmdline_cword(a:cmdline.backward_word(), self.cword)) + elseif char == "\" + call a:cmdline.setchar(self.cWORD) + elseif char == "\" + call a:cmdline.setchar(self.cfile) + elseif char == "\" + call a:cmdline.setchar('"') + else + call a:cmdline.setchar("") + endif +" elseif a:cmdline.is_input('=', self.prefix_key) +" call a:cmdline.setchar(s:input(a:cmdline)) +" elseif a:cmdline.is_input("\", self.prefix_key) +" call a:cmdline.setchar(self.cword) +" elseif a:cmdline.is_input("\", self.prefix_key) +" call a:cmdline.setchar(self.cWORD) +" elseif a:cmdline.is_input("\", self.prefix_key) +" call a:cmdline.setchar(self.cfile) +" elseif a:cmdline.is_input("\", self.prefix_key) +" call a:cmdline.setchar('"') +" else +" call a:cmdline.setchar("") +" endif + endif +endfunction + + +function! s:module.on_char(cmdline) + if a:cmdline.is_input("\") + call a:cmdline.tap_keyinput(self.prefix_key) + call a:cmdline.disable_keymapping() + call a:cmdline.setpos(a:cmdline.getpos()-1) + else + if exists("self.prefix_key") + call a:cmdline.untap_keyinput(self.prefix_key) + call a:cmdline.enable_keymapping() + unlet! self.prefix_key + endif + endif +endfunction + + + +function! s:make() + return deepcopy(s:module) +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/KeyMapping.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/KeyMapping.vim new file mode 100644 index 000000000..8c6599ed0 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/KeyMapping.vim @@ -0,0 +1,149 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#KeyMapping#import() abort', printf("return map({'_vital_depends': '', 'make_emacs': '', 'make_vim_cmdline_mapping': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:_vital_loaded(V) + let s:Keymapping = a:V.import("Palette.Keymapping") +endfunction + + +function! s:_vital_depends() + return [ +\ "Palette.Keymapping", +\ ] +endfunction + + +let s:emacs = { +\ "name" : "KeyMapping_emacs_like" +\} + +function! s:emacs.keymapping(cmdline) + return { +\ "\" : { +\ "key" : "\", +\ "noremap" : 1, +\ "lock" : 1, +\ }, +\ "\" : { +\ "key" : "\", +\ "noremap" : 1, +\ "lock" : 1, +\ }, +\ "\" : { +\ "key" : "\", +\ "noremap" : 1, +\ "lock" : 1, +\ }, +\ "\" : { +\ "key" : "\", +\ "noremap" : 1, +\ "lock" : 1, +\ }, +\ "\" : { +\ "key" : "\", +\ "noremap" : 1, +\ "lock" : 1, +\ }, +\ "\" : { +\ "key" : "\", +\ "noremap" : 1, +\ "lock" : 1, +\ }, +\ "\" : { +\ "key" : "\", +\ "noremap" : 1, +\ "lock" : 1, +\ }, +\ "\" : { +\ "key" : "\", +\ "noremap" : 1, +\ "lock" : 1, +\ }, +\ "\" : { +\ "key" : "\", +\ "noremap" : 1, +\ "lock" : 1, +\ }, +\ "\" : { +\ "key" : "\", +\ "noremap" : 1, +\ "lock" : 1, +\ }, +\ } +endfunction + + +function! s:make_emacs() + return deepcopy(s:emacs) +endfunction + + +let s:vim_cmdline_mapping = { +\ "name" : "KeyMapping_vim_cmdline_mapping", +\ "_cmaps" : {} +\} + +function! s:_convert_sid(rhs, sid) abort + return substitute(a:rhs, '', '' . a:sid . '_', 'g') +endfunction + +function! s:_auto_cmap() + let cmaps = {} + let cmap_info = s:Keymapping.rhs_key_list("c", 0, 1) + " vital-over currently doesn't support mappings + for c in filter(cmap_info, "v:val['buffer'] ==# 0") + let cmaps[s:Keymapping.escape_special_key(c['lhs'])] = { + \ 'noremap' : c['noremap'], + \ 'key' : s:Keymapping.escape_special_key(s:_convert_sid(c['rhs'], c['sid'])), + \ 'expr' : s:Keymapping.escape_special_key(c['expr']), + \ } + endfor + return cmaps +endfunction + + +function! s:vim_cmdline_mapping.on_enter(cmdline) + let self._cmaps = s:_auto_cmap() + if exists("*execute") + let self._old_cmap = execute("cmap") + endif +endfunction + + +function! s:vim_cmdline_mapping.on_update(cmdline) + if !exists("*execute") + return + endif + + let cmap_ = execute("cmap") + if self._old_cmap != cmap_ + let self._cmaps = s:_auto_cmap() + let self._old_cmap = cmap_ + endif +endfunction + + +function! s:vim_cmdline_mapping.keymapping(cmdline) + return self._cmaps +endfunction + + +function! s:make_vim_cmdline_mapping() + return deepcopy(s:vim_cmdline_mapping) +endfunction + + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/LiteralInsert.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/LiteralInsert.vim new file mode 100644 index 000000000..3d2dc6f49 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/LiteralInsert.vim @@ -0,0 +1,39 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#LiteralInsert#import() abort', printf("return map({'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +let s:module = { +\ "name" : "LiteralInsert", +\} + +function! s:module.on_char_pre(cmdline) + if a:cmdline.is_input("\") +\ || a:cmdline.is_input("\") + let old_line = a:cmdline.getline() + let old_pos = a:cmdline.getpos() + call a:cmdline.insert('^') + call a:cmdline.setpos(old_pos) + call a:cmdline.draw() + let char = a:cmdline.getchar() + call a:cmdline.setline(old_line) + call a:cmdline.setpos(old_pos) + call a:cmdline.setchar(char) + endif +endfunction + +function! s:make() + return deepcopy(s:module) +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/NoInsert.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/NoInsert.vim new file mode 100644 index 000000000..9aab04edb --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/NoInsert.vim @@ -0,0 +1,49 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#NoInsert#import() abort', printf("return map({'make_special_chars': '', 'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +let s:module = { +\ "name" : "NoInsert", +\ "chars" : [] +\} + + +function! s:module.is_no_insert(char) + return index(self.chars, a:char) >= 0 +endfunction + + +function! s:module.on_char_pre(cmdline) + if self.is_no_insert(a:cmdline.char()) + call a:cmdline.setchar("", 0) + endif +endfunction + + +function! s:make(chars) + let module = deepcopy(s:module) + let module.chars = type(a:chars) == type([]) ? a:chars : [a:chars] + return module +endfunction + + +function! s:make_special_chars() + let module = s:make([]) + function! module.is_no_insert(char) + return char2nr(a:char) == 128 || char2nr(a:char) < 27 + endfunction + return module +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Paste.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Paste.vim new file mode 100644 index 000000000..6403c6f76 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Paste.vim @@ -0,0 +1,34 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#Paste#import() abort', printf("return map({'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +let s:module = { +\ "name" : "Paste" +\} + +function! s:module.on_char_pre(cmdline) + if a:cmdline.is_input("(paste)") + let register = v:register == "" ? '"' : v:register + call a:cmdline.insert(tr(getreg("*"), "\n", "\r")) + call a:cmdline.setchar('') + endif +endfunction + + +function! s:make() + return deepcopy(s:module) +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Redraw.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Redraw.vim new file mode 100644 index 000000000..88409a42b --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Redraw.vim @@ -0,0 +1,66 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#Redraw#import() abort', printf("return map({'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +let s:module = { +\ "name" : "Redraw", +\} + +function! s:module.on_execute_pre(cmdline) + call self.redraw(a:cmdline) +endfunction + +function! s:module.on_enter(...) + let self.is_execute = 0 +endfunction + +function! s:module.on_execute(...) + let self.is_execute = 1 +endfunction + +function! s:module.on_execute_failed(...) + let self.is_execute = 0 +endfunction + +function! s:module.on_leave(cmdline) + if self.is_execute == 0 && a:cmdline.exit_code() != -1 + call self.redraw(a:cmdline) + endif +endfunction + + +" function! s:module.on_draw_pre(cmdline) +" call self.redraw(a:cmdline) +" endfunction + + +function! s:module.redraw(cmdline) + redraw + " Workaround for the :set cedit= + " https://github.com/osyo-manga/vital-over/issues/52 + " https://github.com/Lokaltog/vim-easymotion/issues/177#issuecomment-53663431 + if &cedit != "" +\ ||(v:version > 704 || v:version == 704 && has("patch441")) + normal! : + else + execute "normal! :\" + endif +endfunction + +function! s:make() + return deepcopy(s:module) +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Scroll.vim b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Scroll.vim new file mode 100644 index 000000000..06844db88 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Commandline/Modules/Scroll.vim @@ -0,0 +1,46 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Commandline#Modules#Scroll#import() abort', printf("return map({'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +let s:module = { +\ "name" : "Scroll" +\} +function! s:module.on_char_pre(cmdline) + if a:cmdline.is_input("(scroll-y)") + execute "normal! \" + call a:cmdline.setchar('') + elseif a:cmdline.is_input("(scroll-u)") + execute "normal! \" + call a:cmdline.setchar('') + elseif a:cmdline.is_input("(scroll-f)") + execute "normal! \" + call a:cmdline.setchar('') + elseif a:cmdline.is_input("(scroll-e)") + execute "normal! \" + call a:cmdline.setchar('') + elseif a:cmdline.is_input("(scroll-d)") + execute "normal! \" + call a:cmdline.setchar('') + elseif a:cmdline.is_input("(scroll-b)") + execute "normal! \" + call a:cmdline.setchar('') + endif +endfunction + + +function! s:make() + return deepcopy(s:module) +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Exception.vim b/bundle/vim-over/autoload/vital/_over/Over/Exception.vim new file mode 100644 index 000000000..a5b2ddd23 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Exception.vim @@ -0,0 +1,40 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Exception#import() abort', printf("return map({'throw': '', 'throw_cmd': '', 'set_prefix': '', 'error': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +let s:vname = expand(":h:h:t") +let s:prefix = printf("vital-over(%s) Exception", s:vname) + +function! s:set_prefix(prefix) + let s:prefix = a:prefix +endfunction + +function! s:throw_cmd(exp, where) + return 'throw ' . string(s:prefix . " : " . a:exp . " in " . a:where) +endfunction + + +function! s:throw(exp, where) + execute s:throw_cmd(a:exp, a:where) +endfunction + + +function! s:error(text, where) + echohl ErrorMsg + echom s:prefix . " : " . a:text . " in " . a:where + echohl None +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Input.vim b/bundle/vim-over/autoload/vital/_over/Over/Input.vim new file mode 100644 index 000000000..0c61ef477 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Input.vim @@ -0,0 +1,34 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Input#import() abort', printf("return map({'getchar': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:getchar(...) + let mode = get(a:, 1, 0) + while 1 + " Workaround for https://github.com/osyo-manga/vital-over/issues/53 + try + let char = call("getchar", a:000) + catch /^Vim:Interrupt$/ + let char = 3 " + endtry + " Workaround for the mappings + if string(char) !=# "\x80\xfd`" + return mode == 1 ? !!char +\ : type(char) == type(0) ? nr2char(char) : char + endif + endwhile +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Keymapping.vim b/bundle/vim-over/autoload/vital/_over/Over/Keymapping.vim new file mode 100644 index 000000000..2d88439d9 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Keymapping.vim @@ -0,0 +1,89 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Keymapping#import() abort', printf("return map({'_vital_depends': '', 'unmapping': '', 'as_key_config': '', 'match_key': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + + +function! s:_vital_loaded(V) + let s:V = a:V + let s:String = s:V.import("Over.String") +endfunction + + +function! s:_vital_depends() + return [ +\ "Over.String", +\ ] +endfunction + + +function! s:as_key_config(config) + let base = { +\ "noremap" : 0, +\ "lock" : 0, +\ "expr" : 0, +\ } + return type(a:config) == type({}) ? extend(base, a:config) +\ : extend(base, { +\ "key" : a:config, +\ }) +endfunction + + +function! s:match_key(keymapping, key) + let keys = sort(keys(a:keymapping)) + return get(filter(keys, 'stridx(a:key, v:val) == 0'), -1, '') +endfunction + + +function! s:_safe_eval(expr, ...) + call extend(l:, get(a:, 1, {})) + let result = get(a:, 2, "") + try + let result = eval(a:expr) + catch + echohl ErrorMsg | echom v:exception | echohl None + endtry + return result +endfunction + + +function! s:_get_key(conf) +" call extend(l:, a:conf) + let self = a:conf + return get(a:conf, "expr", 0) ? s:_safe_eval(a:conf.key, l:) : a:conf.key +endfunction + + +function! s:unmapping(keymapping, key, ...) + let is_locking = get(a:, 1, 0) + let key = s:match_key(a:keymapping, a:key) + if key == "" + return s:String.length(a:key) <= 1 ? a:key : s:unmapping(a:keymapping, a:key[0], is_locking) . s:unmapping(a:keymapping, a:key[1:], is_locking) + endif + + let map_conf = s:as_key_config(a:keymapping[key]) + + let next_input = s:unmapping(a:keymapping, a:key[len(key) : ], is_locking) + if map_conf.lock == 0 && is_locking + return key . next_input + elseif map_conf.lock + return s:unmapping(a:keymapping, s:_get_key(map_conf), is_locking) . next_input + else + return s:unmapping(a:keymapping, s:_get_key(map_conf), map_conf.noremap) . next_input + endif +endfunction + + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/Signals.vim b/bundle/vim-over/autoload/vital/_over/Over/Signals.vim new file mode 100644 index 000000000..e6365415f --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/Signals.vim @@ -0,0 +1,113 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#Signals#import() abort', printf("return map({'_vital_depends': '', 'call': '', 'make': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:_vital_loaded(V) + let s:V = a:V + let s:L = s:V.import("Data.List") +endfunction + + +function! s:_vital_depends() + return ["Data.List"] +endfunction + + +let s:base = { +\ "variables" : { +\ "slots" : [], +\ "counter" : 0, +\ } +\} + + +function! s:base.connect(slot) + let self.variables.counter += 1 + let slot = { "id" : self.variables.counter, "slot" : a:slot } + call add(self.variables.slots, slot) + return slot +endfunction + + +function! s:base.disconnect(slot) + if empty(a:slot) + return -1 + endif + for i in range(len(self.variables.slots)) + if self.variables.slots[i].id == a:slot.id + unlet self.variables.slots[i] + return + endif + endfor + return -1 +endfunction + + +function! s:base.disconnect_by(expr) + return self.disconnect(self.find_first_by(a:expr)) +endfunction + + +function! s:call(list, func, ...) + let args = get(a:, 1, []) + let def = get(a:, 2, 0) + return map(copy(a:list), "has_key(v:val, a:func) ? call(v:val.".a:func.", args, v:val) : def") +endfunction + +function! s:base.call(func, ...) + return call("s:call", [self.slots(), a:func] + a:000) +endfunction + + +function! s:base.find_by(expr) + return filter(copy(self.variables.slots), a:expr) +endfunction + + +function! s:base.find_first_by(expr) + return get(self.find_by(a:expr), 0, {}) +endfunction + + +function! s:base.sort_by(expr) + let self.variables.slots = s:L.sort_by(self.variables.slots, a:expr) +endfunction + + +function! s:base.get_slot(val) + return a:val.slot +endfunction + + +function! s:base.slots() + return map(copy(self.variables.slots), "self.get_slot(v:val)") +endfunction + + +" function! s:base.dict() +" let result = {} +" for _ in self.variables.slots +" let result[_.id] = _.value +" endfor +" return result +" endfunction + + +function! s:make() + let result = deepcopy(s:base) + return result +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Over/String.vim b/bundle/vim-over/autoload/vital/_over/Over/String.vim new file mode 100644 index 000000000..0a6238a28 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Over/String.vim @@ -0,0 +1,158 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Over#String#import() abort', printf("return map({'_vital_depends': '', 'length': '', 'index': '', 'split_by_keys': '', 'make': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:_vital_loaded(V) + let s:V = a:V + let s:List = s:V.import("Data.List") +endfunction + + +function! s:_vital_depends() + return [ +\ "Data.List", +\ ] +endfunction + + +function! s:_clamp(x, max, min) + return min([max([a:x, a:max]), a:min]) +endfunction + + +let s:base = {} + +function! s:base.set(item) + return type(a:item) == type("") ? self.set_str(a:item) +\ : type(a:item) == type(0) ? self.set_pos(a:item) +\ : self +endfunction + +function! s:base.str() + return join(self.list, "") +endfunction + +function! s:base.set_pos(pos) + let self.col = s:_clamp(a:pos, 0, self.length()) + return self +endfunction + +function! s:base.backward() + return self.col > 0 ? join(self.list[ : self.col-1], '') : "" +endfunction + +function! s:base.forward() + return join(self.list[self.col+1 : ], '') +endfunction + +function! s:base.pos_char() + return get(self.list, self.col, "") +endfunction + +function! s:base.set_str(str) + let self.list = split(a:str, '\zs') + let self.col = strchars(a:str, 1) + return self +endfunction + +function! s:base.pos() + return self.col +endfunction + +function! s:base.input(str) + call extend(self.list, split(a:str, '\zs'), self.col) + let self.col += len(split(a:str, '\zs')) + return self +endfunction + +function! s:base.length() + return len(self.list) +endfunction + +function! s:base.next() + return self.set_pos(self.col + 1) +endfunction + +function! s:base.prev() + return self.set_pos(self.col - 1) +endfunction + +function! s:base.remove(index) + if a:index < 0 || self.length() <= a:index + return "" + endif + let result = self.list[a:index] + unlet self.list[a:index] + if a:index < self.col + call self.set(self.col - 1) + endif + return result +endfunction + +function! s:base.remove_pos() + return self.remove(self.col) +endfunction + +function! s:base.remove_prev() + return self.remove(self.col - 1) +endfunction + +function! s:base.remove_next() + return self.remove(self.col + 1) +endfunction + + +function! s:make(...) + let default = get(a:, 1, "") + let result = deepcopy(s:base) + call result.set(default) + return result +endfunction + +" NOTE: old regexpengine has a bug with string which contains binary +" :echo "\x80" =~ "\\%#=1\x80" | " => 0 +" But it matches correctly with :h /collection +" :echo "\x80" =~ "\\%#=1[\x80]" | " => 1 +" http://lingr.com/room/vim/archives/2015/02/13#message-21261450 +let s:_engine = exists("+regexpengine") ? '\%#=2' : '' +" \ => Û\xfdQ +" \ => À\xfeX +let s:_regex = exists("+regexpengine") +\ ? "\\%(Û\xfdQ\\|À\xfeX\\|\x80\xfc.\\%(\x80..\\|.\\)\\|\x80..\\|.\\)\\zs" +\ : "\\%(Û[\xfd]Q\\|À[\xfe]X\\|[\x80][\xfc].\\%([\x80]..\\|.\\)\\|[\x80]..\\|.\\)\\zs" +function! s:_split_keystring(str, ...) + return split(a:str, s:_engine . '\m\%(' . get(a:, 1, '') . s:_regex . '\)') +endfunction + +function! s:split_by_keys(str) + return s:_split_keystring(a:str, "\\%(\\\|\\)(.\\{-})\\zs\\|") +endfunction + +function! s:index(haystack, needle, ...) + let start = get(a:, 1, 0) + let ignorecase = get(a:, 2, &ignorecase) + if ignorecase + return stridx(tolower(a:haystack), tolower(a:needle), start) + else + return stridx(a:haystack, a:needle, start) + endif +endfunction + + +function! s:length(str) + return len(s:split_by_keys(a:str)) +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Palette/Capture.vim b/bundle/vim-over/autoload/vital/_over/Palette/Capture.vim new file mode 100644 index 000000000..454ce491b --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Palette/Capture.vim @@ -0,0 +1,79 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Palette#Capture#import() abort', printf("return map({'help': '', 'extend': '', 'command': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +let s:verbosefiles = [] + +function! s:_verbosefile_push(file) + call add(s:verbosefiles, &verbosefile) + let &verbosefile = a:file + return a:file +endfunction + + +function! s:_verbosefile_pop() + let filename = &verbosefile + let &verbosefile = get(s:verbosefiles, -1) + call remove(s:verbosefiles, -1) + return filename +endfunction + + +function! s:_reset() + let s:verbosefiles = [] +endfunction + + +function! s:extend(dict, src) + for [key, value] in items(a:src) + let a:dict[key] = value + unlet value + endfor +endfunction + + +function! s:command(cmd, ...) + " Workaround : Vim 7.3.xxx in Travis and Ubuntu + " https://github.com/osyo-manga/vital-palette/issues/5 +" call extend(l:, get(a:, 1, {})) + if a:0 > 0 + call s:extend(l:, a:1) + endif + + call s:_verbosefile_push(tempname()) + try + redir =>result + silent! execute a:cmd + finally + redir END + endtry + call s:_verbosefile_pop() +" let result = substitute(result, "", "\", "g") +" let result = substitute(result, "", "\", "g") + return result +endfunction + + +function! s:_is_help_open() + return index(map(range(1, winnr("$")), "getbufvar(winbufnr(v:val), '&buftype')"), "help") >= 0 +endfunction + + +function! s:help(word) + let opened = s:_is_help_open() + silent execute "help" a:word +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Palette/Highlight.vim b/bundle/vim-over/autoload/vital/_over/Palette/Highlight.vim new file mode 100644 index 000000000..004b2bf55 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Palette/Highlight.vim @@ -0,0 +1,127 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Palette#Highlight#import() abort', printf("return map({'capture': '', '_vital_depends': '', 'parse': '', 'group_list': '', 'set': '', 'parse_to_name': '', 'links_to': '', 'get': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:_vital_loaded(V) + let s:V = a:V + let s:Message = s:V.import("Vim.Message") +endfunction + + +function! s:_vital_depends() + return [ +\ "Vim.Message", +\ ] +endfunction + + +function! s:_execute(cmd) + execute a:cmd +endfunction + + +function! s:capture(name) + if hlexists(a:name) == 0 + return "" + endif + return s:Message.capture("highlight " . a:name) +endfunction + + +function! s:links_to(highlight) + return matchstr(a:highlight, '^\S\+\s\+xxx links to \zs.*\ze$') +endfunction + + +function! s:parse_to_name(highlight) + return matchstr(a:highlight, '^\zs\w\+\ze') +endfunction + + +function! s:parse(highlight) + let highlight = a:highlight + + if highlight !~# '^\w\+\s\+xxx\s' + return {} + endif + + let name = s:parse_to_name(a:highlight) + let result = { "_name" : name } + + if highlight =~# '^\w\+\s\+xxx cleared' + let result.cleared = 1 + return result + endif + + let link = s:links_to(highlight) + if link != "" + let result.link = link + return result + endif + + let attrs = [ +\ "term", +\ "cterm", +\ "ctermfg", +\ "ctermbg", +\ "gui", +\ "font", +\ "guifg", +\ "guibg", +\ "guisp", +\ ] + for attr in attrs + let item = matchstr(highlight, '\s' . attr . '=\zs#\?\w\+\ze') + if item != "" + let result[attr] = item + endif + endfor + return result +endfunction + + +function! s:get(name, ...) + if !hlexists(a:name) + return {} + endif + let result = s:parse(substitute(s:capture(a:name), "\n", "", "g")) + if has_key(result, "link") && get(a:, 1, 0) + return s:get(result.link, get(a:, 1, 0)) + else + return result + endif +endfunction + + +function! s:set(name, config) + if type(a:config) == type("") + return s:set(a:config, s:get(a:config)) + endif + if has_key(a:config, "cleared") + return s:_execute("highlight clear " . a:name) + endif + if has_key(a:config, "link") + return s:_execute("highlight link " . a:name . " " . a:config.link) + endif + return s:_execute("highlight " . a:name . " " . join(map(items(filter(a:config, "v:key !=# '_name'")), "v:val[0] . '=' . v:val[1]"), " ")) +endfunction + + +function! s:group_list() + let highlights = split(s:Message.capture("highlight"), "\n") + return filter(map(highlights, "s:parse_to_name(v:val)"), "v:val != ''") +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Palette/Keymapping.vim b/bundle/vim-over/autoload/vital/_over/Palette/Keymapping.vim new file mode 100644 index 000000000..d708dad6a --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Palette/Keymapping.vim @@ -0,0 +1,115 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Palette#Keymapping#import() abort', printf("return map({'capture': '', '_vital_depends': '', 'escape_special_key': '', 'rhs_key_list': '', 'parse_lhs_list': '', 'lhs_key_list': '', 'capture_list': '', 'parse_lhs': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +let s:modep = "[nvoicsxl]" + + +function! s:_vital_loaded(V) + let s:V = a:V + let s:Capture = s:V.import("Palette.Capture") +endfunction + + +function! s:_vital_depends() + return [ +\ "Palette.Capture", +\ ] +endfunction + + +function! s:_capture(mode) + let cmd = "map" + if a:mode ==# "!" + let cmd = cmd . "!" + elseif a:mode =~# "[nvoicsxl]" + let cmd = a:mode . cmd + endif + return s:Capture.command(cmd) +endfunction + + +function! s:capture(...) + let mode = get(a:, 1, "") + let modes = split(mode, '\zs') + return join(map(modes, "s:_capture(v:val)"), "\n") +endfunction + + +function! s:_keymapping(str) + return a:str =~ '^[!nvoicsxl]\s' +endfunction + + +function! s:capture_list(...) + let mode = get(a:, 1, "") + return filter(split(s:capture(mode), "\n"), "s:_keymapping(v:val)") +endfunction + + +function! s:escape_special_key(key) + " Workaround : https://github.com/osyo-manga/vital-palette/issues/5 + if a:key ==# "<^?>" + return "\" + endif + execute 'let result = "' . substitute(escape(a:key, '\"'), '\(<.\{-}>\)', '\\\1', 'g') . '"' + return result +endfunction + + +function! s:parse_lhs(text, ...) + let mode = get(a:, 1, '[!nvoicsxl]') + " NOTE: :map! Surpport : https://github.com/osyo-manga/vital-palette/issues/4 + if get(a:, 1, "") =~# '[!ci]' + let mode = '[!ci]' + endif + return matchstr(a:text, mode . '\{1,3\}\s*\zs\S\{-}\ze\s\+') +endfunction + + +function! s:parse_lhs_list(...) + let mode = get(a:, 1, "") + return map(s:capture_list(mode), "s:parse_lhs(v:val, mode)") +endfunction + + +function! s:lhs_key_list(...) + let mode = get(a:, 1, "") + return map(s:parse_lhs_list(mode), "s:escape_special_key(v:val)") +endfunction + + +function! s:_maparg(name, mode, abbr, dict) + " Workaround : https://github.com/osyo-manga/vital-palette/issues/5 + if a:name ==# "<^?>" + return maparg("\", a:mode, a:abbr, a:dict) + endif + return maparg(a:name, a:mode, a:abbr, a:dict) +endfunction + + +function! s:rhs_key_list(...) + let mode = get(a:, 1, "") + let abbr = get(a:, 2, 0) + let dict = get(a:, 3, 0) + + let result = [] + for m in split(mode, '\zs') + let result += map(s:parse_lhs_list(m), "s:_maparg(v:val, m, abbr, dict)") + endfor + return filter(result, "empty(v:val) == 0") +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Prelude.vim b/bundle/vim-over/autoload/vital/_over/Prelude.vim new file mode 100644 index 000000000..4b48712b5 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Prelude.vim @@ -0,0 +1,424 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Prelude#import() abort', printf("return map({'escape_pattern': '', 'is_funcref': '', 'path2directory': '', 'wcswidth': '', 'is_string': '', 'input_helper': '', 'is_number': '', 'is_cygwin': '', 'path2project_directory': '', 'strwidthpart_reverse': '', 'input_safe': '', 'is_list': '', 'truncate_skipping': '', 'glob': '', 'truncate': '', 'is_dict': '', 'set_default': '', 'is_numeric': '', 'getchar_safe': '', 'substitute_path_separator': '', 'is_mac': '', 'strwidthpart': '', 'getchar': '', 'is_unix': '', 'is_windows': '', 'globpath': '', 'escape_file_searching': '', 'is_float': '', 'smart_execute_command': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +let s:save_cpo = &cpo +set cpo&vim + +if v:version > 703 || +\ (v:version == 703 && has('patch465')) + function! s:glob(expr) abort + return glob(a:expr, 1, 1) + endfunction +else + function! s:glob(expr) abort + return split(glob(a:expr, 1), '\n') + endfunction +endif + +if v:version > 704 || +\ (v:version == 704 && has('patch279')) + function! s:globpath(path, expr) abort + return globpath(a:path, a:expr, 1, 1) + endfunction +else + function! s:globpath(path, expr) abort + return split(globpath(a:path, a:expr, 1), '\n') + endfunction +endif + +" Wrapper functions for type(). +" NOTE: __TYPE_FLOAT = -1 when -float. +" this doesn't match to anything. +if has('patch-7.4.2071') + let [ + \ s:__TYPE_NUMBER, + \ s:__TYPE_STRING, + \ s:__TYPE_FUNCREF, + \ s:__TYPE_LIST, + \ s:__TYPE_DICT, + \ s:__TYPE_FLOAT] = [ + \ v:t_number, + \ v:t_string, + \ v:t_func, + \ v:t_list, + \ v:t_dict, + \ v:t_float] +else + let [ + \ s:__TYPE_NUMBER, + \ s:__TYPE_STRING, + \ s:__TYPE_FUNCREF, + \ s:__TYPE_LIST, + \ s:__TYPE_DICT, + \ s:__TYPE_FLOAT] = [ + \ type(3), + \ type(''), + \ type(function('tr')), + \ type([]), + \ type({}), + \ has('float') ? type(str2float('0')) : -1] +endif + +" Number or Float +function! s:is_numeric(Value) abort + let _ = type(a:Value) + return _ ==# s:__TYPE_NUMBER + \ || _ ==# s:__TYPE_FLOAT +endfunction + +" Number +function! s:is_number(Value) abort + return type(a:Value) ==# s:__TYPE_NUMBER +endfunction + +" String +function! s:is_string(Value) abort + return type(a:Value) ==# s:__TYPE_STRING +endfunction + +" Funcref +function! s:is_funcref(Value) abort + return type(a:Value) ==# s:__TYPE_FUNCREF +endfunction + +" List +function! s:is_list(Value) abort + return type(a:Value) ==# s:__TYPE_LIST +endfunction + +" Dictionary +function! s:is_dict(Value) abort + return type(a:Value) ==# s:__TYPE_DICT +endfunction + +" Float +function! s:is_float(Value) abort + return type(a:Value) ==# s:__TYPE_FLOAT +endfunction + + +function! s:truncate_skipping(str, max, footer_width, separator) abort + call s:_warn_deprecated('truncate_skipping', 'Data.String.truncate_skipping') + + let width = s:wcswidth(a:str) + if width <= a:max + let ret = a:str + else + let header_width = a:max - s:wcswidth(a:separator) - a:footer_width + let ret = s:strwidthpart(a:str, header_width) . a:separator + \ . s:strwidthpart_reverse(a:str, a:footer_width) + endif + + return s:truncate(ret, a:max) +endfunction + +function! s:truncate(str, width) abort + " Original function is from mattn. + " http://github.com/mattn/googlereader-vim/tree/master + + call s:_warn_deprecated('truncate', 'Data.String.truncate') + + if a:str =~# '^[\x00-\x7f]*$' + return len(a:str) < a:width ? + \ printf('%-'.a:width.'s', a:str) : strpart(a:str, 0, a:width) + endif + + let ret = a:str + let width = s:wcswidth(a:str) + if width > a:width + let ret = s:strwidthpart(ret, a:width) + let width = s:wcswidth(ret) + endif + + if width < a:width + let ret .= repeat(' ', a:width - width) + endif + + return ret +endfunction + +function! s:strwidthpart(str, width) abort + call s:_warn_deprecated('strwidthpart', 'Data.String.strwidthpart') + + if a:width <= 0 + return '' + endif + let ret = a:str + let width = s:wcswidth(a:str) + while width > a:width + let char = matchstr(ret, '.$') + let ret = ret[: -1 - len(char)] + let width -= s:wcswidth(char) + endwhile + + return ret +endfunction +function! s:strwidthpart_reverse(str, width) abort + call s:_warn_deprecated('strwidthpart_reverse', 'Data.String.strwidthpart_reverse') + + if a:width <= 0 + return '' + endif + let ret = a:str + let width = s:wcswidth(a:str) + while width > a:width + let char = matchstr(ret, '^.') + let ret = ret[len(char) :] + let width -= s:wcswidth(char) + endwhile + + return ret +endfunction + +if v:version >= 703 + " Use builtin function. + function! s:wcswidth(str) abort + call s:_warn_deprecated('wcswidth', 'Data.String.wcswidth') + return strwidth(a:str) + endfunction +else + function! s:wcswidth(str) abort + call s:_warn_deprecated('wcswidth', 'Data.String.wcswidth') + + if a:str =~# '^[\x00-\x7f]*$' + return strlen(a:str) + end + + let mx_first = '^\(.\)' + let str = a:str + let width = 0 + while 1 + let ucs = char2nr(substitute(str, mx_first, '\1', '')) + if ucs == 0 + break + endif + let width += s:_wcwidth(ucs) + let str = substitute(str, mx_first, '', '') + endwhile + return width + endfunction + + " UTF-8 only. + function! s:_wcwidth(ucs) abort + let ucs = a:ucs + if (ucs >= 0x1100 + \ && (ucs <= 0x115f + \ || ucs == 0x2329 + \ || ucs == 0x232a + \ || (ucs >= 0x2e80 && ucs <= 0xa4cf + \ && ucs != 0x303f) + \ || (ucs >= 0xac00 && ucs <= 0xd7a3) + \ || (ucs >= 0xf900 && ucs <= 0xfaff) + \ || (ucs >= 0xfe30 && ucs <= 0xfe6f) + \ || (ucs >= 0xff00 && ucs <= 0xff60) + \ || (ucs >= 0xffe0 && ucs <= 0xffe6) + \ || (ucs >= 0x20000 && ucs <= 0x2fffd) + \ || (ucs >= 0x30000 && ucs <= 0x3fffd) + \ )) + return 2 + endif + return 1 + endfunction +endif + +let s:is_windows = has('win16') || has('win32') || has('win64') || has('win95') +let s:is_cygwin = has('win32unix') +let s:is_mac = !s:is_windows && !s:is_cygwin + \ && (has('mac') || has('macunix') || has('gui_macvim') || + \ (!isdirectory('/proc') && executable('sw_vers'))) +let s:is_unix = has('unix') + +function! s:is_windows() abort + return s:is_windows +endfunction + +function! s:is_cygwin() abort + return s:is_cygwin +endfunction + +function! s:is_mac() abort + return s:is_mac +endfunction + +function! s:is_unix() abort + return s:is_unix +endfunction + +function! s:_warn_deprecated(name, alternative) abort + try + echohl Error + echomsg 'Prelude.' . a:name . ' is deprecated! Please use ' . a:alternative . ' instead.' + finally + echohl None + endtry +endfunction + +function! s:smart_execute_command(action, word) abort + execute a:action . ' ' . (a:word ==# '' ? '' : '`=a:word`') +endfunction + +function! s:escape_file_searching(buffer_name) abort + return escape(a:buffer_name, '*[]?{}, ') +endfunction + +function! s:escape_pattern(str) abort + call s:_warn_deprecated( + \ 'escape_pattern', + \ 'Data.String.escape_pattern', + \) + return escape(a:str, '~"\.^$[]*') +endfunction + +function! s:getchar(...) abort + let c = call('getchar', a:000) + return type(c) == type(0) ? nr2char(c) : c +endfunction + +function! s:getchar_safe(...) abort + let c = s:input_helper('getchar', a:000) + return type(c) == type('') ? c : nr2char(c) +endfunction + +function! s:input_safe(...) abort + return s:input_helper('input', a:000) +endfunction + +function! s:input_helper(funcname, args) abort + let success = 0 + if inputsave() !=# success + throw 'vital: Prelude: inputsave() failed' + endif + try + return call(a:funcname, a:args) + finally + if inputrestore() !=# success + throw 'vital: Prelude: inputrestore() failed' + endif + endtry +endfunction + +function! s:set_default(var, val) abort + if !exists(a:var) || type({a:var}) != type(a:val) + let {a:var} = a:val + endif +endfunction + +function! s:substitute_path_separator(path) abort + return s:is_windows ? substitute(a:path, '\\', '/', 'g') : a:path +endfunction + +function! s:path2directory(path) abort + return s:substitute_path_separator(isdirectory(a:path) ? a:path : fnamemodify(a:path, ':p:h')) +endfunction + +function! s:_path2project_directory_git(path) abort + let parent = a:path + + while 1 + let path = parent . '/.git' + if isdirectory(path) || filereadable(path) + return parent + endif + let next = fnamemodify(parent, ':h') + if next == parent + return '' + endif + let parent = next + endwhile +endfunction + +function! s:_path2project_directory_svn(path) abort + let search_directory = a:path + let directory = '' + + let find_directory = s:escape_file_searching(search_directory) + let d = finddir('.svn', find_directory . ';') + if d ==# '' + return '' + endif + + let directory = fnamemodify(d, ':p:h:h') + + " Search parent directories. + let parent_directory = s:path2directory( + \ fnamemodify(directory, ':h')) + + if parent_directory !=# '' + let d = finddir('.svn', parent_directory . ';') + if d !=# '' + let directory = s:_path2project_directory_svn(parent_directory) + endif + endif + return directory +endfunction + +function! s:_path2project_directory_others(vcs, path) abort + let vcs = a:vcs + let search_directory = a:path + + let find_directory = s:escape_file_searching(search_directory) + let d = finddir(vcs, find_directory . ';') + if d ==# '' + return '' + endif + return fnamemodify(d, ':p:h:h') +endfunction + +function! s:path2project_directory(path, ...) abort + let is_allow_empty = get(a:000, 0, 0) + let search_directory = s:path2directory(a:path) + let directory = '' + + " Search VCS directory. + for vcs in ['.git', '.bzr', '.hg', '.svn'] + if vcs ==# '.git' + let directory = s:_path2project_directory_git(search_directory) + elseif vcs ==# '.svn' + let directory = s:_path2project_directory_svn(search_directory) + else + let directory = s:_path2project_directory_others(vcs, search_directory) + endif + if directory !=# '' + break + endif + endfor + + " Search project file. + if directory ==# '' + for d in ['build.xml', 'prj.el', '.project', 'pom.xml', 'package.json', + \ 'Makefile', 'configure', 'Rakefile', 'NAnt.build', + \ 'P4CONFIG', 'tags', 'gtags'] + let d = findfile(d, s:escape_file_searching(search_directory) . ';') + if d !=# '' + let directory = fnamemodify(d, ':p:h') + break + endif + endfor + endif + + if directory ==# '' + " Search /src/ directory. + let base = s:substitute_path_separator(search_directory) + if base =~# '/src/' + let directory = base[: strridx(base, '/src/') + 3] + endif + endif + + if directory ==# '' && !is_allow_empty + " Use original path. + let directory = search_directory + endif + + return s:substitute_path_separator(directory) +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo + +" vim:set et ts=2 sts=2 sw=2 tw=0: diff --git a/bundle/vim-over/autoload/vital/_over/Unlocker/Holder.vim b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder.vim new file mode 100644 index 000000000..db8e23d9b --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder.vim @@ -0,0 +1,108 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Unlocker#Holder#import() abort', printf("return map({'_vital_depends': '', 'as_get_deepcopy': '', 'exists': '', 'as_set_extend': '', 'get': '', 'make': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:_glob(expr, dir) + let cwd = getcwd() + try + execute "lcd" fnameescape(a:dir) + return filter(split(glob(a:expr), '\n'), "!isdirectory(v:val)") + finally + execute "lcd" fnameescape(cwd) + endtry +endfunction + + +let s:holder_files = s:_glob("Holder/**", expand(":h")) + +function! s:_to_modulename(file) + let result = substitute(a:file, '^Holder[\/]', '', 'g') + let result = fnamemodify(result, ':r') + let result = substitute(result, '[\/]', ".", "g") + return result +endfunction + + +let s:holder_module_names = map(copy(s:holder_files), "s:_to_modulename(v:val)") + + +let s:holder_module = {} +function! s:_vital_loaded(V) + let s:V = a:V + for name in s:holder_module_names + let s:holder_module[name] = a:V.import("Unlocker.Holder." . name) + endfor +endfunction + + +function! s:_vital_depends() + return map(copy(s:holder_module_names), "'Unlocker.Holder.' . v:val") +endfunction + + +function! s:as_get_deepcopy(holder) + if has_key(a:holder, "__holder_as_get_deepcopy_get") + return a:holder + endif + let result = copy(a:holder) + let result.__holder_as_get_deepcopy_get = result.get + function! result.get() + return deepcopy(self.__holder_as_get_deepcopy_get()) + endfunction + return result +endfunction + + +function! s:as_set_extend(holder) + if has_key(a:holder, "__holder_as_set_extend_set") + return a:holder + endif + let result = copy(a:holder) + let result.__holder_as_set_extend_set = result.set + function! result.set(value) + let result = deepcopy(extend(self.get(), a:value)) + call self.__holder_as_set_extend_set(result) + endfunction + return result +endfunction + + +function! s:get(name) + return get(s:holder_module, a:name, {}) +endfunction + + +function! s:exists(name) + return has_key(s:holder_module, a:name) +endfunction + + +function! s:make(name, ...) + let module = s:get(a:name) + if empty(module) + return {} + endif + return call(module.make, a:000, module) +endfunction + + +" for s:name in s:holder_module_names +" execute +" \ "function! s:" . tolower(substitute(s:name, '\.', '_', 'g')) . "(...)\n" +" \ " return call(s:" . s:name . ".make, a:000, s:" . s:name . ")\n" +" \ "endfunction\n" +" endfor + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Any.vim b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Any.vim new file mode 100644 index 000000000..743228135 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Any.vim @@ -0,0 +1,82 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Unlocker#Holder#Any#import() abort', printf("return map({'is_option': '', '_vital_depends': '', 'throw': '', 'is_variable': '', 'is_value': '', 'is_holder': '', 'make': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:_is_string(src) + return type(a:src) == type("") +endfunction + +function! s:_vital_loaded(V) + let s:V = a:V + let s:Value = a:V.import("Unlocker.Holder.Value") + let s:Variable = a:V.import("Unlocker.Holder.Variable") + let s:Multi = a:V.import("Unlocker.Holder.Multi") + let s:Register = a:V.import("Unlocker.Holder.Register") +endfunction + + +function! s:_vital_depends() + return [ +\ "Unlocker.Holder.Variable", +\ "Unlocker.Holder.Value", +\ "Unlocker.Holder.Multi", +\ "Unlocker.Holder.Register", +\ ] +endfunction + + +function! s:is_holder(rhs) + return type(a:rhs) == type({}) +\ && type(get(a:rhs, "get", "")) == type(function("tr")) +\ && type(get(a:rhs, "set", "")) == type(function("tr")) +endfunction + + +function! s:is_option(rhs) + return type(a:rhs) == type("") +\ && exists("&" . a:rhs) +endfunction + + +function! s:is_variable(rhs) + return !s:is_option(a:rhs) +\ && s:_is_string(a:rhs) +\ && a:rhs =~ '^[a-zA-Z&]' +\ && exists(a:rhs) +endfunction + + +function! s:is_value(rhs) + let type = type(a:rhs) + return type == type({}) || type == type([]) +endfunction + + +function! s:throw(exp) + execute "throw" string(a:exp) +endfunction + + +function! s:make(rhs, ...) + return a:0 >= 1 ? s:Multi.make(map([a:rhs] + a:000, "s:make(v:val)")) +\ : s:is_holder(a:rhs) ? a:rhs +\ : s:Value.is_makeable(a:rhs) ? s:Value.make(a:rhs) +\ : s:Variable.is_makeable(a:rhs) ? s:Variable.make(a:rhs) +\ : s:Register.is_makeable(a:rhs) ? s:Register.make(a:rhs) +\ : s:is_option(a:rhs) ? s:Variable.make("&" . a:rhs) +\ : s:throw("vital-unlocker Unlocker.Holder.Any.make() : No supported value.") +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Buffer/Text.vim b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Buffer/Text.vim new file mode 100644 index 000000000..1611737e8 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Buffer/Text.vim @@ -0,0 +1,60 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Unlocker#Holder#Buffer#Text#import() abort', printf("return map({'_vital_depends': '', 'is_makeable': '', 'make': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim +let s:obj = {} + + + +function! s:_vital_loaded(V) + let s:Buffer = a:V.import("Coaster.Buffer") +endfunction + + +function! s:_vital_depends() + return [ +\ "Coaster.Buffer", +\ ] +endfunction + + + +function! s:obj.get() + return getbufline(self.__expr, self.__lnum, self.__end) +endfunction + + +function! s:obj.set(value) + if bufnr(self.__expr) == bufnr("%") + call setline(self.__lnum, a:value) + else + call s:Buffer.setbufline(self.__expr, self.__lnum, a:value) + endif + return self +endfunction + + +function! s:is_makeable(rhs) + return bufexists(a:rhs) +endfunction + + +function! s:make(expr, ...) + let result = deepcopy(s:obj) + let result.__expr = a:expr + let result.__lnum = get(a:, 1, 1) + let result.__end = get(a:, 2, "$") + return result +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Buffer/Undofile.vim b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Buffer/Undofile.vim new file mode 100644 index 000000000..a760d4a72 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Buffer/Undofile.vim @@ -0,0 +1,45 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Unlocker#Holder#Buffer#Undofile#import() abort', printf("return map({'is_makeable': '', 'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim +let s:obj = {} + + +function! s:obj.get() + let file = get(a:, 1, tempname()) + execute "wundo!" file + return file +endfunction + + +function! s:obj.set(value) + if filereadable(a:value) + silent execute "rundo" a:value + else + throw "vital-unlocker Unlocker.Holder.Buffer.Undofile : No filereadable '" . a:value . "'." + endif + return self +endfunction + + +function! s:is_makeable(rhs) + return filereadable(a:rhs) +endfunction + + +function! s:make() + let result = deepcopy(s:obj) + return result +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/File.vim b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/File.vim new file mode 100644 index 000000000..5700bed95 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/File.vim @@ -0,0 +1,40 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Unlocker#Holder#File#import() abort', printf("return map({'is_makeable': '', 'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +let s:obj = {} + +function! s:obj.get() + return readfile(self.__file) +endfunction + + +function! s:obj.set(value) + call writefile(a:value, self.__file) + return self +endfunction + + +function! s:is_makeable(expr) + return filereadable(a:expr) +endfunction + + +function! s:make(expr) + let result = deepcopy(s:obj) + let result.__file = a:expr + return result +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Multi.vim b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Multi.vim new file mode 100644 index 000000000..ff8907178 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Multi.vim @@ -0,0 +1,43 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Unlocker#Holder#Multi#import() abort', printf("return map({'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:_as_list(value) + return type(a:value) == type([]) ? a:value : [a:value] +endfunction + +let s:obj = {} + +function! s:obj.get() + return map(copy(self.__holders), "v:val.get()") +endfunction + + +function! s:obj.set(values) + call map(copy(self.__holders), "v:val.set(a:values[v:key])") + return self +endfunction + + +function! s:make(holders) + let result = deepcopy(s:obj) + let result.__holders = s:_as_list(a:holders) + return result +endfunction + + + + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Option.vim b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Option.vim new file mode 100644 index 000000000..d93e113d1 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Option.vim @@ -0,0 +1,42 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Unlocker#Holder#Option#import() abort', printf("return map({'is_makeable': '', 'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim +let s:obj = {} + + +function! s:obj.get() + return eval(self.__name) +endfunction + + +function! s:obj.set(value) + execute "let " . self.__name . " = a:value" + return self +endfunction + + +function! s:is_makeable(rhs) + return type(a:rhs) == type("") +\ && a:rhs =~ '^[a-zA-Z&]' +\ && exists(a:rhs) +endfunction + + +function! s:make(name) + let result = deepcopy(s:obj) + let result.__name = a:name + return result +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Position.vim b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Position.vim new file mode 100644 index 000000000..f50533d4a --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Position.vim @@ -0,0 +1,40 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Unlocker#Holder#Position#import() abort', printf("return map({'is_makeable': '', 'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +let s:obj = {} + +function! s:obj.get() + return getpos(self.__expr) +endfunction + + +function! s:obj.set(value) + call setpos(self.__expr, a:value) + return self +endfunction + + +function! s:is_makeable(expr) + return a:expr =~ '\.\|''[a-zA-Z]' +endfunction + + +function! s:make(expr) + let result = deepcopy(s:obj) + let result.__expr = a:expr + return result +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Register.vim b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Register.vim new file mode 100644 index 000000000..61922aa5a --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Register.vim @@ -0,0 +1,45 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Unlocker#Holder#Register#import() abort', printf("return map({'is_makeable': '', 'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +let s:obj = {} + +function! s:obj.get() + return getreg(self.__name) +endfunction + + +function! s:obj.set(value) + if self.__option == "" + call setreg(self.__name, a:value) + else + call setreg(self.__name, a:value, self.__option) + endif + return self +endfunction + + +function! s:is_makeable(expr) + return type(a:expr) == type("") && a:expr =~# '^@.\+' +endfunction + + +function! s:make(expr, ...) + let result = deepcopy(s:obj) + let result.__name = (strlen(a:expr) == 1 ? a:expr : a:expr[1:]) + let result.__option = get(a:, 1, "") + return result +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Value.vim b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Value.vim new file mode 100644 index 000000000..ab8c761a0 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Value.vim @@ -0,0 +1,67 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Unlocker#Holder#Value#import() abort', printf("return map({'is_makeable': '', 'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:_copy_list(lhs, rhs) + call filter(a:lhs, "0") + for i in range(len(a:rhs)) + call add(a:lhs, a:rhs[i]) + endfor +endfunction + + +function! s:_copy_dict(lhs, rhs) + call filter(a:lhs, "0") + call extend(a:lhs, a:rhs) +endfunction + + +function! s:_copy(lhs, rhs) + return type(a:lhs) == type({}) ? s:_copy_dict(a:lhs, a:rhs) +\ : type(a:lhs) == type([]) ? s:_copy_list(a:lhs, a:rhs) +\ : 0 +endfunction + + +let s:obj = {} + +function! s:obj.get() + return self.__value +endfunction + + +function! s:obj.set(value) + call s:_copy(self.__value, a:value) + return self +endfunction + + +function! s:is_makeable(rhs) + let type = type(a:rhs) + return type == type({}) || type == type([]) +endfunction + + +function! s:make(value) + if !(type(a:value) == type([]) +\ || type(a:value) == type({})) + throw "vital-unlocker Unlocker.Holder.Value.make() : No supported value type." + endif + let result = deepcopy(s:obj) + let result.__value = a:value + return result +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Variable.vim b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Variable.vim new file mode 100644 index 000000000..aabf6512c --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Variable.vim @@ -0,0 +1,42 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Unlocker#Holder#Variable#import() abort', printf("return map({'is_makeable': '', 'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim +let s:obj = {} + + +function! s:obj.get() + return eval(self.__name) +endfunction + + +function! s:obj.set(value) + execute "let " . self.__name . " = a:value" + return self +endfunction + + +function! s:is_makeable(rhs) + return type(a:rhs) == type("") +\ && a:rhs =~ '^[a-zA-Z&]' +\ && exists(a:rhs) +endfunction + + +function! s:make(name) + let result = deepcopy(s:obj) + let result.__name = a:name + return result +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Winview.vim b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Winview.vim new file mode 100644 index 000000000..c6e162e9f --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Winview.vim @@ -0,0 +1,39 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Unlocker#Holder#Winview#import() abort', printf("return map({'is_makeable': '', 'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + +let s:obj = {} + +function! s:obj.get() + return winsaveview() +endfunction + + +function! s:obj.set(value) + call winrestview(a:value) + return self +endfunction + + +function! s:is_makeable(expr) + return 0 +endfunction + + +function! s:make() + let result = deepcopy(s:obj) + return result +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Unlocker/Rocker.vim b/bundle/vim-over/autoload/vital/_over/Unlocker/Rocker.vim new file mode 100644 index 000000000..69e5c1bd0 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Unlocker/Rocker.vim @@ -0,0 +1,100 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Unlocker#Rocker#import() abort', printf("return map({'file': '', '_vital_depends': '', 'as_locker_by_holder': '', 'any_by_holder': '', 'is_locker': '', 'any': '', 'option': '', 'variable': '', 'as_locker': '', 'get': '', 'lock': '', 'value': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:_vital_loaded(V) + let s:V = a:V + let s:Holder = a:V.import("Unlocker.Holder") + let s:Multi = a:V.import("Unlocker.Rocker.Multi") + let s:HolderBase = a:V.import("Unlocker.Rocker.HolderBase") +endfunction + + +function! s:_vital_depends() + return [ +\ "Unlocker.Rocker.HolderBase", +\ "Unlocker.Rocker.Multi", +\ "Unlocker.Holder", +\ ] +endfunction + + + +function! s:is_locker(obj) + return type(a:obj) == type({}) +\ && type(get(a:obj, "lock", "")) == type(function("tr")) +\ && type(get(a:obj, "unlock", "")) == type(function("tr")) +endfunction + + +function! s:as_locker_by_holder(obj) + return s:HolderBase.make(s:Holder.as_get_deepcopy(a:obj)) +endfunction + + +function! s:as_locker(obj) + return s:is_locker(a:obj) ? a:obj : s:as_locker_by_holder(a:obj) +endfunction + + +function! s:any_by_holder(...) + let any = s:Holder.get("Any") + return s:as_locker_by_holder(call(any.make, a:000, any)) +endfunction + + +function! s:any(obj) + return s:is_locker(a:obj) ? a:obj : s:any_by_holder(a:obj) +endfunction + + +function! s:lock(...) + return s:Multi.make(map(copy(a:000), "s:any(v:val)")).lock() +endfunction + + +function! s:get(holdername) + let holder = s:Holder.get(a:holdername) + return s:as_locker_by_holder(call(holder.make, a:000, holder)) +endfunction + + +let s:holders = [ +\ "Value", +\ "Variable", +\ "Option", +\ "File", +\] + + +for s:name in s:holders + execute join([ +\ "function! s:" . tolower(s:name) . "(...)", +\ " let holder = s:Holder.get('". s:name . "')", +\ " return s:as_locker_by_holder(call(holder.make, a:000, holder))", +\ "endfunction", +\ ], "\n") +endfor + + +" function! s:value(value) +" return s:as_locker_by_holder(s:Holder.value(a:value)) +" endfunction +" +" +" function! s:variable(value) +" return s:as_locker_by_holder(s:Holder.variable(a:value)) +" endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Unlocker/Rocker/HolderBase.vim b/bundle/vim-over/autoload/vital/_over/Unlocker/Rocker/HolderBase.vim new file mode 100644 index 000000000..394ec1a70 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Unlocker/Rocker/HolderBase.vim @@ -0,0 +1,55 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Unlocker#Rocker#HolderBase#import() abort', printf("return map({'make': '', 'has_concept': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +let s:locker = {} +function! s:locker.lock() + let self.__old = self.get() + return self +endfunction + + +function! s:locker.unlock() + if !has_key(self, "__old") + return -1 + endif + call self.set(self.__old) + unlet self.__old +endfunction + + +function! s:locker.relock() + call self.unlock() + call self.lock() +endfunction + + +function! s:has_concept(obj) + return type(a:obj) == type({}) +\ && type(get(a:obj, "get", "")) == type(function("tr")) +\ && type(get(a:obj, "set", "")) == type(function("tr")) +endfunction + + +function! s:make(derived) + if !s:has_concept(a:derived) + throw "vital-unlocker Unlocker.Rocker.HolderBase.make() : Don't has locker concept." + endif + let result = extend(deepcopy(s:locker), a:derived) + return result +endfunction + + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Unlocker/Rocker/Multi.vim b/bundle/vim-over/autoload/vital/_over/Unlocker/Rocker/Multi.vim new file mode 100644 index 000000000..6dd1ebf0f --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Unlocker/Rocker/Multi.vim @@ -0,0 +1,45 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Unlocker#Rocker#Multi#import() abort', printf("return map({'make': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:_as_list(value) + return type(a:value) == type([]) ? a:value : [a:value] +endfunction + +let s:obj = {} + +function! s:obj.lock() + call map(copy(self.__rockers), "v:val.lock()") + return self +endfunction + + +function! s:obj.unlock() + call map(copy(self.__rockers), "v:val.unlock()") +endfunction + + +function! s:obj.relock() + call map(copy(self.__rockers), "v:val.relock()") +endfunction + + +function! s:make(rockers) + let result = deepcopy(s:obj) + let result.__rockers = s:_as_list(a:rockers) + return result +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Unlocker/Rocker/Undotree.vim b/bundle/vim-over/autoload/vital/_over/Unlocker/Rocker/Undotree.vim new file mode 100644 index 000000000..d6820875b --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Unlocker/Rocker/Undotree.vim @@ -0,0 +1,68 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Unlocker#Rocker#Undotree#import() abort', printf("return map({'_vital_depends': '', 'make': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +scriptencoding utf-8 +let s:save_cpo = &cpo +set cpo&vim + + +function! s:_vital_loaded(V) + let s:Undofile = a:V.import("Unlocker.Holder.Buffer.Undofile") + let s:Option = a:V.import("Unlocker.Holder.Option") + let s:Base = a:V.import("Unlocker.Rocker.HolderBase") +endfunction + + +function! s:_vital_depends() + return [ +\ "Unlocker.Holder.Buffer.Undofile", +\ "Unlocker.Rocker.HolderBase", +\ ] +endfunction + + +let s:obj = {} + +function! s:obj.lock() + if undotree().seq_last == 0 + call self.__undolevels.lock() + let &l:undolevels = -1 + else + call self.__undofile.lock() + endif + return self +endfunction + + +function! s:obj.unlock() + call self.__undolevels.unlock() + try + call self.__undofile.unlock() + catch /^Vim\%((\a\+)\)\=:E605/ + endtry + return self +endfunction + + +function! s:obj.relock() + call self.unlock() + call self.lock() +endfunction + + +function! s:make() + let result = deepcopy(s:obj) + let result.__undolevels = s:Base.make(s:Option.make("&l:undolevels")) + let result.__undofile = s:Base.make(s:Undofile.make()) + return result +endfunction + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/autoload/vital/_over/Vim/Buffer.vim b/bundle/vim-over/autoload/vital/_over/Vim/Buffer.vim new file mode 100644 index 000000000..1d2e50dba --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Vim/Buffer.vim @@ -0,0 +1,207 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Vim#Buffer#import() abort', printf("return map({'parse_cmdarg': '', '_vital_depends': '', 'read_content': '', 'get_selected_text': '', 'is_cmdwin': '', 'edit_content': '', 'open': '', 'get_last_selected': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +let s:save_cpo = &cpo +set cpo&vim + +let s:t_funcref = type(function('tr')) +let s:t_string = type('') +let s:t_number = type(0) + +function! s:_vital_loaded(V) abort + let s:V = a:V + let s:Guard = s:V.import('Vim.Guard') +endfunction + +function! s:_vital_depends() abort + return ['Vim.Guard'] +endfunction + +if exists('*getcmdwintype') + function! s:is_cmdwin() abort + return getcmdwintype() !=# '' + endfunction +else + function! s:is_cmdwin() abort + return bufname('%') ==# '[Command Line]' + endfunction +endif + +function! s:open(buffer, ...) abort + if a:0 == 1 && (type(a:1) == s:t_string || type(a:1) == s:t_funcref) + " For backward compatibility + let options = {'opener': a:1} + else + let options = get(a:000, 0, {}) + endif + let options = extend({ + \ 'mods': '', + \ 'cmdarg': '', + \ 'opener': empty(a:buffer) ? 'enew' : 'edit', + \}, options + \) + + let guard = s:Guard.store(['&wildignore']) + try + let &wildignore = '' + if type(options.opener) == s:t_funcref + let loaded = !bufloaded(a:buffer) + call options.opener(a:buffer) + elseif a:buffer is 0 || a:buffer is# '' + let loaded = 1 + silent execute options.mods options.opener + enew + else + let loaded = !bufloaded(a:buffer) + if type(a:buffer) == s:t_string + execute options.mods options.opener options.cmdarg '`=a:buffer`' + elseif type(a:buffer) == s:t_number + silent execute options.mods options.opener + execute a:buffer 'buffer' + else + throw 'vital: Vim.Buffer: Unknown {buffer} type.' + endif + endif + finally + call guard.restore() + endtry + return loaded +endfunction + +function! s:get_selected_text(...) abort + echohl WarningMsg + echom "vital: Vim.Buffer: Warning: s:get_selected_text() is deprecated. Use 's:get_last_selected()'." + echohl None + return call('s:get_last_selected', a:000) +endfunction + +" Get the last selected text in visual mode +" without using |gv| to avoid |textlock|. +" NOTE: +" * This function uses |gv| only when using |CTRL-V| +" because |gv| is the only way to get selected text +" when using $ . +" Please see #192 for the details. +" * If you don't care about |textlock|, +" you can use simple version of this function. +" https://github.com/vim-jp/vital.vim/commit/39aae80f3839fdbeebd838ff14d87327a6b889a9 +function! s:get_last_selected() abort + if visualmode() ==# "\" + let save = getreg('"', 1) + let save_type = getregtype('"') + try + normal! gv""y + return @" + finally + call setreg('"', save, save_type) + endtry + else + let [begin, end] = [getpos("'<"), getpos("'>")] + let lastchar = matchstr(getline(end[1])[end[2]-1 :], '.') + if begin[1] ==# end[1] + let lines = [getline(begin[1])[begin[2]-1 : end[2]-2]] + else + let lines = [getline(begin[1])[begin[2]-1 :]] + \ + (end[1] - begin[1] <# 2 ? [] : getline(begin[1]+1, end[1]-1)) + \ + [getline(end[1])[: end[2]-2]] + endif + return join(lines, "\n") . lastchar . (visualmode() ==# 'V' ? "\n" : '') + endif +endfunction + +function! s:read_content(content, ...) abort + let options = extend({ + \ 'tempfile': '', + \ 'fileformat': '', + \ 'encoding': '', + \ 'binary': 0, + \ 'nobinary': 0, + \ 'bad': '', + \ 'edit': 0, + \ 'line': '', + \ 'lockmarks': 0, + \}, get(a:000, 0, {})) + let tempfile = empty(options.tempfile) ? tempname() : options.tempfile + let optnames = [ + \ empty(options.fileformat) ? '' : '++ff=' . options.fileformat, + \ empty(options.encoding) ? '' : '++enc=' . options.encoding, + \ empty(options.binary) ? '' : '++bin', + \ empty(options.nobinary) ? '' : '++nobin', + \ empty(options.bad) ? '' : '++bad=' . options.bad, + \ empty(options.edit) ? '' : '++edit', + \] + let optname = join(filter(optnames, '!empty(v:val)')) + try + call writefile(a:content, tempfile) + execute printf('keepalt keepjumps %s%sread %s%s', + \ options.lockmarks ? 'lockmarks ' : '', + \ options.line, + \ empty(optname) ? '' : optname . ' ', + \ fnameescape(tempfile), + \) + finally + call delete(tempfile) + " To remove 'tempfile' from unlisted-buffer #439 + silent execute 'bwipeout!' fnameescape(tempfile) + endtry +endfunction + +function! s:edit_content(content, ...) abort + let options = extend({ + \ 'edit': 1, + \ 'lockmarks': 0, + \}, get(a:000, 0, {})) + let guard = s:Guard.store(['&l:modifiable']) + let saved_view = winsaveview() + try + let &l:modifiable=1 + silent execute printf( + \ 'keepjumps %s%%delete _', + \ options.lockmarks ? 'lockmarks ' : '', + \) + silent call s:read_content(a:content, options) + silent execute printf( + \ 'keepjumps %s1delete _', + \ options.lockmarks ? 'lockmarks ' : '', + \) + finally + keepjumps call winrestview(saved_view) + call guard.restore() + endtry + setlocal nomodified +endfunction + +function! s:parse_cmdarg(...) abort + let cmdarg = get(a:000, 0, v:cmdarg) + let options = {} + if cmdarg =~# '++enc=' + let options.encoding = matchstr(cmdarg, '++enc=\zs[^ ]\+\ze') + endif + if cmdarg =~# '++ff=' + let options.fileformat = matchstr(cmdarg, '++ff=\zs[^ ]\+\ze') + endif + if cmdarg =~# '++bad=' + let options.bad = matchstr(cmdarg, '++bad=\zs[^ ]\+\ze') + endif + if cmdarg =~# '++bin' + let options.binary = 1 + endif + if cmdarg =~# '++nobin' + let options.nobinary = 1 + endif + if cmdarg =~# '++edit' + let options.edit = 1 + endif + return options +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo + +" vim:set et ts=2 sts=2 sw=2 tw=0: diff --git a/bundle/vim-over/autoload/vital/_over/Vim/Guard.vim b/bundle/vim-over/autoload/vital/_over/Vim/Guard.vim new file mode 100644 index 000000000..73161bc59 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Vim/Guard.vim @@ -0,0 +1,234 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Vim#Guard#import() abort', printf("return map({'_vital_depends': '', '_vital_created': '', 'store': '', '_vital_loaded': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +let s:save_cpo = &cpo +set cpo&vim + +" Use a Funcref as a special term _UNDEFINED +function! s:_undefined() abort + return 'undefined' +endfunction +let s:_UNDEFINED = function('s:_undefined') + +function! s:_vital_loaded(V) abort + let s:V = a:V + let s:Prelude = s:V.import('Prelude') + let s:List = s:V.import('Data.List') + let s:Dict = s:V.import('Data.Dict') +endfunction +function! s:_vital_depends() abort + return ['Prelude', 'Data.List', 'Data.Dict'] +endfunction +function! s:_vital_created(module) abort + " define constant variables + if !exists('s:const') + let s:const = {} + let s:const.is_local_variable_supported = + \ v:version > 703 || (v:version == 703 && has('patch560')) + " NOTE: + " The third argument is available from 7.4.242 but it had bug and that + " bug was fixed from 7.4.513 + let s:const.is_third_argument_of_getreg_supported = has('patch-7.4.513') + lockvar s:const + endif + call extend(a:module, s:const) +endfunction +function! s:_throw(msg) abort + throw printf('vital: Vim.Guard: %s', a:msg) +endfunction + +let s:option = {} +function! s:_new_option(name) abort + if a:name !~# '^&' + call s:_throw(printf( + \'An option name "%s" requires to be started from "&"', a:name + \)) + elseif !exists(a:name) + call s:_throw(printf( + \'An option name "%s" does not exist', a:name + \)) + endif + let option = copy(s:option) + let option.name = a:name + let option.value = eval(a:name) + return option +endfunction +function! s:option.restore() abort + execute printf('let %s = %s', self.name, string(self.value)) +endfunction + +let s:register = {} +function! s:_new_register(name) abort + if len(a:name) != 2 + call s:_throw(printf( + \'A register name "%s" requires to be "@" + a single character', a:name + \)) + elseif a:name !~# '^@' + call s:_throw(printf( + \'A register name "%s" requires to be started from "@"', a:name + \)) + elseif a:name =~# '^@[:.%]$' + call s:_throw(printf( + \'A register name "%s" is read only', a:name + \)) + elseif a:name !~# '^@[@0-9a-zA-Z#=*+~_/-]$' + call s:_throw(printf( + \'A register name "%s" does not exist. See ":help let-register"', a:name + \)) + endif + let name = a:name ==# '@@' ? '' : a:name[1] + let register = copy(s:register) + let register.name = name + if s:const.is_third_argument_of_getreg_supported + let register.value = getreg(name, 1, 1) + else + let register.value = getreg(name, 1) + endif + let register.type = getregtype(name) + return register +endfunction +function! s:register.restore() abort + " https://github.com/vim/vim/commit/5a50c2255c447838d08d3b4895a3be3a41cd8eda + if has('patch-7.4.243') || self.name !=# '=' + call setreg(self.name, self.value, self.type) + else + let @= = self.value + endif +endfunction + +let s:environment = {} +function! s:_new_environment(name) abort + if a:name !~# '^\$' + call s:_throw(printf( + \'An environment variable name "%s" requires to be started from "$"', a:name + \)) + elseif !exists(a:name) + call s:_throw(printf( + \'An environment variable name "%s" does not exist. While Vim cannot unlet environment variable, it requires to exist', a:name + \)) + endif + let environment = copy(s:environment) + let environment.name = a:name + let environment.value = eval(a:name) + return environment +endfunction +function! s:environment.restore() abort + execute printf('let %s = %s', self.name, string(self.value)) +endfunction + +let s:variable = {} +function! s:_new_variable(name, ...) abort + if a:0 == 0 + let m = matchlist(a:name, '^\([bwtg]:\)\(.*\)$') + if empty(m) + call s:_throw(printf( + \ join([ + \ 'An variable name "%s" requires to start from b:, w:, t:, or g:', + \ 'while no {namespace} is specified', + \ ]), + \ a:name, + \)) + endif + let [prefix, name] = m[1 : 2] + let namespace = eval(prefix) + else + let name = a:name + let namespace = a:1 + endif + let variable = copy(s:variable) + let variable.name = name + let variable.value = get(namespace, name, s:_UNDEFINED) + let variable.value = + \ type(variable.value) == type({}) || type(variable.value) == type([]) + \ ? deepcopy(variable.value) + \ : variable.value + let variable._namespace = namespace + return variable +endfunction +function! s:variable.restore() abort + " unlet the variable to prevent variable type mis-match in case + silent! unlet! self._namespace[self.name] + if type(self.value) == type(s:_UNDEFINED) && self.value == s:_UNDEFINED + " do nothing, leave the variable as undefined + else + let self._namespace[self.name] = self.value + endif +endfunction + +let s:instance = {} +function! s:_new_instance(instance, ...) abort + let shallow = get(a:000, 0, 0) + if !s:Prelude.is_list(a:instance) && !s:Prelude.is_dict(a:instance) + call s:_throw(printf( + \'An instance "%s" requires to be List or Dictionary', string(a:instance) + \)) + endif + let instance = copy(s:instance) + let instance.instance = a:instance + let instance.values = shallow ? copy(a:instance) : deepcopy(a:instance) + return instance +endfunction +function! s:instance.restore() abort + if s:Prelude.is_list(self.instance) + call s:List.clear(self.instance) + else + call s:Dict.clear(self.instance) + endif + call extend(self.instance, self.values) +endfunction + +let s:guard = {} +function! s:store(targets) abort + let resources = [] + for meta in a:targets + if s:Prelude.is_list(meta) + if len(meta) == 1 + call add(resources, s:_new_instance(meta[0])) + elseif len(meta) == 2 + if s:Prelude.is_string(meta[0]) + call add(resources, call('s:_new_variable', meta)) + else + call add(resources, call('s:_new_instance', meta)) + endif + else + call s:_throw('List assignment requires one or two elements') + endif + elseif type(meta) == type('') + if meta =~# '^[bwtgls]:' + " Note: + " To improve an error message, handle l:XXX or s:XXX as well + call add(resources, s:_new_variable(meta)) + elseif meta =~# '^&' + call add(resources, s:_new_option(meta)) + elseif meta =~# '^@' + call add(resources, s:_new_register(meta)) + elseif meta =~# '^\$' + call add(resources, s:_new_environment(meta)) + else + call s:_throw(printf( + \ 'Unknown value "%s" was specified', + \ meta + \)) + endif + endif + unlet meta + endfor + let guard = copy(s:guard) + let guard._resources = resources + return guard +endfunction +function! s:guard.restore() abort + for resource in self._resources + call resource.restore() + endfor +endfunction + +let &cpo = s:save_cpo +unlet! s:save_cpo +" vim:set et ts=2 sts=2 sw=2 tw=0 fdm=marker: diff --git a/bundle/vim-over/autoload/vital/_over/Vim/Message.vim b/bundle/vim-over/autoload/vital/_over/Vim/Message.vim new file mode 100644 index 000000000..da9118917 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Vim/Message.vim @@ -0,0 +1,74 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Vim#Message#import() abort', printf("return map({'capture': '', 'echomsg': '', 'echo': '', 'warn': '', 'get_hit_enter_max_length': '', 'error': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +let s:save_cpo = &cpo +set cpo&vim + + + +function! s:echo(hl, msg) abort + execute 'echohl' a:hl + try + echo a:msg + finally + echohl None + endtry +endfunction + +function! s:echomsg(hl, msg) abort + execute 'echohl' a:hl + try + for m in split(a:msg, "\n") + echomsg m + endfor + finally + echohl None + endtry +endfunction + +function! s:error(msg) abort + call s:echomsg('ErrorMsg', a:msg) +endfunction + +function! s:warn(msg) abort + call s:echomsg('WarningMsg', a:msg) +endfunction + +function! s:capture(command) abort + try + redir => out + silent execute a:command + finally + redir END + endtry + return out +endfunction + +" * Get max length of |hit-enter|. +" If a string length of a message is greater than the max length, +" Vim waits for user input according to |hit-enter|. +" XXX: Those fixed values may be different between different OSes? +" Currently tested on only Windows. +function! s:get_hit_enter_max_length() abort + let maxlen = &columns * &cmdheight - 1 + if &ruler + " TODO + endif + if &showcmd + let maxlen -= 11 + endif + return maxlen +endfunction + + + +let &cpo = s:save_cpo +unlet s:save_cpo + +" vim:set et ts=2 sts=2 sw=2 tw=0: diff --git a/bundle/vim-over/autoload/vital/_over/Vim/Type.vim b/bundle/vim-over/autoload/vital/_over/Vim/Type.vim new file mode 100644 index 000000000..be0cfa801 --- /dev/null +++ b/bundle/vim-over/autoload/vital/_over/Vim/Type.vim @@ -0,0 +1,92 @@ +" ___vital___ +" NOTE: lines between '" ___vital___' is generated by :Vitalize. +" Do not mofidify the code nor insert new lines before '" ___vital___' +function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') +endfunction +execute join(['function! vital#_over#Vim#Type#import() abort', printf("return map({'is_comparable': '', '_vital_created': '', 'is_predicate': '', 'is_numeric': '', 'is_special': ''}, \"vital#_over#function('%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n") +delfunction s:_SID +" ___vital___ +let s:types = { +\ 'number': 0, +\ 'string': 1, +\ 'func': 2, +\ 'list': 3, +\ 'dict': 4, +\ 'float': 5, +\ 'bool': 6, +\ 'none': 7, +\ 'job': 8, +\ 'channel': 9, +\ } +lockvar 1 s:types + +let s:type_names = { +\ '0': 'number', +\ '1': 'string', +\ '2': 'func', +\ '3': 'list', +\ '4': 'dict', +\ '5': 'float', +\ '6': 'bool', +\ '7': 'none', +\ '8': 'job', +\ '9': 'channel', +\ } +lockvar 1 s:type_names + +function! s:_vital_created(module) abort + let a:module.types = s:types + let a:module.type_names = s:type_names +endfunction + + +function! s:is_numeric(value) abort + let t = type(a:value) + return t == s:types.number || t == s:types.float +endfunction + +function! s:is_special(value) abort + let t = type(a:value) + return t == s:types.bool || t == s:types.none +endfunction + +function! s:is_predicate(value) abort + let t = type(a:value) + return t == s:types.number || t == s:types.string || + \ t == s:types.bool || t == s:types.none +endfunction + +function! s:is_comparable(value1, value2) abort + if !exists('s:is_comparable_cache') + let s:is_comparable_cache = s:_make_is_comparable_cache() + endif + return s:is_comparable_cache[type(a:value1)][type(a:value2)] +endfunction + +function! s:_make_is_comparable_cache() abort + let vals = [ + \ 0, '', function('type'), [], {}, 0.0, + \ get(v:, 'false'), + \ get(v:, 'null'), + \ exists('*test_null_job') ? test_null_job() : 0, + \ exists('*test_null_channel') ? test_null_channel() : 0, + \ ] + + let result = [] + for l:V1 in vals + let result_V1 = [] + let result += [result_V1] + for l:V2 in vals + try + let _ = V1 == V2 + let result_V1 += [1] + catch + let result_V1 += [0] + endtry + unlet V2 + endfor + unlet V1 + endfor + return result +endfunction diff --git a/bundle/vim-over/autoload/vital/over.vim b/bundle/vim-over/autoload/vital/over.vim new file mode 100644 index 000000000..eb8aeb606 --- /dev/null +++ b/bundle/vim-over/autoload/vital/over.vim @@ -0,0 +1,328 @@ +let s:plugin_name = expand(':t:r') +let s:vital_base_dir = expand(':h') +let s:project_root = expand(':h:h:h') +let s:is_vital_vim = s:plugin_name is# 'vital' + +let s:loaded = {} +let s:cache_sid = {} + +" function() wrapper +if v:version > 703 || v:version == 703 && has('patch1170') + function! s:_function(fstr) abort + return function(a:fstr) + endfunction +else + function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') + endfunction + let s:_s = '' . s:_SID() . '_' + function! s:_function(fstr) abort + return function(substitute(a:fstr, 's:', s:_s, 'g')) + endfunction +endif + +function! vital#{s:plugin_name}#new() abort + return s:new(s:plugin_name) +endfunction + +function! vital#{s:plugin_name}#import(...) abort + if !exists('s:V') + let s:V = s:new(s:plugin_name) + endif + return call(s:V.import, a:000, s:V) +endfunction + +let s:Vital = {} + +function! s:new(plugin_name) abort + let base = deepcopy(s:Vital) + let base._plugin_name = a:plugin_name + return base +endfunction + +function! s:vital_files() abort + if !exists('s:vital_files') + let s:vital_files = map( + \ s:is_vital_vim ? s:_global_vital_files() : s:_self_vital_files(), + \ 'fnamemodify(v:val, ":p:gs?[\\\\/]?/?")') + endif + return copy(s:vital_files) +endfunction +let s:Vital.vital_files = s:_function('s:vital_files') + +function! s:import(name, ...) abort dict + let target = {} + let functions = [] + for a in a:000 + if type(a) == type({}) + let target = a + elseif type(a) == type([]) + let functions = a + endif + unlet a + endfor + let module = self._import(a:name) + if empty(functions) + call extend(target, module, 'keep') + else + for f in functions + if has_key(module, f) && !has_key(target, f) + let target[f] = module[f] + endif + endfor + endif + return target +endfunction +let s:Vital.import = s:_function('s:import') + +function! s:load(...) abort dict + for arg in a:000 + let [name; as] = type(arg) == type([]) ? arg[: 1] : [arg, arg] + let target = split(join(as, ''), '\W\+') + let dict = self + let dict_type = type({}) + while !empty(target) + let ns = remove(target, 0) + if !has_key(dict, ns) + let dict[ns] = {} + endif + if type(dict[ns]) == dict_type + let dict = dict[ns] + else + unlet dict + break + endif + endwhile + if exists('dict') + call extend(dict, self._import(name)) + endif + unlet arg + endfor + return self +endfunction +let s:Vital.load = s:_function('s:load') + +function! s:unload() abort dict + let s:loaded = {} + let s:cache_sid = {} + unlet! s:vital_files +endfunction +let s:Vital.unload = s:_function('s:unload') + +function! s:exists(name) abort dict + if a:name !~# '\v^\u\w*%(\.\u\w*)*$' + throw 'vital: Invalid module name: ' . a:name + endif + return s:_module_path(a:name) isnot# '' +endfunction +let s:Vital.exists = s:_function('s:exists') + +function! s:search(pattern) abort dict + let paths = s:_extract_files(a:pattern, self.vital_files()) + let modules = sort(map(paths, 's:_file2module(v:val)')) + return s:_uniq(modules) +endfunction +let s:Vital.search = s:_function('s:search') + +function! s:plugin_name() abort dict + return self._plugin_name +endfunction +let s:Vital.plugin_name = s:_function('s:plugin_name') + +function! s:_self_vital_files() abort + let builtin = printf('%s/__%s__/', s:vital_base_dir, s:plugin_name) + let installed = printf('%s/_%s/', s:vital_base_dir, s:plugin_name) + let base = builtin . ',' . installed + return split(globpath(base, '**/*.vim', 1), "\n") +endfunction + +function! s:_global_vital_files() abort + let pattern = 'autoload/vital/__*__/**/*.vim' + return split(globpath(&runtimepath, pattern, 1), "\n") +endfunction + +function! s:_extract_files(pattern, files) abort + let tr = {'.': '/', '*': '[^/]*', '**': '.*'} + let target = substitute(a:pattern, '\.\|\*\*\?', '\=tr[submatch(0)]', 'g') + let regexp = printf('autoload/vital/[^/]\+/%s.vim$', target) + return filter(a:files, 'v:val =~# regexp') +endfunction + +function! s:_file2module(file) abort + let filename = fnamemodify(a:file, ':p:gs?[\\/]?/?') + let tail = matchstr(filename, 'autoload/vital/_\w\+/\zs.*\ze\.vim$') + return join(split(tail, '[\\/]\+'), '.') +endfunction + +" @param {string} name e.g. Data.List +function! s:_import(name) abort dict + if has_key(s:loaded, a:name) + return copy(s:loaded[a:name]) + endif + let module = self._get_module(a:name) + if has_key(module, '_vital_created') + call module._vital_created(module) + endif + let export_module = filter(copy(module), 'v:key =~# "^\\a"') + " Cache module before calling module.vital_loaded() to avoid cyclic + " dependences but remove the cache if module._vital_loaded() fails. + " let s:loaded[a:name] = export_module + let s:loaded[a:name] = export_module + if has_key(module, '_vital_loaded') + try + call module._vital_loaded(vital#{s:plugin_name}#new()) + catch + unlet s:loaded[a:name] + throw 'vital: fail to call ._vital_loaded(): ' . v:exception + endtry + endif + return copy(s:loaded[a:name]) +endfunction +let s:Vital._import = s:_function('s:_import') + +" s:_get_module() returns module object wihch has all script local functions. +function! s:_get_module(name) abort dict + let funcname = s:_import_func_name(self.plugin_name(), a:name) + try + return call(funcname, []) + catch /^Vim\%((\a\+)\)\?:E117/ + return s:_get_builtin_module(a:name) + endtry +endfunction + +function! s:_get_builtin_module(name) abort + return s:sid2sfuncs(s:_module_sid(a:name)) +endfunction + +if s:is_vital_vim + " For vital.vim, we can use s:_get_builtin_module directly + let s:Vital._get_module = s:_function('s:_get_builtin_module') +else + let s:Vital._get_module = s:_function('s:_get_module') +endif + +function! s:_import_func_name(plugin_name, module_name) abort + return printf('vital#_%s#%s#import', a:plugin_name, s:_dot_to_sharp(a:module_name)) +endfunction + +function! s:_module_sid(name) abort + let path = s:_module_path(a:name) + if !filereadable(path) + throw 'vital: module not found: ' . a:name + endif + let vital_dir = s:is_vital_vim ? '__\w\+__' : printf('_\{1,2}%s\%%(__\)\?', s:plugin_name) + let base = join([vital_dir, ''], '[/\\]\+') + let p = base . substitute('' . a:name, '\.', '[/\\\\]\\+', 'g') + let sid = s:_sid(path, p) + if !sid + call s:_source(path) + let sid = s:_sid(path, p) + if !sid + throw printf('vital: cannot get from path: %s', path) + endif + endif + return sid +endfunction + +function! s:_module_path(name) abort + return get(s:_extract_files(a:name, s:vital_files()), 0, '') +endfunction + +function! s:_module_sid_base_dir() abort + return s:is_vital_vim ? &rtp : s:project_root +endfunction + +function! s:_dot_to_sharp(name) abort + return substitute(a:name, '\.', '#', 'g') +endfunction + +function! s:_source(path) abort + execute 'source' fnameescape(a:path) +endfunction + +" @vimlint(EVL102, 1, l:_) +" @vimlint(EVL102, 1, l:__) +function! s:_sid(path, filter_pattern) abort + let unified_path = s:_unify_path(a:path) + if has_key(s:cache_sid, unified_path) + return s:cache_sid[unified_path] + endif + for line in filter(split(s:_execute(':scriptnames'), "\n"), 'v:val =~# a:filter_pattern') + let [_, sid, path; __] = matchlist(line, '^\s*\(\d\+\):\s\+\(.\+\)\s*$') + if s:_unify_path(path) is# unified_path + let s:cache_sid[unified_path] = sid + return s:cache_sid[unified_path] + endif + endfor + return 0 +endfunction + +" We want to use a execute() builtin function instead of s:_execute(), +" however there is a bug in execute(). +" execute() returns empty string when it is called in +" completion function of user defined ex command. +" https://github.com/vim-jp/issues/issues/1129 +function! s:_execute(cmd) abort + let [save_verbose, save_verbosefile] = [&verbose, &verbosefile] + set verbose=0 verbosefile= + redir => res + silent! execute a:cmd + redir END + let [&verbose, &verbosefile] = [save_verbose, save_verbosefile] + return res +endfunction + +if filereadable(expand(':r') . '.VIM') " is case-insensitive or not + let s:_unify_path_cache = {} + " resolve() is slow, so we cache results. + " Note: On windows, vim can't expand path names from 8.3 formats. + " So if getting full path via and $HOME was set as 8.3 format, + " vital load duplicated scripts. Below's :~ avoid this issue. + function! s:_unify_path(path) abort + if has_key(s:_unify_path_cache, a:path) + return s:_unify_path_cache[a:path] + endif + let value = tolower(fnamemodify(resolve(fnamemodify( + \ a:path, ':p')), ':~:gs?[\\/]?/?')) + let s:_unify_path_cache[a:path] = value + return value + endfunction +else + function! s:_unify_path(path) abort + return resolve(fnamemodify(a:path, ':p:gs?[\\/]?/?')) + endfunction +endif + +" copied and modified from Vim.ScriptLocal +let s:SNR = join(map(range(len("\")), '"[\\x" . printf("%0x", char2nr("\"[v:val])) . "]"'), '') +function! s:sid2sfuncs(sid) abort + let fs = split(s:_execute(printf(':function /^%s%s_', s:SNR, a:sid)), "\n") + let r = {} + let pattern = printf('\m^function\s%d_\zs\w\{-}\ze(', a:sid) + for fname in map(fs, 'matchstr(v:val, pattern)') + let r[fname] = function(s:_sfuncname(a:sid, fname)) + endfor + return r +endfunction + +"" Return funcname of script local functions with SID +function! s:_sfuncname(sid, funcname) abort + return printf('%s_%s', a:sid, a:funcname) +endfunction + +if exists('*uniq') + function! s:_uniq(list) abort + return uniq(a:list) + endfunction +else + function! s:_uniq(list) abort + let i = len(a:list) - 1 + while 0 < i + if a:list[i] ==# a:list[i - 1] + call remove(a:list, i) + endif + let i -= 1 + endwhile + return a:list + endfunction +endif diff --git a/bundle/vim-over/autoload/vital/over.vital b/bundle/vim-over/autoload/vital/over.vital new file mode 100644 index 000000000..eddb89bb9 --- /dev/null +++ b/bundle/vim-over/autoload/vital/over.vital @@ -0,0 +1,43 @@ +over +e67960bda7f797f9a494215e624950346a1c43cd + +Over +Over.Commandline +Over.Commandline.Modules.Doautocmd +Over.Commandline.Base +Over.Commandline.Maker +Over.Commandline.Modules +Over.Commandline.Modules.All +Over.Commandline.Modules.BufferComplete +Over.Commandline.Modules.Cancel +Over.Commandline.Modules.CursorMove +Over.Commandline.Modules.Delete +Over.Commandline.Modules.DrawCommandline +Over.Commandline.Modules.ExceptionExit +Over.Commandline.Modules.ExceptionMessage +Over.Commandline.Modules.Execute +Over.Commandline.Modules.ExecuteFailedMessage +Over.Commandline.Modules.Exit +Over.Commandline.Modules.HighlightBufferCursor +Over.Commandline.Modules.HistAdd +Over.Commandline.Modules.History +Over.Commandline.Modules.Incsearch +Over.Commandline.Modules.InsertRegister +Over.Commandline.Modules.KeyMapping +Over.Commandline.Modules.NoInsert +Over.Commandline.Modules.Paste +Over.Commandline.Modules.Redraw +Over.Commandline.Modules.Scroll +Over.Signals +Over.String +Over.Commandline.Modules.AsyncUpdate +Over.Commandline.Modules.Digraphs +Over.Commandline.Modules.IgnoreRegexpBackwardWord +Over.Input +Over.Keymapping +Over.Commandline.Modules.LiteralInsert +Over.Exception +Unlocker.Rocker +Unlocker.Rocker.Undotree +Unlocker.Holder +Coaster.Highlight diff --git a/bundle/vim-over/doc/over.jax b/bundle/vim-over/doc/over.jax new file mode 100644 index 000000000..42b3e1ab2 --- /dev/null +++ b/bundle/vim-over/doc/over.jax @@ -0,0 +1,297 @@ +*over.txt* |:s| のパターンをハイライトするプラグイン + +============================================================================== +目次 *over-contents* + +概要 |over-introduction| +インターフェース |over-interface| + コマンド |over-commands| +設定 |over-setting| + over の変数 |over-variables| +over のコマンドラインのハイライト |over-command_line-highlight| +over のコマンドラインのキーマッピング |over-command_line-key-mappings| +over のコマンドラインの autocmd |over-command_line-autocmd| + + +============================================================================== +概要 *over-introduction* + +*over.vim* は |:substitute| の {pattern} をハイライトするプラグインです。 +この機能を使用する場合、コマンドラインではなくてコマンドラインウィンドウから +|:substitute| を行う必要があります。 +また、この場合は {pattern} のみがハイライトされます。 + +|:OverCommandLine| を使用すると {pattern} がハイライトされ、{string} のプレ +ビューも行われます。 + +Requirements: + Vim 7.3 or above. + |strchars()| and |+conceal| + + +============================================================================== +インターフェース *over-interface* + +------------------------------------------------------------------------------ +コマンド *over-commands* + +:OverCommandLine [{input}] *:OverCommandLine* + |over.vim| 独自のコマンドラインを使用して |:substitute| を行います。 + このコマンドラインを使用すると {pattern} のハイライトを行い、{string} + のプレビューも行われます。 + ただし、独自のコマンドラインなので特定のキーマッピングのみ使用できま + す。 + 使用できるキーマッピングは |over-command_line-key-mappings| を参照して + 下さい。 + {input} を渡すとその文字列が入力された状態で開始されます。 + +:OverCommandLineNoremap {lhs} {rhs} *:OverCommandLineNoremap* + コマンドラインで使用するキーを設定します。 + {lhs} のキーが {rhs} に割り当てられます。 + また、再マップは行われません。 + この設定は |g:over_command_line_key_mappings| に反映されます。 +Example: > + OverCommandLineNoremap + OverCommandLineNoremap +< + +:OverCommandLineMap {lhs} {rhs} *:OverCommandLineMap* + |:OverCommandLineNoremap| と同等ですが再マップされます。 + +:OverCommandLineUnmap {lhs} *:OverCommandLineUnmap* + {lhs} に設定されているキーマッピングを削除します。 + + +============================================================================== +設定 *over-setting* + +------------------------------------------------------------------------------ +over の変数 *over-variables* + +g:over_enable_auto_nohlsearch *g:over_enable_auto_nohlsearch* + 1 が設定されていればコマンドラインウィンドウで |:s| した後に自動的に + |nohlsearch| を呼び出します。 +Default: > + let g:over_enable_auto_nohlsearch = 1 +< + +g:over_enable_cmd_window *g:over_enable_cmd_window* + 1 が設定されていればコマンドラインウィンドウで |:s| 時にパターン箇所の + ハイライトを行います。 +Default: > + let g:over_enable_cmd_window = 1 +< + +g:over_command_line_prompt *g:over_command_line_prompt* + |:OverCommandLine| のプロンプトです。 +Default: > + let g:over_command_line_prompt = "> " +< + +g:over_command_line_key_mappings *g:over_command_line_key_mappings* + コマンドラインで使用されるキーマッピングを設定します。 + {lhs} に複数のキーを設定することもできます。 +Example: > + " に + " に割り当てる + " でコマンドラインを抜ける + let g:over_command_line_key_mappings = { + \ "\" : "\", + \ "\" : "\", + \ "\\" : "\", + \} +< + また、以下のようにして式を展開することも出います。 +Example: > + " を入力すると "expand('%')" を評価した値が挿入される + let g:over_command_line_key_mappings = { + \ "\" : { + \ "expr" : 1, + \ "key" : "expand('%')", + \ } + \} +< + + *g:over#command_line#search#enable_incsearch* +g:over#command_line#search#enable_incsearch + 0 以外が設定されていれば :/ or :? 時にそのパータンをハイライトする。 +Default: > + let g:over#command_line#search#enable_incsearch = 1 +< + *g:over#command_line#search#enable_move_cursor* +g:over#command_line#search#enable_move_cursor + 0 以外が設定されていれば :/ or :? 時にそのパータンへカーソルを移動す + る。 +Default: > + let g:over#command_line#search#enable_move_cursor = 0 +< + *g:over#command_line#paste_escape_chars* +g:over#command_line#paste_escape_chars + 時に挿入するテキストを \ でエスケープする文字を設定する。 +Example: > + " $foo.bar / 2 + 1 を挿入すると + " \$foo\.bar \/ 2 + 1 が挿入される + let g:over#command_line#paste_escape_chars = '/.*$^~' +< + +g:over#command_line#paste_filters *g:over#command_line#paste_filters* + 時に挿入するテキストを任意の文字で置換える設定をする。 +Default: > + " 改行コードを "\n" や "\r" に置き換えて挿入する + let g:over#command_line#paste_filters = { + \ "\n" : '\\n', + \ "\r" : '\\r', + \} +< + + *g:over#command_line#substitute#highlight_pattern* +g:over#command_line#substitute#highlight_pattern + |:substitute| の {pattern} をハイライトするグループ名です。 + +Default: > + let g:over#command_line#substitute#highlight_pattern = "Search" +< + *g:over#command_line#substitute#highlight_string* +g:over#command_line#substitute#highlight_string + |:substitute| の {string} をハイライトするグループ名です。 + +Default: > + let g:over#command_line#substitute#highlight_string = "Error" +< + *g:over#command_line#enable_Digraphs* +g:over#command_line#enable_Digraphs + 0 が設定されている場合 |Digraphs| が無効になります。 +Default: > + le g:over#command_line#enable_Digraphs = 1 +< + NONE:|Digraphs| を有効にすると GUI 版の Vim で起動時にちらつく問題が + あるので、それを抑制したい場合はこの設定を利用してください。 + https://github.com/osyo-manga/vital-over/issues + + *g:over#command_line#enable_import_commandline_map* +g:over#command_line#enable_import_commandline_map + 0 が設定されている場合、|:cmap| |:cnoremap| の設定が反映されなくな + ります。 + |:cmap| |:cnoremap| の設定が競合してしまう場合は 0 を設定してく + ださい。 + + +============================================================================== +over のコマンドラインのハイライト *over-command_line-highlight* + +|over.vim| で使用される |:highlight| です。 + +OverCommandLineCursor *OverCommandLineCursor* + カーソル位置のハイライトです。 + コマンドラインの末尾で使用されます。 + デフォルトでは |hl-Cursor| が使用されます。 + +OverCommandLineCursorInsert *OverCommandLineCursorInsert* + カーソル位置のハイライトです。 + コマンドラインの文字上で使用されます。 + デフォルトでは |hl-Cursor| を使用し、|underline| が設定されます。 + + + +============================================================================== +over のコマンドラインのキーマッピング *over-command_line-key-mappings* + +コマンドラインで使用できるキーマッピングです。 +このキーマッピングは |g:over_command_line_key_map| で変更することが可能で +す。 +また、|:cmap| |:cnoremap| で設定したキーマッピングも反映されます。 +|:cmap| |:cnoremap| よりも |g:over_command_line_key_map| 等で設定した +キーマッピングが優先されることに注意してください。 + + +キー 処理~ +----------- ------------------------------- + コマンドの実行 + コマンドラインから抜ける + 最後にヤンクしたテキストを挿入する + or 1文字削除 + カーソルの前にある単語を削除 + or カーソルを右に移動 + or カーソルを左に移動 + or カーソル上の文字を削除 + or カーソルを先頭へ移動 + or カーソルを末尾へ移動 + or 1つ前のコマンド履歴を挿入 + or 1つ後のコマンド履歴を挿入 + カーソル下のファイル名を挿入 + カーソル下の word を挿入 + カーソル下の WORD を挿入 + バッファ上のワードで補完を行う +{0-9a-z"%#:-.*=} 番号/名前付きレジスタの挿入 + 次に打ち込まれた非数字文字をその通りに挿入 + + +以下は特殊なマッピングです。 +使用する場合は |OverCommandLineNoremap| で任意のキーに割り当てて下さい。 + +キー 処理~ +(over-cmdline-substitute-jump-pattern) |:substitute| の {pattenr} へ + カーソルを移動 +(over-cmdline-substitute-jump-string) |:substitute| の {string} へ + カーソルを移動 +(over-cmdline-scroll-y) |CTRL-y| 相当 +(over-cmdline-scroll-u) |CTRL-u| 相当 +(over-cmdline-scroll-f) |CTRL-f| 相当 +(over-cmdline-scroll-e) |CTRL-e| 相当 +(over-cmdline-scroll-d) |CTRL-d| 相当 +(over-cmdline-scroll-b) |CTRL-b| 相当 + +Example: > + OverCommandLineNoremap (over-cmdline-substitute-jump-string) + OverCommandLineNoremap (over-cmdline-substitute-jump-pattern) +< + + +============================================================================== +over のコマンドラインの autocmd *over-command_line-autocmd* + +|:OverCommandLine| から発行される |autocmd| |User| です。 + +名前 発生するとき~ +OverCmdLineEnter コマンドラインが開始された時 +OverCmdLineLeave コマンドラインが終了した時 +OverCmdLineExecutePre コマンドが実行される直前 +OverCmdLineExecute コマンドが実行された後 +OverCmdLineCharPre いずれかのキーが入力された時 + コマンドラインにキーが追加される前 +OverCmdLineChar いずれかのキーが入力されてコマンドラインに追加された後 +OverCmdLineCancel コマンドラインを実行しないで終了した時 + + +============================================================================== +FAQ *over-command_line-faq* + +Q. 時に特殊文字を挿入したい + +A. 次のマッピングを追加してください + +> + OverCommandLineMap +< + + +============================================================================== +更新履歴 *over-changelog* + +3.0 (2015/04/01) + - cmap/cnoremap の設定のインポート + - 時に正規表現を考慮した単語を削除 + - digraph の対応 + - ( )機能の追加 + - キーマッピング時の lhs に複数キーの割り当に対応 + - の対応 + +2.0 + - リファクタリング + - カーソルのハイライトを変更 + - |:/|,:%g/ 時のハイライトを追加 + - 特殊キー(CTRL + 文字等)が入力されないように変更 + + +============================================================================== +vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl diff --git a/bundle/vim-over/doc/over.txt b/bundle/vim-over/doc/over.txt new file mode 100644 index 000000000..50c9077d5 --- /dev/null +++ b/bundle/vim-over/doc/over.txt @@ -0,0 +1,236 @@ +*over.txt* highlighter for |:s| + +============================================================================== +CONTENTS *over-contents* + +Overview |over-introduction| +Interface |over-interface| +Commands |over-commands| +Settings |over-setting| +Variables |over-variables| +Highlight settings |over-command_line-highlight| +Key mappings |over-command_line-key-mappings| +autocmd |over-command_line-autocmd| +Change log |over-changelog| + + +============================================================================== +OVERVIEW *over-introduction* + +*over.vim* is a plug-in that highlights the {pattern} parameter +from |:substitute| {pattern}. + +Alternatively you can switch to the command line with |:OverCommandLine|. +Here, you can directly type your {pattern} and it will be automatically +highlighted and the {string} replacement will be previewed. + +Requirements: + Vim 7.3 or above. + |strchars()| and |+conceal| + + +============================================================================== +INTERFACE *over-interface* + +------------------------------------------------------------------------------ +COMMANDS *over-commands* + +:OverCommandLine [{input}] *:OverCommandLine* + |over.vim| standalone command line mode emulating |:substitute|. + It will highlight your {pattern} and the {string} replacement will be + previewed. + + While in command line mode, only a subset of key mappings are available see + |over-command_line-key-mappings| for details. + + {input} pre-feed the command line with the given input. + +:OverCommandLineNoremap {lhs} {rhs} *:OverCommandLineNoremap* + It is the same as :OverCommandLine but with a specified key remap. + {lhs} will be substitued by {rhs}. + You can only substitute one key or one key with at most one modifier. + You can set it up in |g:over_command_line_key_mappings|. +Example: > + OverCommandLineNoremap + OverCommandLineNoremap +< + +============================================================================== +SETTINGS *over-setting* + +------------------------------------------------------------------------------ +VARIABLES *over-variables* + +g:over_enable_auto_nohlsearch *g:over_enable_auto_nohlsearch* + set to 1 to enable the highlighting from the command line automatically +Default: > + let g:over_enable_auto_nohlsearch = 1 +< + +g:over_enable_cmd_window *g:over_enable_cmd_window* + set to 1 in order to enable the command line + +Default: > + let g:over_enable_cmd_window = 1 +< + +g:over_command_line_prompt *g:over_command_line_prompt* + sets the |:OverCommandLine| prompt. +Default: > + let g:over_command_line_prompt = "> " +< + +g:over_command_line_key_mappings *g:over_command_line_key_mappings* + Sets the key mapping used on the command line. + You can only substitute one key or one key with at most one modifier. +Example: > + " assigned to + " assigned to + let g:over_command_line_key_mappings = { + \ "\" : "\", + \ "\" : "\", + \} +< + *g:over#command_line#search#enable_incsearch* +g:over#command_line#search#enable_incsearch + Set to 1 if you want to highlight :/ or :? searches. +Default: > + let g:over#command_line#search#enable_incsearch = 1 +< + *g:over#command_line#search#enable_move_cursor* +g:over#command_line#search#enable_move_cursor + Set to 1 the pattern highlight will follow the cursor on the + :/ or :? command. +Default: > + let g:over#command_line#search#enable_move_cursor = 0 +< + *g:over#command_line#paste_escape_chars* +g:over#command_line#paste_escape_chars + Sets the set of characters to be automatically escaped when a buffer is + pasted on the command line with . +Example: > + " If you paste $foo.bar / 2 + 1 + " \$foo\.bar \/ 2 + 1 will be generated on the command line + let g:over#command_line#paste_escape_chars = '/.*$^~' +< + +g:over#command_line#paste_filters *g:over#command_line#paste_filters* + This is a generic way of remplacing the content of the paste buffer + when you paste on the command line with . +Default: > + " This will escape "\n" and "\r" automatically. + let g:over#command_line#paste_filters = { + \ "\n" : '\\n', + \ "\r" : '\\r', + \} +< +g:over#command_line#substitute#replace_pattern_visually +*g:over#command_line#substitute#replace_pattern_visually* + Instead of previewing the replacement next to the replaced pattern, it + visually replaces the pattern instead. +Default: + Not enabled. To enable, set it to 1. +Example: > + The wolf jumps over the sheep. + /\ + || --- You want to replace 'wolf' with 'bear'. + + The [wolf][bear] jumps over the sheep. + /\ + || --- Here is how vim-over will show you the preview normally. + + The [bear] jumps over the sheep. + /\ + || --- Here is how vim-over will show you the preview with this + option enabled. +< + + +============================================================================== +HIGHLIGHT SETTINGS *over-command_line-highlight* + +|:highlight| color settings are used by |over.vim|. + +OverCommandLineCursor *OverCommandLineCursor* + This is the highlight color of the current cursor position. + The default value is |hl-Cursor|. + +OverCommandLineCursorInsert *OverCommandLineCursorInsert* + This is the highlight color of the current cursor position in insert mode. + The default value is |hl-Cursor| with |underline| set. + + +============================================================================== +KEY MAPPINGS *over-command_line-key-mappings* + +This is the key mapping that can be used on the command line. +It is specified by setting |g:over_command_line_key_map|. + +Key Action~ +----------- ------------------------------- + Executes the command + Exits from the command line + Yank into the command line + or Deletes the character the cursor is on + Deletes the previous character + or Moves the cursor to the right + or Moves the cursor to the left + or Deletes the character the cursor is on + or Moves the cursor at the beginning on the line + or Moves the cursor at the end of the line + or Moves up in the command history + or Moves down in the command history + Inserts the name of the current file + Inserts word from under the cursor + Inserts WORD from under the cursor + Autocomplete from the words in the file +{0-9a-z"%#:-.*=} Insert the specified register or named register + + +You can also specify those specific mapping that can be +assigned from |OverCommandLineNoremap|. + +Key Action +----------- -------- +(over-cmdline-substitute-jump-pattern) Move the cursor to the next + |:substitute| {pattern} +(over-cmdline-substitute-jump-string) Move the cursor to the next + |:substitute| {string} +(over-cmdline-scroll-y) |CTRL-y| equivalent +(over-cmdline-scroll-u) |CTRL-u| equivalent +(over-cmdline-scroll-f) |CTRL-f| equivalent +(over-cmdline-scroll-e) |CTRL-e| equivalent +(over-cmdline-scroll-d) |CTRL-d| equivalent +(over-cmdline-scroll-b) |CTRL-b| equivalent + +Example: > + OverCommandLineNoremap (over-cmdline-substitute-jump-string) + OverCommandLineNoremap (over-cmdline-substitute-jump-pattern) +< + +============================================================================== +AUTOCMD *over-command_line-autocmd* + +|:OverCommandLine| triggers those following |User| |autocmd|. + +Function Event +OverCmdLineEnter triggered when you enter the command line mode +OverCmdLineLeave triggered when you leave the command line mode +OverCmdLineExecutePre triggered before a command execution +OverCmdLineExecute triggered after a command execution +OverCmdLineCharPre triggered before every character insertion +OverCmdLineChar triggered after every character insertion +OverCmdLineCancel triggered when you exit without running the line + + +============================================================================== +CHANGE LOG *over-changelog* + +2.0 + - Refactoring + - Change cursor highlight + - Add highlighting :/ and :%g/ + - No input special keys(e.g. , ) + +============================================================================== +vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl diff --git a/bundle/vim-over/plugin/over.vim b/bundle/vim-over/plugin/over.vim new file mode 100644 index 000000000..616f97ff5 --- /dev/null +++ b/bundle/vim-over/plugin/over.vim @@ -0,0 +1,63 @@ +scriptencoding utf-8 +if exists('g:loaded_over') + finish +endif +let g:loaded_over = 1 + +let s:save_cpo = &cpo +set cpo&vim + + +let g:over_enable_auto_nohlsearch = get(g:, "over_enable_auto_nohlsearch", 1) +let g:over_enable_cmd_window = get(g:, "over_enable_cmd_window", 1) +let g:over_command_line_prompt = get(g:, "over_command_line_prompt", "> ") +let g:over_command_line_key_mappings = get(g:, "over_command_line_key_mappings", {}) + + +augroup plugin-over + autocmd! + autocmd CmdwinEnter * if g:over_enable_cmd_window | call over#setup() | endif + autocmd CmdwinLeave * if g:over_enable_cmd_window | call over#unsetup() | endif +augroup END + + +command! -range -nargs=* +\ OverCommandLine +\ call over#command_line( +\ g:over_command_line_prompt, +\ != ? printf("'<,'>%s", ) : , +\ { "line1" : , "line2" : } +\ ) + + +function! s:key_mapping(lhs, rhs, noremap) + let g:over_command_line_key_mappings[a:lhs] = { +\ "key" : a:rhs, +\ "noremap" : a:noremap, +\ } +endfunction + +function! s:as_keymapping(key) + execute 'let result = "' . substitute(a:key, '\(<.\{-}>\)', '\\\1', 'g') . '"' + return result +endfunction + +function! s:unmapping(key) + execute 'let key = "' . substitute(a:key, '\(<.\{-}>\)', '\\\1', 'g') . '"' + unlet g:over_command_line_key_mappings[key] +endfunction + +command! -nargs=* +\ OverCommandLineNoremap +\ call call("s:key_mapping", map([], "s:as_keymapping(v:val)") + [1]) + +command! -nargs=* +\ OverCommandLineMap +\ call call("s:key_mapping", map([], "s:as_keymapping(v:val)") + [0]) + +command! -nargs=* +\ OverCommandLineUnmap call s:unmapping() + + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/bundle/vim-over/test/autoload/over.vim b/bundle/vim-over/test/autoload/over.vim new file mode 100644 index 000000000..01cb5c78f --- /dev/null +++ b/bundle/vim-over/test/autoload/over.vim @@ -0,0 +1,13 @@ + +function! s:test_parse_substitute() + let owl_SID = owl#filename_to_SID("vim-over/autoload/over.vim") + + OwlCheck s:parse_substitute('/homu') == [] + OwlCheck s:parse_substitute('s/homu') == ["", "homu", "", ""] + OwlCheck s:parse_substitute('%s/homu') == ["%", "homu", "", ""] + OwlCheck s:parse_substitute("'<,'>s/homu") == ["'<,'>", "homu", "", ""] + OwlCheck s:parse_substitute("'<,'>s/homu/mami") == ["'<,'>", "homu", "mami", ""] + OwlCheck s:parse_substitute('''<,''>s/ho\/ou/ma\/mi') == ["'<,'>", 'ho\/ou', 'ma\/mi', ""] + OwlCheck s:parse_substitute('%sa/a//g') == [] +endfunction + diff --git a/bundle/vim-over/test/autoload/over/command_line/complete.vim b/bundle/vim-over/test/autoload/over/command_line/complete.vim new file mode 100644 index 000000000..ee53753fe --- /dev/null +++ b/bundle/vim-over/test/autoload/over/command_line/complete.vim @@ -0,0 +1,10 @@ + +function! s:test_parse_line() + let owl_SID = owl#filename_to_SID("vim-over/autoload/over/command_line/complete.vim") + + OwlCheck s:parse_line("homu/h") == [5, "h"] + OwlCheck s:parse_line("homu") == [0, "homu"] + OwlCheck s:parse_line("//") == [2, ""] + +endfunction + diff --git a/bundle/vim-over/test/autoload/over/command_line/substitute.vim b/bundle/vim-over/test/autoload/over/command_line/substitute.vim new file mode 100644 index 000000000..716198e70 --- /dev/null +++ b/bundle/vim-over/test/autoload/over/command_line/substitute.vim @@ -0,0 +1,20 @@ + +function! s:test_restore_option() + let conceallevel = &conceallevel + let &conceallevel = 3 + call over#command_line#do("%s/mado/mado\") + echo &conceallevel + OwlCheck &conceallevel == 3 + let &conceallevel = conceallevel +endfunction + + +function! s:test_setting_option() + let conceallevel = &conceallevel + let &conceallevel = 3 + call over#command_line#do("set conceallevel=0\") + echo &conceallevel + OwlCheck &conceallevel == 0 + let &conceallevel = conceallevel +endfunction +