Klimi's new dotfiles with stow.
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

203 líneas
8.7 KiB

hace 5 años
  1. ;;; multiple-cursors.el --- Multiple cursors for emacs.
  2. ;; Copyright (C) 2012-2016 Magnar Sveen
  3. ;; Author: Magnar Sveen <magnars@gmail.com>
  4. ;; Version: 1.4.0
  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-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.
  43. ;; - `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.
  44. ;; - `mc/mark-next-word-like-this`: Like `mc/mark-next-like-this` but only for whole words.
  45. ;; - `mc/mark-next-symbol-like-this`: Like `mc/mark-next-like-this` but only for whole symbols.
  46. ;; - `mc/mark-previous-like-this`: Adds a cursor and region at the next part of the buffer backwards that matches the current region.
  47. ;; - `mc/mark-previous-word-like-this`: Like `mc/mark-previous-like-this` but only for whole words.
  48. ;; - `mc/mark-previous-symbol-like-this`: Like `mc/mark-previous-like-this` but only for whole symbols.
  49. ;; - `mc/mark-more-like-this-extended`: Use arrow keys to quickly mark/skip next/previous occurances.
  50. ;; - `mc/add-cursor-on-click`: Bind to a mouse event to add cursors by clicking. See tips-section.
  51. ;; ### Mark many occurrences
  52. ;; - `mc/mark-all-like-this`: Marks all parts of the buffer that matches the current region.
  53. ;; - `mc/mark-all-words-like-this`: Like `mc/mark-all-like-this` but only for whole words.
  54. ;; - `mc/mark-all-symbols-like-this`: Like `mc/mark-all-like-this` but only for whole symbols.
  55. ;; - `mc/mark-all-in-region`: Prompts for a string to match in the region, adding cursors to all of them.
  56. ;; - `mc/mark-all-like-this-in-defun`: Marks all parts of the current defun that matches the current region.
  57. ;; - `mc/mark-all-words-like-this-in-defun`: Like `mc/mark-all-like-this-in-defun` but only for whole words.
  58. ;; - `mc/mark-all-symbols-like-this-in-defun`: Like `mc/mark-all-like-this-in-defun` but only for whole symbols.
  59. ;; - `mc/mark-all-like-this-dwim`: Tries to be smart about marking everything you want. Can be pressed multiple times.
  60. ;; ### Special
  61. ;; - `set-rectangular-region-anchor`: Think of this one as `set-mark` except you're marking a rectangular region.
  62. ;; - `mc/mark-sgml-tag-pair`: Mark the current opening and closing tag.
  63. ;; - `mc/insert-numbers`: Insert increasing numbers for each cursor, top to bottom.
  64. ;; - `mc/insert-letters`: Insert increasing letters for each cursor, top to bottom.
  65. ;; - `mc/sort-regions`: Sort the marked regions alphabetically.
  66. ;; - `mc/reverse-regions`: Reverse the order of the marked regions.
  67. ;; ## Tips and tricks
  68. ;; - To get out of multiple-cursors-mode, press `<return>` or `C-g`. The latter will
  69. ;; first disable multiple regions before disabling multiple cursors. If you want to
  70. ;; insert a newline in multiple-cursors-mode, use `C-j`.
  71. ;;
  72. ;; - Sometimes you end up with cursors outside of your view. You can
  73. ;; scroll the screen to center on each cursor with `C-v` and `M-v`.
  74. ;;
  75. ;; - Try pressing `mc/mark-next-like-this` with no region selected. It will just add a cursor
  76. ;; on the next line.
  77. ;;
  78. ;; - Try pressing `mc/mark-next-like-this-word` or
  79. ;; `mc/mark-next-like-this-symbol` with no region selected. It will
  80. ;; mark the symbol and add a cursor at the next occurance
  81. ;;
  82. ;; - Try pressing `mc/mark-all-like-this-dwim` on a tagname in html-mode.
  83. ;;
  84. ;; - Notice that the number of cursors active can be seen in the modeline.
  85. ;;
  86. ;; - If you get out of multiple-cursors-mode and yank - it will yank only
  87. ;; from the kill-ring of main cursor. To yank from the kill-rings of
  88. ;; every cursor use yank-rectangle, normally found at C-x r y.
  89. ;;
  90. ;; - You can use `mc/reverse-regions` with nothing selected and just one cursor.
  91. ;; It will then flip the sexp at point and the one below it.
  92. ;;
  93. ;; - If you would like to keep the global bindings clean, and get custom keybindings
  94. ;; when the region is active, you can try [region-bindings-mode](https://github.com/fgallina/region-bindings-mode).
  95. ;;
  96. ;; BTW, I highly recommend adding `mc/mark-next-like-this` to a key binding that's
  97. ;; right next to the key for `er/expand-region`.
  98. ;; ### Binding mouse events
  99. ;; To override a mouse event, you will likely have to also unbind the
  100. ;; `down-mouse` part of the event. Like this:
  101. ;;
  102. ;; (global-unset-key (kbd "M-<down-mouse-1>"))
  103. ;; (global-set-key (kbd "M-<mouse-1>") 'mc/add-cursor-on-click)
  104. ;;
  105. ;; Or you can do like me and find an unused, but less convenient, binding:
  106. ;;
  107. ;; (global-set-key (kbd "C-S-<mouse-1>") 'mc/add-cursor-on-click)
  108. ;; ## Unknown commands
  109. ;; Multiple-cursors uses two lists of commands to know what to do: the run-once list
  110. ;; and the run-for-all list. It comes with a set of defaults, but it would be beyond silly
  111. ;; to try and include all the known Emacs commands.
  112. ;; So that's why multiple-cursors occasionally asks what to do about a command. It will
  113. ;; then remember your choice by saving it in `~/.emacs.d/.mc-lists.el`. You can change
  114. ;; the location with:
  115. ;; (setq mc/list-file "/my/preferred/file")
  116. ;; ## Known limitations
  117. ;; * isearch-forward and isearch-backward aren't supported with multiple cursors.
  118. ;; You should feel free to add a simplified version that can work with it.
  119. ;; * Commands run with `M-x` won't be repeated for all cursors.
  120. ;; * All key bindings that refer to lambdas are always run for all cursors. If you
  121. ;; need to limit it, you will have to give it a name.
  122. ;; * Redo might screw with your cursors. Undo works very well.
  123. ;; ## Contribute
  124. ;; Yes, please do. There's a suite of tests, so remember to add tests for your
  125. ;; specific feature, or I might break it later.
  126. ;; You'll find the repo at:
  127. ;; https://github.com/magnars/multiple-cursors.el
  128. ;; To fetch the test dependencies:
  129. ;; $ cd /path/to/multiple-cursors
  130. ;; $ git submodule update --init
  131. ;; Run the tests with:
  132. ;; $ ./util/ecukes/ecukes --graphical
  133. ;; ## Contributors
  134. ;; * [Takafumi Arakaki](https://github.com/tkf) made .mc-lists.el diff friendly
  135. ;; * [Marco Baringer](https://github.com/segv) contributed looping to mc/cycle and adding cursors without region for mark-more.
  136. ;; * [Ivan Andrus](https://github.com/gvol) added showing number of cursors in mode-line
  137. ;; * [Fuco](https://github.com/Fuco1) added the first version of `mc/mark-all-like-this-dwim`
  138. ;; Thanks!
  139. ;;; Code:
  140. (defgroup multiple-cursors nil
  141. "Multiple cursors for emacs."
  142. :group 'editing)
  143. (require 'mc-edit-lines)
  144. (require 'mc-cycle-cursors)
  145. (require 'mc-mark-more)
  146. (require 'mc-mark-pop)
  147. (require 'rectangular-region-mode)
  148. (require 'mc-separate-operations)
  149. (require 'mc-hide-unmatched-lines-mode)
  150. (provide 'multiple-cursors)
  151. ;;; multiple-cursors.el ends here