phi-search
phi-search copied to clipboard
First cursor duplicated with multiple-cursors
Under certain circumstances, when using phi-search with multiple-cursors, the first cursor becomes duplicated.
To reproduce:
- Start with a new blank buffer
- Make some repetitive text, e.g.
<f3> foo bar baz RET <f4> C-u 30 <f4> - Select all, in this order: jump to beginning of buffer, set mark, jump to end of buffer
M-x mc/edit-lines- Assuming
phi-searchis bound toC-s, invokeC-s bar RET
Observe that the first cursor is duplicated: two cursors appear at the end of the first bar.
To see that point position matters, perform the same steps again, but replace item 3 with:
- Select all, in this order: jump to end of buffer, set mark, jump to beginning of buffer
Observe that now each match gets exactly one cursor, as expected.
Seems related to #8, but multiple-cursors no longer has mc/remove-duplicated-cursors, so the workaround is not available.
My environment is Spacemacs develop on Emacs 27.0.50 (snapshot 20190620). Multiple-cursors was installed automatically by the multiple-cursors layer (so should be the latest from MELPA), and phi-search is git HEAD from this repository (installed using Spacemacs's github fetcher).
Addendum: seems mc/remove-duplicated-cursors is now available from mc-extras, but I would still like an opinion on this.
Playing around with it some more, this seems to be related to having the real cursor (point) at the start of the blank line (at the end of the buffer) when mc/edit-lines is invoked. This leads to having one more cursor than there are occurrences of bar. This extra cursor then must go somewhere...
With mc-extras installed and this incantation in my init.el:
(require 'mc-extras)
(with-eval-after-load "phi-search"
(defadvice phi-search-complete (after phi-search-auto-dedup last activate protect)
(mc/remove-duplicated-cursors)))
the advice actually fires (tested with message; seems this needs the protect or it won't fire), and it looks like it worked, but upon typing something, the extra cursor still remains.
For now, I suppose I'll just try to be careful with what exactly is selected before invoking mc/edit-lines, since the problem is related to having that extra cursor to start with (before phi-search is even invoked).