New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not play well with evil-mode #17

Open
Jell opened this Issue Sep 30, 2012 · 26 comments

Comments

Projects
None yet
@Jell
Copy link

Jell commented Sep 30, 2012

Alright, that might be impossible to solve and might not be worth solving, but here are the issues I encounter when using multiple cursors with evil: (http://emacswiki.org/emacs/Evil)

  • Every time I run mark-previous-like-this and the cursor is at the end of the selection, an extra character is added to my original selection.

Example: (brackets represent marked regions)

;; Original selection:
text1234567
text1234567
text1234567
[text]1234567

;; After running mark-previous-like-this 3 times:
[text123]4567
[text12]34567
[text1]234567
[text123]4567
  • When run mark-next-like-this and the cursor is at the end of the selection, the next marked regions include one extra character.
;; Original selection:
[text]1234567
text1234567
text1234567
text1234567

;; After running mark-next-like-this 3 times:
[text]1234567
[text1]234567
[text1]234567
[text1]234567
  • When leaving insert mode, only the main cursor moves back one char, while the others remain at the same point.

All of this can be fixed if I set (setq evil-visual-char 'exclusive) and (setq evil-move-cursor-back nil), hence changing the behavior of evil and making it behave more like emacs and less like vim, but I'd rather not do that.

@magnars

This comment has been minimized.

Copy link
Owner

magnars commented Sep 30, 2012

The last point should be fixable by adding a hook to evil, basically running

 (mc/execute-command-for-all-fake-cursors 'backward-char)

The first two, well, somewhere in multiple-cursors there's some code that expects the cursor to behave emacsy. Which isn't very surprising. If it is only the functions in mc-mark-more.el that behaves this way, that might be a good point to start I guess.

It could also be mc/create-fake-cursor-at-point or mc/pop-state-from-overlay that are culprits.

If you'd like to look into it, I'd be happy to answer any questions you have.

@Jell

This comment has been minimized.

Copy link
Author

Jell commented Sep 30, 2012

Thanks! I'm looking into it, I'll see if I can do something about it :)

@dlobraico

This comment has been minimized.

Copy link

dlobraico commented Apr 14, 2013

@Jell Did you ever end up getting a chance to examine these issues? Is there a more up to date list of the ways in which multiple-cursors.el and evil don't get along?

Someone posted a new version of multiple-cursors for vim on Hacker News today (https://github.com/terryma/vim-multiple-cursors) and I'm wondering if perhaps we should take inspiration from the default keybindings that the developer used there for an evil-specific multiple-cursors config. I'd be happy to take a look sometime soon as long as I know I'm not duplicating work and what exactly still needs to be examined.

@magnars

This comment has been minimized.

Copy link
Owner

magnars commented Apr 14, 2013

I haven't investigated anything, but I would wager a guess that part of the
problem is the differing views on cursor position.

On Sun, Apr 14, 2013 at 10:06 PM, Dominick LoBraico <
notifications@github.com> wrote:

@Jell https://github.com/Jell Did you ever end up getting a chance to
examine this issues? Is there a more up to date list of the ways in which
multiple-cursors.el and evil don't get along?

Someone posted a new version of multiple-cursors for vim on Hacker News
today (https://github.com/terryma/vim-multiple-cursors) and I'm wondering
if perhaps we should take inspiration from the default keybindings that the
developer used there for an evil-specific multiple-cursors config.


Reply to this email directly or view it on GitHubhttps://github.com//issues/17#issuecomment-16358367
.

@Jell

This comment has been minimized.

Copy link
Author

Jell commented Apr 15, 2013

Sorry, I never got around to examining the problems, so you won't be duplicating anything!

I have a larger list of things that do not work with evil:

  • Replace char "rx" prompts for a replacement for every cursor
  • Change/Delete+motion "ce", "ciw", "di(" moves all the fake cursors under the main cursor

Basically most operations containing more than one element are broken.

@jojojames

This comment has been minimized.

Copy link

jojojames commented May 19, 2013

+1 on what Jell said.

I'm also randomly getting confirmation prompts when running both Evil and Multicursors together along the lines of 'Are you sure you want to [do this] with multiple cursors?'.

Any motion command will only operate on one cursor.

@Silex

This comment has been minimized.

Copy link
Contributor

Silex commented Nov 4, 2013

I just wanted to say that almost all motion commands works with multiple-cursors!!! This is very nice.

Here are the commands working so far:

(setq mc/cmds-to-run-for-all
      '(
        evil-append-line
        evil-backward-WORD-begin
        evil-backward-word-begin
        evil-delete-char
        evil-delete-line
        evil-digit-argument-or-evil-beginning-of-line
        evil-emacs-state
        evil-end-of-line
        evil-force-normal-state
        evil-forward-WORD-begin
        evil-forward-WORD-end
        evil-forward-word-begin
        evil-forward-word-end
        evil-insert
        evil-next-line
        evil-normal-state
        evil-previous-line
        ))

I now wonder how hard it'd be to make evil-delete and evil-change be multiple cursors compatible...

@mijoharas

This comment has been minimized.

Copy link

mijoharas commented Jan 31, 2014

has anyone managed to debug what causes the problems when trying to do cw or dw and so on? do people think it's a change needed to evil or to multiple-cursors?

@Silex

This comment has been minimized.

Copy link
Contributor

Silex commented Jan 31, 2014

It's a change needed in evil. See #113

@magnars

This comment has been minimized.

Copy link
Owner

magnars commented Jan 31, 2014

If someone would figure out what is needed to support evil, I would be happy to include it in multiple-cursors. It's just a very weird case, and would likely need someone intimately familiar with evil to get right.

@expez

This comment has been minimized.

Copy link

expez commented Mar 7, 2014

Evil has two concepts that are relevant to this discussion: motions and operators. Motion commands move the cursor in some way. Operators, like evil-delete, evil-change, set the mark and then rely on a motion command to move the cursor to update the region, then the operator concludes by doing its thing on the active region.

Thus if we do dw we trigger the evil-delete operator which in turn relies on evil-forward-word-begin to move the cursor and highlight the word that is to be deleted.

This means that the (call-interactively cmd) call, that is at the heart of duplicating the action on the fake cursors won't work for operators.

Evil has it's own functionality for repeating actions. Pressing . in normal-mode will call evil-repeat. evil-repeat relies on the var evil-repeat-ring to repeat the most recent actions. The quickest hack to get multiple-cursors to work with Evil would therefore be to wait until the user is done and then update all the fake cursors using evil-repeat or the contents of the evil-repeat-ring. This would be consistent with how evil-insert works for block insertion.

In order to update all the fake cursors simultaneously one can use the contents of the evil-repeat-info variable. As the user edits the actions are added to evil-repeat-info. When the user is done the contents are moved from evil-repeat-info and into the evil-repeat-ring. At present not everything is added to evil-repeat-info, because they don't belong in evil-repeat-ring.

On the MC part of things (call-interactively cmd) would have to be replaced with (evil-repeat-for-mc) (or something similar) when evil-mode is active. On the Evil side of things evil-repeat-for-mc has to be written and most likely the repeat code has to be cleaned up a little. Some functions, like evil-next-line and evil-previous-line have to be handled specifically because they modify buffer variables, and therefore can't be repeated willy nilly.

The maintainer of Evil estimates that it would take him ~5h to add this functionality. I was prepared to take this on, yesterday, but something has come up so I don't have 5 * x hours to spend on this in the foreseeable future. Hopefully this write-up makes it easier for someone else to get started.

Lyro, the current maintainer of Evil, is super helpful and can be found in #evil-mode on irc.freenode.net.

@Silex @mhauserr @Jell

@Silex

This comment has been minimized.

Copy link
Contributor

Silex commented Mar 7, 2014

@expez: thanks for the research, I probably won't have time for it but it's nice to know what needs to be done.

@mijoharas

This comment has been minimized.

Copy link

mijoharas commented Mar 7, 2014

@expez thanks for this. Unfortunately I don't think I know enough to be able to make these changes at the moment, I may try but I don't expect my efforts to bear fruit. Definitely incredibly helpful to have an idea of how to go about making this change. 👍

@PythonNut

This comment has been minimized.

Copy link

PythonNut commented Nov 6, 2014

Has any progress been made on this on either end? I'd probably die of joy if this were ever to be fixed.

@expez

This comment has been minimized.

Copy link

expez commented Nov 6, 2014

Nobody has been working on this, afaik. I asked @lyro a while back about the efforts required and it isn't as simple as just writing a bridge between these two libraries. It would probably mean re-implementing large parts of mc in terms of evil's abstractions.

@jcpetkovich

This comment has been minimized.

Copy link

jcpetkovich commented Nov 6, 2014

Obviously this isn't the ideal solution, but if you can tolerate using emacs keybindings in multiple cursors, I've written a few small hacks to get transitioning between evil mode and emacs mode when pressing mc keys smoother than the defaults. Mainly these involve translating the cursor and mark positions between what evil and emacs expect. You can see them within the progn here:

https://github.com/jcpetkovich/.emacs.d/blob/291a2b06ac4952381475c0d9a1f50192992c04c1/global-key-bindings.el#L257

@druska

This comment has been minimized.

Copy link

druska commented Nov 26, 2014

+1

1 similar comment
@rap1ds

This comment has been minimized.

Copy link

rap1ds commented Dec 1, 2014

+1

@darfink

This comment has been minimized.

Copy link

darfink commented Mar 14, 2015

+1

@duerrp

This comment has been minimized.

Copy link

duerrp commented Jun 9, 2015

+1, mc is such a cool package!

@sollidsnake

This comment has been minimized.

Copy link

sollidsnake commented Jun 26, 2015

+1. All vim power with multiple cursors; it'd be a perfect combination.

@lexi-lambda

This comment has been minimized.

Copy link

lexi-lambda commented Aug 3, 2015

👍

@expez

This comment has been minimized.

Copy link

expez commented Aug 3, 2015

Please stop bumping this thread for no reason. This is non-trivial and won't get fixed just because you :+1:

@myrjola

This comment has been minimized.

Copy link

myrjola commented Sep 6, 2015

My pull request #216 for Evil compatibility to multiple-cursors is reaching an usable state. I welcome all code reviewers and testers so that we can flesh out the remaining issues.

@rdinse

This comment has been minimized.

Copy link

rdinse commented Nov 7, 2015

There is also this package: https://github.com/gabesoft/evil-mc

@shiro-42

This comment has been minimized.

Copy link

shiro-42 commented Jun 12, 2016

+1 evil-mc work really nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment