1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 04:10:05 +08:00

feat(incsearch): update incsearch layer

This commit is contained in:
wsdjeg 2022-06-10 16:31:14 +08:00
parent d66173b58a
commit c4cc14ea26
119 changed files with 11698 additions and 5 deletions

View File

@ -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}])

View File

@ -34,10 +34,10 @@ let s:filename = expand('<sfile>:~')
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 <silent><expr> <Plug>(incsearch-fuzzymotion) incsearch#go(<SID>config_easyfuzzymotion())
let lnum = expand('<slnum>') + s:lnum - 1
call SpaceVim#mapping#space#def('nmap', ['b', '/'], '<Plug>(incsearch-fuzzyword-/)', ['fuzzy-find-word',
\ [
@ -91,6 +92,15 @@ function! SpaceVim#layers#incsearch#config() abort
\ ]
\ ]
\ , 0)
let lnum = expand('<slnum>') + s:lnum - 1
call SpaceVim#mapping#space#def('nmap', ['/'], '<Plug>(incsearch-fuzzymotion)', ['fuzzy-easymotion',
\ [
\ '[SPC /] is to run fuzzy easymotion',
\ '',
\ 'Definition: ' . s:filename . ':' . lnum,
\ ]
\ ]
\ , 0)
endfunction

9
bundle/README.md vendored
View File

@ -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)
<!-- vim-markdown-toc -->
@ -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)

View File

@ -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/ <Plug>(incsearch-easymotion-/)
map z? <Plug>(incsearch-easymotion-?)
map zg/ <Plug>(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': {"\<CR>": '<Over>(easymotion)'},
\ 'is_expr': 0,
\ 'is_stay': 1
\ }), get(a:, 1, {}))
endfunction
noremap <silent><expr> <Space>/ incsearch#go(<SID>config_easyfuzzymotion())
```
### API
- `incsearch#config#easymotion#module()`: return easymotion module for incsearch.vim
- It provide `<Over>(easymotion)` key to invoke easymotion feature from incsearch.vim
- `incsearch#config#easymotion#make`: return default config

View File

