multiple-cursors.el (8866B)
1 ;;; multiple-cursors.el --- Multiple cursors for emacs. 2 3 ;; Copyright (C) 2012-2013 Magnar Sveen 4 5 ;; Author: Magnar Sveen <magnars@gmail.com> 6 ;; Version: 1.4.0 7 ;; Keywords: editing cursors 8 9 ;; This program is free software; you can redistribute it and/or modify 10 ;; it under the terms of the GNU General Public License as published by 11 ;; the Free Software Foundation, either version 3 of the License, or 12 ;; (at your option) any later version. 13 14 ;; This program is distributed in the hope that it will be useful, 15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 ;; GNU General Public License for more details. 18 19 ;; You should have received a copy of the GNU General Public License 20 ;; along with this program. If not, see <http://www.gnu.org/licenses/>. 21 22 ;;; Commentary: 23 24 ;; Multiple cursors for Emacs. This is some pretty crazy functionality, so yes, 25 ;; there are kinks. Don't be afraid tho, I've been using it since 2011 with 26 ;; great success and much merriment. 27 28 ;; ## Basic usage 29 30 ;; Start out with: 31 32 ;; (require 'multiple-cursors) 33 34 ;; Then you have to set up your keybindings - multiple-cursors doesn't presume to 35 ;; know how you'd like them laid out. Here are some examples: 36 37 ;; When you have an active region that spans multiple lines, the following will 38 ;; add a cursor to each line: 39 40 ;; (global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines) 41 42 ;; When you want to add multiple cursors not based on continuous lines, but based on 43 ;; keywords in the buffer, use: 44 45 ;; (global-set-key (kbd "C->") 'mc/mark-next-like-this) 46 ;; (global-set-key (kbd "C-<") 'mc/mark-previous-like-this) 47 ;; (global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this) 48 49 ;; First mark the word, then add more cursors. 50 51 ;; To get out of multiple-cursors-mode, press `<return>` or `C-g`. The latter will 52 ;; first disable multiple regions before disabling multiple cursors. If you want to 53 ;; insert a newline in multiple-cursors-mode, use `C-j`. 54 55 ;; ## Video 56 57 ;; You can [watch an intro to multiple-cursors at Emacs Rocks](http://emacsrocks.com/e13.html). 58 59 ;; ## Command overview 60 61 ;; ### Mark one more occurrence 62 63 ;; - `mc/mark-next-like-this`: Adds a cursor and region at the next part of the buffer forwards that matches the current region. 64 ;; - `mc/mark-next-like-this-word`: Adds a cursor and region at the next part of the buffer forwards that matches the current region, if no region is selected it selects the word at the point. 65 ;; - `mc/mark-next-like-this-symbol`: Adds a cursor and region at the next part of the buffer forwards that matches the current region, if no region is selected it selects the symbol at the point. 66 ;; - `mc/mark-next-word-like-this`: Like `mc/mark-next-like-this` but only for whole words. 67 ;; - `mc/mark-next-symbol-like-this`: Like `mc/mark-next-like-this` but only for whole symbols. 68 ;; - `mc/mark-previous-like-this`: Adds a cursor and region at the next part of the buffer backwards that matches the current region. 69 ;; - `mc/mark-previous-word-like-this`: Like `mc/mark-previous-like-this` but only for whole words. 70 ;; - `mc/mark-previous-symbol-like-this`: Like `mc/mark-previous-like-this` but only for whole symbols. 71 ;; - `mc/mark-more-like-this-extended`: Use arrow keys to quickly mark/skip next/previous occurances. 72 ;; - `mc/add-cursor-on-click`: Bind to a mouse event to add cursors by clicking. See tips-section. 73 74 ;; ### Mark many occurrences 75 76 ;; - `mc/mark-all-like-this`: Marks all parts of the buffer that matches the current region. 77 ;; - `mc/mark-all-words-like-this`: Like `mc/mark-all-like-this` but only for whole words. 78 ;; - `mc/mark-all-symbols-like-this`: Like `mc/mark-all-like-this` but only for whole symbols. 79 ;; - `mc/mark-all-in-region`: Prompts for a string to match in the region, adding cursors to all of them. 80 ;; - `mc/mark-all-like-this-in-defun`: Marks all parts of the current defun that matches the current region. 81 ;; - `mc/mark-all-words-like-this-in-defun`: Like `mc/mark-all-like-this-in-defun` but only for whole words. 82 ;; - `mc/mark-all-symbols-like-this-in-defun`: Like `mc/mark-all-like-this-in-defun` but only for whole symbols. 83 ;; - `mc/mark-all-like-this-dwim`: Tries to be smart about marking everything you want. Can be pressed multiple times. 84 85 ;; ### Special 86 87 ;; - `set-rectangular-region-anchor`: Think of this one as `set-mark` except you're marking a rectangular region. 88 ;; - `mc/mark-sgml-tag-pair`: Mark the current opening and closing tag. 89 ;; - `mc/insert-numbers`: Insert increasing numbers for each cursor, top to bottom. 90 ;; - `mc/insert-letters`: Insert increasing letters for each cursor, top to bottom. 91 ;; - `mc/sort-regions`: Sort the marked regions alphabetically. 92 ;; - `mc/reverse-regions`: Reverse the order of the marked regions. 93 94 ;; ## Tips and tricks 95 96 ;; - To get out of multiple-cursors-mode, press `<return>` or `C-g`. The latter will 97 ;; first disable multiple regions before disabling multiple cursors. If you want to 98 ;; insert a newline in multiple-cursors-mode, use `C-j`. 99 ;; 100 ;; - Sometimes you end up with cursors outside of your view. You can 101 ;; scroll the screen to center on each cursor with `C-v` and `M-v`. 102 ;; 103 ;; - Try pressing `mc/mark-next-like-this` with no region selected. It will just add a cursor 104 ;; on the next line. 105 ;; 106 ;; - Try pressing `mc/mark-next-like-this-word` or 107 ;; `mc/mark-next-like-this-symbol` with no region selected. It will 108 ;; mark the symbol and add a cursor at the next occurance 109 ;; 110 ;; - Try pressing `mc/mark-all-like-this-dwim` on a tagname in html-mode. 111 ;; 112 ;; - Notice that the number of cursors active can be seen in the modeline. 113 ;; 114 ;; - If you get out of multiple-cursors-mode and yank - it will yank only 115 ;; from the kill-ring of main cursor. To yank from the kill-rings of 116 ;; every cursor use yank-rectangle, normally found at C-x r y. 117 ;; 118 ;; - You can use `mc/reverse-regions` with nothing selected and just one cursor. 119 ;; It will then flip the sexp at point and the one below it. 120 ;; 121 ;; - If you would like to keep the global bindings clean, and get custom keybindings 122 ;; when the region is active, you can try [region-bindings-mode](https://github.com/fgallina/region-bindings-mode). 123 ;; 124 ;; BTW, I highly recommend adding `mc/mark-next-like-this` to a key binding that's 125 ;; right next to the key for `er/expand-region`. 126 127 ;; ### Binding mouse events 128 129 ;; To override a mouse event, you will likely have to also unbind the 130 ;; `down-mouse` part of the event. Like this: 131 ;; 132 ;; (global-unset-key (kbd "M-<down-mouse-1>")) 133 ;; (global-set-key (kbd "M-<mouse-1>") 'mc/add-cursor-on-click) 134 ;; 135 ;; Or you can do like me and find an unused, but less convenient, binding: 136 ;; 137 ;; (global-set-key (kbd "C-S-<mouse-1>") 'mc/add-cursor-on-click) 138 139 ;; ## Unknown commands 140 141 ;; Multiple-cursors uses two lists of commands to know what to do: the run-once list 142 ;; and the run-for-all list. It comes with a set of defaults, but it would be beyond silly 143 ;; to try and include all the known Emacs commands. 144 145 ;; So that's why multiple-cursors occasionally asks what to do about a command. It will 146 ;; then remember your choice by saving it in `~/.emacs.d/.mc-lists.el`. You can change 147 ;; the location with: 148 149 ;; (setq mc/list-file "/my/preferred/file") 150 151 ;; ## Known limitations 152 153 ;; * isearch-forward and isearch-backward aren't supported with multiple cursors. 154 ;; You should feel free to add a simplified version that can work with it. 155 ;; * Commands run with `M-x` won't be repeated for all cursors. 156 ;; * All key bindings that refer to lambdas are always run for all cursors. If you 157 ;; need to limit it, you will have to give it a name. 158 ;; * Redo might screw with your cursors. Undo works very well. 159 160 ;; ## Contribute 161 162 ;; Yes, please do. There's a suite of tests, so remember to add tests for your 163 ;; specific feature, or I might break it later. 164 165 ;; You'll find the repo at: 166 167 ;; https://github.com/magnars/multiple-cursors.el 168 169 ;; To fetch the test dependencies: 170 171 ;; $ cd /path/to/multiple-cursors 172 ;; $ git submodule update --init 173 174 ;; Run the tests with: 175 176 ;; $ ./util/ecukes/ecukes --graphical 177 178 ;; ## Contributors 179 180 ;; * [Takafumi Arakaki](https://github.com/tkf) made .mc-lists.el diff friendly 181 ;; * [Marco Baringer](https://github.com/segv) contributed looping to mc/cycle and adding cursors without region for mark-more. 182 ;; * [Ivan Andrus](https://github.com/gvol) added showing number of cursors in mode-line 183 ;; * [Fuco](https://github.com/Fuco1) added the first version of `mc/mark-all-like-this-dwim` 184 185 ;; Thanks! 186 187 ;;; Code: 188 189 (require 'mc-edit-lines) 190 (require 'mc-cycle-cursors) 191 (require 'mc-mark-more) 192 (require 'mc-mark-pop) 193 (require 'rectangular-region-mode) 194 (require 'mc-separate-operations) 195 (require 'mc-hide-unmatched-lines-mode) 196 197 (provide 'multiple-cursors) 198 199 ;;; multiple-cursors.el ends here