I’m trying to implement this when I press C-return:
- If there’s an active region, it activates multiple cursors by calling
mc/edit-lines
- If there’s no active region, it initiates rectangular selection by
calling
cua-rectangle-mark-mode
.
Here’s the code I wrote:
(defun cua-or-multicursor ()
(interactive)
(if (use-region-p)
(progn
(message "Using multi cursor~~") ;; For debug
(mc/edit-lines))
(progn
(message "Using cua...") ;; For debug
(cua-rectangle-mark-mode))))
(global-set-key (kbd "C-<return>") 'cua-or-multicursor)
The cua part of it seems to work appropriately. The problem is the multiple cursors part. I selected for example 2 lines (by setting the mark and moving down once), and pressed C-return, it prompted me whether I wanted to call cua-rectangle-mark-mode
for all lines. I said yes. Then I started moving my cursors (it did give me 2 cursors), and I saw that the 2 cursors left a region behind them (which doesn’t happen if I just bind mc/edit-lines
to C-return), just like if I set the mark and then move my cursor. Here’s what I mean:
In the message buffer it said
Mark set
Using multicursor~~
Using cua...
Mark set
C-?:help M-p:pad M-o:open M-c:close M-b:blank M-s:string M-f:fill M-i:incr M-n:seq
It seems cua-rectangle-mark-mode
is called right after multiple cursors… Any idea on why this would happen?
BTW I have GNU Emacs 24.4.1 on a Mac.
(region-active-p)
instead?region-active-p
seems to behave the same here.