[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/multiple-cursors 82a1fe3 209/434: Add mc/sort-regions and
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/multiple-cursors 82a1fe3 209/434: Add mc/sort-regions and mc/reverse-regions |
Date: |
Sat, 7 Aug 2021 09:20:27 -0400 (EDT) |
branch: elpa/multiple-cursors
commit 82a1fe37469c075c5fff9381b8826ede9228bbd0
Author: Magnar Sveen <magnars@gmail.com>
Commit: Magnar Sveen <magnars@gmail.com>
Add mc/sort-regions and mc/reverse-regions
---
README.md | 2 +
features/sort-and-reverse.feature | 19 +++++++++
features/support/env.el | 2 +
mc-insert-numbers.el | 47 ----------------------
mc-separate-operations.el | 85 +++++++++++++++++++++++++++++++++++++++
multiple-cursors-core.el | 2 +
multiple-cursors.el | 4 +-
7 files changed, 113 insertions(+), 48 deletions(-)
diff --git a/README.md b/README.md
index 9366cb0..968ec56 100644
--- a/README.md
+++ b/README.md
@@ -66,6 +66,8 @@ You can [watch an intro to multiple-cursors at Emacs
Rocks](http://emacsrocks.co
- `set-rectangular-region-anchor`: Think of this one as `set-mark` except
you're marking a rectangular region.
- `mc/mark-sgml-tag-pair`: Mark the current opening and closing tag.
- `mc/insert-numbers`: Insert increasing numbers for each cursor, top to
bottom.
+ - `mc/sort-regions`: Sort the marked regions alphabetically.
+ - `mc/reverse-regions`: Reverse the order of the marked regions.
## Tips and tricks
diff --git a/features/sort-and-reverse.feature
b/features/sort-and-reverse.feature
new file mode 100644
index 0000000..f5eea12
--- /dev/null
+++ b/features/sort-and-reverse.feature
@@ -0,0 +1,19 @@
+Feature: Sorting and reversing cursor regions
+
+ Scenario: Reversing regions
+ Given I have cursors at "text" in "This text contains the word text thrice
(text here)"
+ When I press "M-f"
+ And I press "C-f"
+ And I press "C-SPC"
+ And I press "M-f"
+ And I press "H-1"
+ Then I should see "This text here the word text thrice (text contains)"
+
+ Scenario: Sorting regions
+ Given I have cursors at "text" in "This text contains the word text thrice
(text here)"
+ When I press "M-f"
+ And I press "C-f"
+ And I press "C-SPC"
+ And I press "M-f"
+ And I press "H-2"
+ Then I should see "This text contains the word text here (text thrice)"
diff --git a/features/support/env.el b/features/support/env.el
index f6da1f5..4f6af30 100644
--- a/features/support/env.el
+++ b/features/support/env.el
@@ -26,6 +26,8 @@
(global-set-key (kbd "M-$") 'mc/mark-all-like-this-dwim)
(global-set-key (kbd "M-#") 'mc/mark-all-in-region)
(global-set-key (kbd "H-0") 'mc/insert-numbers)
+ (global-set-key (kbd "H-1") 'mc/reverse-regions)
+ (global-set-key (kbd "H-2") 'mc/sort-regions)
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
(global-set-key (kbd "H-SPC") 'set-rectangular-region-anchor)
(switch-to-buffer
diff --git a/mc-insert-numbers.el b/mc-insert-numbers.el
deleted file mode 100644
index d226c69..0000000
--- a/mc-insert-numbers.el
+++ /dev/null
@@ -1,47 +0,0 @@
-;;; mc-insert-numbers.el
-
-;; Copyright (C) 2012 Magnar Sveen
-
-;; Author: Magnar Sveen <magnars@gmail.com>
-;; Keywords: editing cursors
-
-;; This program is free software; you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-
-;; This program is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; This file contains functions for adding increasing integers to
-;; each cursor.
-
-;; Please see multiple-cursors.el for more commentary.
-
-;;; Code:
-
-(require 'multiple-cursors-core)
-
-;;;###autoload
-(defun mc/insert-numbers (arg)
- (interactive "P")
- (setq mc--insert-numbers-number (or arg 0))
- (mc/for-each-cursor-ordered
- (mc/execute-command-for-fake-cursor 'mc--insert-number-and-increase
cursor)))
-
-(defvar mc--insert-numbers-number 0)
-
-(defun mc--insert-number-and-increase ()
- (interactive)
- (insert (number-to-string mc--insert-numbers-number))
- (setq mc--insert-numbers-number (1+ mc--insert-numbers-number)))
-
-(provide 'mc-insert-numbers)
-;;; mc-insert-numbers.el ends here
diff --git a/mc-separate-operations.el b/mc-separate-operations.el
new file mode 100644
index 0000000..f15dc7d
--- /dev/null
+++ b/mc-separate-operations.el
@@ -0,0 +1,85 @@
+;;; mc-separate-operations.el - functions that work differently on each cursor
+
+;; Copyright (C) 2012 Magnar Sveen
+
+;; Author: Magnar Sveen <magnars@gmail.com>
+;; Keywords: editing cursors
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This file contains functions that work differently on each cursor,
+;; instead of treating all of them the same.
+
+;; Please see multiple-cursors.el for more commentary.
+
+;;; Code:
+
+(require 'multiple-cursors-core)
+
+;;;###autoload
+(defun mc/insert-numbers (arg)
+ "Insert increasing numbers for each cursor, starting at 0 or ARG."
+ (interactive "P")
+ (setq mc--insert-numbers-number (or arg 0))
+ (mc/for-each-cursor-ordered
+ (mc/execute-command-for-fake-cursor 'mc--insert-number-and-increase
cursor)))
+
+(defvar mc--insert-numbers-number 0)
+
+(defun mc--insert-number-and-increase ()
+ (interactive)
+ (insert (number-to-string mc--insert-numbers-number))
+ (setq mc--insert-numbers-number (1+ mc--insert-numbers-number)))
+
+(defun mc--ordered-region-strings ()
+ (let (strings)
+ (save-excursion
+ (mc/for-each-cursor-ordered
+ (add-to-list 'strings (buffer-substring-no-properties
+ (mc/cursor-beg cursor)
+ (mc/cursor-end cursor))))strings)
+ (nreverse strings)))
+
+(defvar mc--strings-to-replace nil)
+
+(defun mc--replace-region-strings-1 ()
+ (interactive)
+ (delete-region (region-beginning) (region-end))
+ (insert (car mc--strings-to-replace))
+ (setq mc--strings-to-replace (cdr mc--strings-to-replace)))
+
+(defun mc--replace-region-strings ()
+ (mc/for-each-cursor-ordered
+ (mc/execute-command-for-fake-cursor 'mc--replace-region-strings-1 cursor)))
+
+;;;###autoload
+(defun mc/reverse-regions ()
+ (interactive)
+ (if (not (use-region-p))
+ (message "Mark regions to reverse first.")
+ (setq mc--strings-to-replace (nreverse (mc--ordered-region-strings)))
+ (mc--replace-region-strings)))
+
+;;;###autoload
+(defun mc/sort-regions ()
+ (interactive)
+ (if (not (use-region-p))
+ (message "Mark regions to sort first.")
+ (setq mc--strings-to-replace (sort (mc--ordered-region-strings) 'string<))
+ (mc--replace-region-strings)))
+
+(provide 'mc-separate-operations)
+;;; mc-separate-operations.el ends here
diff --git a/multiple-cursors-core.el b/multiple-cursors-core.el
index be66a69..fc358cb 100644
--- a/multiple-cursors-core.el
+++ b/multiple-cursors-core.el
@@ -566,6 +566,8 @@ for running commands with multiple cursors.")
mc/mark-all-like-this-dwim
mc/mark-sgml-tag-pair
mc/insert-numbers
+ mc/sort-regions
+ mc/reverse-regions
mc/cycle-forward
mc/cycle-backward
rrm/switch-to-multiple-cursors
diff --git a/multiple-cursors.el b/multiple-cursors.el
index b618e3c..7ada1cc 100644
--- a/multiple-cursors.el
+++ b/multiple-cursors.el
@@ -83,6 +83,8 @@
;; - `set-rectangular-region-anchor`: Think of this one as `set-mark` except
you're marking a rectangular region.
;; - `mc/mark-sgml-tag-pair`: Mark the current opening and closing tag.
;; - `mc/insert-numbers`: Insert increasing numbers for each cursor, top to
bottom.
+;; - `mc/sort-regions`: Sort the marked regions alphabetically.
+;; - `mc/reverse-regions`: Reverse the order of the marked regions.
;; ## Tips and tricks
@@ -164,7 +166,7 @@
(require 'mc-cycle-cursors)
(require 'mc-mark-more)
(require 'rectangular-region-mode)
-(require 'mc-insert-numbers)
+(require 'mc-separate-operations)
(provide 'multiple-cursors)
- [nongnu] elpa/multiple-cursors c2bb81f 042/434: Dont forget to require rectangular-region-mode, (continued)
- [nongnu] elpa/multiple-cursors c2bb81f 042/434: Dont forget to require rectangular-region-mode, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors ba11b12 051/434: Make interprogram-paste work for all cursors., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 8c8d52f 049/434: Run pre-command-hooks for each cursor, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors c1fba2c 111/434: Add travis badge, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors f73569f 125/434: Update documentation., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors ce777dc 134/434: Add some mouse-commands to the run-once list., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 879ddb0 150/434: Add Takafumi Arakaki to list of contributors, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 64ffd81 142/434: Add quoted-insert to run-for-all list., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 00f9055 146/434: Add mc/dump-list to make mc/save-lists diff-friendly, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 7a6eb0d 145/434: Never execute keyboard macros for fake cursors., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 82a1fe3 209/434: Add mc/sort-regions and mc/reverse-regions,
ELPA Syncer <=
- [nongnu] elpa/multiple-cursors aa9a1ec 220/434: Add failing scenarios for mark-all-symbols/words, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors e7a5fe6 213/434: Release 1.2.1, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 6b09b9c 172/434: Add some more basic commands to the run-all and run-once lists., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 7382b46 170/434: Merge pull request #30 from gvol/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 5f7c92b 173/434: Add more backward-delete commands to run-for-all, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 3f3cdc6 207/434: Merge pull request #56 from paradoxxxzero/transient-mark-mode, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 7d79b98 182/434: Autoload new functions., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 0b9aae1 188/434: Merge pull request #40 from tkf/fix-dump-list, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 56839df 208/434: Update docs with mc/edit-*-lines, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors dc0aa99 193/434: Simplify travis run script, and make it work when ECUKES_EMACS has a space in the path, ELPA Syncer, 2021/08/07