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 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 25 deletions(-) (limited to 'autoload') 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 -- 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 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'autoload') 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 -- 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(-) (limited to 'autoload') 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(-) (limited to 'autoload') 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'autoload') 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 -- 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'autoload') 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 -- 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 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'autoload') 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 -- 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(+) (limited to 'autoload') 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