gabesoft / evil-mc

Multiple cursors implementation for evil-mode
MIT License
383 stars 35 forks source link

Change motion adds one letter on the active cursor #63

Open dchrzanowski opened 7 years ago

dchrzanowski commented 7 years ago

Let it be that I have 4 cursors active as follows:

set[q] set[q] set[q] set[q] <- active cursor

After running cb I get: [] [] [] [q]

The q gets left behind on the active cursor. This behavior occurs about 99% of the time, sometimes it just works, most of the time it fails. It is the same case with other motions: e, E, b, B, w, W, f, F, t, T. However, any command, be it: change,delete or even surround command work absolutely perfectly when used from visual state.

Is this a problem for anyone else? Apart from this little issue the package is excellent!

gabesoft commented 7 years ago

I wasn't able to reproduce this issue. I've added more tests that cover this scenario though in this commit 93ba56560bb54f6a8f076be9975cab08bc0f942c. I wonder if there's some interference from other plugin or maybe it's your Emacs version (the tests run against 25.1). In your example it seems that the fake cursors are misbehaving by removing the entire word. The real cursor has the correct behavior.

dchrzanowski commented 7 years ago

I am using the same version of Emacs 25.1 . I do wonder why is this happening. Realistically if I want it to do, what it needs to do, reliably, I need to use the visual state.

I'll try to switch off some other packages. Rerun the tests on Win as well. I'll get back to you asap.

gabesoft commented 7 years ago

Also, do you get any errors in the messages buffer?

gabesoft commented 7 years ago

Oh, so you're on Windows. That could be the reason. Let me know how the tests behave there.

dchrzanowski commented 7 years ago

I'll check the error messages. I am on Arch Linux, but I have the same Emacs setup on Win 7,which I haven't checked for this problem. I'll try to run the tests tonight, otherwise it'll have to be tomorrow then.

dchrzanowski commented 7 years ago

Ok! It seems that I have found the problem. I use (setq evil-move-cursor-back nil) as I don't like the cursor going back after exiting insert mode. Changing the variable to t removed the problem, now all the cursors behave the same way. However, I prefer the original cursor behaviour. Would there be a way of fixing this somehow? Or a small workaround perhaps?

gabesoft commented 7 years ago

Oh, I see. Interesting. I'm not sure if there's an easy way to fix that. I'll think about it.

dchrzanowski commented 7 years ago

That's great! Thanks!

I just thought that there must a bit of code that makes the "clone cursors" enter and exit the insert state at the beginning of the change motion, this might be the cause of the disturbance. Just food for thought. I would love to help, but my knowledge of elisp is very basic :-(

dchrzanowski commented 7 years ago

I thought that I do not mind the standard evil behaviour while the multiple cursors are active, so I thought of just switching the evil-move-cursor-back variable to t while the cursors are active and toggle it back to nil when the cursors are deleted, thus this solves the problem for me:

(add-hook 'evil-mc-before-cursors-created (lambda () (setq-default evil-move-cursor-back t)))

(add-hook 'evil-mc-after-cursors-deleted (lambda () (setq-default evil-move-cursor-back nil)))

EDIT: changed setq to setq-default, makes the change persistent across buffers when leaving helm-multi-swoop-edit or helm-ag-edit buffers