[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/multiple-cursors ca822cd 347/434: Add mc/insert-letters fu
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/multiple-cursors ca822cd 347/434: Add mc/insert-letters function and test cases |
Date: |
Sat, 7 Aug 2021 09:20:57 -0400 (EDT) |
branch: elpa/multiple-cursors
commit ca822cd0d07468b58dc4a43169be8471721a960a
Author: Jules Tamagnan <jtamagnan@gmail.com>
Commit: Jules Tamagnan <jtamagnan@gmail.com>
Add mc/insert-letters function and test cases
* README.md: Add to readme, under special section.
* features/insert-letters.feature: Add scenarios.
* features/step-definitions/multiple-cursors-steps.el: Add call.
* features/support/env.el: Add keybinding for insert-letters to H-3.
* mc-separate-operations.el: Add function and helper functions.
* multiple-cursors-core.el: Add insert-letters to functions that run once.
* multiple-cursors.el: Add to readme.
---
README.md | 1 +
features/insert-letters.feature | 19 +++++++++++++
.../step-definitions/multiple-cursors-steps.el | 3 +++
features/support/env.el | 1 +
mc-separate-operations.el | 31 +++++++++++++++++++---
multiple-cursors-core.el | 1 +
multiple-cursors.el | 1 +
7 files changed, 54 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index d97345a..9ebb654 100644
--- a/README.md
+++ b/README.md
@@ -85,6 +85,7 @@ 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/insert-letters`: Insert increasing letters for each cursor, top to
bottom.
- `mc/sort-regions`: Sort the marked regions alphabetically.
- `mc/reverse-regions`: Reverse the order of the marked regions.
diff --git a/features/insert-letters.feature b/features/insert-letters.feature
new file mode 100644
index 0000000..7bf56a3
--- /dev/null
+++ b/features/insert-letters.feature
@@ -0,0 +1,19 @@
+Feature: Insert increasing letters
+
+ Scenario: Three cursors, a-b-c
+ Given I have cursors at "text" in "This text contains the word text thrice
(text)"
+ When I press "H-3"
+ And I press "SPC"
+ Then I should see "This a text contains the word b text thrice (c text)"
+
+ Scenario: Three cursors, j-k-l
+ Given I have cursors at "text" in "This text contains the word text thrice
(text)"
+ When I press "C-9 H-3"
+ And I press "SPC"
+ Then I should see "This j text contains the word k text thrice (l text)"
+
+ Scenario: Three cursors, z-aa-ab
+ Given I have cursors at "text" in "This text contains the word text thrice
(text)"
+ When I press "C-u 2 5 H-3"
+ And I press "SPC"
+ Then I should see "This z text contains the word aa text thrice (ab text)"
\ No newline at end of file
diff --git a/features/step-definitions/multiple-cursors-steps.el
b/features/step-definitions/multiple-cursors-steps.el
index a5590b7..a2f70b5 100644
--- a/features/step-definitions/multiple-cursors-steps.el
+++ b/features/step-definitions/multiple-cursors-steps.el
@@ -16,6 +16,9 @@
(When "^I insert numbers$"
(lambda () (call-interactively 'mc/insert-numbers)))
+(When "^I insert letters$"
+ (lambda () (call-interactively 'mc/insert-letters)))
+
(When "^I reverse regions$"
(lambda () (call-interactively 'mc/reverse-regions)))
diff --git a/features/support/env.el b/features/support/env.el
index 3ce7c91..7829abf 100644
--- a/features/support/env.el
+++ b/features/support/env.el
@@ -27,6 +27,7 @@
(global-set-key (kbd "C-$") 'mc/mark-all-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-3") 'mc/insert-letters)
(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)
diff --git a/mc-separate-operations.el b/mc-separate-operations.el
index b587530..412a443 100644
--- a/mc-separate-operations.el
+++ b/mc-separate-operations.el
@@ -53,6 +53,31 @@
(mc/cursor-end cursor)) strings))))
(nreverse strings)))
+;;;###autoload
+(defun mc/insert-letters (arg)
+ "Insert increasing letters for each cursor, starting at 0 or ARG.
+ Where letter[0]=a letter[2]=c letter[26]=aa"
+ (interactive "P")
+ (setq mc--insert-letters-number (or arg 0))
+ (mc/for-each-cursor-ordered
+ (mc/execute-command-for-fake-cursor 'mc--insert-letter-and-increase
cursor)))
+
+(defun mc--number-to-letters (number)
+ (let ((letter
+ (char-to-string
+ (nth (mod number 26) '(?a ?b ?c ?d ?e ?f ?g ?h ?i ?j ?k ?l ?m ?n ?o
?p ?q ?r ?s ?t ?u ?v ?w ?x ?y ?z))))
+ (number2 (/ number 26)))
+ (if (> number2 0)
+ (concat (mc--number-to-letters (- number2 1)) letter)
+ letter)))
+
+(defvar mc--insert-letters-number 0)
+
+(defun mc--insert-letter-and-increase ()
+ (interactive)
+ (insert (mc--number-to-letters mc--insert-letters-number))
+ (setq mc--insert-letters-number (1+ mc--insert-letters-number)))
+
(defvar mc--strings-to-replace nil)
(defun mc--replace-region-strings-1 ()
@@ -94,13 +119,13 @@ highest colum number (the rightest).
Might not behave as intended if more than one cursors are on the same line."
(interactive "c")
(let ((rightest-column (current-column)))
- (mc/execute-command-for-all-cursors
+ (mc/execute-command-for-all-cursors
(lambda () "get the rightest cursor"
(interactive)
(setq rightest-column (max (current-column) rightest-column))
))
- (mc/execute-command-for-all-cursors
- (lambda ()
+ (mc/execute-command-for-all-cursors
+ (lambda ()
(interactive)
(let ((missing-spaces (- rightest-column (current-column))))
(save-excursion (insert (make-string missing-spaces character)))
diff --git a/multiple-cursors-core.el b/multiple-cursors-core.el
index 6602703..94edf7b 100644
--- a/multiple-cursors-core.el
+++ b/multiple-cursors-core.el
@@ -612,6 +612,7 @@ for running commands with multiple cursors.")
mc/mark-all-dwim
mc/mark-sgml-tag-pair
mc/insert-numbers
+ mc/insert-letters
mc/sort-regions
mc/reverse-regions
mc/cycle-forward
diff --git a/multiple-cursors.el b/multiple-cursors.el
index 9c44db9..be2d389 100644
--- a/multiple-cursors.el
+++ b/multiple-cursors.el
@@ -85,6 +85,7 @@
;; - `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/insert-letters`: Insert increasing letters for each cursor, top to
bottom.
;; - `mc/sort-regions`: Sort the marked regions alphabetically.
;; - `mc/reverse-regions`: Reverse the order of the marked regions.
- [nongnu] elpa/multiple-cursors fc39dab 299/434: Adds jedi-mode to list of unsupported minor modes, (continued)
- [nongnu] elpa/multiple-cursors fc39dab 299/434: Adds jedi-mode to list of unsupported minor modes, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors da2a9ab 298/434: Add mc/mark-all-in-region-regexp, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 7ddda85 312/434: Added vertical align commands, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 912342e 315/434: Add missing ###autoload markers, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 66eefa2 317/434: Add cperl-electric-backspace to default run-for-all list, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors dc1bfbf 325/434: Add cua-delete-region to default run-for-all, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 89e360e 333/434: Merge pull request #193 from dovej/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 4969d38 331/434: Move mc/list-file to the user-emacs-directory, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 49c9f7f 340/434: Merge remote-tracking branch 'upstream/master', ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 9b53e89 344/434: Merge pull request #203 from dovej/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors ca822cd 347/434: Add mc/insert-letters function and test cases,
ELPA Syncer <=
- [nongnu] elpa/multiple-cursors 54c05c3 356/434: Add more aliases for cl stuff, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 40eb74e 357/434: Extend mc/add-cursor-on-click to toggle fake cursors, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 06a2985 362/434: * mc-mark-more.el (mc/mark-all-in-region-regexp): Don't infloop when regexp matches empty string, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 4bf9860 364/434: Use cl-lib instead of shimming, which breaks in older emacsen, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors d5b544e 365/434: Merge pull request #246 from purcell/cl-lib, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors b3bd49c 372/434: Bump version to 1.4.0, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 741eec6 374/434: Update some copyright years, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors a9daac1 375/434: Add/fix docstring to functions. fix #161, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors be149f9 378/434: Create customizable mc/insert-numbers-default, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors fd847ae 379/434: added mc/always-run-for-all, ELPA Syncer, 2021/08/07