Merge pull request #227 from jtamagnan/insert_letters

Add mc/insert-letters function and test cases
This commit is contained in:
Magnar Sveen 2015-12-05 21:25:04 +01:00
commit a393384b35
7 changed files with 54 additions and 3 deletions

View File

@ -87,6 +87,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. - `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/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-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/sort-regions`: Sort the marked regions alphabetically.
- `mc/reverse-regions`: Reverse the order of the marked regions. - `mc/reverse-regions`: Reverse the order of the marked regions.

View File

@ -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)"

View File

@ -22,6 +22,9 @@
(When "^I insert numbers$" (When "^I insert numbers$"
(lambda () (call-interactively 'mc/insert-numbers))) (lambda () (call-interactively 'mc/insert-numbers)))
(When "^I insert letters$"
(lambda () (call-interactively 'mc/insert-letters)))
(When "^I reverse regions$" (When "^I reverse regions$"
(lambda () (call-interactively 'mc/reverse-regions))) (lambda () (call-interactively 'mc/reverse-regions)))

View File

@ -29,6 +29,7 @@
(global-set-key (kbd "C-$") 'mc/mark-all-dwim) (global-set-key (kbd "C-$") 'mc/mark-all-dwim)
(global-set-key (kbd "M-#") 'mc/mark-all-in-region) (global-set-key (kbd "M-#") 'mc/mark-all-in-region)
(global-set-key (kbd "H-0") 'mc/insert-numbers) (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-1") 'mc/reverse-regions)
(global-set-key (kbd "H-2") 'mc/sort-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 "C-S-c C-S-c") 'mc/edit-lines)

View File

@ -53,6 +53,31 @@
(mc/cursor-end cursor)) strings)))) (mc/cursor-end cursor)) strings))))
(nreverse 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) (defvar mc--strings-to-replace nil)
(defun mc--replace-region-strings-1 () (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." Might not behave as intended if more than one cursors are on the same line."
(interactive "c") (interactive "c")
(let ((rightest-column (current-column))) (let ((rightest-column (current-column)))
(mc/execute-command-for-all-cursors (mc/execute-command-for-all-cursors
(lambda () "get the rightest cursor" (lambda () "get the rightest cursor"
(interactive) (interactive)
(setq rightest-column (max (current-column) rightest-column)) (setq rightest-column (max (current-column) rightest-column))
)) ))
(mc/execute-command-for-all-cursors (mc/execute-command-for-all-cursors
(lambda () (lambda ()
(interactive) (interactive)
(let ((missing-spaces (- rightest-column (current-column)))) (let ((missing-spaces (- rightest-column (current-column))))
(save-excursion (insert (make-string missing-spaces character))) (save-excursion (insert (make-string missing-spaces character)))

View File

@ -614,6 +614,7 @@ for running commands with multiple cursors.")
mc/mark-all-dwim mc/mark-all-dwim
mc/mark-sgml-tag-pair mc/mark-sgml-tag-pair
mc/insert-numbers mc/insert-numbers
mc/insert-letters
mc/sort-regions mc/sort-regions
mc/reverse-regions mc/reverse-regions
mc/cycle-forward mc/cycle-forward

View File

@ -87,6 +87,7 @@
;; - `set-rectangular-region-anchor`: Think of this one as `set-mark` except you're marking a rectangular region. ;; - `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/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-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/sort-regions`: Sort the marked regions alphabetically.
;; - `mc/reverse-regions`: Reverse the order of the marked regions. ;; - `mc/reverse-regions`: Reverse the order of the marked regions.