@ -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': {"\<CR>": '<Over>(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

View File

@ -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("\<Plug>(_incsearch-hlsearch)", 'm')
endfunction
function! s:module.on_char_pre(cmdline)
if a:cmdline.is_input('<Over>(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\<C-v>]"
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo
" __END__
" vim: expandtab softtabstop=2 shiftwidth=2 foldmethod=marker

View File

@ -0,0 +1,29 @@
"=============================================================================
" FILE: plugin/incsearch/easymotion.vim
" AUTHOR: haya14busa
" License: MIT license
"=============================================================================
scriptencoding utf-8
if expand('%:p') ==# expand('<sfile>: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 <silent><expr> <Plug>(incsearch-easymotion-/) incsearch#go(<SID>config())
noremap <silent><expr> <Plug>(incsearch-easymotion-?) incsearch#go(<SID>config({'command': '?'}))
noremap <silent><expr> <Plug>(incsearch-easymotion-stay) incsearch#go(<SID>config({'is_stay': 1}))
let &cpo = s:save_cpo
unlet s:save_cpo
" __END__
" vim: expandtab softtabstop=2 shiftwidth=2 foldmethod=marker

81
bundle/incsearch-fuzzy.vim/README.md vendored Normal file
View File

@ -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/ <Plug>(incsearch-fuzzy-/)
map z? <Plug>(incsearch-fuzzy-?)
map zg/ <Plug>(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/ <Plug>(incsearch-fuzzyspell-/)
map z? <Plug>(incsearch-fuzzyspell-?)
map zg/ <Plug>(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 <silent><expr> z/ incsearch#go(<SID>config_fuzzyall())
noremap <silent><expr> z? incsearch#go(<SID>config_fuzzyall({'command': '?'}))
noremap <silent><expr> zg? incsearch#go(<SID>config_fuzzyall({'is_stay': 1}))
```

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,5 @@
let s:_plugin_name = expand('<sfile>:t:r')
function! vital#{s:_plugin_name}#new() abort
return vital#{s:_plugin_name[1:]}#new()
endfunction

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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

View File

@ -0,0 +1,339 @@
let s:plugin_name = expand('<sfile>:t:r')
let s:vital_base_dir = expand('<sfile>:h')
let s:project_root = expand('<sfile>: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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
let s:_s = '<SNR>' . 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 <SID> 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('<sfile>: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 <sfile> 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("\<SNR>")), '"[\\x" . printf("%0x", char2nr("\<SNR>"[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<SNR>%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('<SNR>%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

View File

@ -0,0 +1,4 @@
incsearch_fuzzy
6e682fce672da9da08aee5db517d227be5ef663f
Data.String.Converter

View File

@ -0,0 +1,44 @@
"=============================================================================
" FILE: plugin/incsearch/fuzzy.vim
" AUTHOR: haya14busa
" License: MIT license
"=============================================================================
scriptencoding utf-8
if expand('%:p') ==# expand('<sfile>: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 <silent><expr> <Plug>(incsearch-fuzzy-/) incsearch#go(<SID>config_fuzzy())
noremap <silent><expr> <Plug>(incsearch-fuzzy-?) incsearch#go(<SID>config_fuzzy({'command': '?'}))
noremap <silent><expr> <Plug>(incsearch-fuzzy-stay) incsearch#go(<SID>config_fuzzy({'is_stay': 1}))
noremap <silent><expr> <Plug>(incsearch-fuzzyword-/) incsearch#go(<SID>config_fuzzyword())
noremap <silent><expr> <Plug>(incsearch-fuzzyword-?) incsearch#go(<SID>config_fuzzyword({'command': '?'}))
noremap <silent><expr> <Plug>(incsearch-fuzzyword-stay) incsearch#go(<SID>config_fuzzyword({'is_stay': 1}))
noremap <silent><expr> <Plug>(incsearch-fuzzyspell-/) incsearch#go(<SID>config_fuzzyspell())
noremap <silent><expr> <Plug>(incsearch-fuzzyspell-?) incsearch#go(<SID>config_fuzzyspell({'command': '?'}))
noremap <silent><expr> <Plug>(incsearch-fuzzyspell-stay) incsearch#go(<SID>config_fuzzyspell({'is_stay': 1}))
let &cpo = s:save_cpo
unlet s:save_cpo
" __END__
" vim: expandtab softtabstop=2 shiftwidth=2 foldmethod=marker

View File

@ -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)

View File

@ -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 }}

10
bundle/vim-asterisk/.travis.yml vendored Normal file
View File

@ -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

20
bundle/vim-asterisk/LICENSE vendored Normal file
View File

@ -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.

92
bundle/vim-asterisk/README.md vendored Normal file
View File

@ -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 * <Plug>(asterisk-*)
map # <Plug>(asterisk-#)
map g* <Plug>(asterisk-g*)
map g# <Plug>(asterisk-g#)
map z* <Plug>(asterisk-z*)
map gz* <Plug>(asterisk-gz*)
map z# <Plug>(asterisk-z#)
map gz# <Plug>(asterisk-gz#)
```
If you want to set "z" (stay) behavior as default
```vim
map * <Plug>(asterisk-z*)
map # <Plug>(asterisk-z#)
map g* <Plug>(asterisk-gz*)
map g# <Plug>(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)

View File

@ -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('<cword>')))
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 ? "\<Esc>" . 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 . "\<CR>"
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' ? "\<Esc>" : '')
\ . '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 = "\<C-o>"
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\<CR>%s:%s\<CR>:%s\<CR>", 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 \<cword\> 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 <thinca+vim@gmail.com>
" License : zlib License
" @return \<selected_pattern\>: 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' ? "\<Esc>" : '')
return printf("%s:\<C-u>%s\<CR>:%s\<CR>:%s\<CR>", 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("\<Esc>:echohl ErrorMsg | echom '%s' | echohl None\<CR>", m)
\ : '*')
endfunction
" @return boolean
function! s:should_plus_one_count(cword, config, mode) abort
" For backward, because count isn't needed with <expr> 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 ==# "\<C-v>"
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\<C-v>]"
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
" }}}

165
bundle/vim-asterisk/doc/asterisk.txt vendored Normal file
View File

@ -0,0 +1,165 @@
*asterisk.txt* *-improved
Author : haya14busa <hayabusa1419@gmail.com>
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' : ['<Plug>(asterisk-']
\ }
\ }
<
2. Install with |:NeoBundleInstall|.
==============================================================================
USAGE *asterisk-usage*
------------------------------------------------------------------------------
KEY MAPPINGS *asterisk-key-mappings*
<Plug>(asterisk-*) *<Plug>(asterisk-star)*
<Plug>(asterisk-#) *<Plug>(asterisk-#)*
<Plug>(asterisk-g*) *<Plug>(asterisk-gstar)*
<Plug>(asterisk-g#) *<Plug>(asterisk-g#)*
<Plug>(asterisk-z*) *<Plug>(asterisk-zstar)*
<Plug>(asterisk-z#) *<Plug>(asterisk-z#)*
<Plug>(asterisk-gz*) *<Plug>(asterisk-gzstar)*
<Plug>(asterisk-gz#) *<Plug>(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 * <Plug>(asterisk-*)
map # <Plug>(asterisk-#)
map g* <Plug>(asterisk-g*)
map g# <Plug>(asterisk-g#)
map z* <Plug>(asterisk-z*)
map gz* <Plug>(asterisk-gz*)
map z# <Plug>(asterisk-z#)
map gz# <Plug>(asterisk-gz#)
<
If you want to set "z" (stay) behavior as default
>
map * <Plug>(asterisk-z*)
map # <Plug>(asterisk-z#)
map g* <Plug>(asterisk-gz*)
map g# <Plug>(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:

57
bundle/vim-asterisk/plugin/asterisk.vim vendored Normal file
View File

@ -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('<sfile>: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 <expr><silent> <Plug>(asterisk-*) asterisk#do(mode(1), {'direction' : 1, 'do_jump' : 1, 'is_whole' : 1})
noremap <expr><silent> <Plug>(asterisk-g*) asterisk#do(mode(1), {'direction' : 1, 'do_jump' : 1, 'is_whole' : 0})
noremap <expr><silent> <Plug>(asterisk-z*) asterisk#do(mode(1), {'direction' : 1, 'do_jump' : 0, 'is_whole' : 1})
noremap <expr><silent> <Plug>(asterisk-gz*) asterisk#do(mode(1), {'direction' : 1, 'do_jump' : 0, 'is_whole' : 0})
noremap <expr><silent> <Plug>(asterisk-#) asterisk#do(mode(1), {'direction' : 0, 'do_jump' : 1, 'is_whole' : 1})
noremap <expr><silent> <Plug>(asterisk-g#) asterisk#do(mode(1), {'direction' : 0, 'do_jump' : 1, 'is_whole' : 0})
noremap <expr><silent> <Plug>(asterisk-z#) asterisk#do(mode(1), {'direction' : 0, 'do_jump' : 0, 'is_whole' : 1})
noremap <expr><silent> <Plug>(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
" }}}

47
bundle/vim-asterisk/test/.themisrc vendored Normal file
View File

@ -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 (<EOL>) formats
" Mapping:
map * <Plug>(asterisk-*)
map # <Plug>(asterisk-#)
map g* <Plug>(asterisk-g*)
map g# <Plug>(asterisk-g#)
map z* <Plug>(asterisk-z*)
map gz* <Plug>(asterisk-gz*)
map z# <Plug>(asterisk-z#)
map gz# <Plug>(asterisk-gz#)
" Default:
noremap <Leader>* *
noremap <Leader># #
noremap <Leader>g g
noremap <Leader>g# g#
noremap <Leader>z z
noremap <Leader>gz gz
noremap <Leader>z# z#
noremap <Leader>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

View File

@ -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(@/, '\<asterisk\>')
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 <cword>
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(@/, '\<asterisk\>')
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 <cword>
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(@/, '\<asterisk\>')
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

106
bundle/vim-asterisk/test/keeppos.vimspec vendored Normal file
View File

@ -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), '\<asterisk\>/s+3')
End
It keep cursor position without offset
normal *
Assert Equals(histget('/', -1), '\<asterisk\>')
End
It doesn't keep cursor position if the char under cursor is not keyword
normal 1h
normal *
Assert Equals(histget('/', -1), '\<asterisk\>')
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), '\<asterisk\>?s+3')
End
It search backward and correct count at the end of word
normal! $
normal #
Assert Equals(histget('/', -1), '\<asterisk\>?s+7')
normal! 9h
Assert Equals(g:Get_pos_char(), '2')
End
It keep cursor position without offset
normal #
Assert Equals(histget('/', -1), '\<asterisk\>')
End
It doesn't keep cursor position if the char under cursor is not keyword
normal 1h
normal #
Assert Equals(histget('/', -1), '\<asterisk\>')
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

131
bundle/vim-asterisk/test/visual.vimspec vendored Normal file
View File

@ -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\<asterisk\>')
End
It search forward only with \<
normal ve5h*
Assert Equals(@/, '\V\<ast')
End
It search forward only with \>
normal 2lve*
Assert Equals(@/, '\Vterisk\>')
End
End
Context #
It search backward and jump to next matchecd pattern
normal $viw2#
Assert Equals(@/, '\V\<asterisk\>')
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\<a')
End
It get character under cursor with <C-v>
silent! execute 'normal' "\<C-v>*"
Assert Equals(@/, '\V\<a')
End
It get line with <C-v>
normal V*
Assert Equals(@/, '\V\<1.asterisk 2.asterisk 3.asterisk\n')
End
End
Context <C-v>*
It search forward with \<\>
silent! execute 'normal' "\<C-v>ej*"
Assert Equals(@/, '\V\<asterisk\nAsterisk\>')
End
End
Context contains \r
It handles correctly
normal 8j$v*
Assert Equals(@/, '\V\r')
End
End
End

62
bundle/vim-asterisk/test/zstar.vimspec vendored Normal file
View File

@ -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(@/, '\<asterisk\>')
End
It add search history with \<\>
call histadd('/', ' ')
Assert Equals(histget('/', -1), ' ')
normal z*
Assert Equals(histget('/', -1), '\<asterisk\>')
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\<Neo')
endfor
let &selection = save
End
End
End

1
bundle/vim-over/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
doc/tags*

46
bundle/vim-over/README.md vendored Normal file
View File

@ -0,0 +1,46 @@
# over.vim 3.0
## Screencapture
### Preview in the command line window
![test](https://f.cloud.github.com/assets/214488/1461854/922bd38c-44d1-11e3-9ca4-eb3902be19f7.gif)
### Preview in the over command line
![test](https://f.cloud.github.com/assets/214488/1490845/da05d670-479d-11e3-93d6-e8b9214df405.gif)
### Buffer word complete in the over command line
![test](https://f.cloud.github.com/assets/214488/1584401/89e13068-520b-11e3-8acb-de8a58538dbb.gif)
## License
[NYSL](http://www.kmonos.net/nysl/)
[NYSL English](http://www.kmonos.net/nysl/index.en.html)
## Change log
* 3.0 (2015/04/01)
* Add digraph
* Add `<C-q>`
* Import cmap/cnoremap setting
* `<C-w>` by regexp
* Multi lhs by keymapping
* Support `<expr>` keymapping
* Refactoring
* 2.0
* Refactoring
* Change cursor highlight
* Add highlighting `:/` and `:%g/`
* No input specital keys(e.g. `<BS>`, `<C->`)
## Special Thanks
* [@haya14busa](https://github.com/haya14busa)

173
bundle/vim-over/autoload/over.vim vendored Normal file
View File

@ -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("<Plug>(%s)", name)
if mode == "n"
let command = "nnoremap"
else
let command = "nmap"
endif
execute command "<silent>" map printf("%s:nunmap %s<CR>", a:expr, map)
call feedkeys(printf("\<Plug>(%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/[^/]*\\@<!%(\\\\)*/|\?[^?]*\\@<!%(\\\\)*\?'
let line_specifier =
\ '\v%(\d+|[.$]|''\S|\\[/?&])?%([+-]\d*|' . search_pattern . ')*'
let range_pattern = '\v%((\%|' . line_specifier . ')' .
\ '%([;,](' . line_specifier . '))*)'
return matchlist(a:string, range_pattern)
endfunction
function! s:search_highlight(line)
let result = s:parse_substitute(a:line)
let text = get(result, 1, "")
if !s:set_flag
let s:search_highlighted = 1
let s:set_flag = 1
call feedkeys("\<C-o>:set hlsearch | set incsearch\<CR>", '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 <silent><expr> <Plug>(over-restore-search-pattern)
\ (mode() =~ '[iR]' ? "\<C-o>" : "") . ":let @/ = " . string(s:old_search_pattern) . "\<CR>"
nnoremap <silent><expr> <Plug>(over-restore-nohlsearch)
\ (mode() =~ '[iR]' ? "\<C-o>" : "") . ":nohlsearch\<CR>"
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\<CR>", "nohlsearch", 'n')
call feedkeys("\<Plug>(over-restore-nohlsearch)")
endif
execute "normal \<Plug>(over-restore-search-pattern)"
" call s:silent_feedkeys(":let @/ = " . string(s:old_search_pattern) . "\<CR>", "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

View File

@ -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("<Over>(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("\<Tab>", "<Over>(buffer-complete)")
let s:base_keymapping = {
\ "\<Tab>" : {
\ "key" : "<Over>(buffer-complete)",
\ "lock" : 1,
\ "noremap" : 1,
\ },
\ "\<C-v>" : {
\ "key" : "<Over>(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("\<Plug>(over-cmdline-scroll-y)")
execute "normal! \<C-y>"
call a:cmdline.setchar('')
elseif a:cmdline.is_input("\<Plug>(over-cmdline-scroll-u)")
execute "normal! \<C-u>"
call a:cmdline.setchar('')
elseif a:cmdline.is_input("\<Plug>(over-cmdline-scroll-f)")
execute "normal! \<C-f>"
call a:cmdline.setchar('')
elseif a:cmdline.is_input("\<Plug>(over-cmdline-scroll-e)")
execute "normal! \<C-e>"
call a:cmdline.setchar('')
elseif a:cmdline.is_input("\<Plug>(over-cmdline-scroll-d)")
execute "normal! \<C-d>"
call a:cmdline.setchar('')
elseif a:cmdline.is_input("\<Plug>(over-cmdline-scroll-b)")
execute "normal! \<C-b>"
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

View File

@ -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("\<C-p>") && !over#command_line#is_input("\<C-n>")
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("\<C-n>")
let s:count = max([s:count - 1, 0])
endif
if over#command_line#is_input("\<C-p>")
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

View File

@ -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("\<Tab>")
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("\<Tab>", "Completion")
\ || over#command_line#is_input("\<C-f>", "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("\<C-b>", "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

View File

@ -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

View File

@ -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("\<C-r>")
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 == "\<C-w>"
call over#command_line#setchar(s:cword)
elseif key == "\<C-a>"
call over#command_line#setchar(s:cWORD)
elseif key == "\<C-f>"
call over#command_line#setchar(s:cfile)
elseif key == "\<C-r>"
call over#command_line#setchar('"')
endif
endif
endfunction
function! s:on_OverCmdLineChar()
if over#command_line#is_input("\<C-r>", "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("<cword>")
let s:cWORD = expand("cWORD")
let s:cfile = expand("<cfile>")
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

View File

@ -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

View File

@ -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("\<CR>")
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("\<Plug>(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("\<Plug>(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

View File

@ -0,0 +1,9 @@
let s:_plugin_name = expand('<sfile>: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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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" ? "\<C-v>"
\ : 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 ==# "\<C-v>"
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 <silent> <Plug>(vital-coaster_buffer_region)
\ :<C-u>set operatorfunc=<SID>_buffer_region_operator<CR>g@
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') '<expr>'
\ '<Plug>(vital-coaster_buffer_region-target)' string(config.textobj)
let tmp = &operatorfunc
silent execute "normal \<Plug>(vital-coaster_buffer_region)\<Plug>(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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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 ==# "\<C-v>"
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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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:

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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:

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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("<sfile>: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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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("<sfile>: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

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Over#import() abort', printf("return map({'error': ''}, \"vital#_over#function('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Over#Commandline#Modules#All#import() abort', printf("return map({'_vital_depends': ''}, \"vital#_over#function('<SNR>%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("<sfile>: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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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("\<C-c>")
endtry
call self.draw()
endfunction
endfunction
function! s:make()
return deepcopy(s:module)
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Over#Commandline#Modules#BufferComplete#import() abort', printf("return map({'make': ''}, \"vital#_over#function('<SNR>%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("<Over>(buffer-complete)")
\ || a:cmdline.is_input("<Over>(buffer-complete-prev)")
if self.complete(a:cmdline) == -1
call s:_finish()
call a:cmdline.setchar('')
return
endif
if a:cmdline.is_input("<Over>(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("\<Tab>", "Completion")
elseif a:cmdline.is_input("<Over>(buffer-complete)", "Completion")
\ || a:cmdline.is_input("\<Right>", "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("<Over>(buffer-complete-prev)", "Completion")
\ || a:cmdline.is_input("\<Left>", "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

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Over#Commandline#Modules#Cancel#import() abort', printf("return map({'make': ''}, \"vital#_over#function('<SNR>%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("\<Esc>")
\ || a:cmdline.is_input("\<C-c>")
" 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

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Over#Commandline#Modules#CursorMove#import() abort', printf("return map({'make': ''}, \"vital#_over#function('<SNR>%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("\<Right>")
call a:cmdline.line.next()
call a:cmdline.setchar('')
elseif a:cmdline.is_input("\<Left>")
call a:cmdline.line.prev()
call a:cmdline.setchar('')
elseif a:cmdline.is_input("\<C-b>")
\ || a:cmdline.is_input("\<Home>")
call a:cmdline.setline(0)
call a:cmdline.setchar('')
elseif a:cmdline.is_input("\<C-e>")
\ || a:cmdline.is_input("\<End>")
call a:cmdline.setline(a:cmdline.line.length())
call a:cmdline.setchar('')
elseif a:cmdline.is_input("\<C-Left>")
\ || a:cmdline.is_input("\<S-Left>")
call a:cmdline.setline(strridx(a:cmdline.backward()[:-2], ' ') + 1)
call a:cmdline.setchar('')
elseif a:cmdline.is_input("\<C-Right>")
\ || a:cmdline.is_input("\<S-Right>")
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

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Over#Commandline#Modules#Delete#import() abort', printf("return map({'make': ''}, \"vital#_over#function('<SNR>%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("\<C-h>")
\ || a:cmdline.is_input("\<BS>")
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("\<Del>")
call a:cmdline.line.remove_pos()
call a:cmdline.setchar('')
elseif a:cmdline.is_input("\<C-w>")
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("\<C-u>")
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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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("\<C-k>")
if empty(self.digraphs)
" Get digraphs when inputting <C-k> 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 <Space> {char} will
" enter {char} with the highest bit set. You can use this to enter
" meta-characters.
let char = x ==# "\<Space>" ?
\ 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("\<C-k>")
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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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 <nomodeline> 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

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Over#Commandline#Modules#DrawCommandline#import() abort', printf("return map({'suffix': '', 'make': ''}, \"vital#_over#function('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Over#Commandline#Modules#ExceptionExit#import() abort', printf("return map({'make': ''}, \"vital#_over#function('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Over#Commandline#Modules#ExceptionMessage#import() abort', printf("return map({'make': ''}, \"vital#_over#function('<SNR>%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("<sfile>: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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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("<Plug>(%s)", a:name)
if mode == "n"
let command = "nnoremap"
else
let command = "nmap"
endif
execute command "<silent>" map printf("%s:nunmap %s<CR>", a:expr, map)
call feedkeys(printf("\<Plug>(%s)", a:name))
endfunction
function! s:_is_input_enter(cmdline)
return a:cmdline.is_input("\<CR>")
\ || a:cmdline.is_input("\<NL>")
\ || a:cmdline.is_input("\<C-j>")
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("<Over>(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)\<CR>", "remove_hist", "n")
let cmd = printf("call s:silent_feedkeys(\"%s%s\<CR>\", '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\<CR>", "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

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Over#Commandline#Modules#ExecuteFailedMessage#import() abort', printf("return map({}, \"vital#_over#function('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Over#Commandline#Modules#Exit#import() abort', printf("return map({'make': ''}, \"vital#_over#function('<SNR>%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("<Over>(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

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Over#Commandline#Modules#HighlightBufferCursor#import() abort', printf("return map({}, \"vital#_over#function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
delfunction s:_SID
" ___vital___

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Over#Commandline#Modules#HistAdd#import() abort', printf("return map({'make': ''}, \"vital#_over#function('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Over#Commandline#Modules#History#import() abort', printf("return map({'make': ''}, \"vital#_over#function('<SNR>%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("\<Up>")
\ || a:cmdline.is_input("\<Down>")
endfunction
function! s:_reset()
let s:cmdhist = []
let s:count = 0
let s:is_match_mode = 0 " <Up>/<Down>: true, <C-n>/<C-p>: false
endfunction
function! s:module.on_enter(...)
call s:_reset()
endfunction
function! s:module.on_char_pre(cmdline)
if !a:cmdline.is_input("\<Up>") && !a:cmdline.is_input("\<Down>")
\ && !a:cmdline.is_input("\<C-p>") && !a:cmdline.is_input("\<C-n>")
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("\<Down>") || a:cmdline.is_input("\<C-n>")
let s:count = max([s:count - 1, 0])
endif
if a:cmdline.is_input("\<Up>") || a:cmdline.is_input("\<C-p>")
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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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(), "\<CR>")
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("<cword>")
let self.cWORD = expand("<cWORD>")
let self.cfile = expand("<cfile>")
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("\<C-r>")
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 == "\<C-w>"
call a:cmdline.setchar(s:get_cmdline_cword(a:cmdline.backward_word(), self.cword))
elseif char == "\<C-a>"
call a:cmdline.setchar(self.cWORD)
elseif char == "\<C-f>"
call a:cmdline.setchar(self.cfile)
elseif char == "\<C-r>"
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("\<C-w>", self.prefix_key)
" call a:cmdline.setchar(self.cword)
" elseif a:cmdline.is_input("\<C-a>", self.prefix_key)
" call a:cmdline.setchar(self.cWORD)
" elseif a:cmdline.is_input("\<C-f>", self.prefix_key)
" call a:cmdline.setchar(self.cfile)
" elseif a:cmdline.is_input("\<C-r>", 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("\<C-r>")
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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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 {
\ "\<C-f>" : {
\ "key" : "\<Right>",
\ "noremap" : 1,
\ "lock" : 1,
\ },
\ "\<C-b>" : {
\ "key" : "\<Left>",
\ "noremap" : 1,
\ "lock" : 1,
\ },
\ "\<C-n>" : {
\ "key" : "\<Down>",
\ "noremap" : 1,
\ "lock" : 1,
\ },
\ "\<C-p>" : {
\ "key" : "\<Up>",
\ "noremap" : 1,
\ "lock" : 1,
\ },
\ "\<C-a>" : {
\ "key" : "\<Home>",
\ "noremap" : 1,
\ "lock" : 1,
\ },
\ "\<C-e>" : {
\ "key" : "\<End>",
\ "noremap" : 1,
\ "lock" : 1,
\ },
\ "\<C-d>" : {
\ "key" : "\<Del>",
\ "noremap" : 1,
\ "lock" : 1,
\ },
\ "\<A-d>" : {
\ "key" : "\<C-w>",
\ "noremap" : 1,
\ "lock" : 1,
\ },
\ "\<A-b>" : {
\ "key" : "\<S-Left>",
\ "noremap" : 1,
\ "lock" : 1,
\ },
\ "\<A-f>" : {
\ "key" : "\<S-Right>",
\ "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, '<SID>', '<SNR>' . 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 <buffer> 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

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Over#Commandline#Modules#LiteralInsert#import() abort', printf("return map({'make': ''}, \"vital#_over#function('<SNR>%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("\<C-v>")
\ || a:cmdline.is_input("\<C-q>")
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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Over#Commandline#Modules#Paste#import() abort', printf("return map({'make': ''}, \"vital#_over#function('<SNR>%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("<Over>(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

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Over#Commandline#Modules#Redraw#import() abort', printf("return map({'make': ''}, \"vital#_over#function('<SNR>%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=<C-c>
" https://github.com/osyo-manga/vital-over/issues/52
" https://github.com/Lokaltog/vim-easymotion/issues/177#issuecomment-53663431
if &cedit != "<C-c>"
\ ||(v:version > 704 || v:version == 704 && has("patch441"))
normal! :
else
execute "normal! :\<Esc>"
endif
endfunction
function! s:make()
return deepcopy(s:module)
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Over#Commandline#Modules#Scroll#import() abort', printf("return map({'make': ''}, \"vital#_over#function('<SNR>%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("<Over>(scroll-y)")
execute "normal! \<C-y>"
call a:cmdline.setchar('')
elseif a:cmdline.is_input("<Over>(scroll-u)")
execute "normal! \<C-u>"
call a:cmdline.setchar('')
elseif a:cmdline.is_input("<Over>(scroll-f)")
execute "normal! \<C-f>"
call a:cmdline.setchar('')
elseif a:cmdline.is_input("<Over>(scroll-e)")
execute "normal! \<C-e>"
call a:cmdline.setchar('')
elseif a:cmdline.is_input("<Over>(scroll-d)")
execute "normal! \<C-d>"
call a:cmdline.setchar('')
elseif a:cmdline.is_input("<Over>(scroll-b)")
execute "normal! \<C-b>"
call a:cmdline.setchar('')
endif
endfunction
function! s:make()
return deepcopy(s:module)
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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("<sfile>: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

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Over#Input#import() abort', printf("return map({'getchar': ''}, \"vital#_over#function('<SNR>%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 " <C-c>
endtry
" Workaround for the <expr> 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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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' : ''
" \<A-]> => Û\xfdQ
" \<A-@> => À\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, "\\%(\<Plug>\\|<Over>\\)(.\\{-})\\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

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Palette#Capture#import() abort', printf("return map({'help': '', 'extend': '', 'command': ''}, \"vital#_over#function('<SNR>%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, "<SRN>", "\<SNR>", "g")
" let result = substitute(result, "<SID>", "\<SID>", "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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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 : <C-?> https://github.com/osyo-manga/vital-palette/issues/5
if a:key ==# "<^?>"
return "\<C-?>"
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 : <C-?> https://github.com/osyo-manga/vital-palette/issues/5
if a:name ==# "<^?>"
return maparg("\<C-?>", 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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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:

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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("<sfile>: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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\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('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Unlocker#Holder#File#import() abort', printf("return map({'is_makeable': '', 'make': ''}, \"vital#_over#function('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Unlocker#Holder#Multi#import() abort', printf("return map({'make': ''}, \"vital#_over#function('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Unlocker#Holder#Option#import() abort', printf("return map({'is_makeable': '', 'make': ''}, \"vital#_over#function('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Unlocker#Holder#Position#import() abort', printf("return map({'is_makeable': '', 'make': ''}, \"vital#_over#function('<SNR>%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

View File

@ -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('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
execute join(['function! vital#_over#Unlocker#Holder#Register#import() abort', printf("return map({'is_makeable': '', 'make': ''}, \"vital#_over#function('<SNR>%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

Some files were not shown because too many files have changed in this diff Show More