75 Commits

Author SHA1 Message Date
Magnar Sveen 23791339eb Release 1.2.1 2013-02-11 07:29:36 +01:00
Magnar Sveen 641eb680ca Can use mc/reverse-regions w/o region or cursors
- will flip sexp at point with the one below it
2013-02-11 07:29:17 +01:00
Magnar Sveen 16add89d29 Bugfix for sort/reverse regions w/similar contents 2013-02-11 07:28:26 +01:00
Magnar Sveen cb7a145153 Release 1.2.0 2013-02-10 21:15:35 +01:00
Magnar Sveen 82a1fe3746 Add mc/sort-regions and mc/reverse-regions 2013-02-10 21:04:09 +01:00
Magnar Sveen 56839dfdca Update docs with mc/edit-*-lines 2013-02-07 05:36:22 +01:00
Magnar Sveen 3f3cdc6c92 Merge pull request #56 from paradoxxxzero/transient-mark-mode
Add transient-mark-mode to mc/cursor-specific-vars to fix other selections than C-SPC.
2013-02-01 02:57:19 -08:00
Florian Mounier 5190e0cdc6 Add test case for shift-select-mode 2013-02-01 11:52:21 +01:00
Florian Mounier a4f6ea179a Add transient-mark-mode to mc/cursor-specific-vars to fix other selections than C-SPC. Fixes #55 2013-01-30 16:34:48 +01:00
Magnar Sveen 9582c7220b Add mc/insert-numbers
- adds increasing numbers for each cursor, top to bottom
2013-01-23 12:05:18 +01:00
Magnar Sveen a6984a1141 Merge pull request #53 from oneself/master
Adding support for using mc/edit-lines without transient mark mode.
2013-01-23 00:31:28 -08:00
Eyal Erez 6a5969e14a Adding support for using mc/edit-lines without transient mark mode. 2013-01-22 15:30:01 -05:00
Magnar Sveen 9a376a6fa2 Add note about yank-rectangle
- thanks to @snosov1 for the text
2013-01-19 08:29:31 +01:00
Magnar Sveen bfb293f200 Merge pull request #48 from tkf/smartrep
Avoid strange behavior with smartrep
2012-12-12 13:12:51 -08:00
Takafumi Arakaki 3ce6e4a670 Avoid strange behavior with smartrep
smartrep `intern`s commands into own obarray to help
`describe-bindings`, but this is bad for multiple-cursors as it makes
impossible to compare command with `memq` (`eq`).  This patch
re-`intern's the command to make the command comparable by `eq'.
2012-12-12 20:55:51 +01:00
Magnar Sveen 424e0667a4 1.1.5 2012-12-02 08:29:52 +01:00
Magnar Sveen f1a5a39b48 Merge pull request #46 from tkf/fix-dump-list-take-2
Fix mc/dump-list (take 2): it looses old setting
2012-12-01 22:34:14 -08:00
Takafumi Arakaki 84ab4ee26a Fix mc/dump-list (take 2): it looses old setting
In the old code, heading part of `value` may lost due to in-place
modification by the `sort` function. ``(symbol-value list-symbol)``
must be re-evaluated before passing it to `mapc`.  To do that,
simply replacing `let` to `symbol-macrolet` works.

See also: #40
2012-12-01 22:01:02 +01:00
Magnar Sveen 07b88080b1 Merge pull request #43 from purcell/travis-script
Simplify travis script, and make it work when ECUKES_EMACS has spaces
2012-11-27 11:03:38 -08:00
Magnar Sveen e7605bbd7c Merge pull request #42 from purcell/cleanup
Fix byte-compilation warnings, and avoid unnecessary use of "eval"
2012-11-27 11:03:22 -08:00
Steve Purcell dc0aa99459 Simplify travis run script, and make it work when ECUKES_EMACS has a space in the path
Yes, on OS X, one might have:

ECUKES_EMACS='/Applications/Emacs 23.app/Contents/MacOS/Emacs'
2012-11-27 16:35:43 +00:00
Steve Purcell 6339657440 Fix byte-compilation warnings, and avoid unnecessary use of "eval"
multiple-cursors-core.el:28:1:Warning: cl package required at runtime

In mc/store-cursor-specific-var:
multiple-cursors-core.el:127:35:Warning: reference to free variable `o'

In mc/restore-cursor-specific-var:
multiple-cursors-core.el:130:44:Warning: reference to free variable `o'
2012-11-27 14:04:36 +00:00
Magnar Sveen 94164f706a Merge pull request #41 from purcell/patch-1
Prevent byte-compilation warnings 'cl functions
2012-11-26 03:28:46 -08:00
Steve Purcell 52300ff852 Prevent byte-compilation warnings 'cl functions
Prevents the following senseless warnings:

    In mc/first-fake-cursor-after:
    mc-cycle-cursors.el:76:70:Warning: function `remove-if' from cl package called
        at runtime
    mc-cycle-cursors.el:78:64:Warning: function `sort*' from cl package called at
        runtime

    In mc/last-fake-cursor-before:
    mc-cycle-cursors.el:85:71:Warning: function `remove-if' from cl package called
        at runtime
    mc-cycle-cursors.el:87:65:Warning: function `sort*' from cl package called at
        runtime
2012-11-26 11:21:27 +00:00
Magnar Sveen 129ea778cc 1.1.4 2012-11-25 09:23:14 +01:00
Magnar Sveen 0b9aae12ca Merge pull request #40 from tkf/fix-dump-list
Fix: mc/dump-list loosing old setting
2012-11-25 00:12:57 -08:00
Takafumi Arakaki fa753aa587 Fix: mc/dump-list loosing old setting 2012-11-24 23:27:46 +01:00
Magnar Sveen bc8af45bfe Use derived-mode-p to check for sgml-mode-ishness. 2012-11-21 13:22:27 +01:00
Magnar Sveen b218a13cf7 Run tests in Emacs 23, Emacs 24 and snapshot. 2012-11-19 20:12:09 +01:00
Magnar Sveen 0a081a7c5f Move mc/maybe-multiple-cursors-mode to core. 2012-11-18 21:10:09 +01:00
Magnar Sveen 839c6ef077 Update README with command overview and tips-n-tricks. 2012-11-18 16:36:45 +01:00
Magnar Sveen 7d79b983ea Autoload new functions. 2012-11-18 16:08:10 +01:00
Magnar Sveen 717c97e32b Added Fuco to list of contributors 2012-11-18 14:47:48 +01:00
Magnar Sveen c010afbbef Rename mc/mark-sgml-tags to mc/mark-sgml-tag-pair 2012-11-18 14:45:25 +01:00
Magnar Sveen f721308591 Tweak mc/mark-all-like-this-dwim and add tests 2012-11-18 14:43:39 +01:00
unknown 1074c88c99 Added mc/mark-all-like-this-dwim 2012-10-27 20:33:51 +02:00
Magnar Sveen a37e02b907 Add new mc-commands to default run-once list.
Fixes #36
2012-10-27 09:13:09 +02:00
Magnar Sveen fe211c018c Add word/symbol limiting mark-more functions:
- mc/mark-next-word-like-this
 - mc/mark-next-symbol-like-this
 - mc/mark-previous-word-like-this
 - mc/mark-previous-symbol-like-this
 - mc/mark-all-words-like-this
 - mc/mark-all-symbols-like-this

Fixes #24
2012-10-26 22:51:40 +02:00
Magnar Sveen 1afbb9317c Add mc/cycle-looping-behaviour to multiple-cursors custom group. 2012-10-26 22:15:12 +02:00
Magnar Sveen dce6c00fab Add mc/cursor-specific-vars to handle vars that need to be tracked per cursor.
- also add autopair-vars to this list.

Fixes #32
2012-10-25 10:57:58 +02:00
Magnar Sveen 5f7c92bb74 Add more backward-delete commands to run-for-all 2012-10-25 10:22:25 +02:00
Magnar Sveen 6b09b9c73f Add some more basic commands to the run-all and run-once lists. 2012-10-24 19:20:03 +02:00
Magnar Sveen b3ca408f52 Have to require 'cl for now, because of count-if. 2012-10-24 08:10:22 +02:00
Magnar Sveen 7382b462b2 Merge pull request #30 from gvol/master
Fixed mode-line not showing up
2012-10-20 15:27:38 -07:00
Ivan Andrus be4067da45 Fixed mode-line not showing up 2012-10-21 00:24:00 +02:00
Magnar Sveen 65d4f873fe Added Ivan Andrus to list of contributors 2012-10-21 00:54:04 +03:00
Magnar Sveen dce196ce9f Merge pull request #28 from gvol/master
Show number of cursors in mode-line
2012-10-20 14:49:04 -07:00
Ivan Andrus bb546b11d8 Display number of cursors in mode-line 2012-10-20 22:01:34 +02:00
Magnar Sveen 796fb640e1 Added segv to contributors list 2012-10-13 09:24:18 +03:00
Magnar Sveen c3b2d8483b Merge pull request #23 from segv/master
Improve mc/cycle and mc/mark-next/prev
2012-10-12 10:26:46 -07:00
Marco Baringer 2818d9e7ef Rename mc/(first|last)-cursor-(before|after)-point to mention that they operate on fake cursors 2012-10-12 17:07:55 +02:00
Marco Baringer 1ec78e195f Don't let mc/mark-lines create 'double' cursors.
Previously using mc/mark-lines in a fowards/backwards/forwards
combination would cause multiple cursors to be placed at the same
point of the same line. This is not useful behaviour.

