Skip to content

Commit

Permalink
Make the code more robust to wrong values of g:remotions_motions to
Browse files Browse the repository at this point in the history
address issue #12 (error info pops up when using TtFfMotion)
  • Loading branch information
vds2212 committed Jul 9, 2024
1 parent 89b7854 commit 3c4515e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
29 changes: 23 additions & 6 deletions plugin/remotions.vim
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,23 @@ function! s:RepeatMotion(forward)

call s:Log('RepeatMotion(' . a:forward . ')')

if type(g:remotions_motions) != v:t_dict
echom $'g:remotions_motions is not a dictionary'
endif

let motion = {}
if has_key(g:remotions_motions, g:remotions_family)
if type(g:remotions_motions) == v:t_dict && has_key(g:remotions_motions, g:remotions_family)
" 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

if type(motion) != v:t_dict
echom $"g:remotions_motions['{g:remotions_family}'] is: {motion} and not a dictionary"
endif

let repeat_count = g:remotions_repeat_count
if has_key(motion, 'repeat_count')
if type(motion) == v:t_dict && has_key(motion, 'repeat_count')
let repeat_count = motion.repeat_count
endif

Expand Down Expand Up @@ -168,13 +176,18 @@ function! s:TtFfMotion(key)
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

if type(motion) != v:t_dict
echom $"g:remotions_motions['TtFf'] is: {motion} and not a dictionary"
endif

if v:count <= 1 && type(motion) == v:t_dict && 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
return
endif

let direction = g:remotions_direction
if has_key(motion, 'direction')
if type(motion) == v:t_dict && has_key(motion, 'direction')
let direction = motion.direction
endif

Expand Down Expand Up @@ -240,13 +253,17 @@ function! s:CustomMotion(forward, backward_plug, forward_plug, motion_plug, moti
endif

let motion = g:remotions_motions[a:motion_family]
if v:count <= 1 && has_key(motion, 'repeat_if_count') && motion.repeat_if_count == 1
if type(motion) != v:t_dict
echom $"g:remotions_motions['{a:motion_family}'] is: {motion} and not a dictionary"
endif

if v:count <= 1 && type(motion) == v:t_dict && 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
return ret
endif

let direction = g:remotions_direction
if has_key(motion, 'direction')
if type(motion) == v:t_dict && has_key(motion, 'direction')
let direction = motion.direction
endif

Expand Down
7 changes: 7 additions & 0 deletions version.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
History
=======

Version 2.3 (2024/07/09)
------------------------

Make the code more robust to wrong g:remotions_motions values.
In particular `g:remotions_motions = { 'TtFf' : [] }` induced by `vim.g.remotions_motions = { TtFf = {}}`


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

Expand Down

0 comments on commit 3c4515e

Please sign in to comment.