From 802d388c9dcc1c75b0acd8bcfe75cbd66c76838d Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 26 Sep 2020 13:50:44 +0200 Subject: Trying to fix omap (WIP) gG omap works characterwise but should work linewise. Adding V to the gG omap causes >17G to indent 17 times instead of once. Try changing `G` to an `` mapping to simplify the code, allowing it to work more exactly like the normal `G`. This resulted in moving the logic to `grappele#Recall()`, causing problems for `gG`. --- autoload/grappele.vim | 70 +++++++++++++++++++++++++++++++++------------------ plugin/grappele.vim | 16 ++++++------ 2 files changed, 53 insertions(+), 33 deletions(-) diff --git a/autoload/grappele.vim b/autoload/grappele.vim index 74af532..418f365 100644 --- a/autoload/grappele.vim +++ b/autoload/grappele.vim @@ -1,36 +1,56 @@ function! grappele#Grappele(line, ...) - let l:current_buffer = 0 - let l:column_position = 0 - let l:column_offset = 0 + " let l:current_buffer = 0 + " let l:column_position = 0 + " let l:column_offset = 0 + " + " let l:mode = get(a:, 1, '') + " let l:visualmode = get(a:, 2, '') + " + " normal! m' + " + " if l:mode ==# 'v' + " execute 'normal! ' . l:visualmode + " elseif l:mode ==# 'o' + " normal! V + " endif + " + " if a:line ==# 0 + " " Go to the end of the buffer + " $ + " else + " let s:line = a:line + " + " call setpos('.', [ + " \ l:current_buffer, + " \ a:line, + " \ l:column_position, + " \ l:column_offset + " \ ]) + " endif - let l:mode = get(a:, 1, '') - let l:visualmode = get(a:, 2, '') + let l:line = '' - normal! m' - - if l:mode ==# 'v' - execute 'normal! ' . l:visualmode - elseif l:mode ==# 'o' - normal! V - endif - - if a:line ==# 0 - " Go to the end of the buffer - $ - else + if a:line !=# 0 let s:line = a:line - - call setpos('.', [ - \ l:current_buffer, - \ a:line, - \ l:column_position, - \ l:column_offset - \ ]) endif + + echom s:line . 'G' + return 'G' endfunction function! grappele#Recall(mode) if exists('s:line') - call grappele#Grappele(s:line, a:mode, visualmode()) + " call grappele#Grappele(s:line, a:mode, visualmode()) + + let l:line = s:line + + if a:mode ==# 'o' + " let l:line += 1 + elseif a:mode ==# 'v' + let l:line = visualmode() . l:line + endif + + echom 'Recall: ' . l:line + execute 'normal! ' . l:line . 'G' endif endfunction diff --git a/plugin/grappele.vim b/plugin/grappele.vim index 9ab1400..e04c8e4 100644 --- a/plugin/grappele.vim +++ b/plugin/grappele.vim @@ -4,22 +4,22 @@ endif let g:loaded_grappele = 1 -nnoremap Grappele :call grappele#Grappele(v:count, 'n') -nnoremap GrappeleRecall :call grappele#Recall('n') -vnoremap GrappeleRecall :call grappele#Recall('v') -onoremap GrappeleRecall :call grappele#Recall('o') +nnoremap Grappele grappele#Grappele(v:count, 'n') +nnoremap GrappeleRecall :call grappele#Recall('n') +vnoremap GrappeleRecall :call grappele#Recall('v') +onoremap GrappeleRecall :call grappele#Recall('o') if !hasmapto('Grappele') || !maparg('G', 'n') - nnoremap G :call grappele#Grappele(v:count, 'n') + nnoremap G grappele#Grappele(v:count, 'n') endif if !hasmapto('Grappele') || !maparg('G', 'v') - vnoremap G - \ :call grappele#Grappele(v:count, 'v', visualmode()) + vnoremap G + \ grappele#Grappele(v:count, 'v', visualmode()) endif if !hasmapto('Grappele') || !maparg('G', 'o') - onoremap G :call grappele#Grappele(v:count, 'o') + onoremap G grappele#Grappele(v:count, 'o') endif if !hasmapto('GrappeleRecall') || !maparg('gG', 'n') -- cgit v1.2.3 From e07089624f0f8b8ba3f024bbf3c0c1a735522d06 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 26 Sep 2020 22:24:54 +0200 Subject: Fix `gG` omap by removing count Previously, if we stored a number in `s:line`, for example with `17G`, then `>gG` would cause lines .,17 to be indented 17 times due to the use of `V`. When I removed `V` from the omap, any commands using `gG` operated characterwise, when they should operate linewise. Found this answer from Liu Sha (https://stackoverflow.com/users/7026980/liu-sha) https://stackoverflow.com/questions/4261177/discarding-count-in-expr-mappings/53182922#53182922 that shows how to discard the count for different types of mappings: > nnoremap s "@_" . ToNthSpace() > vnoremap s "@_" . ToNthSpace() > onoremap s printf(":normal %s\", ToNthSpace()) The `:normal!` looks like it discards the count, so this gives us what we want. Adapted the suggestion into a new `` omap that indents only once for e.g. .,17. --- autoload/grappele.vim | 13 ++++++++++--- plugin/grappele.vim | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/autoload/grappele.vim b/autoload/grappele.vim index 418f365..1b1a71a 100644 --- a/autoload/grappele.vim +++ b/autoload/grappele.vim @@ -44,13 +44,20 @@ function! grappele#Recall(mode) let l:line = s:line - if a:mode ==# 'o' + " if a:mode ==# 'o' " let l:line += 1 - elseif a:mode ==# 'v' + " return ':normal! V' . l:line . "G\" + if a:mode ==# 'v' let l:line = visualmode() . l:line endif - echom 'Recall: ' . l:line + " echom 'Recall: ' . l:line execute 'normal! ' . l:line . 'G' endif endfunction + +function! grappele#ORecall() + if exists('s:line') + return ':normal! V' . s:line . "G\" + endif +endfunction diff --git a/plugin/grappele.vim b/plugin/grappele.vim index e04c8e4..21c5cc7 100644 --- a/plugin/grappele.vim +++ b/plugin/grappele.vim @@ -7,7 +7,7 @@ let g:loaded_grappele = 1 nnoremap Grappele grappele#Grappele(v:count, 'n') nnoremap GrappeleRecall :call grappele#Recall('n') vnoremap GrappeleRecall :call grappele#Recall('v') -onoremap GrappeleRecall :call grappele#Recall('o') +onoremap GrappeleRecall grappele#ORecall() if !hasmapto('Grappele') || !maparg('G', 'n') nnoremap G grappele#Grappele(v:count, 'n') -- cgit v1.2.3 From 51f66aee90c4362a37b0c203939686283499dae3 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 29 Sep 2020 01:03:04 +0200 Subject: autoload/grappele.vim: Remove old commented code Clean up the file by removing old code that's no longer necessary. --- autoload/grappele.vim | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/autoload/grappele.vim b/autoload/grappele.vim index 1b1a71a..84766be 100644 --- a/autoload/grappele.vim +++ b/autoload/grappele.vim @@ -1,57 +1,21 @@ function! grappele#Grappele(line, ...) - " let l:current_buffer = 0 - " let l:column_position = 0 - " let l:column_offset = 0 - " - " let l:mode = get(a:, 1, '') - " let l:visualmode = get(a:, 2, '') - " - " normal! m' - " - " if l:mode ==# 'v' - " execute 'normal! ' . l:visualmode - " elseif l:mode ==# 'o' - " normal! V - " endif - " - " if a:line ==# 0 - " " Go to the end of the buffer - " $ - " else - " let s:line = a:line - " - " call setpos('.', [ - " \ l:current_buffer, - " \ a:line, - " \ l:column_position, - " \ l:column_offset - " \ ]) - " endif - let l:line = '' if a:line !=# 0 let s:line = a:line endif - echom s:line . 'G' return 'G' endfunction function! grappele#Recall(mode) if exists('s:line') - " call grappele#Grappele(s:line, a:mode, visualmode()) - let l:line = s:line - " if a:mode ==# 'o' - " let l:line += 1 - " return ':normal! V' . l:line . "G\" if a:mode ==# 'v' let l:line = visualmode() . l:line endif - " echom 'Recall: ' . l:line execute 'normal! ' . l:line . 'G' endif endfunction -- cgit v1.2.3 From 5b5a30da2230b5cd78434c7195c83bd9e108e744 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 29 Sep 2020 01:05:41 +0200 Subject: grappele#Grappele(): Remove unnecessary `l:line` variable Holdover from old code. --- autoload/grappele.vim | 2 -- 1 file changed, 2 deletions(-) diff --git a/autoload/grappele.vim b/autoload/grappele.vim index 84766be..c2257d8 100644 --- a/autoload/grappele.vim +++ b/autoload/grappele.vim @@ -1,6 +1,4 @@ function! grappele#Grappele(line, ...) - let l:line = '' - if a:line !=# 0 let s:line = a:line endif -- cgit v1.2.3 From b39b957b700e98035dd8aa7608feab71d6181c95 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 29 Sep 2020 01:08:31 +0200 Subject: Change v_gG and o_gG to mappings Fix visual mode bug where when the cursor is at the top of a visual selection, pressing `gG` changes the bottom of the visual selection instead of the top. --- autoload/grappele.vim | 2 +- plugin/grappele.vim | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/autoload/grappele.vim b/autoload/grappele.vim index c2257d8..423723b 100644 --- a/autoload/grappele.vim +++ b/autoload/grappele.vim @@ -14,7 +14,7 @@ function! grappele#Recall(mode) let l:line = visualmode() . l:line endif - execute 'normal! ' . l:line . 'G' + return l:line . 'G' endif endfunction diff --git a/plugin/grappele.vim b/plugin/grappele.vim index 21c5cc7..f85b2b4 100644 --- a/plugin/grappele.vim +++ b/plugin/grappele.vim @@ -5,8 +5,8 @@ let g:loaded_grappele = 1 nnoremap Grappele grappele#Grappele(v:count, 'n') -nnoremap GrappeleRecall :call grappele#Recall('n') -vnoremap GrappeleRecall :call grappele#Recall('v') +nnoremap GrappeleRecall grappele#Recall('n') +vnoremap GrappeleRecall grappele#Recall('v') onoremap GrappeleRecall grappele#ORecall() if !hasmapto('Grappele') || !maparg('G', 'n') -- cgit v1.2.3 From 47a6ae90ca533f32576c88b21b988d92d33f865c Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 29 Sep 2020 01:12:15 +0200 Subject: grappele#Grappele(): Remove varargs This function no longer needs any extra arguments. --- autoload/grappele.vim | 2 +- plugin/grappele.vim | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/autoload/grappele.vim b/autoload/grappele.vim index 423723b..34971dc 100644 --- a/autoload/grappele.vim +++ b/autoload/grappele.vim @@ -1,4 +1,4 @@ -function! grappele#Grappele(line, ...) +function! grappele#Grappele(line) if a:line !=# 0 let s:line = a:line endif diff --git a/plugin/grappele.vim b/plugin/grappele.vim index f85b2b4..97b81e7 100644 --- a/plugin/grappele.vim +++ b/plugin/grappele.vim @@ -10,16 +10,15 @@ vnoremap GrappeleRecall grappele#Recall('v') onoremap GrappeleRecall grappele#ORecall() if !hasmapto('Grappele') || !maparg('G', 'n') - nnoremap G grappele#Grappele(v:count, 'n') + nnoremap G grappele#Grappele(v:count) endif if !hasmapto('Grappele') || !maparg('G', 'v') - vnoremap G - \ grappele#Grappele(v:count, 'v', visualmode()) + vnoremap G grappele#Grappele(v:count) endif if !hasmapto('Grappele') || !maparg('G', 'o') - onoremap G grappele#Grappele(v:count, 'o') + onoremap G grappele#Grappele(v:count) endif if !hasmapto('GrappeleRecall') || !maparg('gG', 'n') -- cgit v1.2.3 From 145c155e419fdcc73129771d8fbb3c32a77295a8 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 29 Sep 2020 01:18:33 +0200 Subject: plugin/grappele.vim: Remove `Grappele` mapping Since the plugin doesn't use this mapping any more due to the performance delay, let's remove it. Tells people that it shouldn't be used. --- plugin/grappele.vim | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/plugin/grappele.vim b/plugin/grappele.vim index 97b81e7..5b6a046 100644 --- a/plugin/grappele.vim +++ b/plugin/grappele.vim @@ -4,20 +4,19 @@ endif let g:loaded_grappele = 1 -nnoremap Grappele grappele#Grappele(v:count, 'n') nnoremap GrappeleRecall grappele#Recall('n') vnoremap GrappeleRecall grappele#Recall('v') onoremap GrappeleRecall grappele#ORecall() -if !hasmapto('Grappele') || !maparg('G', 'n') +if !maparg('G', 'n') nnoremap G grappele#Grappele(v:count) endif -if !hasmapto('Grappele') || !maparg('G', 'v') +if !maparg('G', 'v') vnoremap G grappele#Grappele(v:count) endif -if !hasmapto('Grappele') || !maparg('G', 'o') +if !maparg('G', 'o') onoremap G grappele#Grappele(v:count) endif -- cgit v1.2.3 From f8bbf6e991d6a5d9768715c0cc915875bc9d9bc9 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 29 Sep 2020 01:31:17 +0200 Subject: grappele#Recall(): Remove special handling for visual mode Now that this is an `` mapping, we don't need any special handling for visual mode as this will be taken care of automatically. Remove the `mode` argument as it's no longer used. --- autoload/grappele.vim | 10 ++-------- plugin/grappele.vim | 4 ++-- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/autoload/grappele.vim b/autoload/grappele.vim index 34971dc..e111409 100644 --- a/autoload/grappele.vim +++ b/autoload/grappele.vim @@ -6,15 +6,9 @@ function! grappele#Grappele(line) return 'G' endfunction -function! grappele#Recall(mode) +function! grappele#Recall() if exists('s:line') - let l:line = s:line - - if a:mode ==# 'v' - let l:line = visualmode() . l:line - endif - - return l:line . 'G' + return s:line . 'G' endif endfunction diff --git a/plugin/grappele.vim b/plugin/grappele.vim index 5b6a046..fe531af 100644 --- a/plugin/grappele.vim +++ b/plugin/grappele.vim @@ -4,8 +4,8 @@ endif let g:loaded_grappele = 1 -nnoremap GrappeleRecall grappele#Recall('n') -vnoremap GrappeleRecall grappele#Recall('v') +nnoremap GrappeleRecall grappele#Recall() +vnoremap GrappeleRecall grappele#Recall() onoremap GrappeleRecall grappele#ORecall() if !maparg('G', 'n') -- cgit v1.2.3 From 8126766ab7a37961096ff9edf69feed15d9f3b65 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 29 Sep 2020 01:34:50 +0200 Subject: autoload/grappele.vim: If no line is stored, make `gG` a no-op Previously, if you typed, for example: dgGk this would perform `dk`, deleting the current line and the one above it. That doesn't really make any sense. Instead, the `gG` should cancel the operator. Do this by mapping to ``. In normal and visual modes, `gG` would move the cursor to the 0th column. Returning an empty {rhs} causes the cursor to stay in the same position it was in before pressing `gG`. --- autoload/grappele.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/autoload/grappele.vim b/autoload/grappele.vim index e111409..c0835c9 100644 --- a/autoload/grappele.vim +++ b/autoload/grappele.vim @@ -10,10 +10,14 @@ function! grappele#Recall() if exists('s:line') return s:line . 'G' endif + + return '' endfunction function! grappele#ORecall() if exists('s:line') return ':normal! V' . s:line . "G\" endif + + return "\" endfunction -- cgit v1.2.3 From 560239bbd9afb7dbf7ce846160bd687b1cfda03f Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 29 Sep 2020 01:51:35 +0200 Subject: plugin/grappele.vim: Add mode to `hasmapto()` call Since these `` mappings are mode-specific, ensure we specify the mode in the `hasmapto()` call. --- plugin/grappele.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/grappele.vim b/plugin/grappele.vim index fe531af..be001ea 100644 --- a/plugin/grappele.vim +++ b/plugin/grappele.vim @@ -20,14 +20,14 @@ if !maparg('G', 'o') onoremap G grappele#Grappele(v:count) endif -if !hasmapto('GrappeleRecall') || !maparg('gG', 'n') +if !hasmapto('GrappeleRecall', 'n') || !maparg('gG', 'n') nmap gG GrappeleRecall endif -if !hasmapto('GrappeleRecall') || !maparg('gG', 'v') +if !hasmapto('GrappeleRecall', 'v') || !maparg('gG', 'v') vmap gG GrappeleRecall endif -if !hasmapto('GrappeleRecall') || !maparg('gG', 'o') +if !hasmapto('GrappeleRecall', 'o') || !maparg('gG', 'o') omap gG GrappeleRecall endif -- cgit v1.2.3