Make mc/cycle-forward and mc/cycle-backward loop around by default.

Instead of erroring if there is no next (respectively previous) cursor
mc/cycle-forward (respectively mc/cycle-backward) will just loop back
to the first (respectively last) cursor.
This commit is contained in:
Marco Baringer 2012-10-10 09:24:19 +02:00
parent a0f771f3e4
commit fcbb7a4df9

View File

@ -54,23 +54,31 @@
(setq prev cursor))))
prev))
(defun mc/cycle-forward ()
(interactive)
(defun mc/cycle-forward (&optional error-if-no-next-cursor)
(interactive (list prefix-arg))
(let ((next-cursor (mc/next-cursor-after-point)))
(unless next-cursor
(error "We're already at the last cursor"))
(cond
(next-cursor
(mc/create-fake-cursor-at-point)
(mc/pop-state-from-overlay next-cursor)
(recenter)))
(recenter))
(error-if-no-next-cursor
(error "We're already at the last cursor"))
(t
(mc/cycle-backward t)))))
(defun mc/cycle-backward ()
(interactive)
(defun mc/cycle-backward (&optional error-if-no-previous-cursor)
(interactive (list prefix-arg))
(let ((prev-cursor (mc/prev-cursor-before-point)))
(unless prev-cursor
(error "We're already at the first cursor"))
(cond
(prev-cursor
(mc/create-fake-cursor-at-point)
(mc/pop-state-from-overlay prev-cursor)
(recenter)))
(recenter))
(error-if-no-previous-cursor
(error "We're already at the first cursor"))
(t
(mc/cycle-forward t)))))
(define-key mc/keymap (kbd "C-v") 'mc/cycle-forward)
(define-key mc/keymap (kbd "M-v") 'mc/cycle-backward)