mirror of
https://github.com/magnars/multiple-cursors.el.git
synced 2026-05-10 01:18:19 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cb7a145153 | |||
| 82a1fe3746 | |||
| 56839dfdca | |||
| 3f3cdc6c92 | |||
| 5190e0cdc6 | |||
| a4f6ea179a | |||
| 9582c7220b | |||
| a6984a1141 | |||
| 6a5969e14a | |||
| 9a376a6fa2 | |||
| bfb293f200 | |||
| 3ce6e4a670 |
@@ -49,6 +49,9 @@ You can [watch an intro to multiple-cursors at Emacs Rocks](http://emacsrocks.co
|
||||
|
||||
### Mark many occurrences
|
||||
|
||||
- `mc/edit-lines`: Adds one cursor to each line in the current region.
|
||||
- `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.
|
||||
@@ -62,6 +65,9 @@ You can [watch an intro to multiple-cursors at Emacs Rocks](http://emacsrocks.co
|
||||
|
||||
- `set-rectangular-region-anchor`: Think of this one as `set-mark` except you're marking a rectangular region.
|
||||
- `mc/mark-sgml-tag-pair`: Mark the current opening and closing tag.
|
||||
- `mc/insert-numbers`: Insert increasing numbers for each cursor, top to bottom.
|
||||
- `mc/sort-regions`: Sort the marked regions alphabetically.
|
||||
- `mc/reverse-regions`: Reverse the order of the marked regions.
|
||||
|
||||
## Tips and tricks
|
||||
|
||||
@@ -72,13 +78,17 @@ You can [watch an intro to multiple-cursors at Emacs Rocks](http://emacsrocks.co
|
||||
- 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-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.
|
||||
|
||||
- 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).
|
||||
|
||||
|
||||
@@ -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 press "C-S-c C-S-c"
|
||||
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
|
||||
|
||||
@@ -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)"
|
||||
@@ -132,3 +132,13 @@ Feature: Marking multiple parts of the buffer
|
||||
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"
|
||||
|
||||
|
||||
@@ -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)"
|
||||
@@ -25,6 +25,9 @@
|
||||
(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 "H-0") 'mc/insert-numbers)
|
||||
(global-set-key (kbd "H-1") 'mc/reverse-regions)
|
||||
(global-set-key (kbd "H-2") 'mc/sort-regions)
|
||||
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
|
||||
(global-set-key (kbd "H-SPC") 'set-rectangular-region-anchor)
|
||||
(switch-to-buffer
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@
|
||||
Starts from mark and moves in straight down or up towards the
|
||||
line point is on."
|
||||
(interactive)
|
||||
(when (not (use-region-p))
|
||||
(when (not (and mark-active (/= (point) (mark))))
|
||||
(error "Mark a set of lines first."))
|
||||
(mc/remove-fake-cursors)
|
||||
(let* ((col (current-column))
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
;;; mc-separate-operations.el - functions that work differently on each cursor
|
||||
|
||||
;; Copyright (C) 2012 Magnar Sveen
|
||||
|
||||
;; Author: Magnar Sveen <magnars@gmail.com>
|
||||
;; Keywords: editing cursors
|
||||
|
||||
;; This program is free software; you can redistribute it and/or modify
|
||||
;; it under the terms of the GNU General Public License as published by
|
||||
;; the Free Software Foundation, either version 3 of the License, or
|
||||
;; (at your option) any later version.
|
||||
|
||||
;; This program is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; This file contains functions that work differently on each cursor,
|
||||
;; instead of treating all of them the same.
|
||||
|
||||
;; Please see multiple-cursors.el for more commentary.
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'multiple-cursors-core)
|
||||
|
||||
;;;###autoload
|
||||
(defun mc/insert-numbers (arg)
|
||||
"Insert increasing numbers for each cursor, starting at 0 or ARG."
|
||||
(interactive "P")
|
||||
(setq mc--insert-numbers-number (or arg 0))
|
||||
(mc/for-each-cursor-ordered
|
||||
(mc/execute-command-for-fake-cursor 'mc--insert-number-and-increase cursor)))
|
||||
|
||||
(defvar mc--insert-numbers-number 0)
|
||||
|
||||
(defun mc--insert-number-and-increase ()
|
||||
(interactive)
|
||||
(insert (number-to-string mc--insert-numbers-number))
|
||||
(setq mc--insert-numbers-number (1+ mc--insert-numbers-number)))
|
||||
|
||||
(defun mc--ordered-region-strings ()
|
||||
(let (strings)
|
||||
(save-excursion
|
||||
(mc/for-each-cursor-ordered
|
||||
(add-to-list 'strings (buffer-substring-no-properties
|
||||
(mc/cursor-beg cursor)
|
||||
(mc/cursor-end cursor))))strings)
|
||||
(nreverse strings)))
|
||||
|
||||
(defvar mc--strings-to-replace nil)
|
||||
|
||||
(defun mc--replace-region-strings-1 ()
|
||||
(interactive)
|
||||
(delete-region (region-beginning) (region-end))
|
||||
(insert (car mc--strings-to-replace))
|
||||
(setq mc--strings-to-replace (cdr mc--strings-to-replace)))
|
||||
|
||||
(defun mc--replace-region-strings ()
|
||||
(mc/for-each-cursor-ordered
|
||||
(mc/execute-command-for-fake-cursor 'mc--replace-region-strings-1 cursor)))
|
||||
|
||||
;;;###autoload
|
||||
(defun mc/reverse-regions ()
|
||||
(interactive)
|
||||
(if (not (use-region-p))
|
||||
(message "Mark regions to reverse first.")
|
||||
(setq mc--strings-to-replace (nreverse (mc--ordered-region-strings)))
|
||||
(mc--replace-region-strings)))
|
||||
|
||||
;;;###autoload
|
||||
(defun mc/sort-regions ()
|
||||
(interactive)
|
||||
(if (not (use-region-p))
|
||||
(message "Mark regions to sort first.")
|
||||
(setq mc--strings-to-replace (sort (mc--ordered-region-strings) 'string<))
|
||||
(mc--replace-region-strings)))
|
||||
|
||||
(provide 'mc-separate-operations)
|
||||
;;; mc-separate-operations.el ends here
|
||||
+26
-12
@@ -72,12 +72,12 @@
|
||||
|
||||
(defmacro mc/for-each-cursor-ordered (&rest forms)
|
||||
"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)
|
||||
(when (mc/fake-cursor-p cursor)
|
||||
,@forms))
|
||||
(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)
|
||||
"Saves and restores the window scroll position"
|
||||
@@ -120,6 +120,7 @@ highlights the entire width of the window."
|
||||
|
||||
(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.")
|
||||
|
||||
@@ -198,6 +199,17 @@ Saves the current state in the overlay to be restored later."
|
||||
|
||||
(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)
|
||||
"Calls CMD interactively for each cursor.
|
||||
It works by moving point to the fake cursor, setting
|
||||
@@ -208,15 +220,7 @@ cursor with updated info."
|
||||
(mc/save-window-scroll
|
||||
(mc/for-each-fake-cursor
|
||||
(save-excursion
|
||||
(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))))))))
|
||||
(mc/execute-command-for-fake-cursor cmd cursor)))))
|
||||
(mc--reset-read-prompts))
|
||||
|
||||
;; Intercept some reading commands so you won't have to
|
||||
@@ -340,9 +344,16 @@ the original cursor, to inform about the lack of support."
|
||||
|
||||
;; 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
|
||||
(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)
|
||||
|
||||
;; 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
|
||||
(if (get original-command 'mc--unsupported)
|
||||
(message "%S is not supported with multiple cursors%s"
|
||||
@@ -554,6 +565,9 @@ for running commands with multiple cursors.")
|
||||
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-backward
|
||||
rrm/switch-to-multiple-cursors
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
(define-package "multiple-cursors" "1.1.5"
|
||||
(define-package "multiple-cursors" "1.2.0"
|
||||
"Multiple cursors for Emacs.")
|
||||
|
||||
@@ -82,6 +82,9 @@
|
||||
|
||||
;; - `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
|
||||
|
||||
@@ -99,6 +102,10 @@
|
||||
|
||||
;; - 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.
|
||||
|
||||
;; - 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).
|
||||
|
||||
@@ -159,6 +166,7 @@
|
||||
(require 'mc-cycle-cursors)
|
||||
(require 'mc-mark-more)
|
||||
(require 'rectangular-region-mode)
|
||||
(require 'mc-separate-operations)
|
||||
|
||||
(provide 'multiple-cursors)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user