[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/multiple-cursors 3f20fc1 154/434: When no region is active
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/multiple-cursors 3f20fc1 154/434: 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). |
Date: |
Sat, 7 Aug 2021 09:20:15 -0400 (EDT) |
branch: elpa/multiple-cursors
commit 3f20fc15a74262eefad3bd95bd0504435f7bbe49
Author: Marco Baringer <mb@bese.it>
Commit: Marco Baringer <mb@bese.it>
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).
---
mc-mark-more.el | 111 ++++++++++++++++++++++++++++++++++----------------------
1 file changed, 67 insertions(+), 44 deletions(-)
diff --git a/mc-mark-more.el b/mc-mark-more.el
index 883fb1e..8dd4bc6 100644
--- a/mc-mark-more.el
+++ b/mc-mark-more.el
@@ -79,34 +79,54 @@
(mc/cursor-end cursor))))
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
(defun mc/mark-next-like-this (arg)
"Find and mark the next part of the buffer matching the currently active
region
With negative ARG, delete the last one instead.
With zero ARG, skip the last one and mark next."
(interactive "p")
- (unless (region-active-p)
- (error "Mark a region to match first."))
- (when (< arg 0)
- (mc/remove-fake-cursor (mc/furthest-cursor-after-point)))
- (when (>= arg 0)
- (let ((case-fold-search nil)
- (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)))
+ (if (region-active-p)
+ (if (< arg 0)
+ (mc/remove-fake-cursor (mc/furthest-cursor-after-point))
+ (mc/mark-more-like-this (= arg 0) 'forwards))
+ (mc/mark-lines arg 'forwards))
+ (mc/maybe-multiple-cursors-mode))
;;;###autoload
(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 zero ARG, skip the last one and mark next."
(interactive "p")
- (unless (region-active-p)
- (error "Mark a region to match first."))
- (when (< arg 0)
- (mc/remove-fake-cursor (mc/furthest-cursor-before-point)))
- (when (>= arg 0)
- (let ((case-fold-search nil)
- (point-first (< (point) (mark)))
- (re (regexp-opt (mc/region-strings)))
- (furthest-cursor (mc/furthest-cursor-before-point)))
- (mc/save-excursion
- (goto-char (mc/first-region-start))
- (when (= arg 0)
- (mc/remove-fake-cursor furthest-cursor))
- (if (search-backward-regexp re nil t)
- (progn
- (push-mark (match-end 0))
- (unless point-first (exchange-point-and-mark))
- (mc/create-fake-cursor-at-point))
- (error "no more found backward")))))
- (if (> (mc/num-cursors) 1)
- (multiple-cursors-mode 1)
- (multiple-cursors-mode 0)))
+ (if (region-active-p)
+ (if (< arg 0)
+ (mc/remove-fake-cursor (mc/furthest-cursor-before-point))
+ (mc/mark-more-like-this (= arg 0) 'backwards))
+ (mc/mark-lines arg 'backwards))
+ (mc/maybe-multiple-cursors-mode))
+
+(defun mc/mark-lines (num-lines direction)
+ (dotimes (i num-lines)
+ (mc/create-fake-cursor-at-point)
+ (ecase direction
+ (forwards (next-line 1 nil))
+ (backwards (previous-line 1 nil)))))
+
+;;;###autoload
+(defun mc/mark-next-lines (arg)
+ (interactive "p")
+ (mc/mark-lines arg 'forwards)
+ (mc/maybe-multiple-cursors-mode))
+
+;;;###autoload
+(defun mc/mark-previous-lines (arg)
+ (interactive "p")
+ (mc/mark-lines arg 'backwards)
+ (mc/maybe-multiple-cursors-mode))
;;;###autoload
(defun mc/unmark-next-like-this (arg)
- [nongnu] elpa/multiple-cursors 56d0373 075/434: Fix rectangular-region-mode when adding cursors over hidden areas of the buffer., (continued)
- [nongnu] elpa/multiple-cursors 56d0373 075/434: Fix rectangular-region-mode when adding cursors over hidden areas of the buffer., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors c3c4544 083/434: Place the file definition with the save definition., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 39e4eb2 091/434: Added mc-version of mark-more-like-this-extended, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors b72e016 098/434: Don't require mark-multiple., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 294d574 093/434: Update README, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors b607794 110/434: Add config for travis-ci, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 32213d4 115/434: Make sure we run the right version of Emacs in travis., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 6e61e3d 114/434: Fix travis badge, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 719fe40 119/434: Integrate with rect.el instead of consolidating/splitting on kill-ring, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 5fcc69c 139/434: Skip keyboard macros, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 3f20fc1 154/434: 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).,
ELPA Syncer <=
- [nongnu] elpa/multiple-cursors 038c9a7 161/434: Added stop as a possible value for mc/cycle-looping-behaviour., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors e4adefc 158/434: Fix issues with mc/cycle-(backward|forward) where the cycling was dependent on not having an active mark., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 1cdd730 221/434: Automatically select word/symbol, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 72ba43a 225/434: add .nosearch to directory with bundled libraries, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 6a5969e 202/434: Adding support for using mc/edit-lines without transient mark mode., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 980a880 223/434: Merge pull request #63 from tkf/select-thing-at-point, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors dce6c00 174/434: Add mc/cursor-specific-vars to handle vars that need to be tracked per cursor., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 0a081a7 184/434: Move mc/maybe-multiple-cursors-mode to core., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 9a376a6 201/434: Add note about yank-rectangle, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors e7605bb 194/434: Merge pull request #42 from purcell/cleanup, ELPA Syncer, 2021/08/07