getting evil-mode to interact well with slime-repl-mode

Frank Fischer frank.fischer at mathematik.tu-chemnitz.de
Mon Dec 5 09:06:31 CET 2011


On Mon, Dec 05, 2011 at 10:27:08AM +1100, Chris Rosengren wrote:
> Over the last few weeks I have been learning elisp and implementing hooks
> into slime-mode
> so that vim bindings feel more natural there. Here is an example
> 
> (defun slime-repl-bol-insert ()
>   (interactive)
>   (slime-repl-bol)
>   (evil-insert 1)
> 
> Then I would add this too a slime-repl-mode-hook
> 
> (define-key evil-normal-state-map "I" 'slime-repl-bol-insert)
> 
> I'm attempting to make all commands such as I, 0, etc work to the start of
> the REPL prompt rather
> than the beginning of the line. I think this has implications not only for
> repl/inferior modes but dired/term/eshell
> modes as well.
> 
> I have two questions, is this general approach i'm taking reasonable -
> defining functions that overwrite the generic
> bindings, and adding them in hooks to slime-mode/eshell-mode etc? 

This is certainly a valid approach. Although it may be preferable to
use `evil-define-key' or `evil-declare-key' to install the
key-bindings for special modes/keymaps or use
`evil-normal-state-local-map', otherwise you would change the global
bindings in all modes, not only in slime-repl-mode.

> the
> second question that I'm having a hard time
> with involves making dd and yy work correctly, I have browsed the source
> and it seems they are implemented in
> motions involving moving to the next line -> what would be a reasonable
> solution to get say dd to delete everything
> on a line except the prompt, and yy to yank everything on a line except the
> prompt.

Currently the internal behavior of evil depends heavily on Emacs
functions like `forward-line', `beginning-of-line' and so on, so there
is no easy way to make evil ignore some prefix in a line.

The only way I could imagine is to redefine
evil-change/evil-delete/evil-yank and friends (perhaps evil-change can
be left unchanged because it uses the others internally). Those
functions are operators which should respect the type of the motion
passed to them as argument (i.e., whether the type is char/line/block).

I think it should not be too difficult to implement the behavior you
desire, but be aware that there may be some pitfalls ... ;)

And think of other operators, like `evil-shift-left' which may have
similar problems.

Frank



More information about the implementations-list mailing list