Simple image host.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

multiple-cursors.el 8.0KB

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