Noted while implementing magnars suggestion: https://github.com/magnars/multiple-cursors.el/pull/23#commitcomment-1983183
2012-10-12 17:04:36 +02:00
Marco Baringer 038c9a7f03 Added stop as a possible value for mc/cycle-looping-behaviour.
Simply disables looping (no warning either).
2012-10-12 16:56:01 +02:00
Marco Baringer 19b1a83925 Refactor mc/first-cursor-after and mc/last-cursor-before to not use extreme.
Sometimes imperative code is more readable.
Suggested by magnars (https://github.com/magnars/multiple-cursors.el/pull/23#commitcomment-1983268)
2012-10-12 16:51:01 +02:00
Marco Baringer a8b632386d Remove superfluous lambda.
Caught by magnars (https://github.com/magnars/multiple-cursors.el/pull/23#commitcomment-1983191)
2012-10-12 16:27:39 +02:00
Marco Baringer e4adefc04e Fix issues with mc/cycle-(backward|forward) where the cycling was dependent on not having an active mark.
This patch also adds two utility functions mc/first-cursor-after and mc/last-cursor-before.
2012-10-10 13:39:28 +02:00
Marco Baringer 324d9354b5 Split macro mc/for-each-fake-cursor into a function returning all the cursor overlays and a macro to loop over this list. 2012-10-10 13:38:47 +02:00
Marco Baringer 80ebdbb35b Added test for mc/mark-(next|previous)-like-this when there is no active region. 2012-10-10 13:37:40 +02:00
Marco Baringer 9ac7675c78 Added tests for mc/cycle-forward and mc/cycle-backward with their new looping behaviour 2012-10-10 13:36:45 +02:00
Marco Baringer 3f20fc15a7 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).
2012-10-10 11:15:22 +02:00
Marco Baringer 876937bfa3 Use (interactive "P") instead of the weird (but equivalent) (interactive (list prefix-arg)) 2012-10-10 10:04:22 +02:00
Marco Baringer fcbb7a4df9 Make mc/cycle-forward and mc/cycle-backward loop around by default.
Instead of erroring if there is no next (respectively previous) cursor
mc/cycle-forward (respectively mc/cycle-backward) will just loop back
to the first (respectively last) cursor.
2012-10-10 09:24:19 +02:00
Magnar Sveen a0f771f3e4 Include interactive commands for deselecting prev/next
Fixes #21
2012-10-04 07:47:31 +02:00
Magnar Sveen 879ddb0e97 Add Takafumi Arakaki to list of contributors 2012-10-03 20:12:56 +03:00
Magnar Sveen 6e9ea1ae52 Merge pull request #20 from tkf/diff-friendly-save-lists
Diff friendly .mc-lists.el
2012-10-03 10:10:41 -07:00
Magnar Sveen 8a12e97b7d Mention region-bindings-mode in README 2012-10-03 20:06:15 +03:00
Takafumi Arakaki f4d5aea860 Sort before saving list in mc/save-lists 2012-10-03 18:50:29 +02:00
Takafumi Arakaki 00f905549e Add mc/dump-list to make mc/save-lists diff-friendly 2012-10-03 18:47:31 +02:00
Magnar Sveen 7a6eb0df90 Never execute keyboard macros for fake cursors.
- The real cursor will execute the keyboard macro, resulting in new
   commands in the command loop, and the fake cursors can pick up on
   those instead.

Fixes #18
2012-10-02 12:19:00 +02:00
Magnar Sveen 6d4979db46 Bump to 1.1.3 2012-09-28 07:26:17 +02:00
Magnar Sveen f040a33e3c Add execute-extended-command to run-once list 2012-09-28 07:24:38 +02:00
Magnar Sveen 64ffd81491 Add quoted-insert to run-for-all list. 2012-09-27 19:44:48 +02:00
Magnar Sveen 97da9778fd Intercept some reading commands
- so you won't have to answer them for every single cursor

Fixes #15
2012-09-27 19:42:38 +02:00
Magnar Sveen ae0033fe3d Protect post-command-hook from errors to avoids undead cursors 2012-09-27 18:53:57 +02:00
Magnar Sveen 5fcc69cc54 Skip keyboard macros
- since they will generate actual commands that are also run in the
   command loop - we'll handle those later instead.
2012-09-27 18:53:05 +02:00
21 changed files with 1328 additions and 212 deletions
+10 -2
View File
@@ -1,12 +1,20 @@
language: emacs-lisp language: emacs-lisp
before_install: before_install:
- if [ "$ECUKES_EMACS" = 'emacs-snapshot' ]; then - if [ "$EMACS" = 'emacs-snapshot' ]; then
sudo add-apt-repository -y ppa:cassou/emacs && sudo add-apt-repository -y ppa:cassou/emacs &&
sudo apt-get update -qq && sudo apt-get update -qq &&
sudo apt-get install -qq sudo apt-get install -qq
emacs-snapshot-el emacs-snapshot-gtk emacs-snapshot; emacs-snapshot-el emacs-snapshot-gtk emacs-snapshot;
fi fi
- if [ "$EMACS" = 'emacs24' ]; then
sudo add-apt-repository -y ppa:cassou/emacs &&
sudo apt-get update -qq &&
sudo apt-get install -qq
emacs24 emacs24-el emacs24-common-non-dfsg;
fi
env: env:
- ECUKES_EMACS=emacs - EMACS=emacs
- EMACS=emacs24
- EMACS=emacs-snapshot
script: script:
./run-travis-ci.sh ./run-travis-ci.sh
+60 -26
View File
@@ -35,43 +35,69 @@ insert a newline in multiple-cursors-mode, use `C-j`.
You can [watch an intro to multiple-cursors at Emacs Rocks](http://emacsrocks.com/e13.html). You can [watch an intro to multiple-cursors at Emacs Rocks](http://emacsrocks.com/e13.html).
## More commands to play around with ## Command overview
I've set up my key-bindings like so: ### Mark one more occurrence
;; From active region to multiple cursors: - `mc/mark-next-like-this`: Adds a cursor and region at the next part of the buffer forwards that matches the current region.
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines) - `mc/mark-next-word-like-this`: Like `mc/mark-next-like-this` but only for whole words.
(global-set-key (kbd "C-S-c C-e") 'mc/edit-ends-of-lines) - `mc/mark-next-symbol-like-this`: Like `mc/mark-next-like-this` but only for whole symbols.
(global-set-key (kbd "C-S-c C-a") 'mc/edit-beginnings-of-lines) - `mc/mark-previous-like-this`: Adds a cursor and region at the next part of the buffer backwards that matches the current region.
- `mc/mark-previous-word-like-this`: Like `mc/mark-previous-like-this` but only for whole words.
- `mc/mark-previous-symbol-like-this`: Like `mc/mark-previous-like-this` but only for whole symbols.
- `mc/mark-more-like-this-extended`: Use arrow keys to quickly mark/skip next/previous occurances.
When you have an active region that spans multiple lines, the preceeding three ### Mark many occurrences
commands will add one cursor to each line.
;; Rectangular region mode - `mc/edit-lines`: Adds one cursor to each line in the current region.
(global-set-key (kbd "H-SPC") 'set-rectangular-region-anchor) - `mc/edit-beginnings-of-lines`: Adds a cursor at the start of each line in the current region.
- `mc/edit-ends-of-lines`: Adds a cursor at the end of each line in the current region.
- `mc/mark-all-like-this`: Marks all parts of the buffer that matches the current region.
- `mc/mark-all-words-like-this`: Like `mc/mark-all-like-this` but only for whole words.
- `mc/mark-all-symbols-like-this`: Like `mc/mark-all-like-this` but only for whole symbols.
- `mc/mark-all-in-region`: Prompts for a string to match in the region, adding cursors to all of them.
- `mc/mark-all-like-this-in-defun`: Marks all parts of the current defun that matches the current region.
- `mc/mark-all-words-like-this-in-defun`: Like `mc/mark-all-like-this-in-defun` but only for whole words.
- `mc/mark-all-symbols-like-this-in-defun`: Like `mc/mark-all-like-this-in-defun` but only for whole symbols.
- `mc/mark-all-like-this-dwim`: Tries to be smart about marking everything you want. Can be pressed multiple times.
Think of this one as `set-mark` except you're marking a rectangular region. It is ### Special
an exceedingly quick way of adding multiple cursors to multiple lines.
;; Mark more like this - `set-rectangular-region-anchor`: Think of this one as `set-mark` except you're marking a rectangular region.
(global-set-key (kbd "M-æ") 'mc/mark-all-like-this) - `mc/mark-sgml-tag-pair`: Mark the current opening and closing tag.
(global-set-key (kbd "C-å") 'mc/mark-previous-like-this) - `mc/insert-numbers`: Insert increasing numbers for each cursor, top to bottom.
(global-set-key (kbd "C-æ") 'mc/mark-next-like-this) - `mc/sort-regions`: Sort the marked regions alphabetically.
(global-set-key (kbd "C-Æ") 'mc/mark-more-like-this-extended) - `mc/reverse-regions`: Reverse the order of the marked regions.
(global-set-key (kbd "M-å") 'mc/mark-all-in-region)
Okay, yes, I have a crazy norwegian keyboard. Regardless, these will look at ## Tips and tricks
whatever you've got selected at the moment, and mark more places like that in
the buffer. - To get out of multiple-cursors-mode, press `<return>` or `C-g`. The latter will
first disable multiple regions before disabling multiple cursors. If you want to
insert a newline in multiple-cursors-mode, use `C-j`.
- Sometimes you end up with cursors outside of your view. You can
scroll the screen to center on each cursor with `C-v` and `M-v`.
- Try pressing `mc/mark-next-like-this` with no region selected. It
will just add a cursor on the next line.
- Try pressing `mc/mark-all-like-this-dwim` on a tagname in html-mode.
- Notice that the number of cursors active can be seen in the modeline.
- If you get out of multiple-cursors-mode and yank - it will yank only
from the kill-ring of main cursor. To yank from the kill-rings of
every cursor use yank-rectangle, normally found at C-x r y.
- You can use `mc/reverse-regions` with nothing selected and just one cursor.
It will then flip the sexp at point and the one below it.
- If you would like to keep the global bindings clean, and get custom keybindings
when the region is active, you can try [region-bindings-mode](https://github.com/fgallina/region-bindings-mode).
BTW, I highly recommend adding `mc/mark-next-like-this` to a key binding that's BTW, I highly recommend adding `mc/mark-next-like-this` to a key binding that's
right next to the key for `er/expand-region`. right next to the key for `er/expand-region`.
## Scrolling
Sometimes you end up with cursors outside of your view. You can scroll the
screen to center on each cursor with `C-v` and `M-v`.
## Unknown commands ## Unknown commands
Multiple-cursors uses two lists of commands to know what to do: the run-once list Multiple-cursors uses two lists of commands to know what to do: the run-once list
@@ -113,6 +139,14 @@ Run the tests with:
$ ./util/ecukes/ecukes --graphical $ ./util/ecukes/ecukes --graphical
## Contributors
* [Takafumi Arakaki](https://github.com/tkf) made .mc-lists.el diff friendly
* [Marco Baringer](https://github.com/segv) contributed looping to mc/cycle and adding cursors without region for mark-more.
* [Ivan Andrus](https://github.com/gvol) added showing number of cursors in mode-line
* [Fuco](https://github.com/Fuco1) added the first version of `mc/mark-all-like-this-dwim`
Thanks!
## License ## License
+13
View File
@@ -42,3 +42,16 @@ Feature: Switching from a multiline region to multiple cursors
And I go to the front of the word "long" And I go to the front of the word "long"
And I press "C-S-c C-S-c" And I press "C-S-c C-S-c"
Then I should have 2 cursors Then I should have 2 cursors
Scenario: Edit without using transient mark mode
Given I turn off transient-mark-mode
And I insert:
"""
hello
there
"""
And I go to the front of the word "hello"
And I set the mark
And I go to the front of the word "there"
And I press "C-S-c C-S-c"
Then I should have 2 cursors
+13
View File
@@ -0,0 +1,13 @@
Feature: Insert increasing numbers
Scenario: Three cursors, 0-1-2
Given I have cursors at "text" in "This text contains the word text thrice (text)"
When I press "H-0"
And I press "SPC"
Then I should see "This 0 text contains the word 1 text thrice (2 text)"
Scenario: Three cursors, 9-10-11
Given I have cursors at "text" in "This text contains the word text thrice (text)"
When I press "C-9 H-0"
And I press "SPC"
Then I should see "This 9 text contains the word 10 text thrice (11 text)"
+94
View File
@@ -0,0 +1,94 @@
Feature: Mark all do-what-I-mean (html)
Background:
Given I turn on html-mode
And I turn on delete-selection-mode
And I insert:
"""
<body>
<div class="abc"> def </div>
<div class="ghi"> jkl </div>
</body>
"""
Scenario: Marks tags in html-mode, from front
When I go to the front of the word "abc"
And I press "M-b"
And I press "M-b"
And I press "M-$"
And I type "h1"
Then I should see:
"""
<body>
<h1 class="abc"> def </h1>
<div class="ghi"> jkl </div>
</body>
"""
Scenario: Marks tags in html-mode, from back
When I go to the end of the word "jkl"
And I press "M-f"
And I press "M-$"
And I type "h1"
Then I should see:
"""
<body>
<div class="abc"> def </div>
<h1 class="ghi"> jkl </h1>
</body>
"""
Scenario: Marks tags in html-mode, from outside front
When I go to the front of the word "abc"
And I press "M-b"
And I press "M-b"
And I press "C-b"
And I press "M-$"
And I type "h1"
Then I should see:
"""
<body>
<h1 class="abc"> def </h1>
<div class="ghi"> jkl </div>
</body>
"""
Scenario: Marks tags in html-mode, from outside back
When I go to the end of the word "jkl"
And I press "M-f"
And I press "C-f"
And I press "M-$"
And I type "h1"
Then I should see:
"""
<body>
<div class="abc"> def </div>
<h1 class="ghi"> jkl </h1>
</body>
"""
Scenario: Marks words in html-mode
When I go to the front of the word "abc"
And I press "M-$"
And I type "def"
Then I should see:
"""
<body>
<div class="def"> def </div>
<div class="ghi"> jkl </div>
</body>
"""
Scenario: Marks words in html-mode
When I go to the front of the word "abc"
And I press "M-$"
And I type "def"
And I press "M-$"
And I type "hah"
Then I should see:
"""
<body>
<div class="hah"> hah </div>
<div class="ghi"> jkl </div>
</body>
"""
+38
View File
@@ -0,0 +1,38 @@
Feature: Mark all do-what-I-mean
Scenario: Mark symbols in defun
Given I turn on emacs-lisp-mode
And I turn on delete-selection-mode
And I insert:
"""
(defun abc (ghi) (message ghi))
(defun def (ghi) (message some-other-ghi))
"""
When I go to the end of the word "abc"
And I press "M-f"
And I press "M-$"
And I type "hmm"
Then I should see:
"""
(defun abc (hmm) (message hmm))
(defun def (ghi) (message some-other-ghi))
"""
Scenario: Mark all symbols by pressing twice
Given I turn on emacs-lisp-mode
And I turn on delete-selection-mode
And I insert:
"""
(defun abc (ghi) (message ghi))
(defun def (ghi) (message ghi))
"""
When I go to the end of the word "abc"
And I press "M-f"
And I press "M-$"
And I press "M-$"
And I type "hmm"
Then I should see:
"""
(defun abc (hmm) (message hmm))
(defun def (hmm) (message hmm))
"""
+48
View File
@@ -94,3 +94,51 @@ Feature: Marking multiple parts of the buffer
And I type "more" And I type "more"
Then I should have 2 cursors Then I should have 2 cursors
And I should see "Here's more, more and text" And I should see "Here's more, more and text"
Scenario: Marking without an active region
When I insert:
"""
aaa
bbb
ccc
"""
And I go to the front of the word "bbb"
And I press "C->"
And I type "_"
Then I should have 2 cursors
And I should see:
"""
aaa
_bbb
_ccc
"""
Scenario: Increasing number of cursors without an active region
When I insert:
"""
aaa
bbb
ccc
"""
And I go to the front of the word "bbb"
And I press "C->"
And I press "C-<"
And i press "C-f"
And I type "_"
Then I should have 3 cursors
And I should see:
"""
a_aa
b_bb
c_cc
"""
Scenario: Multiple cursor with shift selection
When I insert "This text contains the word text twice"
And I go to the front of the word "text"
And I press "M-S-f"
And I press "C->"
And I press "C-f"
And I press "<deletechar>"
Then I should see "This text ontains the word text wice"
+31
View File
@@ -119,6 +119,23 @@ Feature: Multiple cursors core
And I type "!" And I type "!"
Then I should see "This ! contains the word ! twice" Then I should see "This ! contains the word ! twice"
Scenario: wrap-region (function turns to keyboard macros)
Given I turn on wrap-region-mode
And I insert "This text contains the word text twice"
And I go to the front of the word "text"
And I press "C-M-SPC"
And I press "C->"
And I press "C-g"
And I type "("
Then I should see "This (text contains the word (text twice"
Scenario: Bound keyboard macros
Given I have bound C-! to a keyboard macro that insert "_"
And I have cursors at "text" in "This text contains the word text twice"
When I press "C-!"
When I press "C-!"
Then I should see "This __text contains the word __text twice"
Scenario: Interprogram paste Scenario: Interprogram paste
Given I have cursors at "text" in "This text contains the word text twice" Given I have cursors at "text" in "This text contains the word text twice"
When I copy "external" in another program When I copy "external" in another program
@@ -141,3 +158,17 @@ Feature: Multiple cursors core
contains contains
twice twice
""" """
Scenario: Looping forwards around cursors
Given I have cursors at "_" in "1_34567_9"
And I press "C-v"
And I press "C-v"
And I press "C-v"
Then the cursor should be at point "8"
Scenario: Looping backwards around cursors
Given I have cursors at "_" in "1_34567_9"
And I press "M-v"
And I press "M-v"
Then the cursor should be at point "2"
+19
View File
@@ -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)"
@@ -68,6 +68,11 @@
(defun mc-test-temp-command-2 () (interactive) (insert ins)) (defun mc-test-temp-command-2 () (interactive) (insert ins))
(global-set-key (kbd "C-!") 'mc-test-temp-command-2)))) (global-set-key (kbd "C-!") 'mc-test-temp-command-2))))
(Given "^I have bound C-! to a keyboard macro that insert \"_\"$"
(lambda ()
(fset 'mc-test-temp-kmacro "\C-q_")
(global-set-key (kbd "C-!") 'mc-test-temp-kmacro)))
(When "^I go to character \"\\(.+\\)\"$" (When "^I go to character \"\\(.+\\)\"$"
(lambda (char) (lambda (char)
(goto-char (point-min)) (goto-char (point-min))
+7
View File
@@ -7,10 +7,12 @@
(add-to-list 'load-path multiple-cursors-root-path) (add-to-list 'load-path multiple-cursors-root-path)
(add-to-list 'load-path multiple-cursors-util-path) (add-to-list 'load-path multiple-cursors-util-path)
(add-to-list 'load-path (expand-file-name "espuds" multiple-cursors-util-path)) (add-to-list 'load-path (expand-file-name "espuds" multiple-cursors-util-path))
(add-to-list 'load-path (expand-file-name "vendor" multiple-cursors-util-path))
(require 'multiple-cursors) (require 'multiple-cursors)
(require 'espuds) (require 'espuds)
(require 'ert) (require 'ert)
(require 'wrap-region)
(defun mc/save-lists ()) ;; redefine to do nothing when running tests (defun mc/save-lists ()) ;; redefine to do nothing when running tests
@@ -21,7 +23,11 @@
(global-set-key (kbd "C->") 'mc/mark-next-like-this) (global-set-key (kbd "C->") 'mc/mark-next-like-this)
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this) (global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
(global-set-key (kbd "M-!") 'mc/mark-all-like-this) (global-set-key (kbd "M-!") 'mc/mark-all-like-this)
(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 "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 "C-S-c C-S-c") 'mc/edit-lines)
(global-set-key (kbd "H-SPC") 'set-rectangular-region-anchor) (global-set-key (kbd "H-SPC") 'set-rectangular-region-anchor)
(switch-to-buffer (switch-to-buffer
@@ -31,6 +37,7 @@
(cua-mode 0) (cua-mode 0)
(delete-selection-mode 0) (delete-selection-mode 0)
(subword-mode 0) (subword-mode 0)
(wrap-region-mode 0)
(setq set-mark-default-inactive nil) (setq set-mark-default-inactive nil)
(deactivate-mark)) (deactivate-mark))
+56 -14
View File
@@ -30,7 +30,7 @@
(eval-when-compile (require 'cl)) (eval-when-compile (require 'cl))
(defun mc/next-cursor-after-point () (defun mc/next-fake-cursor-after-point ()
(let ((pos (point)) (let ((pos (point))
(next-pos (point-max)) (next-pos (point-max))
next) next)
@@ -42,7 +42,7 @@
(setq next cursor)))) (setq next cursor))))
next)) next))
(defun mc/prev-cursor-before-point () (defun mc/prev-fake-cursor-before-point ()
(let ((pos (point)) (let ((pos (point))
(prev-pos (point-min)) (prev-pos (point-min))
prev) prev)
@@ -54,27 +54,69 @@
(setq prev cursor)))) (setq prev cursor))))
prev)) prev))
(defun mc/cycle-forward () (defcustom mc/cycle-looping-behaviour 'continue
(interactive) "What to do if asked to cycle beyond the last cursor or before the first cursor."
(let ((next-cursor (mc/next-cursor-after-point))) :type '(radio (const :tag "Loop around to beginning/end of document." continue)
(unless next-cursor (const :tag "Warn and then loop around." warn)
(error "We're already at the last cursor")) (const :tag "Signal an error." error)
(const :tag "Don't loop." stop))
:group 'multiple-cursors)
(defun mc/handle-loop-condition (error-message)
(ecase mc/cycle-looping-behaviour
(error (error error-message))
(warn (message error-message))
(continue 'continue)
(stop 'stop)))
(defun mc/first-fake-cursor-after (point)
"Very similar to mc/furthest-cursor-before-point, but ignores (mark) and (point)."
(let* ((cursors (mc/all-fake-cursors))
(cursors-after-point (remove-if (lambda (cursor)
(< (mc/cursor-beg cursor) point))
cursors))
(cursors-in-order (sort* cursors-after-point '< :key 'mc/cursor-beg)))
(first cursors-in-order)))
(defun mc/last-fake-cursor-before (point)
"Very similar to mc/furthest-cursor-before-point, but ignores (mark) and (point)."
(let* ((cursors (mc/all-fake-cursors))
(cursors-before-point (remove-if (lambda (cursor)
(> (mc/cursor-end cursor) point))
cursors))
(cursors-in-order (sort* cursors-before-point '> :key 'mc/cursor-end)))
(first cursors-in-order)))
(defun* mc/cycle (next-cursor fallback-cursor loop-message)
(when (null next-cursor)
(when (eql 'stop (mc/handle-loop-condition loop-message))
(return-from mc/cycle nil))
(setf next-cursor fallback-cursor))
(mc/create-fake-cursor-at-point) (mc/create-fake-cursor-at-point)
(mc/pop-state-from-overlay next-cursor) (mc/pop-state-from-overlay next-cursor)
(recenter))) (recenter))
(defun mc/cycle-forward ()
(interactive)
(mc/cycle (mc/next-fake-cursor-after-point)
(mc/first-fake-cursor-after (point-min))
"We're already at the last cursor."))
(defun mc/cycle-backward () (defun mc/cycle-backward ()
(interactive) (interactive)
(let ((prev-cursor (mc/prev-cursor-before-point))) (mc/cycle (mc/prev-fake-cursor-before-point)
(unless prev-cursor (mc/last-fake-cursor-before (point-max))
(error "We're already at the first cursor")) "We're already at the last cursor"))
(mc/create-fake-cursor-at-point)
(mc/pop-state-from-overlay prev-cursor)
(recenter)))
(define-key mc/keymap (kbd "C-v") 'mc/cycle-forward) (define-key mc/keymap (kbd "C-v") 'mc/cycle-forward)
(define-key mc/keymap (kbd "M-v") 'mc/cycle-backward) (define-key mc/keymap (kbd "M-v") 'mc/cycle-backward)
(provide 'mc-cycle-cursors) (provide 'mc-cycle-cursors)
;; Local Variables:
;; coding: utf-8
;; byte-compile-warnings: (not cl-functions)
;; End:
;;; mc-cycle-cursors.el ends here ;;; mc-cycle-cursors.el ends here
+3 -5
View File
@@ -35,7 +35,7 @@
Starts from mark and moves in straight down or up towards the Starts from mark and moves in straight down or up towards the
line point is on." line point is on."
(interactive) (interactive)
(when (not (use-region-p)) (when (not (and mark-active (/= (point) (mark))))
(error "Mark a set of lines first.")) (error "Mark a set of lines first."))
(mc/remove-fake-cursors) (mc/remove-fake-cursors)
(let* ((col (current-column)) (let* ((col (current-column))
@@ -57,16 +57,14 @@ line point is on."
"Add one cursor to the end of each line in the active region." "Add one cursor to the end of each line in the active region."
(interactive) (interactive)
(mc/edit-lines) (mc/edit-lines)
(mc/execute-command-for-all-fake-cursors 'end-of-line) (mc/execute-command-for-all-cursors 'end-of-line))
(end-of-line))
;;;###autoload ;;;###autoload
(defun mc/edit-beginnings-of-lines () (defun mc/edit-beginnings-of-lines ()
"Add one cursor to the beginning of each line in the active region." "Add one cursor to the beginning of each line in the active region."
(interactive) (interactive)
(mc/edit-lines) (mc/edit-lines)
(mc/execute-command-for-all-fake-cursors 'beginning-of-line) (mc/execute-command-for-all-cursors 'beginning-of-line))
(beginning-of-line))
(provide 'mc-edit-lines) (provide 'mc-edit-lines)
+244 -45
View File
@@ -28,6 +28,7 @@
;;; Code: ;;; Code:
(require 'multiple-cursors-core) (require 'multiple-cursors-core)
(require 'thingatpt)
(defun mc/cursor-end (cursor) (defun mc/cursor-end (cursor)
(if (overlay-get cursor 'mark-active) (if (overlay-get cursor 'mark-active)
@@ -79,34 +80,69 @@
(mc/cursor-end cursor)))) (mc/cursor-end cursor))))
strings)) strings))
(defvar mc/enclose-search-term nil
"How should mc/mark-more-* search for more matches?
Match everything: nil
Match only whole words: 'words
Match only whole symbols: 'symbols
Use like case-fold-search, don't recommend setting it globally.")
(defun mc/mark-more-like-this (skip-last direction)
(let ((case-fold-search nil)
(re (regexp-opt (mc/region-strings) mc/enclose-search-term))
(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))) ;;;###autoload
(furthest-cursor (mc/furthest-cursor-after-point))) (defun mc/mark-next-word-like-this (arg)
(mc/save-excursion (interactive "p")
(goto-char (mc/furthest-region-end)) (let ((mc/enclose-search-term 'words))
(when (= arg 0) (mc/mark-next-like-this arg)))
(mc/remove-fake-cursor furthest-cursor))
(if (search-forward-regexp re nil t) ;;;###autoload
(progn (defun mc/mark-next-symbol-like-this (arg)
(push-mark (match-beginning 0)) (interactive "p")
(when point-first (exchange-point-and-mark)) (let ((mc/enclose-search-term 'symbols))
(mc/create-fake-cursor-at-point)) (mc/mark-next-like-this arg)))
(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 +150,57 @@ 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))) ;;;###autoload
(furthest-cursor (mc/furthest-cursor-before-point))) (defun mc/mark-previous-word-like-this (arg)
(mc/save-excursion (interactive "p")
(goto-char (mc/first-region-start)) (let ((mc/enclose-search-term 'words))
(when (= arg 0) (mc/mark-previous-like-this arg)))
(mc/remove-fake-cursor furthest-cursor))
(if (search-backward-regexp re nil t) ;;;###autoload
(progn (defun mc/mark-previous-symbol-like-this (arg)
(push-mark (match-end 0)) (interactive "p")
(unless point-first (exchange-point-and-mark)) (let ((mc/enclose-search-term 'symbols))
(mc/create-fake-cursor-at-point)) (mc/mark-previous-like-this arg)))
(error "no more found backward")))))
(if (> (mc/num-cursors) 1) (defun mc/mark-lines (num-lines direction)
(multiple-cursors-mode 1) (dotimes (i num-lines)
(multiple-cursors-mode 0))) (mc/create-fake-cursor-at-point)
(ecase direction
(forwards (loop do (next-line 1 nil)
while (mc/all-fake-cursors (point) (1+ (point)))))
(backwards (loop do (previous-line 1 nil)
while (mc/all-fake-cursors (point) (1+ (point))))))))
;;;###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)
"Deselect next part of the buffer matching the currently active region."
(interactive)
(mc/mark-next-like-this -1))
;;;###autoload
(defun mc/unmark-previous-like-this (arg)
"Deselect prev part of the buffer matching the currently active region."
(interactive)
(mc/mark-previous-like-this -1))
;;;###autoload ;;;###autoload
(defun mc/mark-all-like-this () (defun mc/mark-all-like-this ()
@@ -147,7 +212,7 @@ With zero ARG, skip the last one and mark next."
(let ((master (point)) (let ((master (point))
(case-fold-search nil) (case-fold-search nil)
(point-first (< (point) (mark))) (point-first (< (point) (mark)))
(re (regexp-opt (mc/region-strings)))) (re (regexp-opt (mc/region-strings) mc/enclose-search-term)))
(mc/save-excursion (mc/save-excursion
(goto-char 0) (goto-char 0)
(while (search-forward-regexp re nil t) (while (search-forward-regexp re nil t)
@@ -160,6 +225,18 @@ With zero ARG, skip the last one and mark next."
(multiple-cursors-mode 1) (multiple-cursors-mode 1)
(multiple-cursors-mode 0))) (multiple-cursors-mode 0)))
;;;###autoload
(defun mc/mark-all-words-like-this ()
(interactive)
(let ((mc/enclose-search-term 'words))
(mc/mark-all-like-this)))
;;;###autoload
(defun mc/mark-all-symbols-like-this ()
(interactive)
(let ((mc/enclose-search-term 'symbols))
(mc/mark-all-like-this)))
;;;###autoload ;;;###autoload
(defun mc/mark-all-in-region (beg end) (defun mc/mark-all-in-region (beg end)
"Find and mark all the parts in the region matching the given search" "Find and mark all the parts in the region matching the given search"
@@ -226,6 +303,128 @@ is one of the above."
(setq ev (read-event "Use arrow keys for more marks: ")))) (setq ev (read-event "Use arrow keys for more marks: "))))
(push ev unread-command-events))) (push ev unread-command-events)))
(defvar mc--restrict-mark-all-to-symbols nil)
;;;###autoload
(defun mc/mark-all-like-this-dwim (arg)
"Tries to guess what you want to mark all of.
Can be pressed multiple times to increase selection.
With prefix, it behaves the same as original `mc/mark-all-like-this'"
(interactive "P")
(if arg
(mc/mark-all-like-this)
(if (and (mc--no-region-and-in-sgmlish-mode)
(mc--on-tag-name-p))
(mc/mark-sgml-tag-pair)
(let ((before (mc/num-cursors)))
(unless (eq last-command 'mc/mark-all-like-this-dwim)
(setq mc--restrict-mark-all-to-symbols nil))
(unless (use-region-p)
(mc--mark-symbol-at-point)
(setq mc--restrict-mark-all-to-symbols t))
(if mc--restrict-mark-all-to-symbols
(mc/mark-all-symbols-like-this-in-defun)
(mc/mark-all-like-this-in-defun))
(when (<= (mc/num-cursors) before)
(if mc--restrict-mark-all-to-symbols
(mc/mark-all-symbols-like-this)
(mc/mark-all-like-this)))
(when (<= (mc/num-cursors) before)
(mc/mark-all-like-this))))))
(defun mc--no-region-and-in-sgmlish-mode ()
(and (not (use-region-p))
(derived-mode-p 'sgml-mode)))
(defun mc--in-defun ()
(bounds-of-thing-at-point 'defun))
;;;###autoload
(defun mc/mark-all-like-this-in-defun ()
"Mark all like this in defun."
(interactive)
(if (mc--in-defun)
(save-restriction
(widen)
(narrow-to-defun)
(mc/mark-all-like-this))
(mc/mark-all-like-this)))
;;;###autoload
(defun mc/mark-all-words-like-this-in-defun ()
"Mark all words like this in defun."
(interactive)
(if (mc--in-defun)
(save-restriction
(widen)
(narrow-to-defun)
(mc/mark-all-words-like-this))
(mc/mark-all-words-like-this)))
;;;###autoload
(defun mc/mark-all-symbols-like-this-in-defun ()
"Mark all symbols like this in defun."
(interactive)
(if (mc--in-defun)
(save-restriction
(widen)
(narrow-to-defun)
(mc/mark-all-symbols-like-this))
(mc/mark-all-symbols-like-this)))
(defun mc--mark-symbol-at-point ()
"Select the symbol under cursor"
(interactive)
(when (not (use-region-p))
(let ((b (bounds-of-thing-at-point 'symbol)))
(goto-char (car b))
(set-mark (cdr b)))))
(defun mc--get-nice-sgml-context ()
(car
(last
(progn
(when (looking-at "<") (forward-char 1))
(when (looking-back ">") (forward-char -1))
(sgml-get-context)))))
(defun mc--on-tag-name-p ()
(let* ((context (save-excursion (mc--get-nice-sgml-context)))
(tag-name-len (length (aref context 4)))
(beg (aref context 2))
(end (+ beg tag-name-len (if (eq 'open (aref context 1)) 1 3))))
(and context
(>= (point) beg)
(<= (point) end))))
;;;###autoload
(defun mc/mark-sgml-tag-pair ()
"Mark the tag we're in and its pair for renaming."
(interactive)
(when (not (mc--inside-tag-p))
(error "Place point inside tag to rename."))
(let ((context (mc--get-nice-sgml-context)))
(if (looking-at "</")
(setq context (car (last (sgml-get-context)))))
(goto-char (aref context 2))
(let* ((tag-name (aref context 4))
(num-chars (length tag-name))
(master-start (1+ (point)))
(mirror-end (save-excursion
(sgml-skip-tag-forward 1)
(1- (point)))))
(goto-char (- mirror-end num-chars))
(set-mark mirror-end)
(mc/create-fake-cursor-at-point)
(goto-char master-start)
(set-mark (+ (point) num-chars))))
(mc/maybe-multiple-cursors-mode))
(defun mc--inside-tag-p ()
(save-excursion
(not (null (sgml-get-context)))))
(provide 'mc-mark-more) (provide 'mc-mark-more)
;;; mc-mark-more.el ends here ;;; mc-mark-more.el ends here
+90
View File
@@ -0,0 +1,90 @@
;;; 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
(setq strings (cons (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))
(save-excursion (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 multiple-cursors-mode)
(progn
(mc/mark-next-lines 1)
(mc/reverse-regions)
(multiple-cursors-mode 0))
(unless (use-region-p)
(mc/execute-command-for-all-cursors 'mark-sexp))
(setq mc--strings-to-replace (nreverse (mc--ordered-region-strings)))
(mc--replace-region-strings)))
;;;###autoload
(defun mc/sort-regions ()
(interactive)
(unless (use-region-p)
(mc/execute-command-for-all-cursors 'mark-sexp))
(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
+151 -36
View File
@@ -25,7 +25,7 @@
;;; Code: ;;; Code:
(eval-when-compile (require 'cl)) (require 'cl)
(require 'rect) (require 'rect)
@@ -49,12 +49,15 @@
(setq buffer-undo-list ;; otherwise add a function to activate this cursor (setq buffer-undo-list ;; otherwise add a function to activate this cursor
(cons (cons 'apply (cons 'activate-cursor-for-undo (list id))) buffer-undo-list))))) (cons (cons 'apply (cons 'activate-cursor-for-undo (list id))) buffer-undo-list)))))
(defun mc/all-fake-cursors (&optional start end)
(remove-if-not 'mc/fake-cursor-p
(overlays-in (or start (point-min))
(or end (point-max)))))
(defmacro mc/for-each-fake-cursor (&rest forms) (defmacro mc/for-each-fake-cursor (&rest forms)
"Runs the body for each fake cursor, bound to the name cursor" "Runs the body for each fake cursor, bound to the name cursor"
`(mapc #'(lambda (cursor) `(mapc #'(lambda (cursor) ,@forms)
(when (mc/fake-cursor-p cursor) (mc/all-fake-cursors)))
,@forms))
(overlays-in (point-min) (point-max))))
(defmacro mc/save-excursion (&rest forms) (defmacro mc/save-excursion (&rest forms)
"Saves and restores all the state that multiple-cursors cares about." "Saves and restores all the state that multiple-cursors cares about."
@@ -69,12 +72,12 @@
(defmacro mc/for-each-cursor-ordered (&rest forms) (defmacro mc/for-each-cursor-ordered (&rest forms)
"Runs the body for each cursor, fake and real, bound to the name cursor" "Runs the body for each cursor, fake and real, bound to the name cursor"
`(let ((real-cursor (mc/create-fake-cursor-at-point))) `(let ((real-cursor-id (overlay-get (mc/create-fake-cursor-at-point) 'mc-id)))
(mapc #'(lambda (cursor) (mapc #'(lambda (cursor)
(when (mc/fake-cursor-p cursor) (when (mc/fake-cursor-p cursor)
,@forms)) ,@forms))
(sort (overlays-in (point-min) (point-max)) 'mc--compare-by-overlay-start)) (sort (overlays-in (point-min) (point-max)) 'mc--compare-by-overlay-start))
(mc/pop-state-from-overlay real-cursor))) (mc/pop-state-from-overlay (mc/cursor-with-id real-cursor-id))))
(defmacro mc/save-window-scroll (&rest forms) (defmacro mc/save-window-scroll (&rest forms)
"Saves and restores the window scroll position" "Saves and restores the window scroll position"
@@ -115,6 +118,12 @@ highlights the entire width of the window."
(overlay-put overlay 'type 'additional-region) (overlay-put overlay 'type 'additional-region)
overlay)) overlay))
(defvar mc/cursor-specific-vars '(autopair-action
autopair-wrap-action
transient-mark-mode
er/history)
"A list of vars that need to be tracked on a per-cursor basis.")
(defun mc/store-current-state-in-overlay (o) (defun mc/store-current-state-in-overlay (o)
"Store relevant info about point and mark in the given overlay." "Store relevant info about point and mark in the given overlay."
(overlay-put o 'point (set-marker (make-marker) (point))) (overlay-put o 'point (set-marker (make-marker) (point)))
@@ -125,7 +134,8 @@ highlights the entire width of the window."
(overlay-put o 'mark-active mark-active) (overlay-put o 'mark-active mark-active)
(overlay-put o 'yank-undo-function yank-undo-function) (overlay-put o 'yank-undo-function yank-undo-function)
(overlay-put o 'kill-ring-yank-pointer kill-ring-yank-pointer) (overlay-put o 'kill-ring-yank-pointer kill-ring-yank-pointer)
(when (boundp 'er/history) (overlay-put o 'er/history er/history)) (dolist (var mc/cursor-specific-vars)
(when (boundp var) (overlay-put o var (symbol-value var))))
o) o)
(defun mc/restore-state-from-overlay (o) (defun mc/restore-state-from-overlay (o)
@@ -138,7 +148,8 @@ highlights the entire width of the window."
(setq mark-active (overlay-get o 'mark-active)) (setq mark-active (overlay-get o 'mark-active))
(setq yank-undo-function (overlay-get o 'yank-undo-function)) (setq yank-undo-function (overlay-get o 'yank-undo-function))
(setq kill-ring-yank-pointer (overlay-get o 'kill-ring-yank-pointer)) (setq kill-ring-yank-pointer (overlay-get o 'kill-ring-yank-pointer))
(when (boundp 'er/history) (setq er/history (overlay-get o 'er/history)))) (dolist (var mc/cursor-specific-vars)
(when (boundp var) (set var (overlay-get o var)))))
(defun mc/remove-fake-cursor (o) (defun mc/remove-fake-cursor (o)
"Delete overlay with state, including dependent overlays and markers." "Delete overlay with state, including dependent overlays and markers."
@@ -183,10 +194,22 @@ Saves the current state in the overlay to be restored later."
(run-hooks 'pre-command-hook) (run-hooks 'pre-command-hook)
(unless (eq this-command 'ignore) (unless (eq this-command 'ignore)
(call-interactively cmd)) (call-interactively cmd))
(run-hooks 'post-command-hook)
(when deactivate-mark (deactivate-mark))) (when deactivate-mark (deactivate-mark)))
(defvar mc--executing-command-for-fake-cursor nil) (defvar mc--executing-command-for-fake-cursor nil)
(defun mc/execute-command-for-fake-cursor (cmd cursor)
(let ((mc--executing-command-for-fake-cursor t)
(id (overlay-get cursor 'mc-id))
(annoying-arrows-mode nil)
(smooth-scroll-margin 0))
(mc/add-fake-cursor-to-undo-list
(mc/pop-state-from-overlay cursor)
(ignore-errors
(mc/execute-command cmd)
(mc/create-fake-cursor-at-point id)))))
(defun mc/execute-command-for-all-fake-cursors (cmd) (defun mc/execute-command-for-all-fake-cursors (cmd)
"Calls CMD interactively for each cursor. "Calls CMD interactively for each cursor.
It works by moving point to the fake cursor, setting It works by moving point to the fake cursor, setting
@@ -197,15 +220,36 @@ cursor with updated info."
(mc/save-window-scroll (mc/save-window-scroll
(mc/for-each-fake-cursor (mc/for-each-fake-cursor
(save-excursion (save-excursion
(let ((mc--executing-command-for-fake-cursor t) (mc/execute-command-for-fake-cursor cmd cursor)))))
(id (overlay-get cursor 'mc-id)) (mc--reset-read-prompts))
(annoying-arrows-mode nil)
(smooth-scroll-margin 0)) (defun mc/execute-command-for-all-cursors (cmd)
(mc/add-fake-cursor-to-undo-list "Calls CMD interactively for the real cursor and all fakes."
(mc/pop-state-from-overlay cursor) (call-interactively cmd)
(ignore-errors (mc/execute-command-for-all-fake-cursors cmd))
(mc/execute-command cmd)
(mc/create-fake-cursor-at-point id))))))))) ;; Intercept some reading commands so you won't have to
;; answer them for every single cursor
(defadvice read-char (around mc-support activate)
(if (not multiple-cursors-mode)
ad-do-it
(unless mc--read-char
(setq mc--read-char ad-do-it))
(setq ad-return-value mc--read-char)))
(defadvice read-quoted-char (around mc-support activate)
(if (not multiple-cursors-mode)
ad-do-it
(unless mc--read-quoted-char
(setq mc--read-quoted-char ad-do-it))
(setq ad-return-value mc--read-quoted-char)))
(defun mc--reset-read-prompts ()
(setq mc--read-char nil)
(setq mc--read-quoted-char nil))
(mc--reset-read-prompts)
(defun mc/fake-cursor-p (o) (defun mc/fake-cursor-p (o)
"Predicate to check if an overlay is a fake cursor" "Predicate to check if an overlay is a fake cursor"
@@ -266,6 +310,21 @@ not be recognized through the command-remapping lookup."
this-original-command)))) this-original-command))))
(defun mc/execute-this-command-for-all-cursors () (defun mc/execute-this-command-for-all-cursors ()
"Wrap around `mc/execute-this-command-for-all-cursors-1' to protect hook."
(condition-case error
(mc/execute-this-command-for-all-cursors-1)
(error
(message "[mc] problem in `mc/execute-this-command-for-all-cursors': %s"
(error-message-string error)))))
;; execute-kbd-macro should never be run for fake cursors. The real cursor will
;; execute the keyboard macro, resulting in new commands in the command loop,
;; and the fake cursors can pick up on those instead.
(defadvice execute-kbd-macro (around skip-fake-cursors activate)
(unless mc--executing-command-for-fake-cursor
ad-do-it))
(defun mc/execute-this-command-for-all-cursors-1 ()
"Used with post-command-hook to execute supported commands for all cursors. "Used with post-command-hook to execute supported commands for all cursors.
It uses two lists of commands to know what to do: the run-once It uses two lists of commands to know what to do: the run-once
@@ -274,6 +333,8 @@ it will prompt for the proper action and then save that preference.
Some commands are so unsupported that they are even prevented for Some commands are so unsupported that they are even prevented for
the original cursor, to inform about the lack of support." the original cursor, to inform about the lack of support."
(unless mc--executing-command-for-fake-cursor
(if (eq 1 (mc/num-cursors)) ;; no fake cursors? disable mc-mode (if (eq 1 (mc/num-cursors)) ;; no fake cursors? disable mc-mode
(multiple-cursors-mode 0) (multiple-cursors-mode 0)
@@ -282,11 +343,22 @@ the original cursor, to inform about the lack of support."
(command-remapping this-original-command) (command-remapping this-original-command)
this-original-command))) this-original-command)))
;; skip keyboard macros, since they will generate actual commands that are
;; also run in the command loop - we'll handle those later instead.
(when (functionp original-command)
;; if it's a lambda, we can't know if it's supported or not ;; if it's a lambda, we can't know if it's supported or not
;; - so go ahead and assume it's ok, because we're just optimistic like that ;; - so go ahead and assume it's ok, because we're just optimistic like that
(if (not (symbolp original-command)) (if (or (not (symbolp original-command))
;; lambda registered by smartrep
(string-prefix-p "(" (symbol-name original-command)))
(mc/execute-command-for-all-fake-cursors original-command) (mc/execute-command-for-all-fake-cursors original-command)
;; smartrep `intern's commands into own obarray to help
;; `describe-bindings'. So, let's re-`intern' here to
;; make the command comparable by `eq'.
(setq original-command (intern (symbol-name original-command)))
;; otherwise it's a symbol, and we can be more thorough ;; otherwise it's a symbol, and we can be more thorough
(if (get original-command 'mc--unsupported) (if (get original-command 'mc--unsupported)
(message "%S is not supported with multiple cursors%s" (message "%S is not supported with multiple cursors%s"
@@ -298,7 +370,7 @@ the original cursor, to inform about the lack of support."
(or (memq original-command mc--default-cmds-to-run-for-all) (or (memq original-command mc--default-cmds-to-run-for-all)
(memq original-command mc/cmds-to-run-for-all) (memq original-command mc/cmds-to-run-for-all)
(mc/prompt-for-inclusion-in-whitelist original-command))) (mc/prompt-for-inclusion-in-whitelist original-command)))
(mc/execute-command-for-all-fake-cursors original-command)))))))) (mc/execute-command-for-all-fake-cursors original-command))))))))))
(defun mc/remove-fake-cursors () (defun mc/remove-fake-cursors ()
"Remove all fake cursors. "Remove all fake cursors.
@@ -372,9 +444,16 @@ They are temporarily disabled when multiple-cursors are active.")
(mapc 'mc/enable-minor-mode mc/temporarily-disabled-minor-modes) (mapc 'mc/enable-minor-mode mc/temporarily-disabled-minor-modes)
(setq mc/temporarily-disabled-minor-modes nil)) (setq mc/temporarily-disabled-minor-modes nil))
(defcustom mc/mode-line
`(" mc:" (:eval (format ,(propertize "%d" 'face 'font-lock-warning-face)
(mc/num-cursors))))
"What to display in the mode line while multiple-cursors-mode is active."
:group 'multiple-cursors)
(put 'mc/mode-line 'risky-local-variable t)
(define-minor-mode multiple-cursors-mode (define-minor-mode multiple-cursors-mode
"Mode while multiple cursors are active." "Mode while multiple cursors are active."
nil " mc" mc/keymap nil mc/mode-line mc/keymap
(if multiple-cursors-mode (if multiple-cursors-mode
(progn (progn
(mc/temporarily-disable-unsupported-minor-modes) (mc/temporarily-disable-unsupported-minor-modes)
@@ -391,6 +470,12 @@ They are temporarily disabled when multiple-cursors are active.")
(add-hook 'after-revert-hook #'(lambda () (multiple-cursors-mode 0))) (add-hook 'after-revert-hook #'(lambda () (multiple-cursors-mode 0)))
(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)))
(defmacro unsupported-cmd (cmd msg) (defmacro unsupported-cmd (cmd msg)
"Adds command to list of unsupported commands and prevents it "Adds command to list of unsupported commands and prevents it
from being executed if in multiple-cursors-mode." from being executed if in multiple-cursors-mode."
@@ -434,6 +519,20 @@ from being executed if in multiple-cursors-mode."
"The position of the file that keeps track of your preferences "The position of the file that keeps track of your preferences
for running commands with multiple cursors.") for running commands with multiple cursors.")
(defun mc/dump-list (list-symbol)
"Insert (setq 'LIST-SYMBOL LIST-VALUE) to current buffer."
(symbol-macrolet ((value (symbol-value list-symbol)))
(insert "(setq " (symbol-name list-symbol) "\n"
" '(")
(newline-and-indent)
(set list-symbol
(sort value (lambda (x y) (string-lessp (symbol-name x)
(symbol-name y)))))
(mapc #'(lambda (cmd) (insert (format "%S" cmd)) (newline-and-indent))
value)
(insert "))")
(newline)))
(defun mc/save-lists () (defun mc/save-lists ()
"Saves preferences for running commands with multiple cursors to `mc/list-file'" "Saves preferences for running commands with multiple cursors to `mc/list-file'"
(with-temp-file mc/list-file (with-temp-file mc/list-file
@@ -443,21 +542,9 @@ for running commands with multiple cursors.")
(insert ";; It keeps track of your preferences for running commands with multiple cursors.") (insert ";; It keeps track of your preferences for running commands with multiple cursors.")
(newline) (newline)
(newline) (newline)
(insert "(setq mc/cmds-to-run-for-all '(") (mc/dump-list 'mc/cmds-to-run-for-all)
(mapc #'(lambda (cmd) (insert (format "%S" cmd)) (newline-and-indent)) mc/cmds-to-run-for-all)
(when mc/cmds-to-run-for-all
(forward-line -1)
(end-of-line))
(insert "))")
(newline) (newline)
(newline) (mc/dump-list 'mc/cmds-to-run-once)))
(insert "(setq mc/cmds-to-run-once '(")
(mapc #'(lambda (cmd) (insert (format "%S" cmd)) (newline-and-indent)) mc/cmds-to-run-once)
(when mc/cmds-to-run-once
(forward-line -1)
(end-of-line))
(insert "))")
(newline)))
(defvar mc/cmds-to-run-once nil (defvar mc/cmds-to-run-once nil
"Commands to run only once in multiple-cursors-mode.") "Commands to run only once in multiple-cursors-mode.")
@@ -469,9 +556,23 @@ for running commands with multiple cursors.")
mc/edit-ends-of-lines mc/edit-ends-of-lines
mc/edit-beginnings-of-lines mc/edit-beginnings-of-lines
mc/mark-next-like-this mc/mark-next-like-this
mc/mark-next-word-like-this
mc/mark-next-symbol-like-this
mc/mark-previous-like-this mc/mark-previous-like-this
mc/mark-more-like-this-extended mc/mark-previous-word-like-this
mc/mark-previous-symbol-like-this
mc/mark-all-like-this mc/mark-all-like-this
mc/mark-all-words-like-this
mc/mark-all-symbols-like-this
mc/mark-more-like-this-extended
mc/mark-all-like-this-in-defun
mc/mark-all-words-like-this-in-defun
mc/mark-all-symbols-like-this-in-defun
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-forward
mc/cycle-backward mc/cycle-backward
rrm/switch-to-multiple-cursors rrm/switch-to-multiple-cursors
@@ -479,6 +580,7 @@ for running commands with multiple cursors.")
ido-exit-minibuffer ido-exit-minibuffer
exit-minibuffer exit-minibuffer
minibuffer-complete-and-exit minibuffer-complete-and-exit
execute-extended-command
undo undo
redo redo
undo-tree-undo undo-tree-undo
@@ -495,6 +597,7 @@ for running commands with multiple cursors.")
describe-function describe-function
describe-bindings describe-bindings
describe-prefix-bindings describe-prefix-bindings
view-echo-area-messages
other-window other-window
kill-buffer-and-window kill-buffer-and-window
split-window-right split-window-right
@@ -502,6 +605,8 @@ for running commands with multiple cursors.")
delete-other-windows delete-other-windows
toggle-window-split toggle-window-split
mwheel-scroll mwheel-scroll
scroll-up-command
scroll-down-command
mouse-set-point mouse-set-point
mouse-drag-region mouse-drag-region
quit-window quit-window
@@ -516,6 +621,7 @@ for running commands with multiple cursors.")
(setq mc--default-cmds-to-run-for-all '(mc/keyboard-quit (setq mc--default-cmds-to-run-for-all '(mc/keyboard-quit
self-insert-command self-insert-command
quoted-insert
previous-line previous-line
next-line next-line
newline newline
@@ -554,6 +660,10 @@ for running commands with multiple cursors.")
backward-delete-char-untabify backward-delete-char-untabify
delete-char delete-forward-char delete-char delete-forward-char
delete-backward-char delete-backward-char
c-electric-backspace
org-delete-backward-char
paredit-backward-delete
autopair-backspace
just-one-space just-one-space
zap-to-char zap-to-char
end-of-line end-of-line
@@ -589,4 +699,9 @@ for running commands with multiple cursors.")
(provide 'multiple-cursors-core) (provide 'multiple-cursors-core)
;; Local Variables:
;; coding: utf-8
;; byte-compile-warnings: (not cl-functions)
;; End:
;;; multiple-cursors-core.el ends here ;;; multiple-cursors-core.el ends here
+1 -1
View File
@@ -1,2 +1,2 @@
(define-package "multiple-cursors" "1.1.2" (define-package "multiple-cursors" "1.2.1"
"Multiple cursors for Emacs.") "Multiple cursors for Emacs.")
+91 -50
View File
@@ -23,112 +23,153 @@
;; Multiple cursors for Emacs. This is some pretty crazy functionality, so yes, ;; Multiple cursors for Emacs. This is some pretty crazy functionality, so yes,
;; there are kinks. Don't be afraid tho, I've been using it since 2011 with ;; there are kinks. Don't be afraid tho, I've been using it since 2011 with
;; great success and much merriment. ;; great success and much merriment.
;;
;; ## Basic usage ;; ## Basic usage
;;
;; Start out with: ;; Start out with:
;;
;; (require 'multiple-cursors) ;; (require 'multiple-cursors)
;;
;; Then you have to set up your keybindings - multiple-cursors doesn't presume to
;; know how you'd like them laid out. Here are some examples:
;; When you have an active region that spans multiple lines, the following will ;; When you have an active region that spans multiple lines, the following will
;; add a cursor to each line: ;; add a cursor to each line:
;;
;; (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)
;;
;; When you want to add multiple cursors not based on continuous lines, but based on ;; When you want to add multiple cursors not based on continuous lines, but based on
;; keywords in the buffer, use: ;; keywords in the buffer, use:
;;
;; (global-set-key (kbd "C->") 'mc/mark-next-like-this) ;; (global-set-key (kbd "C->") 'mc/mark-next-like-this)
;; (global-set-key (kbd "C-<") 'mc/mark-previous-like-this) ;; (global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
;; (global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this) ;; (global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)
;;
;; First mark the word, then add more cursors. ;; First mark the word, then add more cursors.
;;
;; To get out of multiple-cursors-mode, press `<return>` or `C-g`. The latter will ;; To get out of multiple-cursors-mode, press `<return>` or `C-g`. The latter will
;; first disable multiple regions before disabling multiple cursors. If you want to ;; first disable multiple regions before disabling multiple cursors. If you want to
;; insert a newline in multiple-cursors-mode, use `C-j`. ;; insert a newline in multiple-cursors-mode, use `C-j`.
;; ## Video
;; You can [watch an intro to multiple-cursors at Emacs Rocks](http://emacsrocks.com/e13.html).
;; ## Command overview
;; ### Mark one more occurrence
;; - `mc/mark-next-like-this`: Adds a cursor and region at the next part of the buffer forwards that matches the current region.
;; - `mc/mark-next-word-like-this`: Like `mc/mark-next-like-this` but only for whole words.
;; - `mc/mark-next-symbol-like-this`: Like `mc/mark-next-like-this` but only for whole symbols.
;; - `mc/mark-previous-like-this`: Adds a cursor and region at the next part of the buffer backwards that matches the current region.
;; - `mc/mark-previous-word-like-this`: Like `mc/mark-previous-like-this` but only for whole words.
;; - `mc/mark-previous-symbol-like-this`: Like `mc/mark-previous-like-this` but only for whole symbols.
;; - `mc/mark-more-like-this-extended`: Use arrow keys to quickly mark/skip next/previous occurances.
;; ### Mark many occurrences
;; - `mc/mark-all-like-this`: Marks all parts of the buffer that matches the current region.
;; - `mc/mark-all-words-like-this`: Like `mc/mark-all-like-this` but only for whole words.
;; - `mc/mark-all-symbols-like-this`: Like `mc/mark-all-like-this` but only for whole symbols.
;; - `mc/mark-all-in-region`: Prompts for a string to match in the region, adding cursors to all of them.
;; - `mc/mark-all-like-this-in-defun`: Marks all parts of the current defun that matches the current region.
;; - `mc/mark-all-words-like-this-in-defun`: Like `mc/mark-all-like-this-in-defun` but only for whole words.
;; - `mc/mark-all-symbols-like-this-in-defun`: Like `mc/mark-all-like-this-in-defun` but only for whole symbols.
;; - `mc/mark-all-like-this-dwim`: Tries to be smart about marking everything you want. Can be pressed multiple times.
;; ### Special
;; - `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
;; - To get out of multiple-cursors-mode, press `<return>` or `C-g`. The latter will
;; first disable multiple regions before disabling multiple cursors. If you want to
;; insert a newline in multiple-cursors-mode, use `C-j`.
;; ;;
;; - Sometimes you end up with cursors outside of your view. You can
;; scroll the screen to center on each cursor with `C-v` and `M-v`.
;; ;;
;; ## More commands to play around with ;; - Try pressing `mc/mark-next-like-this` with no region selected. It will just add a cursor
;; on the next line.
;; ;;
;; I've set up my key-bindings like so: ;; - Try pressing `mc/mark-all-like-this-dwim` on a tagname in html-mode.
;; ;;
;; ;; From active region to multiple cursors: ;; - Notice that the number of cursors active can be seen in the modeline.
;; (global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
;; (global-set-key (kbd "C-S-c C-e") 'mc/edit-ends-of-lines)
;; (global-set-key (kbd "C-S-c C-a") 'mc/edit-beginnings-of-lines)
;; ;;
;; When you have an active region that spans multiple lines, the preceeding three ;; - If you get out of multiple-cursors-mode and yank - it will yank only
;; commands will add one cursor to each line. ;; from the kill-ring of main cursor. To yank from the kill-rings of
;; every cursor use yank-rectangle, normally found at C-x r y.
;; ;;
;; ;; Rectangular region mode ;; - You can use `mc/reverse-regions` with nothing selected and just one cursor.
;; (global-set-key (kbd "H-SPC") 'set-rectangular-region-anchor) ;; It will then flip the sexp at point and the one below it.
;; ;;
;; Think of this one as `set-mark` except you're marking a rectangular region. It is ;; - If you would like to keep the global bindings clean, and get custom keybindings
;; an exceedingly quick way of adding multiple cursors to multiple lines. ;; when the region is active, you can try [region-bindings-mode](https://github.com/fgallina/region-bindings-mode).
;;
;; ;; Mark more like this
;; (global-set-key (kbd "M-æ") 'mc/mark-all-like-this)
;; (global-set-key (kbd "C-å") 'mc/mark-previous-like-this)
;; (global-set-key (kbd "C-æ") 'mc/mark-next-like-this)
;; (global-set-key (kbd "C-Æ") 'mc/mark-more-like-this-extended)
;; (global-set-key (kbd "M-å") 'mc/mark-all-in-region)
;;
;; Okay, yes, I have a crazy norwegian keyboard. Regardless, these will look at
;; whatever you've got selected at the moment, and mark more places like that in
;; the buffer.
;; ;;
;; BTW, I highly recommend adding `mc/mark-next-like-this` to a key binding that's ;; BTW, I highly recommend adding `mc/mark-next-like-this` to a key binding that's
;; right next to the key for `er/expand-region`. ;; right next to the key for `er/expand-region`.
;;
;;
;; ## Unknown commands ;; ## Unknown commands
;;
;; Multiple-cursors uses two lists of commands to know what to do: the run-once list ;; Multiple-cursors uses two lists of commands to know what to do: the run-once list
;; and the run-for-all list. It comes with a set of defaults, but it would be beyond silly ;; and the run-for-all list. It comes with a set of defaults, but it would be beyond silly
;; to try and include all the known Emacs commands. ;; to try and include all the known Emacs commands.
;;
;; So that's why multiple-cursors occasionally asks what to do about a command. It will ;; So that's why multiple-cursors occasionally asks what to do about a command. It will
;; then remember your choice by saving it in `~/.emacs.d/.mc-lists.el`. You can change ;; then remember your choice by saving it in `~/.emacs.d/.mc-lists.el`. You can change
;; the location with: ;; the location with:
;;
;; (setq mc/list-file "/my/preferred/file") ;; (setq mc/list-file "/my/preferred/file")
;;
;;
;; ## Known limitations ;; ## Known limitations
;;
;; * isearch-forward and isearch-backward aren't supported with multiple cursors. ;; * isearch-forward and isearch-backward aren't supported with multiple cursors.
;; You should feel free to add a simplified version that can work with it. ;; You should feel free to add a simplified version that can work with it.
;; * Commands run with `M-x` won't be repeated for all cursors. ;; * Commands run with `M-x` won't be repeated for all cursors.
;; * All key bindings that refer to lambdas are always run for all cursors. If you ;; * All key bindings that refer to lambdas are always run for all cursors. If you
;; need to limit it, you will have to give it a name. ;; need to limit it, you will have to give it a name.
;; * Redo might screw with your cursors. Undo works very well. ;; * Redo might screw with your cursors. Undo works very well.
;;
;;
;; ## Contribute ;; ## Contribute
;;
;; Yes, please do. There's a suite of tests, so remember to add tests for your ;; Yes, please do. There's a suite of tests, so remember to add tests for your
;; specific feature, or I might break it later. ;; specific feature, or I might break it later.
;;
;; You'll find the repo at: ;; You'll find the repo at:
;;
;; https://github.com/magnars/multiple-cursors.el ;; https://github.com/magnars/multiple-cursors.el
;;
;; To fetch the test dependencies: ;; To fetch the test dependencies:
;;
;; $ cd /path/to/multiple-cursors ;; $ cd /path/to/multiple-cursors
;; $ git submodule update --init ;; $ git submodule update --init
;;
;; Run the tests with: ;; Run the tests with:
;;
;; $ ./util/ecukes/ecukes --graphical ;; $ ./util/ecukes/ecukes --graphical
;;
;; ## Contributors
;; * [Takafumi Arakaki](https://github.com/tkf) made .mc-lists.el diff friendly
;; * [Marco Baringer](https://github.com/segv) contributed looping to mc/cycle and adding cursors without region for mark-more.
;; * [Ivan Andrus](https://github.com/gvol) added showing number of cursors in mode-line
;; * [Fuco](https://github.com/Fuco1) added the first version of `mc/mark-all-like-this-dwim`
;; Thanks!
;;; Code: ;;; Code:
(require 'mc-edit-lines) (require 'mc-edit-lines)
(require 'mc-cycle-cursors) (require 'mc-cycle-cursors)
(require 'mc-mark-more) (require 'mc-mark-more)
(require 'rectangular-region-mode) (require 'rectangular-region-mode)
(require 'mc-separate-operations)
(provide 'multiple-cursors) (provide 'multiple-cursors)
+4 -12
View File
@@ -1,20 +1,12 @@
#!/bin/sh #!/bin/sh -e
cd "$(dirname "$0")" cd "$(dirname "$0")"
set_default () { ECUKES_EMACS=${ECUKES_EMACS:-$(which emacs)}
eval "
if [ -z \$$1 ]; then
$1=$2
fi
"
}
set_default ECUKES_EMACS "$(which emacs)"
echo "*** Emacs version ***" echo "*** Emacs version ***"
echo "ECUKES_EMACS =" $(which $ECUKES_EMACS) echo "ECUKES_EMACS = $ECUKES_EMACS"
$ECUKES_EMACS --version "$ECUKES_EMACS" --version
echo echo
exec ./util/ecukes/ecukes --graphical exec ./util/ecukes/ecukes --graphical
+329
View File
@@ -0,0 +1,329 @@
;;; wrap-region.el --- Wrap text with punctation or tag
;; Copyright (C) 2008-2012 Johan Andersson
;; Author: Johan Andersson <johan.rejeep@gmail.com>
;; Maintainer: Johan Andersson <johan.rejeep@gmail.com>
;; Version: 0.6.0
;; Keywords: speed, convenience
;; URL: http://github.com/rejeep/wrap-region
;; This file is NOT part of GNU Emacs.
;;; License:
;; 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, 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 GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;; wrap-region is a minor mode that wraps a region with
;; punctuations. For tagged markup modes, such as HTML and XML, it
;; wraps with tags.
;;
;; To use wrap-region, make sure that this file is in Emacs load-path:
;; (add-to-list 'load-path "/path/to/directory/or/file")
;;
;; Then require wrap-region:
;; (require 'wrap-region)
;; To start wrap-region:
;; (wrap-region-mode t) or M-x wrap-region-mode
;;
;; If you only want wrap-region active in some mode, use hooks:
;; (add-hook 'ruby-mode-hook 'wrap-region-mode)
;;
;; Or if you want to activate it in all buffers, use the global mode:
;; (wrap-region-global-mode t)
;; To wrap a region, select that region and hit one of the punctuation
;; keys. In "tag-modes"" (see `wrap-region-tag-active-modes'), "<" is
;; replaced and wraps the region with a tag. To activate this behavior
;; in a mode that is not default:
;; (add-to-list 'wrap-region-tag-active-modes 'some-tag-mode)
;;
;; `wrap-region-table' contains the default punctuations
;; that wraps. You can add and remove new wrappers by using the
;; functions `wrap-region-add-wrapper' and
;; `wrap-region-remove-wrapper' respectively.
;; (wrap-region-add-wrapper "`" "'") ; hit ` then region -> `region'
;; (wrap-region-add-wrapper "/*" "*/" "/") ; hit / then region -> /*region*/
;; (wrap-region-add-wrapper "$" "$" nil 'latex-mode) ; hit $ then region -> $region$ in latex-mode
;; (wrap-region-remove-wrapper "(")
;; (wrap-region-remove-wrapper "$" 'latex-mode)
;;
;; Some modes may have conflicting key bindings with wrap-region. To
;; avoid conflicts, the list `wrap-region-except-modes' contains names
;; of modes where wrap-region should not be activated (note, only in
;; the global mode). You can add new modes like this:
;; (add-to-list 'wrap-region-except-modes 'conflicting-mode)
;;; Code:
(require 'edmacro)
(eval-when-compile
(require 'cl))
(defstruct wrap-region-wrapper key left right modes)
(defvar wrap-region-mode-map (make-sparse-keymap)
"Keymap for `wrap-region-mode'.")
(defvar wrap-region-table (make-hash-table :test 'equal)
"Table with wrapper pairs.")
(defvar wrap-region-tag-active-modes '(html-mode sgml-mode rhtml-mode nxml-mode nxhtml-mode)
"List of modes that uses tags.")
(defvar wrap-region-except-modes '(calc-mode dired-mode)
"A list of modes in which `wrap-region-mode' should not be activated.")
(defvar wrap-region-hook nil
"Called when `wrap-region-mode' is turned on.")
(defvar wrap-region-before-wrap-hook nil
"Called before wrapping.")
(defvar wrap-region-after-wrap-hook nil
"Called after wrapping.")
(defvar wrap-region-only-with-negative-prefix nil
"Only wrap if the trigger key is prefixed with a negative value.")
(defvar wrap-region-keep-mark nil
"Keep the wrapped region active.")
(defun wrap-region-trigger (arg key)
"Called when trigger key is pressed."
(let* ((wrapper (wrap-region-find key)))
(if (and wrapper
(region-active-p)
(if wrap-region-only-with-negative-prefix (< arg 0) t))
(if (wrap-region-insert-tag-p key)
(wrap-region-with-tag)
(wrap-region-with-punctuations
(wrap-region-wrapper-left wrapper)
(wrap-region-wrapper-right wrapper)))
(wrap-region-fallback key))))
(defun wrap-region-find (key)
"Find first wrapper with trigger KEY that should be active in MAJOR-MODE."
(let ((wrappers (gethash key wrap-region-table)))
(or
(find-if
(lambda (wrapper)
(member major-mode (wrap-region-wrapper-modes wrapper)))
wrappers)
(find-if
(lambda (wrapper)
(not (wrap-region-wrapper-modes wrapper)))
wrappers))))
(defun wrap-region-insert-tag-p (key)
"Check if tag should be inserted or not."
(and
(equal key "<")
(member major-mode wrap-region-tag-active-modes)))
(defun wrap-region-with-tag ()
"Wraps region with tag."
(let* ((tag (read-string "Enter Tag (with optional attributes): "))
(split (split-string tag " "))
(tag-name (car split))
(left (concat "<" tag ">"))
(right (concat "</" tag-name ">")))
(wrap-region-with left right)))
(defun wrap-region-with-punctuations (left right)
"Wraps region with LEFT and RIGHT punctuations."
(wrap-region-with left right))
(defun wrap-region-with (left right)
"Wraps region with LEFT and RIGHT."
(run-hooks 'wrap-region-before-wrap-hook)
(let ((beg (region-beginning))
(end (region-end))
(pos (point))
(deactivate-mark nil))
(save-excursion
(goto-char beg)
(insert left)
(goto-char (+ end (length left)))
(insert right))
(if wrap-region-keep-mark
(let* ((beg-p (eq beg pos))
(beg* (+ beg (length left)))
(end* (+ end (length left)))
(pos* (if beg-p beg* end*)))
(push-mark (if beg-p end* beg*) nil t)
(goto-char (if beg-p beg* end*)))
(deactivate-mark)))
(run-hooks 'wrap-region-after-wrap-hook))
(defun wrap-region-fallback (key)
"Execute function that KEY was bound to before `wrap-region-mode'."
(let ((wrap-region-mode nil))
(execute-kbd-macro
(edmacro-parse-keys key))))
(defun wrap-region-add-wrappers (wrappers)
"Add WRAPPERS by calling `wrap-region-add-wrapper' for each one."
(mapc
(lambda (wrapper)
(apply 'wrap-region-add-wrapper wrapper))
wrappers))
(defun wrap-region-add-wrapper (left right &optional key mode-or-modes)
"Add new LEFT and RIGHT wrapper.
Optional KEY is the trigger key and MODE-OR-MODES is a single
mode or multiple modes that the wrapper should trigger in."
(or key (setq key left))
(let ((wrappers (gethash key wrap-region-table))
(modes
(if mode-or-modes
(if (listp mode-or-modes)
mode-or-modes
(list mode-or-modes)))))
(if wrappers
(let ((wrapper-exactly-same
(find-if
(lambda (wrapper)
(and
(equal (wrap-region-wrapper-key wrapper) key)
(equal (wrap-region-wrapper-left wrapper) left)
(equal (wrap-region-wrapper-right wrapper) right)))
wrappers)))
(if wrapper-exactly-same
(when (wrap-region-wrapper-modes wrapper-exactly-same)
(if modes
(setf
(wrap-region-wrapper-modes wrapper-exactly-same)
(union modes (wrap-region-wrapper-modes wrapper-exactly-same)))
(let ((new-wrapper (make-wrap-region-wrapper :key key :left left :right right)))
(puthash key (cons new-wrapper wrappers) wrap-region-table))))
(let* ((new-wrapper (make-wrap-region-wrapper :key key :left left :right right :modes modes))
(wrapper-same-trigger
(find-if
(lambda (wrapper)
(equal (wrap-region-wrapper-key wrapper) key))
wrappers))
(wrapper-same-trigger-modes
(wrap-region-wrapper-modes wrapper-same-trigger)))
(when (and wrapper-same-trigger wrapper-same-trigger-modes)
(let ((new-modes (nset-difference (wrap-region-wrapper-modes wrapper-same-trigger) modes)))
(if new-modes
(setf (wrap-region-wrapper-modes wrapper-same-trigger) new-modes)
(setq wrappers (delete wrapper-same-trigger wrappers)))))
(puthash key (cons new-wrapper wrappers) wrap-region-table))))
(let ((new-wrapper (make-wrap-region-wrapper :key key :left left :right right :modes modes)))
(puthash key (list new-wrapper) wrap-region-table))))
(wrap-region-define-trigger key))
(defun wrap-region-remove-wrapper (key &optional mode-or-modes)
"Remove wrapper with trigger KEY or exclude from MODE-OR-MODES.
If MODE-OR-MODES is not present, all wrappers for KEY are removed."
(if mode-or-modes
(let ((wrappers (gethash key wrap-region-table))
(modes
(if mode-or-modes
(if (listp mode-or-modes)
mode-or-modes
(list mode-or-modes)))))
(mapc
(lambda (mode)
(let ((wrapper-including-mode
(find-if
(lambda (wrapper)
(member mode (wrap-region-wrapper-modes wrapper)))
wrappers)))
(when wrapper-including-mode
(let ((new-modes (delete mode (wrap-region-wrapper-modes wrapper-including-mode))))
(if new-modes
(setf (wrap-region-wrapper-modes wrapper-including-mode) new-modes)
(puthash key (delete wrapper-including-mode wrappers) wrap-region-table))))))
modes))
(wrap-region-destroy-wrapper key)))
(defun wrap-region-destroy-wrapper (key)
"Remove the wrapper bound to KEY, no questions asked."
(remhash key wrap-region-table)
(wrap-region-unset-key key))
(defun wrap-region-define-wrappers ()
"Defines defaults wrappers."
(mapc
(lambda (pair)
(apply 'wrap-region-add-wrapper pair))
'(("\"" "\"")
("'" "'")
("(" ")")
("{" "}")
("[" "]")
("<" ">"))))
(defun wrap-region-define-trigger (key)
"Defines KEY as wrapper."
(wrap-region-define-key
key
`(lambda (arg)
(interactive "p")
(wrap-region-trigger arg ,key))))
(defun wrap-region-unset-key (key)
"Remove KEY from `wrap-region-mode-map'."
(wrap-region-define-key key))
(defun wrap-region-define-key (key &optional fn)
"Binds KEY to FN in `wrap-region-mode-map'."
(define-key wrap-region-mode-map (read-kbd-macro key) fn))
;;;###autoload
(define-minor-mode wrap-region-mode
"Wrap region with stuff."
:init-value nil
:lighter " wr"
:keymap wrap-region-mode-map
(when wrap-region-mode
(wrap-region-define-wrappers)
(run-hooks 'wrap-region-hook)))
;;;###autoload
(defun turn-on-wrap-region-mode ()
"Turn on `wrap-region-mode'"
(interactive)
(unless (member major-mode wrap-region-except-modes)
(wrap-region-mode +1)))
;;;###autoload
(defun turn-off-wrap-region-mode ()
"Turn off `wrap-region-mode'."
(interactive)
(wrap-region-mode -1))
;;;###autoload
(define-globalized-minor-mode wrap-region-global-mode
wrap-region-mode
turn-on-wrap-region-mode)
(provide 'wrap-region)
;;; wrap-region.el ends here