Merge pull request #203 from dovej/master

Changed mc/furthest-cursor-after(before)-point to check if mark is active.
This commit is contained in:
Magnar Sveen 2015-06-27 10:48:00 +02:00
commit 9b53e892e6

View File

@ -55,8 +55,8 @@
beg)) beg))
(defun mc/furthest-cursor-before-point () (defun mc/furthest-cursor-before-point ()
(let ((beg (min (mark) (point))) (let ((beg (if mark-active (min (mark) (point)) (point)))
furthest) furthest)
(mc/for-each-fake-cursor (mc/for-each-fake-cursor
(when (< (mc/cursor-beg cursor) beg) (when (< (mc/cursor-beg cursor) beg)
(setq beg (mc/cursor-beg cursor)) (setq beg (mc/cursor-beg cursor))
@ -64,8 +64,8 @@
furthest)) furthest))
(defun mc/furthest-cursor-after-point () (defun mc/furthest-cursor-after-point ()
(let ((end (max (mark) (point))) (let ((end (if mark-active (max (mark) (point)) (point)))
furthest) furthest)
(mc/for-each-fake-cursor (mc/for-each-fake-cursor
(when (> (mc/cursor-end cursor) end) (when (> (mc/cursor-end cursor) end)
(setq end (mc/cursor-end cursor)) (setq end (mc/cursor-end cursor))
@ -127,14 +127,14 @@ Use like case-fold-search, don't recommend setting it globally.")
With negative ARG, delete the last one instead. With negative ARG, delete the last one instead.
With zero ARG, skip the last one and mark next." With zero ARG, skip the last one and mark next."
(interactive "p") (interactive "p")
(if (region-active-p) (if (< arg 0)
(if (< arg 0) (let ((cursor (mc/furthest-cursor-after-point)))
(let ((cursor (mc/furthest-cursor-after-point))) (if cursor
(if cursor (mc/remove-fake-cursor cursor)
(mc/remove-fake-cursor cursor) (error "No cursors to be unmarked")))
(error "No cursors to be unmarked"))) (if (region-active-p)
(mc/mark-more-like-this (= arg 0) 'forwards)) (mc/mark-more-like-this (= arg 0) 'forwards)
(mc/mark-lines arg 'forwards)) (mc/mark-lines arg 'forwards)))
(mc/maybe-multiple-cursors-mode)) (mc/maybe-multiple-cursors-mode))
;;;###autoload ;;;###autoload
@ -155,14 +155,14 @@ With zero ARG, skip the last one and mark next."
With negative ARG, delete the last one instead. With negative ARG, delete the last one instead.
With zero ARG, skip the last one and mark next." With zero ARG, skip the last one and mark next."
(interactive "p") (interactive "p")
(if (region-active-p) (if (< arg 0)
(if (< arg 0) (let ((cursor (mc/furthest-cursor-before-point)))
(let ((cursor (mc/furthest-cursor-before-point))) (if cursor
(if cursor (mc/remove-fake-cursor cursor)
(mc/remove-fake-cursor cursor) (error "No cursors to be unmarked")))
(error "No cursors to be unmarked"))) (if (region-active-p)
(mc/mark-more-like-this (= arg 0) 'backwards)) (mc/mark-more-like-this (= arg 0) 'backwards)
(mc/mark-lines arg 'backwards)) (mc/mark-lines arg 'backwards)))
(mc/maybe-multiple-cursors-mode)) (mc/maybe-multiple-cursors-mode))
;;;###autoload ;;;###autoload
@ -179,12 +179,16 @@ With zero ARG, skip the last one and mark next."
(defun mc/mark-lines (num-lines direction) (defun mc/mark-lines (num-lines direction)
(dotimes (i num-lines) (dotimes (i num-lines)
(mc/create-fake-cursor-at-point) (mc/save-excursion
(ecase direction (let ((furthest-cursor (ecase direction
(forwards (loop do (next-logical-line 1 nil) (forwards (mc/furthest-cursor-after-point))
while (mc/all-fake-cursors (point) (1+ (point))))) (backwards (mc/furthest-cursor-before-point)))))
(backwards (loop do (previous-logical-line 1 nil) (if (overlayp furthest-cursor)
while (mc/all-fake-cursors (point) (1+ (point)))))))) (goto-char (overlay-get furthest-cursor 'point))))
(ecase direction
(forwards (next-logical-line 1 nil))
(backwards (previous-logical-line 1 nil)))
(mc/create-fake-cursor-at-point))))
;;;###autoload ;;;###autoload
(defun mc/mark-next-lines (arg) (defun mc/mark-next-lines (arg)