From b55751be0331a455b539ba56496aed2c8ffe8d22 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Wed, 28 Jun 2017 21:36:51 +0800 Subject: [PATCH 01/22] Add text manipulation commands example PR --- autoload/SpaceVim/layers/edit.vim | 17 ++++++++++------- docs/documentation.md | 11 +++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/autoload/SpaceVim/layers/edit.vim b/autoload/SpaceVim/layers/edit.vim index b07429a21..3bcca38b8 100644 --- a/autoload/SpaceVim/layers/edit.vim +++ b/autoload/SpaceVim/layers/edit.vim @@ -23,14 +23,14 @@ function! SpaceVim#layers#edit#plugins() abort endfunction function! SpaceVim#layers#edit#config() abort - let g:multi_cursor_next_key='' - let g:multi_cursor_prev_key='' - let g:multi_cursor_skip_key='' - let g:multi_cursor_quit_key='' + let g:multi_cursor_next_key = '' + let g:multi_cursor_prev_key = '' + let g:multi_cursor_skip_key = '' + let g:multi_cursor_quit_key = '' let g:user_emmet_install_global = 0 - let g:user_emmet_leader_key='' - let g:user_emmet_mode='a' - let g:user_emmet_settings = { + let g:user_emmet_leader_key = '' + let g:user_emmet_mode = 'a' + let g:user_emmet_settings = { \ 'jsp' : { \ 'extends' : 'html', \ }, @@ -38,4 +38,7 @@ function! SpaceVim#layers#edit#config() abort "noremap (wildfire-fuel) vnoremap (wildfire-water) let g:wildfire_objects = ["i'", 'i"', 'i)', 'i]', 'i}', 'ip', 'it'] + let g:_spacevim_mappings_space.x = {'name' : '+Text'} + let g:_spacevim_mappings_space.x.a = {'name' : '+align'} + call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '&'], 'Tabularize /&', 'align region at &', 1) endfunction diff --git a/docs/documentation.md b/docs/documentation.md index 029940ed8..a951b4001 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -77,6 +77,9 @@ title: "Documentation" * [Searching the web](#searching-the-web) * [Persistent highlighting](#persistent-highlighting) * [Editing](#editing) + * [Paste text](#paste-text) + * [Auto-indent pasted text](#auto-indent-pasted-text) + * [Text manipulation commands](#text-manipulation-commands) * [Multi-Encodings](#multi-encodings) * [Errors handling](#errors-handling) * [Features](#features) @@ -1104,6 +1107,14 @@ SpaceVim uses `g:spacevim_search_highlight_persist` to keep the searched express ### Editing +#### Paste text + +##### Auto-indent pasted text + +#### Text manipulation commands + +Text related commands (start with `x`): + #### Multi-Encodings SpaceVim use utf-8 as default encoding. there are four options for these case: From cb37777f5b0e694100ef3ce8835df8fc7e2a00b6 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Wed, 28 Jun 2017 22:11:26 +0800 Subject: [PATCH 02/22] Add mappings need to be impl --- docs/documentation.md | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/docs/documentation.md b/docs/documentation.md index a951b4001..41ffc165a 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -1115,6 +1115,62 @@ SpaceVim uses `g:spacevim_search_highlight_persist` to keep the searched express Text related commands (start with `x`): +Key Binding | Description +---------- | ------------ +`SPC x a &` | align region at & +`SPC x a (` | align region at ( +`SPC x a )` | align region at ) +`SPC x a [` | align region at [ +`SPC x a ]` | align region at ] +`SPC x a {` | align region at { +`SPC x a }` | align region at } +`SPC x a ,` | align region at , +`SPC x a .` | align region at . (for numeric tables) +`SPC x a :` | align region at : +`SPC x a ;` | align region at ; +`SPC x a =` | align region at = +`SPC x a a` | align region (or guessed section) using default rules +`SPC x a c` | align current indentation region using default rules +`SPC x a l` | left-align with evil-lion +`SPC x a L` | right-align with evil-lion +`SPC x a r` | align region using user-specified regexp +`SPC x a m` | align region at arithmetic operators `` (+-*/) `` +`SPC x a ¦` | align region at ¦ +`SPC x c` | cunt the number of chars/words/lines in the selection region +`SPC x d w` | delete trailing whitespaces +`SPC x d SPC` | Delete all spaces and tabs around point, leaving one space +`SPC x g l` | set languages used by translate commands +`SPC x g t` | translate current word using Google Translate +`SPC x g T` | reverse source and target languages +`SPC x i c` | change symbol style to lowerCamelCase +`SPC x i C` | change symbol style to UpperCamelCase +`SPC x i i` | cycle symbol naming styles (i to keep cycling) +`SPC x i -` | change symbol style to kebab-case +`SPC x i k` | change symbol style to kebab-case +`SPC x i _` | change symbol style to under_score +`SPC x i u` | change symbol style to under_score +`SPC x i U` | change symbol style to UP_CASE +`SPC x j c` | set the justification to center +`SPC x j f` | set the justification to full +`SPC x j l` | set the justification to left +`SPC x j n` | set the justification to none +`SPC x j r` | set the justification to right +`SPC x J` | move down a line of text (enter transient state) +`SPC x K` | move up a line of text (enter transient state) +`SPC x l d` | duplicate line or region +`SPC x l s` | sort lines +`SPC x l u` | uniquify lines +`SPC x o` | use avy to select a link in the frame and open it +`SPC x O` | use avy to select multiple links in the frame and open them +`SPC x t c` | swap (transpose) the current character with the previous one +`SPC x t w` | swap (transpose) the current word with the previous one +`SPC x t l` | swap (transpose) the current line with the previous one +`SPC x u` | set the selected text to lower case +`SPC x U` | set the selected text to upper case +`SPC x w c` | count the number of occurrences per word in the select region +`SPC x w d` | show dictionary entry of word from wordnik.com +`SPC x TAB` | indent or dedent a region rigidly + #### Multi-Encodings SpaceVim use utf-8 as default encoding. there are four options for these case: From 6934599450e2190eeda90c0746cdd178f148009e Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Thu, 29 Jun 2017 22:49:30 +0800 Subject: [PATCH 03/22] Add SPC a * --- autoload/SpaceVim/layers/edit.vim | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/autoload/SpaceVim/layers/edit.vim b/autoload/SpaceVim/layers/edit.vim index 3bcca38b8..956a7d22d 100644 --- a/autoload/SpaceVim/layers/edit.vim +++ b/autoload/SpaceVim/layers/edit.vim @@ -41,4 +41,14 @@ function! SpaceVim#layers#edit#config() abort let g:_spacevim_mappings_space.x = {'name' : '+Text'} let g:_spacevim_mappings_space.x.a = {'name' : '+align'} call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '&'], 'Tabularize /&', 'align region at &', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '('], 'Tabularize /(', 'align region at (', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', ')'], 'Tabularize /)', 'align region at )', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '['], 'Tabularize /[', 'align region at [', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', ']'], 'Tabularize /]', 'align region at ]', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '{'], 'Tabularize /{', 'align region at {', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '}'], 'Tabularize /}', 'align region at }', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', ','], 'Tabularize /,', 'align region at ,', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '.'], 'Tabularize /.', 'align region at .', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', ':'], 'Tabularize /:', 'align region at :', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '='], 'Tabularize /=', 'align region at =', 1) endfunction From f53fc71e3fa994f23b891f4b1f48ac6006f000ff Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Mon, 17 Jul 2017 07:08:53 +0800 Subject: [PATCH 04/22] Add mappings for changing symbol style --- autoload/SpaceVim/layers/edit.vim | 57 ++++++++++++++++++++++++++++++ autoload/SpaceVim/layers/tools.vim | 1 + docs/documentation.md | 2 +- 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/autoload/SpaceVim/layers/edit.vim b/autoload/SpaceVim/layers/edit.vim index 956a7d22d..1ba58281c 100644 --- a/autoload/SpaceVim/layers/edit.vim +++ b/autoload/SpaceVim/layers/edit.vim @@ -1,3 +1,4 @@ +scriptencoding utf-8 function! SpaceVim#layers#edit#plugins() abort let plugins = [ \ ['tpope/vim-surround'], @@ -40,6 +41,8 @@ function! SpaceVim#layers#edit#config() abort let g:wildfire_objects = ["i'", 'i"', 'i)', 'i]', 'i}', 'ip', 'it'] let g:_spacevim_mappings_space.x = {'name' : '+Text'} let g:_spacevim_mappings_space.x.a = {'name' : '+align'} + let g:_spacevim_mappings_space.x.d = {'name' : '+delete'} + let g:_spacevim_mappings_space.x.i = {'name' : '+change symbol style'} call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '&'], 'Tabularize /&', 'align region at &', 1) call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '('], 'Tabularize /(', 'align region at (', 1) call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', ')'], 'Tabularize /)', 'align region at )', 1) @@ -50,5 +53,59 @@ function! SpaceVim#layers#edit#config() abort call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', ','], 'Tabularize /,', 'align region at ,', 1) call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '.'], 'Tabularize /.', 'align region at .', 1) call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', ':'], 'Tabularize /:', 'align region at :', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', ';'], 'Tabularize /;', 'align region at ;', 1) call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '='], 'Tabularize /=', 'align region at =', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '¦'], 'Tabularize /¦', 'align region at ¦', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'd', 'w'], 'StripWhitespace', 'delete trailing whitespaces', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'd', '[SPC]'], 'silent call call(' + \ . string(s:_function('s:delete_extra_space')) . ', [])', + \ 'delete extra space arround cursor', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'i', 'c'], 'silent call call(' + \ . string(s:_function('s:lowerCamelCase')) . ', [])', + \ 'change symbol style to lowerCamelCase', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'i', 'C'], 'silent call call(' + \ . string(s:_function('s:UpperCamelCase')) . ', [])', + \ 'change symbol style to UpperCamelCase', 1) endfunction + +function! s:lowerCamelCase() abort + let cword = expand('') + if !empty(cword) && cword[0:0] =~# '[A-Z]' + let save_cursor = getcurpos() + normal! b~ + call setpos('.', save_cursor) + endif +endfunction + +function! s:UpperCamelCase() abort + let cword = expand('') + if !empty(cword) && cword[0:0] =~# '[a-z]' + let save_cursor = getcurpos() + normal! b~ + call setpos('.', save_cursor) + endif +endfunction + + +function! s:delete_extra_space() abort + if !empty(getline('.')) + if getline('.')[col('.')-1] ==# ' ' + exe "normal! viw\"_di\\" + endif + endif +endfunction + +" function() wrapper +if v:version > 703 || v:version == 703 && has('patch1170') + function! s:_function(fstr) abort + return function(a:fstr) + endfunction +else + function! s:_SID() abort + return matchstr(expand(''), '\zs\d\+\ze__SID$') + endfunction + let s:_s = '' . s:_SID() . '_' + function! s:_function(fstr) abort + return function(substitute(a:fstr, 's:', s:_s, 'g')) + endfunction +endif diff --git a/autoload/SpaceVim/layers/tools.vim b/autoload/SpaceVim/layers/tools.vim index 13fabf06f..0c7877e20 100644 --- a/autoload/SpaceVim/layers/tools.vim +++ b/autoload/SpaceVim/layers/tools.vim @@ -47,6 +47,7 @@ function! SpaceVim#layers#tools#plugins() abort endfunction function! SpaceVim#layers#tools#config() abort + let g:better_whitespace_filetypes_blacklist = ['diff', 'gitcommit', 'unite', 'qf', 'help', 'markdown', 'leaderGuide'] call SpaceVim#mapping#space#def('nnoremap', ['a', 'c'], 'Calendar', 'vim calendar', 1) call SpaceVim#mapping#space#def('nnoremap', ['e', 'a'], 'FencAutoDetect', \ 'Auto detect the file encoding', 1) diff --git a/docs/documentation.md b/docs/documentation.md index 41ffc165a..a568ca164 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -1129,13 +1129,13 @@ Key Binding | Description `SPC x a :` | align region at : `SPC x a ;` | align region at ; `SPC x a =` | align region at = +`SPC x a ¦` | align region at ¦ `SPC x a a` | align region (or guessed section) using default rules `SPC x a c` | align current indentation region using default rules `SPC x a l` | left-align with evil-lion `SPC x a L` | right-align with evil-lion `SPC x a r` | align region using user-specified regexp `SPC x a m` | align region at arithmetic operators `` (+-*/) `` -`SPC x a ¦` | align region at ¦ `SPC x c` | cunt the number of chars/words/lines in the selection region `SPC x d w` | delete trailing whitespaces `SPC x d SPC` | Delete all spaces and tabs around point, leaving one space From 8dae2365c5ba288d542b1c489be24dd677d9ceec Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Mon, 17 Jul 2017 07:36:55 +0800 Subject: [PATCH 05/22] Add symbol parse func --- autoload/SpaceVim/layers/edit.vim | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/autoload/SpaceVim/layers/edit.vim b/autoload/SpaceVim/layers/edit.vim index 1ba58281c..391d64de5 100644 --- a/autoload/SpaceVim/layers/edit.vim +++ b/autoload/SpaceVim/layers/edit.vim @@ -69,6 +69,7 @@ function! SpaceVim#layers#edit#config() abort endfunction function! s:lowerCamelCase() abort + " fooFzz let cword = expand('') if !empty(cword) && cword[0:0] =~# '[A-Z]' let save_cursor = getcurpos() @@ -78,6 +79,7 @@ function! s:lowerCamelCase() abort endfunction function! s:UpperCamelCase() abort + " FooFzz let cword = expand('') if !empty(cword) && cword[0:0] =~# '[a-z]' let save_cursor = getcurpos() @@ -86,6 +88,22 @@ function! s:UpperCamelCase() abort endif endfunction +function! s:kebab_case() abort + " foo-fzz + + +endfunction + +function! s:parse_symbol(symbol) abort + if a:symbol =~ '^[a-z]\+\(-[a-zA-Z]\+\)*$' + return split(a:symbol, '-') + elseif a:symbol =~ '^[a-z]\+\(_[a-zA-Z]\+\)*$' + return split(a:symbol, '_') + elseif a:symbol =~ '^[a-z]\+\([A-Z][a-z]\+\)*$' + else + endif +endfunction + function! s:delete_extra_space() abort if !empty(getline('.')) From 7c0123e761fd31b8420c0cbd8d594136161e9e4c Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Mon, 17 Jul 2017 07:44:46 +0800 Subject: [PATCH 06/22] Add symbol parse func --- autoload/SpaceVim/layers/edit.vim | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/autoload/SpaceVim/layers/edit.vim b/autoload/SpaceVim/layers/edit.vim index 391d64de5..ab97034ec 100644 --- a/autoload/SpaceVim/layers/edit.vim +++ b/autoload/SpaceVim/layers/edit.vim @@ -91,16 +91,33 @@ endfunction function! s:kebab_case() abort " foo-fzz - + endfunction +let s:STRING = SpaceVim#api#import('data#string') function! s:parse_symbol(symbol) abort if a:symbol =~ '^[a-z]\+\(-[a-zA-Z]\+\)*$' return split(a:symbol, '-') elseif a:symbol =~ '^[a-z]\+\(_[a-zA-Z]\+\)*$' return split(a:symbol, '_') elseif a:symbol =~ '^[a-z]\+\([A-Z][a-z]\+\)*$' + let chars = s:STRING.str2chars(a:symbol) + let rst = [] + let word = '' + for char in chars + if char =~# '[a-z]' + let word .= char + else + call add(rst, word) + let word = char + endif + endfor + if !empty(word) + call add(rst, word) + endif + return rst else + return [a:symbol] endif endfunction From b4c2c6c66edc9572a711c872843a8afa40b97442 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Mon, 17 Jul 2017 07:54:57 +0800 Subject: [PATCH 07/22] Add case func --- autoload/SpaceVim/layers/edit.vim | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/autoload/SpaceVim/layers/edit.vim b/autoload/SpaceVim/layers/edit.vim index 89fa8f532..72e668e42 100644 --- a/autoload/SpaceVim/layers/edit.vim +++ b/autoload/SpaceVim/layers/edit.vim @@ -70,6 +70,23 @@ function! SpaceVim#layers#edit#config() abort call SpaceVim#mapping#space#def('nnoremap', ['x', 'i', 'C'], 'silent call call(' \ . string(s:_function('s:UpperCamelCase')) . ', [])', \ 'change symbol style to UpperCamelCase', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'i', '_'], 'silent call call(' + \ . string(s:_function('s:under_score')) . ', [])', + \ 'change symbol style to under_score', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'i', 'u'], 'silent call call(' + \ . string(s:_function('s:under_score')) . ', [])', + \ 'change symbol style to under_score', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'i', 'U'], 'silent call call(' + \ . string(s:_function('s:up_case')) . ', [])', + \ 'change symbol style to UP_CACE', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'i', 'k'], 'silent call call(' + \ . string(s:_function('s:kebab_case')) . ', [])', + \ 'change symbol style to kebab-case', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'i', '-'], 'silent call call(' + \ . string(s:_function('s:kebab_case')) . ', [])', + \ 'change symbol style to kebab-case', 1) + + let g:_spacevim_mappings_space.i = {'name' : '+Insertion'} let g:_spacevim_mappings_space.i.l = {'name' : '+Lorem-ipsum'} let g:_spacevim_mappings_space.i.p = {'name' : '+Passwords'} @@ -126,8 +143,14 @@ endfunction function! s:kebab_case() abort " foo-fzz +endfunction +function! s:under_score() abort + +endfunction +function! s:up_case() abort + endfunction let s:STRING = SpaceVim#api#import('data#string') From 2c8b4c6cbc3a1d19104f287e54ebdd7ddd937a88 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Wed, 19 Jul 2017 05:01:34 +0800 Subject: [PATCH 08/22] Fix up --- autoload/SpaceVim/layers/edit.vim | 78 +++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 13 deletions(-) diff --git a/autoload/SpaceVim/layers/edit.vim b/autoload/SpaceVim/layers/edit.vim index 72e668e42..2e5b08f45 100644 --- a/autoload/SpaceVim/layers/edit.vim +++ b/autoload/SpaceVim/layers/edit.vim @@ -123,34 +123,72 @@ endfunction function! s:lowerCamelCase() abort " fooFzz - let cword = expand('') - if !empty(cword) && cword[0:0] =~# '[A-Z]' + let cword = s:parse_symbol(expand('')) + if !empty(cword) + let rst = [cword[0]] + if len(cword) > 1 + let rst += map(cword[1:], "substitute(v:val, '^.', '\\u&', 'g')") + endif + let save_register = @k let save_cursor = getcurpos() - normal! b~ + let @k = join(rst, '') + normal! viw"kp call setpos('.', save_cursor) + let @k = save_register endif endfunction function! s:UpperCamelCase() abort " FooFzz - let cword = expand('') - if !empty(cword) && cword[0:0] =~# '[a-z]' + let cword = s:parse_symbol(expand('')) + if !empty(cword) + let rst = map(cword, "substitute(v:val, '^.', '\\u&', 'g')") + let save_register = @k let save_cursor = getcurpos() - normal! b~ + let @k = join(rst, '') + normal! viw"kp call setpos('.', save_cursor) + let @k = save_register endif endfunction function! s:kebab_case() abort " foo-fzz + let cword = s:parse_symbol(expand('')) + if !empty(cword) + let save_register = @k + let save_cursor = getcurpos() + let @k = join(cword, '-') + normal! viw"kp + call setpos('.', save_cursor) + let @k = save_register + endif endfunction function! s:under_score() abort - + " foo_fzz + let cword = s:parse_symbol(expand('')) + if !empty(cword) + let save_register = @k + let save_cursor = getcurpos() + let @k = join(cword, '_') + normal! viw"kp + call setpos('.', save_cursor) + let @k = save_register + endif endfunction function! s:up_case() abort - + " FOO_FZZ + let cword =map(s:parse_symbol(expand('')), 'toupper(v:val)') + if !empty(cword) + let save_register = @k + let save_cursor = getcurpos() + let @k = join(cword, '_') + normal! viw"kp + call setpos('.', save_cursor) + let @k = save_register + endif endfunction let s:STRING = SpaceVim#api#import('data#string') @@ -160,20 +198,34 @@ function! s:parse_symbol(symbol) abort elseif a:symbol =~ '^[a-z]\+\(_[a-zA-Z]\+\)*$' return split(a:symbol, '_') elseif a:symbol =~ '^[a-z]\+\([A-Z][a-z]\+\)*$' - let chars = s:STRING.str2chars(a:symbol) + let chars = s:STRING.string2chars(a:symbol) let rst = [] let word = '' for char in chars if char =~# '[a-z]' let word .= char else - call add(rst, word) + call add(rst, tolower(word)) let word = char endif endfor - if !empty(word) - call add(rst, word) - endif + call add(rst, tolower(word)) + return rst + elseif a:symbol =~ '^[A-Z][a-z]\+\([A-Z][a-z]\+\)*$' + let chars = s:STRING.string2chars(a:symbol) + let rst = [] + let word = '' + for char in chars + if char =~# '[a-z]' + let word .= char + else + if !empty(word) + call add(rst, tolower(word)) + endif + let word = char + endif + endfor + call add(rst, tolower(word)) return rst else return [a:symbol] From b1ebe04d44a198b22e67cb97c22483bceded7350 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Wed, 19 Jul 2017 07:09:41 +0800 Subject: [PATCH 09/22] Add SPC x c --- autoload/SpaceVim/layers/edit.vim | 9 +++++++++ docs/documentation.md | 30 +++++++++++++++--------------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/autoload/SpaceVim/layers/edit.vim b/autoload/SpaceVim/layers/edit.vim index 2e5b08f45..26dc16b6d 100644 --- a/autoload/SpaceVim/layers/edit.vim +++ b/autoload/SpaceVim/layers/edit.vim @@ -47,6 +47,9 @@ function! SpaceVim#layers#edit#config() abort let g:_spacevim_mappings_space.x.a = {'name' : '+align'} let g:_spacevim_mappings_space.x.d = {'name' : '+delete'} let g:_spacevim_mappings_space.x.i = {'name' : '+change symbol style'} + nnoremap CountSelectionRegion :call count_selection_region() + xnoremap CountSelectionRegion :call count_selection_region() + call SpaceVim#mapping#space#def('nmap', ['x', 'c'], 'CountSelectionRegion', 'cunt in the selection region', 0, 1) call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '&'], 'Tabularize /&', 'align region at &', 1) call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '('], 'Tabularize /(', 'align region at (', 1) call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', ')'], 'Tabularize /)', 'align region at )', 1) @@ -119,6 +122,8 @@ function! SpaceVim#layers#edit#config() abort call SpaceVim#mapping#space#def('nnoremap', ['i', 'l', 's'], 'call call(' \ . string(s:_function('s:insert_lorem_ipsum_sentence')) . ', [])', \ 'insert lorem-ipsum sentence', 1) + let g:_spacevim_mappings_space.x.g = {'name' : '+translate'} + call SpaceVim#mapping#space#def('nnoremap', ['x', 'g', 't'], 'Ydc', 'translate current word', 1) endfunction function! s:lowerCamelCase() abort @@ -232,6 +237,10 @@ function! s:parse_symbol(symbol) abort endif endfunction +function! s:count_selection_region() abort + call feedkeys("gvg\\", 'ti') +endfunction + function! s:delete_extra_space() abort if !empty(getline('.')) diff --git a/docs/documentation.md b/docs/documentation.md index 09e04bba2..e9f047076 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -1180,26 +1180,26 @@ Key Binding | Description `SPC x a ;` | align region at ; `SPC x a =` | align region at = `SPC x a ¦` | align region at ¦ -`SPC x a a` | align region (or guessed section) using default rules -`SPC x a c` | align current indentation region using default rules -`SPC x a l` | left-align with evil-lion -`SPC x a L` | right-align with evil-lion -`SPC x a r` | align region using user-specified regexp -`SPC x a m` | align region at arithmetic operators `` (+-*/) `` +`SPC x a a` | align region (or guessed section) using default rules (TODO) +`SPC x a c` | align current indentation region using default rules (TODO) +`SPC x a l` | left-align with evil-lion (TODO) +`SPC x a L` | right-align with evil-lion (TODO) +`SPC x a r` | align region using user-specified regexp (TODO) +`SPC x a m` | align region at arithmetic operators `` (+-*/) `` (TODO) `SPC x c` | cunt the number of chars/words/lines in the selection region `SPC x d w` | delete trailing whitespaces `SPC x d SPC` | Delete all spaces and tabs around point, leaving one space -`SPC x g l` | set languages used by translate commands +`SPC x g l` | set languages used by translate commands (TODO) `SPC x g t` | translate current word using Google Translate -`SPC x g T` | reverse source and target languages -`SPC x i c` | change symbol style to lowerCamelCase -`SPC x i C` | change symbol style to UpperCamelCase +`SPC x g T` | reverse source and target languages (TODO) +`SPC x i c` | change symbol style to `lowerCamelCase` +`SPC x i C` | change symbol style to `UpperCamelCase` `SPC x i i` | cycle symbol naming styles (i to keep cycling) -`SPC x i -` | change symbol style to kebab-case -`SPC x i k` | change symbol style to kebab-case -`SPC x i _` | change symbol style to under_score -`SPC x i u` | change symbol style to under_score -`SPC x i U` | change symbol style to UP_CASE +`SPC x i -` | change symbol style to `kebab-case` +`SPC x i k` | change symbol style to `kebab-case` +`SPC x i _` | change symbol style to `under_score` +`SPC x i u` | change symbol style to `under_score` +`SPC x i U` | change symbol style to `UP_CASE` `SPC x j c` | set the justification to center `SPC x j f` | set the justification to full `SPC x j l` | set the justification to left From 5521e64072cfd4675e515a533f69723be4f9b87a Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sat, 22 Jul 2017 07:30:17 +0800 Subject: [PATCH 10/22] Add transient state api --- autoload/SpaceVim/api/transient_state.vim | 76 +++++++++++++++++++++++ autoload/SpaceVim/layers/edit.vim | 24 +++++++ docs/documentation.md | 12 ++-- 3 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 autoload/SpaceVim/api/transient_state.vim diff --git a/autoload/SpaceVim/api/transient_state.vim b/autoload/SpaceVim/api/transient_state.vim new file mode 100644 index 000000000..171a6499c --- /dev/null +++ b/autoload/SpaceVim/api/transient_state.vim @@ -0,0 +1,76 @@ +let s:self = {} + +let s:self._keys = {} +let s:self._on_syntax = '' +let s:self._title = 'Transient State' + +function! s:self.open() abort + noautocmd rightbelow split __transient_state__ + let self._bufid = bufnr('%') + setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell nonu norelativenumber + " let save_tve = &t_ve + " setlocal t_ve= + " setlocal nomodifiable + " setf SpaceVimFlyGrep + " let &t_ve = save_tve + if !empty(self._on_syntax) && type(self._on_syntax) ==# 2 + call call(self._on_syntax, []) + else + hi def link SpaceVim_Transient_State_Exit Keyword + hi def link SpaceVim_Transient_State_Notexit Number + hi def link SpaceVim_Transient_State_Title Title + endif + call setline(1, self._title) + call append(line('$'), '') + call self.highlight_title() + call self._update_content() + call append(line('$'), '') + call append(line('$'), '[KEY] exits state [KEY] will not exit') + call self.highlight_keys(1, line('$') - 1, 1, 4) + call self.highlight_keys(0, line('$') - 1, 21, 24) + " move to prvious window + wincmd w + redraw! + while 1 + let char = getchar() + if char ==# "\" || char ==# "\" || char2nr(char) == 128 + continue + endif + if !has_key(self._keys, char) + break + endif + endwhile + exe 'bd ' . self._bufid +endfunction + +function! s:self.defind_keys(dict) abort + let self._keys = a:dict +endfunction + +function! s:self.set_syntax(func) abort + let self._on_syntax = a:func +endfunction + +function! s:self.set_title(title) abort + let self._title = a:title +endfunction + +function! s:self.highlight_keys(exit, line, begin, end) abort + if a:exit + call nvim_buf_add_highlight(self._bufid, 0, 'SpaceVim_Transient_State_Exit', a:line, a:begin, a:end) + else + call nvim_buf_add_highlight(self._bufid, 0, 'SpaceVim_Transient_State_Notexit', a:line, a:begin, a:end) + endif +endfunction + +function! s:self.highlight_title() abort + call nvim_buf_add_highlight(self._bufid, 0, 'SpaceVim_Transient_State_Title', 0, 0, len(self._title)) +endfunction + +function! s:self._update_content() abort + +endfunction + +function! SpaceVim#api#transient_state#get() abort + return deepcopy(s:self) +endfunction diff --git a/autoload/SpaceVim/layers/edit.vim b/autoload/SpaceVim/layers/edit.vim index 26dc16b6d..92a5e4601 100644 --- a/autoload/SpaceVim/layers/edit.vim +++ b/autoload/SpaceVim/layers/edit.vim @@ -124,6 +124,30 @@ function! SpaceVim#layers#edit#config() abort \ 'insert lorem-ipsum sentence', 1) let g:_spacevim_mappings_space.x.g = {'name' : '+translate'} call SpaceVim#mapping#space#def('nnoremap', ['x', 'g', 't'], 'Ydc', 'translate current word', 1) + + " move line + call SpaceVim#mapping#space#def('nnoremap', ['x', 'J'], 'call call(' + \ . string(s:_function('s:move_text_down_transient_state')) . ', [])', + \ 'move text down(enter transient state)', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'K'], 'call call(' + \ . string(s:_function('s:move_text_up_transient_state')) . ', [])', + \ 'move text up(enter transient state)', 1) +endfunction + +function! s:move_text_down_transient_state() abort + normal! "_ddp + call s:text_transient_state() +endfunction + +function! s:move_text_up_transient_state() abort + normal! "_ddkP + call s:text_transient_state() +endfunction + +function! s:text_transient_state() abort + let state = SpaceVim#api#import('transient_state') + call state.set_title('Move Text Transient State') + call state.open() endfunction function! s:lowerCamelCase() abort diff --git a/docs/documentation.md b/docs/documentation.md index e9f047076..95eed0a94 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -1189,7 +1189,7 @@ Key Binding | Description `SPC x c` | cunt the number of chars/words/lines in the selection region `SPC x d w` | delete trailing whitespaces `SPC x d SPC` | Delete all spaces and tabs around point, leaving one space -`SPC x g l` | set languages used by translate commands (TODO) +`SPC x g l` | set lanuages used by translate commands (TODO) `SPC x g t` | translate current word using Google Translate `SPC x g T` | reverse source and target languages (TODO) `SPC x i c` | change symbol style to `lowerCamelCase` @@ -1200,11 +1200,11 @@ Key Binding | Description `SPC x i _` | change symbol style to `under_score` `SPC x i u` | change symbol style to `under_score` `SPC x i U` | change symbol style to `UP_CASE` -`SPC x j c` | set the justification to center -`SPC x j f` | set the justification to full -`SPC x j l` | set the justification to left -`SPC x j n` | set the justification to none -`SPC x j r` | set the justification to right +`SPC x j c` | set the justification to center (TODO) +`SPC x j f` | set the justification to full (TODO) +`SPC x j l` | set the justification to left (TODO) +`SPC x j n` | set the justification to none (TODO) +`SPC x j r` | set the justification to right (TODO) `SPC x J` | move down a line of text (enter transient state) `SPC x K` | move up a line of text (enter transient state) `SPC x l d` | duplicate line or region From b202edc9b61f040fe04287939f6dc68d63888325 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sat, 22 Jul 2017 07:58:08 +0800 Subject: [PATCH 11/22] Add key parse --- autoload/SpaceVim/api/transient_state.vim | 17 ++++++++++++- autoload/SpaceVim/layers/edit.vim | 29 ++++++++++++++++++++--- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/autoload/SpaceVim/api/transient_state.vim b/autoload/SpaceVim/api/transient_state.vim index 171a6499c..bd2af54df 100644 --- a/autoload/SpaceVim/api/transient_state.vim +++ b/autoload/SpaceVim/api/transient_state.vim @@ -68,7 +68,22 @@ function! s:self.highlight_title() abort endfunction function! s:self._update_content() abort - + if self._keys.layout == 'vertical split' + let linenum = max([len(self._keys.right), len(self._keys.left)]) + for i in range(linenum) + let left = get(self._keys.left, i) + let right = get(self._keys.right, i) + let line = '' + if !empty(left) + let line .= '[' . left.key . '] ' . left.desc + endif + let line .= repeat(' ', 40 - len(line)) + if !empty(right) + let line .= '[' . right.key . '] ' . right.desc + endif + call append(line('$'), line) + endfor + endif endfunction function! SpaceVim#api#transient_state#get() abort diff --git a/autoload/SpaceVim/layers/edit.vim b/autoload/SpaceVim/layers/edit.vim index 92a5e4601..b766d23c5 100644 --- a/autoload/SpaceVim/layers/edit.vim +++ b/autoload/SpaceVim/layers/edit.vim @@ -145,9 +145,32 @@ function! s:move_text_up_transient_state() abort endfunction function! s:text_transient_state() abort - let state = SpaceVim#api#import('transient_state') - call state.set_title('Move Text Transient State') - call state.open() + let state = SpaceVim#api#import('transient_state') + call state.set_title('Move Text Transient State') + call state.defind_keys( + \ { + \ 'layout' : 'vertical split', + \ 'left' : [ + \ { + \ 'key' : 'J', + \ 'desc' : 'move text down', + \ 'func' : '', + \ 'cmd' : 'normal! "_ddp', + \ 'exit' : 0, + \ }, + \ ], + \ 'right' : [ + \ { + \ 'key' : 'K', + \ 'desc' : 'move text up', + \ 'func' : '', + \ 'cmd' : 'normal! "_ddkP', + \ 'exit' : 0, + \ }, + \ ], + \ } + \ ) + call state.open() endfunction function! s:lowerCamelCase() abort From 441cb9e1d4c507b08415c2c2e2b4ca20abfed2a5 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sat, 22 Jul 2017 08:33:41 +0800 Subject: [PATCH 12/22] Handle input --- autoload/SpaceVim/api/transient_state.vim | 33 +++++++++++++++++++++-- autoload/SpaceVim/layers/edit.vim | 4 +-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/autoload/SpaceVim/api/transient_state.vim b/autoload/SpaceVim/api/transient_state.vim index bd2af54df..91fcad24b 100644 --- a/autoload/SpaceVim/api/transient_state.vim +++ b/autoload/SpaceVim/api/transient_state.vim @@ -3,6 +3,7 @@ let s:self = {} let s:self._keys = {} let s:self._on_syntax = '' let s:self._title = 'Transient State' +let s:self._handle_inputs = {} function! s:self.open() abort noautocmd rightbelow split __transient_state__ @@ -28,21 +29,37 @@ function! s:self.open() abort call append(line('$'), '[KEY] exits state [KEY] will not exit') call self.highlight_keys(1, line('$') - 1, 1, 4) call self.highlight_keys(0, line('$') - 1, 21, 24) + if winheight(0) > line('$') + exe 'resize ' . line('$') + endif " move to prvious window wincmd w redraw! while 1 - let char = getchar() + let char = self._getchar() if char ==# "\" || char ==# "\" || char2nr(char) == 128 continue endif - if !has_key(self._keys, char) + if !has_key(self._handle_inputs, char) break + else + if type(self._handle_inputs[char]) == 2 + call call(self._handle_inputs[char], []) + else + if type(self._handle_inputs[char]) == 1 + exe self._handle_inputs[char] + endif endif endwhile exe 'bd ' . self._bufid endfunction + +function! s:self._getchar(...) abort + let ret = call('getchar', a:000) + return (type(ret) == type(0) ? nr2char(ret) : ret) +endfunction + function! s:self.defind_keys(dict) abort let self._keys = a:dict endfunction @@ -76,10 +93,22 @@ function! s:self._update_content() abort let line = '' if !empty(left) let line .= '[' . left.key . '] ' . left.desc + call self.highlight_keys(left.exit, i + 2, 1, 1 + len(left.key)) + if !empty(left.cmd) + call extend(self._handle_inputs, {left.key : left.cmd}) + elseif !empty(left.func) + call extend(self._handle_inputs, {left.key : left.func}) + endif endif let line .= repeat(' ', 40 - len(line)) if !empty(right) let line .= '[' . right.key . '] ' . right.desc + call self.highlight_keys(right.exit, i + 2, 41, 41 + len(right.key)) + if !empty(right.cmd) + call extend(self._handle_inputs, {right.key : right.cmd}) + elseif !empty(right.func) + call extend(self._handle_inputs, {right.key : right.func}) + endif endif call append(line('$'), line) endfor diff --git a/autoload/SpaceVim/layers/edit.vim b/autoload/SpaceVim/layers/edit.vim index b766d23c5..06c09cc48 100644 --- a/autoload/SpaceVim/layers/edit.vim +++ b/autoload/SpaceVim/layers/edit.vim @@ -135,12 +135,12 @@ function! SpaceVim#layers#edit#config() abort endfunction function! s:move_text_down_transient_state() abort - normal! "_ddp + normal! ddp call s:text_transient_state() endfunction function! s:move_text_up_transient_state() abort - normal! "_ddkP + normal! ddkP call s:text_transient_state() endfunction From 15fb53b64ebeb1ef49037e63f232b10507dd4f94 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sat, 22 Jul 2017 08:45:28 +0800 Subject: [PATCH 13/22] Fixup --- autoload/SpaceVim/api/transient_state.vim | 5 +++-- autoload/SpaceVim/layers/core/statusline.vim | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/autoload/SpaceVim/api/transient_state.vim b/autoload/SpaceVim/api/transient_state.vim index 91fcad24b..cda02736e 100644 --- a/autoload/SpaceVim/api/transient_state.vim +++ b/autoload/SpaceVim/api/transient_state.vim @@ -9,6 +9,7 @@ function! s:self.open() abort noautocmd rightbelow split __transient_state__ let self._bufid = bufnr('%') setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell nonu norelativenumber + set filetype=TransientState " let save_tve = &t_ve " setlocal t_ve= " setlocal nomodifiable @@ -22,6 +23,7 @@ function! s:self.open() abort hi def link SpaceVim_Transient_State_Title Title endif call setline(1, self._title) + let b:transient_state_title = self._title call append(line('$'), '') call self.highlight_title() call self._update_content() @@ -45,8 +47,7 @@ function! s:self.open() abort else if type(self._handle_inputs[char]) == 2 call call(self._handle_inputs[char], []) - else - if type(self._handle_inputs[char]) == 1 + elseif type(self._handle_inputs[char]) == 1 exe self._handle_inputs[char] endif endif diff --git a/autoload/SpaceVim/layers/core/statusline.vim b/autoload/SpaceVim/layers/core/statusline.vim index 63b6a3d99..10e2f053a 100644 --- a/autoload/SpaceVim/layers/core/statusline.vim +++ b/autoload/SpaceVim/layers/core/statusline.vim @@ -218,6 +218,8 @@ function! SpaceVim#layers#core#statusline#get(...) abort return '%#SpaceVim_statusline_a# FlyGrep %#SpaceVim_statusline_a_SpaceVim_statusline_b#' \ . '%#SpaceVim_statusline_b# %{getcwd()}%#SpaceVim_statusline_b_SpaceVim_statusline_c#' \ . '%#SpaceVim_statusline_c# %{SpaceVim#plugins#flygrep#lineNr()}' + elseif &filetype ==# 'TransientState' + return '%#SpaceVim_statusline_a# Transient State %#SpaceVim_statusline_a_SpaceVim_statusline_b#' endif if a:0 > 0 return s:active() From ab9a50d21bb7d8bf442d07df745562990916e8d8 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sat, 22 Jul 2017 08:47:46 +0800 Subject: [PATCH 14/22] Redraw in while loop --- autoload/SpaceVim/api/transient_state.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/SpaceVim/api/transient_state.vim b/autoload/SpaceVim/api/transient_state.vim index cda02736e..73d482df7 100644 --- a/autoload/SpaceVim/api/transient_state.vim +++ b/autoload/SpaceVim/api/transient_state.vim @@ -36,8 +36,8 @@ function! s:self.open() abort endif " move to prvious window wincmd w - redraw! while 1 + redraw! let char = self._getchar() if char ==# "\" || char ==# "\" || char2nr(char) == 128 continue From 9733fb6da40d8eb07e9a980bca348c05acdf81e0 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sat, 22 Jul 2017 08:52:09 +0800 Subject: [PATCH 15/22] Do autocmd WinEnter to make statusline active --- autoload/SpaceVim/api/transient_state.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/autoload/SpaceVim/api/transient_state.vim b/autoload/SpaceVim/api/transient_state.vim index 73d482df7..699bbf796 100644 --- a/autoload/SpaceVim/api/transient_state.vim +++ b/autoload/SpaceVim/api/transient_state.vim @@ -53,6 +53,7 @@ function! s:self.open() abort endif endwhile exe 'bd ' . self._bufid + doautocmd WinEnter endfunction From c8c700efe179ac4f096330f64314f3d0f9d08f9e Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sat, 22 Jul 2017 22:52:15 +0800 Subject: [PATCH 16/22] Add buffer selection transient state --- autoload/SpaceVim/api/transient_state.vim | 2 +- autoload/SpaceVim/layers/default.vim | 10 ++++++++++ docs/documentation.md | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/autoload/SpaceVim/api/transient_state.vim b/autoload/SpaceVim/api/transient_state.vim index 699bbf796..48b794ca5 100644 --- a/autoload/SpaceVim/api/transient_state.vim +++ b/autoload/SpaceVim/api/transient_state.vim @@ -87,7 +87,7 @@ function! s:self.highlight_title() abort endfunction function! s:self._update_content() abort - if self._keys.layout == 'vertical split' + if get(self._keys, 'layout', '') == 'vertical split' let linenum = max([len(self._keys.right), len(self._keys.left)]) for i in range(linenum) let left = get(self._keys.left, i) diff --git a/autoload/SpaceVim/layers/default.vim b/autoload/SpaceVim/layers/default.vim index 32a0769a3..5e5da556a 100644 --- a/autoload/SpaceVim/layers/default.vim +++ b/autoload/SpaceVim/layers/default.vim @@ -93,6 +93,9 @@ function! SpaceVim#layers#default#config() abort \ . string(s:_function('s:jump_to_url')) . ', [])', \ 'jump to url', 1) call SpaceVim#mapping#space#def('nnoremap', [''], 'try | b# | catch | endtry', 'last buffer', 1) + call SpaceVim#mapping#space#def('nnoremap', ['b', '.'], 'call call(' + \ . string(s:_function('s:buffer_transient_state')) . ', [])', + \ 'buffer transient state', 1) call SpaceVim#mapping#space#def('nnoremap', ['b', 'd'], 'call SpaceVim#mapping#close_current_buffer()', 'kill-this-buffer', 1) call SpaceVim#mapping#space#def('nnoremap', ['b', 'D'], \ 'call SpaceVim#mapping#kill_visible_buffer_choosewin()', @@ -285,3 +288,10 @@ function! s:delete_current_buffer_file() abort redraw! endfunction + +function! s:buffer_transient_state() abort + let state = SpaceVim#api#import('transient_state') + call state.set_title('Buffer Selection Transient State') + call state.defind_keys({}) + call state.open() +endfunction diff --git a/docs/documentation.md b/docs/documentation.md index 95eed0a94..d782e06da 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -759,6 +759,7 @@ Buffer manipulation commands (start with `b`): Key Binding | Description ----------- | ----------- `SPC TAB` | switch to alternate buffer in the current window (switch back and forth) +`SPC b .` | buffer transient state `SPC b b` | switch to a buffer (via denite/unite) `SPC b d` | kill the current buffer (does not delete the visited file) `SPC u SPC b d` | kill the current buffer and window (does not delete the visited file) (TODO) From d75ff533c7fc875ede0b8d5f788d21924c4997b4 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sat, 22 Jul 2017 22:56:39 +0800 Subject: [PATCH 17/22] Open transient state at the bottom --- autoload/SpaceVim/api/transient_state.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/SpaceVim/api/transient_state.vim b/autoload/SpaceVim/api/transient_state.vim index 48b794ca5..eddd3611d 100644 --- a/autoload/SpaceVim/api/transient_state.vim +++ b/autoload/SpaceVim/api/transient_state.vim @@ -6,7 +6,7 @@ let s:self._title = 'Transient State' let s:self._handle_inputs = {} function! s:self.open() abort - noautocmd rightbelow split __transient_state__ + noautocmd botright split __transient_state__ let self._bufid = bufnr('%') setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell nonu norelativenumber set filetype=TransientState From 26a87d2fcc0fda8a35dad305dc45ea4b818cb203 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sat, 22 Jul 2017 23:11:53 +0800 Subject: [PATCH 18/22] Add keys in buffer transient state --- autoload/SpaceVim/layers/default.vim | 38 +++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/autoload/SpaceVim/layers/default.vim b/autoload/SpaceVim/layers/default.vim index 5e5da556a..f564213e7 100644 --- a/autoload/SpaceVim/layers/default.vim +++ b/autoload/SpaceVim/layers/default.vim @@ -292,6 +292,42 @@ endfunction function! s:buffer_transient_state() abort let state = SpaceVim#api#import('transient_state') call state.set_title('Buffer Selection Transient State') - call state.defind_keys({}) + call state.defind_keys( + \ { + \ 'layout' : 'vertical split', + \ 'left' : [ + \ { + \ 'key' : 'J', + \ 'desc' : 'move text down', + \ 'func' : '', + \ 'cmd' : 'normal! "_ddp', + \ 'exit' : 0, + \ }, + \ ], + \ 'right' : [ + \ { + \ 'key' : 'n', + \ 'desc' : 'next buffer', + \ 'func' : '', + \ 'cmd' : 'bnext', + \ 'exit' : 0, + \ }, + \ { + \ 'key' : 'd', + \ 'desc' : 'kill buffer', + \ 'func' : '', + \ 'cmd' : 'call SpaceVim#mapping#close_current_buffer()', + \ 'exit' : 0, + \ }, + \ { + \ 'key' : 'q', + \ 'desc' : 'quit', + \ 'func' : '', + \ 'cmd' : '', + \ 'exit' : 1, + \ }, + \ ], + \ } + \ ) call state.open() endfunction From 45149ba8b049c85911dfc672c8a214c6981c7c77 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sat, 22 Jul 2017 23:57:37 +0800 Subject: [PATCH 19/22] Support list in transient keys --- autoload/SpaceVim/api/transient_state.vim | 44 ++++++++++++++++------- autoload/SpaceVim/layers/default.vim | 7 ++++ 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/autoload/SpaceVim/api/transient_state.vim b/autoload/SpaceVim/api/transient_state.vim index eddd3611d..9acb98f84 100644 --- a/autoload/SpaceVim/api/transient_state.vim +++ b/autoload/SpaceVim/api/transient_state.vim @@ -94,22 +94,42 @@ function! s:self._update_content() abort let right = get(self._keys.right, i) let line = '' if !empty(left) - let line .= '[' . left.key . '] ' . left.desc - call self.highlight_keys(left.exit, i + 2, 1, 1 + len(left.key)) - if !empty(left.cmd) - call extend(self._handle_inputs, {left.key : left.cmd}) - elseif !empty(left.func) - call extend(self._handle_inputs, {left.key : left.func}) + if type(left.key) ==# type('') + let line .= '[' . left.key . '] ' . left.desc + call self.highlight_keys(left.exit, i + 2, 1, 1 + len(left.key)) + if !empty(left.cmd) + call extend(self._handle_inputs, {left.key : left.cmd}) + elseif !empty(left.func) + call extend(self._handle_inputs, {left.key : left.func}) + endif endif endif let line .= repeat(' ', 40 - len(line)) if !empty(right) - let line .= '[' . right.key . '] ' . right.desc - call self.highlight_keys(right.exit, i + 2, 41, 41 + len(right.key)) - if !empty(right.cmd) - call extend(self._handle_inputs, {right.key : right.cmd}) - elseif !empty(right.func) - call extend(self._handle_inputs, {right.key : right.func}) + if type(right.key) == 1 + let line .= '[' . right.key . '] ' . right.desc + call self.highlight_keys(right.exit, i + 2, 41, 41 + len(right.key)) + if !empty(right.cmd) + call extend(self._handle_inputs, {right.key : right.cmd}) + elseif !empty(right.func) + call extend(self._handle_inputs, {right.key : right.func}) + endif + elseif type(right.key) == 3 + let line .= '[' . join(right.key, '/') . '] ' . right.desc + let begin = 41 + for key in right.key + call self.highlight_keys(right.exit, i + 2, begin, begin + len(key)) + let begin = begin + len(key) + 1 + endfor + if !empty(right.cmd) + for key in right.key + call extend(self._handle_inputs, {key : right.cmd}) + endfor + elseif !empty(right.func) + for key in right.key + call extend(self._handle_inputs, {key : right.func}) + endfor + endif endif endif call append(line('$'), line) diff --git a/autoload/SpaceVim/layers/default.vim b/autoload/SpaceVim/layers/default.vim index f564213e7..af9767089 100644 --- a/autoload/SpaceVim/layers/default.vim +++ b/autoload/SpaceVim/layers/default.vim @@ -313,6 +313,13 @@ function! s:buffer_transient_state() abort \ 'exit' : 0, \ }, \ { + \ 'key' : ['N', 'p'], + \ 'desc' : 'previous buffer', + \ 'func' : '', + \ 'cmd' : 'bp', + \ 'exit' : 0, + \ }, + \ { \ 'key' : 'd', \ 'desc' : 'kill buffer', \ 'func' : '', From 08ee17ab3ba348d1f70263efe3e6e01cffb8a4be Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 23 Jul 2017 00:07:25 +0800 Subject: [PATCH 20/22] Add doc for transient state --- docs/documentation.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/documentation.md b/docs/documentation.md index d782e06da..7f3f77a7d 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -25,6 +25,8 @@ title: "Documentation" * [Custom Configuration](#custom-configuration) * [Automatic Generation](#automatic-generation) * [Alternative directory](#alternative-directory) +* [Concepts](#concepts) + * [Transient-states](#transient-states) * [Awesome ui](#awesome-ui) * [Colorschemes](#colorschemes) * [Font](#font) @@ -294,6 +296,19 @@ let g:spacevim_guifont = 'DejaVu\ Sans\ Mono\ for\ Powerline\ 11' Comprehensive documentation is available for each layer by :h SpaceVim. +## Concepts + +### Transient-states + +SpaceVim defines a wide variety of transient states (temporary overlay maps) where it makes sense. This prevents one from doing repetitive and tedious presses on the SPC key. + +When a transient state is active, a documentation is displayed in the transient state buffer. Additional information may as well be displayed in it. + + +Move Text Transient State: + +![Move Text Transient State](https://user-images.githubusercontent.com/13142418/28489559-4fbc1930-6ef8-11e7-9d5a-716fe8dbb881.png) + ## Awesome ui SpaceVim has a minimalistic and distraction free UI: From f8989a9269b450fadc9ceef4f40f065d69b4aec5 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 23 Jul 2017 05:35:49 +0800 Subject: [PATCH 21/22] Add keys for buffer transient state --- autoload/SpaceVim/api/transient_state.vim | 13 ++++- autoload/SpaceVim/layers/default.vim | 64 +++++++++++++++++++++-- 2 files changed, 72 insertions(+), 5 deletions(-) diff --git a/autoload/SpaceVim/api/transient_state.vim b/autoload/SpaceVim/api/transient_state.vim index 9acb98f84..1e039944f 100644 --- a/autoload/SpaceVim/api/transient_state.vim +++ b/autoload/SpaceVim/api/transient_state.vim @@ -35,7 +35,7 @@ function! s:self.open() abort exe 'resize ' . line('$') endif " move to prvious window - wincmd w + wincmd p while 1 redraw! let char = self._getchar() @@ -94,7 +94,7 @@ function! s:self._update_content() abort let right = get(self._keys.right, i) let line = '' if !empty(left) - if type(left.key) ==# type('') + if type(left.key) == 1 let line .= '[' . left.key . '] ' . left.desc call self.highlight_keys(left.exit, i + 2, 1, 1 + len(left.key)) if !empty(left.cmd) @@ -102,6 +102,15 @@ function! s:self._update_content() abort elseif !empty(left.func) call extend(self._handle_inputs, {left.key : left.func}) endif + elseif type(left.key) == 3 + elseif type(left.key) == 4 + let line .= '[' . left.key.name . '] ' . left.desc + for pos in left.key.pos + call self.highlight_keys(left.exit, i + 2, pos[0], pos[1]) + endfor + for handles in left.key.handles + call extend(self._handle_inputs, {handles[0] : handles[1]}) + endfor endif endif let line .= repeat(' ', 40 - len(line)) diff --git a/autoload/SpaceVim/layers/default.vim b/autoload/SpaceVim/layers/default.vim index af9767089..7fad6179d 100644 --- a/autoload/SpaceVim/layers/default.vim +++ b/autoload/SpaceVim/layers/default.vim @@ -289,6 +289,29 @@ function! s:delete_current_buffer_file() abort endfunction +function! s:swap_buffer_with_nth_win(nr) abort + if a:nr <= winnr('$') && a:nr != winnr() + let cb = bufnr('%') + let tb = winbufnr(a:nr) + if cb != tb + exe a:nr . 'wincmd w' + exe 'b' . cb + wincmd p + exe 'b' . tb + endif + endif +endfunction + +function! s:move_buffer_to_nth_win(nr) abort + if a:nr <= winnr('$') && a:nr != winnr() + let cb = bufnr('%') + bp + exe a:nr . 'wincmd w' + exe 'b' . cb + wincmd p + endif +endfunction + function! s:buffer_transient_state() abort let state = SpaceVim#api#import('transient_state') call state.set_title('Buffer Selection Transient State') @@ -297,10 +320,45 @@ function! s:buffer_transient_state() abort \ 'layout' : 'vertical split', \ 'left' : [ \ { - \ 'key' : 'J', - \ 'desc' : 'move text down', + \ 'key' : { + \ 'name' : 'C-1..C-9', + \ 'pos' : [[1,4], [6,9]], + \ 'handles' : [ + \ ["\" , ''], + \ ["\" , ''], + \ ["\" , ''], + \ ["\" , ''], + \ ["\" , ''], + \ ["\" , ''], + \ ["\" , ''], + \ ["\" , ''], + \ ["\" , ''], + \ ], + \ }, + \ 'desc' : 'goto nth window', \ 'func' : '', - \ 'cmd' : 'normal! "_ddp', + \ 'cmd' : '', + \ 'exit' : 0, + \ }, + \ { + \ 'key' : { + \ 'name' : '1..9', + \ 'pos' : [[1,2], [4,5]], + \ 'handles' : [ + \ ['1' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [1])'], + \ ['2' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [2])'], + \ ['3' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [3])'], + \ ['4' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [4])'], + \ ['5' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [5])'], + \ ['6' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [6])'], + \ ['7' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [7])'], + \ ['8' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [8])'], + \ ['9' , 'call call(' . string(s:_function('s:move_buffer_to_nth_win')) . ', [9])'], + \ ], + \ }, + \ 'desc' : 'move buffer to nth window', + \ 'func' : '', + \ 'cmd' : '', \ 'exit' : 0, \ }, \ ], From c390713bbd91d87d298b122594ae230223bcc6a9 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 23 Jul 2017 05:46:56 +0800 Subject: [PATCH 22/22] Add keys for buffer transient state --- autoload/SpaceVim/layers/default.vim | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/autoload/SpaceVim/layers/default.vim b/autoload/SpaceVim/layers/default.vim index 7fad6179d..8103aaa9d 100644 --- a/autoload/SpaceVim/layers/default.vim +++ b/autoload/SpaceVim/layers/default.vim @@ -361,6 +361,27 @@ function! s:buffer_transient_state() abort \ 'cmd' : '', \ 'exit' : 0, \ }, + \ { + \ 'key' : { + \ 'name' : 'M-1..M-9', + \ 'pos' : [[1,4], [6,9]], + \ 'handles' : [ + \ ["\" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [1])'], + \ ["\" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [2])'], + \ ["\" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [3])'], + \ ["\" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [4])'], + \ ["\" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [5])'], + \ ["\" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [6])'], + \ ["\" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [7])'], + \ ["\" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [8])'], + \ ["\" , 'call call(' . string(s:_function('s:swap_buffer_with_nth_win')) . ', [9])'], + \ ], + \ }, + \ 'desc' : 'swap buffer with nth window', + \ 'func' : '', + \ 'cmd' : '', + \ 'exit' : 0, + \ }, \ ], \ 'right' : [ \ {