weird behavior with evil visual

Frank Fischer frank-fischer at shadow-soft.de
Tue Apr 28 11:14:51 CEST 2015


Am 28.04.2015 um 05:26 schrieb William Hatch:
> Hello, I hope this is the right list for this.
> 
> I just made an emacs plugin to repeat motions -- I just wrap motion 
> functions into a new repeatable version.  Upon initial testing it worked 
> great, but when used in evil-mode with operators or in visual state I get 
> weird one-off behavior.  For example, in normal state my 
> repeatable-evil-find-char goes to the desired character, but in 
> operator-pending state or visual state it goes to one character before 
> that.  My repeatable-evil-find-char-to goes to the character before the 
> target character in normal state, but two characters before it in visual or 
> operator state.  Also my repeatable-evil-next-line doesn't work at all in 
> visual line state.  Can anyone point me to why this might be happening?  
> I'm aware that there is a macro in evil called evil-define-motion, but I 
> haven't had time to read through and understand it all, so I thought a 
> quick probe on a mailing list might save me a lot of time if I were barking 
> up the wrong tree.

The problem is the difference between Evil ranges (usually inclusive)
and Emacs ranges (usually exclusive). On order to make Emacs commands
(that do not know anything about Evil) work correctly on the selected
visual range, Evil has to move point one character so that the Emacs
region matches Evil's visually selected region.

However, if the command to be executed is a motion it usually does not
work on the region, so this "fix" is not necessary. Because it's
impossible for Evil to find out whether a certain command uses the
region or not, Evil provides a function to mark commands as motion:

  (evil-declare-motion 'your-motion-command)

This should be enough. The macro `evil-define-motion` does the same
automatically (and a little bit more).

Frank




More information about the implementations-list mailing list