Skip to content

Commit

Permalink
solve overridding t mapping (issue #8) and RepeatMotion line 15 Dicti…
Browse files Browse the repository at this point in the history
…onary required for argument 1 (issue #7)
  • Loading branch information
vds2212 committed May 25, 2024
1 parent 6269fae commit fede402
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 24 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ For each motion three information have to be provided and some options can be se
Here is the Remotions default:
```vim
let g:remotions_motions = {
\ 'EeFf' : {},
\ 'TtFf' : {},
\ 'para' : { 'backward' : '{', 'forward' : '}' },
\ 'change' : { 'backward' : 'g,', 'forward' : 'g;' },
\ 'class' : { 'backward' : '[[', 'forward' : ']]' },
Expand Down Expand Up @@ -104,11 +104,17 @@ let g:remotions_motions = {
\ 'methodend' : { 'backward' : '[M', 'forward' : ']M' },
\
\ 'line' : {
\ 'backward' : 'k',
\ 'backward' : 'k',
\ 'forward' : 'j',
\ 'repeat_if_count' : 1,
\ 'repeat_count': 1
\ },
\ 'displayline' : {
\ 'backward' : 'gk',
\ 'forward' : 'gj',
\ 'repeat_count': 1
\ },
\
\ 'char' : { 'backward' : 'h',
\ 'forward' : 'l',
\ 'repeat_if_count' : 1,
Expand Down Expand Up @@ -140,7 +146,8 @@ let g:remotions_motions = {
\ 'undo' : { 'backward' : 'u', 'forward' : '<C-r>', 'direction' : 1 },
\
\ 'linescroll' : { 'backward' : '<C-e>', 'forward' : '<C-y>' },
\ 'charscroll' : { 'backward' : 'zh', 'forward' : 'zl' },
\ 'columnscroll' : { 'backward' : 'zh', 'forward' : 'zl' },
\ 'columnsscroll' : { 'backward' : 'zH', 'forward' : 'zL' },
\
\ 'vsplit' : { 'backward' : '<C-w><', 'forward' : '<C-w>>' },
\ 'hsplit' : { 'backward' : '<C-w>-', 'forward' : '<C-w>+' },
Expand Down
62 changes: 41 additions & 21 deletions plugin/remotions.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let g:remotions_debug = 0

if !exists("g:remotions_motions")
let g:remotions_motions = {
\ 'EeFf' : {},
\ 'TtFf' : {},
\ 'para' : { 'backward' : '{', 'forward' : '}' },
\ 'sentence' : { 'backward' : '(', 'forward' : ')' },
\ 'change' : { 'backward' : 'g,', 'forward' : 'g;' },
Expand All @@ -25,7 +25,7 @@ if !exists("g:remotions_motions")
\ }

" let g:remotions_motions = {
" \ 'EeFf' : {},
" \ 'TtFf' : {},
" \ 'para' : { 'backward' : '{', 'forward' : '}' },
" \ 'sentence' : { 'backward' : '(', 'forward' : ')' },
" \ 'change' : { 'backward' : 'g,', 'forward' : 'g;', 'direction' : 0 },
Expand Down Expand Up @@ -105,7 +105,7 @@ function! s:RepeatMotion(forward)

let motion = {}
if has_key(g:remotions_motions, g:remotions_family)
" For the 'EeFf' key there is no guarantee that the motion exist in the
" For the 'TtFf' key there is no guarantee that the motion exist in the
" g:remotions_motions map
let motion = g:remotions_motions[g:remotions_family]
endif
Expand Down Expand Up @@ -155,14 +155,18 @@ vmap <silent> <expr> , <SID>RepeatMotion(0)
" nnoremap <silent> <expr> ; <SID>RepeatMotion(1) " vim9
" nnoremap <silent> <expr> , <SID>RepeatMotion(0) " vim9

function! s:EeFfMotion(key)
function! s:TtFfMotion(key)
" Method called when the single char motion are used:
" - 'f' calls EeFfMotion('f')
" - 'f' calls TtFfMotion('f')
" The method set the variables to be able to replay the motion

let motion = {}
if has_key(g:remotions_motions, 'EfFf')
let motion = g:remotions_motions[a:key]
if has_key(g:remotions_motions, 'EeFf')
" For backward compatibility reason the old document key was 'EeFf'
let motion = g:remotions_motions['EeFf']
endif
if has_key(g:remotions_motions, 'TtFf')
let motion = g:remotions_motions['TtFf']
endif
if v:count <= 1 && has_key(motion, 'repeat_if_count') && motion.repeat_if_count == 1
" Skip the motion with the option 'repeat_if_count' if the count is <= 1
Expand All @@ -174,7 +178,7 @@ function! s:EeFfMotion(key)
let direction = motion.direction
endif

let g:remotions_family = 'EeFf'
let g:remotions_family = 'TtFf'
let g:remotions_backward_plug = ''
let g:remotions_forward_plug = ''

Expand All @@ -189,22 +193,38 @@ function! s:EeFfMotion(key)
return a:key
endfunction

nmap <expr> f <SID>EeFfMotion('f')
vmap <expr> f <SID>EeFfMotion('f')
if maparg('f', 'n', 0, 1)->empty()
nmap <expr> f <SID>TtFfMotion('f')
endif
if maparg('f', 'v', 0, 1)->empty()
vmap <expr> f <SID>TtFfMotion('f')
endif

nmap <expr> F <SID>EeFfMotion('F')
vmap <expr> F <SID>EeFfMotion('F')
if maparg('F', 'n', 0, 1)->empty()
nmap <expr> F <SID>TtFfMotion('F')
endif
if maparg('F', 'v', 0, 1)->empty()
vmap <expr> F <SID>TtFfMotion('F')
endif

nmap <expr> t <SID>EeFfMotion('t')
vmap <expr> t <SID>EeFfMotion('t')
if maparg('t', 'n', 0, 1)->empty()
nmap <expr> t <SID>TtFfMotion('t')
endif
if maparg('t', 'v', 0, 1)->empty()
vmap <expr> t <SID>TtFfMotion('t')
endif

nmap <expr> T <SID>EeFfMotion('T')
vmap <expr> T <SID>EeFfMotion('T')
if maparg('T', 'n', 0, 1)->empty()
nmap <expr> T <SID>TtFfMotion('T')
endif
if maparg('T', 'v', 0, 1)->empty()
vmap <expr> T <SID>TtFfMotion('T')
endif

" nnoremap <expr> f <SID>EeFfMotion('f')
" nnoremap <expr> F <SID>EeFfMotion('F')
" nnoremap <expr> t <SID>EeFfMotion('t')
" nnoremap <expr> T <SID>EeFfMotion('T')
" nnoremap <expr> f <SID>TtFfMotion('f')
" nnoremap <expr> F <SID>TtFfMotion('F')
" nnoremap <expr> t <SID>TtFfMotion('t')
" nnoremap <expr> T <SID>TtFfMotion('T')

function! s:CustomMotion(forward, backward_plug, forward_plug, motion_plug, motion_family)
" Method called when the original motion are used.
Expand Down Expand Up @@ -416,7 +436,7 @@ function! s:SetMappings()
call RemotionsResetMappings()

for motion_family in keys(g:remotions_motions)
if motion_family ==# 'EeFf'
if motion_family ==# 'TtFf'
continue
endif
let motion = ''
Expand Down
12 changes: 12 additions & 0 deletions version.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
History
=======

Version 2.2 (2024/05/25)
------------------------

Make sure custom `t`, `T`, `f`, `F` mappings are not overridden (if defined) (issue #8)

Prevent the warning message to appear (issue #7):
```
Error detected while processing function <SNR>183_RepeatMotion:
line 15:
E1206: Dictionary required for argument 1
```

Version 2.1 (2023/12/04)
----------------------

Expand Down

0 comments on commit fede402

Please sign in to comment.