mirror of
https://github.com/magnars/multiple-cursors.el.git
synced 2025-10-13 21:03:05 +00:00
When no region is active mc/mark-next-like-this and mc/mark-previous-like-this should create a cursor one like up (or down).
Added the functions mc/mark-next-lines and mc/mark-previous-lines which create cursors one line above and below point. Refactored common mc/mark-previous-like-this and mc/mark-next-like-this functionality into mc/mark-more-like-this. Changed mc/mark-next-like-this and mc/mark-more-like-this to call mc/mark-next-lines and mc/mark-previous-lines when there is no active region (instead of erroring).
This commit is contained in:
parent
876937bfa3
commit
3f20fc15a7
111
mc-mark-more.el
111
mc-mark-more.el
@ -79,34 +79,54 @@
|
|||||||
(mc/cursor-end cursor))))
|
(mc/cursor-end cursor))))
|
||||||
strings))
|
strings))
|
||||||
|
|
||||||
|
(defun mc/maybe-multiple-cursors-mode ()
|
||||||
|
"Enable multiple-cursors-mode if there is more than one currently active cursor."
|
||||||
|
(if (> (mc/num-cursors) 1)
|
||||||
|
(multiple-cursors-mode 1)
|
||||||
|
(multiple-cursors-mode 0)))
|
||||||
|
|
||||||
|
(defun mc/mark-more-like-this (skip-last direction)
|
||||||
|
(let ((case-fold-search nil)
|
||||||
|
(re (regexp-opt (mc/region-strings)))
|
||||||
|
(point-out-of-order (ecase direction
|
||||||
|
(forwards (< (point) (mark)))
|
||||||
|
(backwards (not (< (point) (mark))))))
|
||||||
|
(furthest-cursor (ecase direction
|
||||||
|
(forwards (mc/furthest-cursor-after-point))
|
||||||
|
(backwards (mc/furthest-cursor-before-point))))
|
||||||
|
(start-char (ecase direction
|
||||||
|
(forwards (mc/furthest-region-end))
|
||||||
|
(backwards (mc/first-region-start))))
|
||||||
|
(search-function (ecase direction
|
||||||
|
(forwards 'search-forward-regexp)
|
||||||
|
(backwards 'search-backward-regexp)))
|
||||||
|
(match-point-getter (ecase direction
|
||||||
|
(forwards 'match-beginning)
|
||||||
|
(backwards 'match-end))))
|
||||||
|
(mc/save-excursion
|
||||||
|
(goto-char start-char)
|
||||||
|
(when skip-last
|
||||||
|
(mc/remove-fake-cursor furthest-cursor))
|
||||||
|
(if (funcall search-function re nil t)
|
||||||
|
(progn
|
||||||
|
(push-mark (funcall match-point-getter 0))
|
||||||
|
(when point-out-of-order
|
||||||
|
(exchange-point-and-mark))
|
||||||
|
(mc/create-fake-cursor-at-point))
|
||||||
|
(error "no more matches found.")))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun mc/mark-next-like-this (arg)
|
(defun mc/mark-next-like-this (arg)
|
||||||
"Find and mark the next part of the buffer matching the currently active region
|
"Find and mark the next part of the buffer matching the currently active region
|
||||||
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")
|
||||||
(unless (region-active-p)
|
(if (region-active-p)
|
||||||
(error "Mark a region to match first."))
|
(if (< arg 0)
|
||||||
(when (< arg 0)
|
(mc/remove-fake-cursor (mc/furthest-cursor-after-point))
|
||||||
(mc/remove-fake-cursor (mc/furthest-cursor-after-point)))
|
(mc/mark-more-like-this (= arg 0) 'forwards))
|
||||||
(when (>= arg 0)
|
(mc/mark-lines arg 'forwards))
|
||||||
(let ((case-fold-search nil)
|
(mc/maybe-multiple-cursors-mode))
|
||||||
(point-first (< (point) (mark)))
|
|
||||||
(re (regexp-opt (mc/region-strings)))
|
|
||||||
(furthest-cursor (mc/furthest-cursor-after-point)))
|
|
||||||
(mc/save-excursion
|
|
||||||
(goto-char (mc/furthest-region-end))
|
|
||||||
(when (= arg 0)
|
|
||||||
(mc/remove-fake-cursor furthest-cursor))
|
|
||||||
(if (search-forward-regexp re nil t)
|
|
||||||
(progn
|
|
||||||
(push-mark (match-beginning 0))
|
|
||||||
(when point-first (exchange-point-and-mark))
|
|
||||||
(mc/create-fake-cursor-at-point))
|
|
||||||
(error "no more found forward")))))
|
|
||||||
(if (> (mc/num-cursors) 1)
|
|
||||||
(multiple-cursors-mode 1)
|
|
||||||
(multiple-cursors-mode 0)))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun mc/mark-previous-like-this (arg)
|
(defun mc/mark-previous-like-this (arg)
|
||||||
@ -114,28 +134,31 @@ 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")
|
||||||
(unless (region-active-p)
|
(if (region-active-p)
|
||||||
(error "Mark a region to match first."))
|
(if (< arg 0)
|
||||||
(when (< arg 0)
|
(mc/remove-fake-cursor (mc/furthest-cursor-before-point))
|
||||||
(mc/remove-fake-cursor (mc/furthest-cursor-before-point)))
|
(mc/mark-more-like-this (= arg 0) 'backwards))
|
||||||
(when (>= arg 0)
|
(mc/mark-lines arg 'backwards))
|
||||||
(let ((case-fold-search nil)
|
(mc/maybe-multiple-cursors-mode))
|
||||||
(point-first (< (point) (mark)))
|
|
||||||
(re (regexp-opt (mc/region-strings)))
|
(defun mc/mark-lines (num-lines direction)
|
||||||
(furthest-cursor (mc/furthest-cursor-before-point)))
|
(dotimes (i num-lines)
|
||||||
(mc/save-excursion
|
(mc/create-fake-cursor-at-point)
|
||||||
(goto-char (mc/first-region-start))
|
(ecase direction
|
||||||
(when (= arg 0)
|
(forwards (next-line 1 nil))
|
||||||
(mc/remove-fake-cursor furthest-cursor))
|
(backwards (previous-line 1 nil)))))
|
||||||
(if (search-backward-regexp re nil t)
|
|
||||||
(progn
|
;;;###autoload
|
||||||
(push-mark (match-end 0))
|
(defun mc/mark-next-lines (arg)
|
||||||
(unless point-first (exchange-point-and-mark))
|
(interactive "p")
|
||||||
(mc/create-fake-cursor-at-point))
|
(mc/mark-lines arg 'forwards)
|
||||||
(error "no more found backward")))))
|
(mc/maybe-multiple-cursors-mode))
|
||||||
(if (> (mc/num-cursors) 1)
|
|
||||||
(multiple-cursors-mode 1)
|
;;;###autoload
|
||||||
(multiple-cursors-mode 0)))
|
(defun mc/mark-previous-lines (arg)
|
||||||
|
(interactive "p")
|
||||||
|
(mc/mark-lines arg 'backwards)
|
||||||
|
(mc/maybe-multiple-cursors-mode))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun mc/unmark-next-like-this (arg)
|
(defun mc/unmark-next-like-this (arg)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user