Evil-mode and camelcase movement

Michael Markert markert.michael at googlemail.com
Sat Jun 2 22:14:17 CEST 2012


On Sat, Jun 02 2012 (21:20), Simon Carter <bbbscarter at gmail.com> wrote: 

> I was wondering if there was a canonical method for allowing camelcase
> and underscore word movement in evil-mode.

Not to my knowledge.

> I've looked at the suggestion in
> http://slashusr.wordpress.com/2011/09/15/heretical-confessions-of-an-emacs-addict-joy-of-the-vim-text-editor/,
> but that solution was somewhat limited (no backward movement, and it
> only worked with other operators, rather than as an actual method of
> movement).

Ok this is the solution posted:

    (evil-define-motion evil-little-word (count)
      :type exclusive
      (let ((case-fold-search nil))
        (forward-char)
        (search-forward-regexp "[_A-Z]\\|\\W" nil t)
        (backward-char)))

it only works with other operators, because it was defined in
`evil-operator-state-map' define in in `evil-motion-state-map' and it
will work on its own (but you maybe want to chose another key sequence
to not shadow `l').

Here is code for the backword movement:

    (evil-define-motion evil-little-word-backward (count)
      :type inclusive
      (let ((case-fold-search nil))
        (backward-char)
        (search-backward-regexp "[_A-Z]\\|\\W" nil t)))

You have to define it as well as keys, of course.

Another change you want to make is the inclusion of `count':

    (evil-define-motion evil-little-word (count)
      :type exclusive
      (let ((case-fold-search nil))
        (forward-char)
        (search-forward-regexp "[_A-Z]\\|\\W" nil t count)
        (backward-char)))
        
respective

    (evil-define-motion evil-little-word-backward (count)
      :type inclusive
      (let ((case-fold-search nil))
        (backward-char)
        (search-backward-regexp "[_A-Z]\\|\\W" nil t count)))
        
As there's `subword-mode' for vanilla Emacs maybe it would be nice to
change the word movements (b, e, w and their ilk) to subword movements
if subword-move is active for a tighter emacs integration?

Michael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
Url : https://lists.ourproject.org/pipermail/implementations-list/attachments/20120602/21416fc5/attachment.pgp 


More information about the implementations-list mailing list