Both iy-go-to-char and zap-up-to-char take a prefix argument and a character argument prompted for in the minibuffer. Both functions seems to implement this by using (interactive "p\ncPrompt string: "). But they behave very differently in multiple-cursors-mode: iy-go-to-char only prompts once for the character and uses that same one for every cursor; zap-up-to-char prompts for a character for each cursor.

I'd like to know why multiple-cursors treats them differently, but above all I'd like to have them both behave as iy-go-to-char does: single prompt, reuse that character for all cursors.

  • Are you asking about changing the appearance of the overlay that multiple-cursors uses for each fake cursor? I have programmed mine to use a thin vertical line to the left of each character, except eol caracters where I use a pilcrow. The overlay can be red, blue, green, pokadot, or a rabbit. The name of the face that it uses is mc/cursor-face and you can customize it. I modified mine and I use a display property instead -- but that is beyond the scope of your question and would require other tweaks/ mods.
    – lawlist
    Feb 23 '15 at 20:39
  • 1
    I believe I know what @Omar is talking about. I've seen that too but never considered looking into it. For some commands, multiple-cursors will execute the same action at all cursor locations without prompting again. And for some, a user entry will be required in the minibuffer interactive prompt for each cursor location. Note that this happens even if the user has agreed for that command to be executed at all cursor locations. Feb 23 '15 at 20:56
  • 1
    I can confirm a similar repeated prompt issue when using multiple-cursors to append the selected text at all cursor points to a register. (1) Select a region (2) mc/edit-lines or M-S-c M-S-c (3) C-a C-SPC C-e (4) M-x append-to-register (5) Say yes to Do append-to-register for all cursors? (6) multiple cursors will still prompt the M-x ido completion and what register to append to for each cursor location. Feb 23 '15 at 21:04
  • No, @lawlist, I'm not talking about appearance but behavior. Some commands in Emacs prompt you in the minibuffer for a character (or others things). When used with multiple cursors, some of these commands will prompt you for input once for each cursor and others will only read input from you once.
    – Omar
    Feb 23 '15 at 22:13

I recently wondered this again and decided to do what I should have the first time: read the source code! The answer is very simple: iy-go-to-char is written with knowledge of multiple-cursors and has some specific code to make it work well with it. Roughly speaking, it stores the character you give it in a variable called iy-go-to-char-last-char and has a separate command, iy-go-to-char--command, that takes no input character and does the actual searching up to the given character, iy-go-to-char-last-char. The point is that that command sets mc--this-command to iy-go-to-char--command, so that when the command is repeated for other cursors, you are not again prompted for a character.

What I still don't understand is why zap-to-char doesn't behave the same way as zap-up-to-char does when used with multiple-cursors. The difference for multiple-cursors between those two seems to come from how they take their interactive arguments: zap-up-to-char uses (interactive "p\ncZap up to char: ") but zap-to-char uses instead

(interactive (list (prefix-numeric-value current-prefix-arg)
                   (read-char "Zap up to char: " t)))

It is not clear to me why exactly that makes multiple-cursors behave differently.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.