phi-search icon indicating copy to clipboard operation
phi-search copied to clipboard

First cursor duplicated with multiple-cursors

Open Technologicat opened this issue 6 years ago • 3 comments
trafficstars

Under certain circumstances, when using phi-search with multiple-cursors, the first cursor becomes duplicated.

To reproduce:

  1. Start with a new blank buffer
  2. Make some repetitive text, e.g. <f3> foo bar baz RET <f4> C-u 30 <f4>
  3. Select all, in this order: jump to beginning of buffer, set mark, jump to end of buffer
  4. M-x mc/edit-lines
  5. Assuming phi-search is bound to C-s, invoke C-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).

Technologicat avatar Jun 21 '19 08:06 Technologicat

Addendum: seems mc/remove-duplicated-cursors is now available from mc-extras, but I would still like an opinion on this.

Technologicat avatar Jun 21 '19 08:06 Technologicat

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...

Technologicat avatar Jun 21 '19 08:06 Technologicat

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).

Technologicat avatar Jun 21 '19 20:06 Technologicat