Add magnars's multiple-cursors backend

This commit is contained in:
bb2020 2019-05-24 21:30:10 +03:00 committed by duianto
parent b4907d0540
commit d68c6311d6
3 changed files with 89 additions and 5 deletions

View File

@ -1775,6 +1775,17 @@ Other:
**** Multiple Cursors
- Disabled Spacemacs paste transient state when pasting to avoid pasting issue
when there are more than one cursor (thanks to braham-snyder)
- Added magnars's multiple-cursors package as a new backend (thanks to bb2020)
- ~SPC s m a~ =mc/mark-all-dwim=
- ~SPC s m b~ =mc/mark-all-like-this=
- ~SPC s m m~ =mc/mark-more-like-this-extended=
- ~SPC s m r~ =mc/edit-lines=
- ~SPC s m s l~ =mc/insert-letters=
- ~SPC s m s m~ =mc/mark-sgml-tag-pair=
- ~SPC s m s n~ =mc/insert-numbers=
- ~SPC s m s r~ =set-rectangular-region-anchor=
- ~SPC s m s s~ =mc/sort-regions=
- ~SPC s m s t~ =mc/reverse-regions=
**** Neotree
- Made neotree an optional instead of a default layer
- Move neotree to its own layer in new +filetree folder

View File

@ -9,6 +9,9 @@
- [[#configuration][Configuration]]
- [[#key-bindings][Key bindings]]
- [[#evil-mc][=evil-mc=]]
- [[#multiple-cursors][=multiple-cursors=]]
- [[#notes][Notes]]
- [[#multiple-cursors-1][=multiple-cursors=]]
* Description
** Features:
@ -20,12 +23,16 @@ add =multiple-cursors= to the existing =dotspacemacs-configuration-layers= list
file.
* Configuration
Currently the only supported backend is =evil-mc=, but more backends will be
available in the future.
Currently supported backends are:
- [[https://github.com/gabesoft/evil-mc][evil-mc]] (default)
- [[https://github.com/magnars/multiple-cursors.el][mc]]
To set your choice of backend, configure =multiple-cursors-backend= variable of
the layer.
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers '(
(multiple-cursors :variables multiple-cursors-backend 'evil-mc))
(multiple-cursors :variables multiple-cursors-backend 'mc))
#+END_SRC
* Key bindings
@ -60,3 +67,44 @@ For easy navigation you also have the following:
| ~C-t~ | evil-mc-skip-and-goto-next-match |
| ~C-M-j~ | evil-mc-make-cursor-move-next-line |
| ~C-M-k~ | evil-mc-make-cursor-move-prev-line |
** =multiple-cursors=
The =multiple-cursors= backend provides the following key bindings to
insert new cursors:
| Key binding | Description |
|-------------+---------------------------------|
| ~SPC s m a~ | mc/mark-all-dwim |
| ~SPC s m b~ | mc/mark-all-like-this |
| ~SPC s m m~ | mc/mark-more-like-this-extended |
| ~SPC s m r~ | mc/edit-lines |
These special bindings manipulate text under cursors:
| Key binding | Description |
|---------------+-------------------------------|
| ~SPC s m s l~ | mc/insert-letters |
| ~SPC s m s m~ | mc/mark-sgml-tag-pair |
| ~SPC s m s n~ | mc/insert-numbers |
| ~SPC s m s r~ | set-rectangular-region-anchor |
| ~SPC s m s s~ | mc/sort-regions |
| ~SPC s m s t~ | mc/reverse-regions |
* Notes
** =multiple-cursors=
Some commands executed during =multiple-cursors= enabled may lead Emacs to go frenzy.
Commands like window manipulation will be executed multiple times if =mc= is active.
Not all Emacs commands may be compatible with =mc=.
To run interactive ~M-x~ commands with =mc=, run the command first. This will result
with application of the command to the leading cursor. Then press =C-:= to apply the
command to consequtive cursors. If this is not the case or you want a command to be
executed only once, configure the =mc/cmds-to-run-once= variable of the layer like
in the following example.
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers '(
(multiple-cursors :variables
multiple-cursors-backend 'mc
mc/cmds-to-run-once '(upcase-region))))
#+END_SRC

View File

@ -13,8 +13,8 @@
(setq multiple-cursors-packages
'(
evil-mc
))
(evil-mc :toggle (eq multiple-cursors-backend 'evil-mc))
(multiple-cursors :toggle (eq multiple-cursors-backend 'mc))))
(defun multiple-cursors/init-evil-mc ()
(use-package evil-mc
@ -34,3 +34,28 @@
(define-key state-map (car keybinding) (cdr keybinding))))
(add-hook 'prog-mode-hook 'turn-on-evil-mc-mode)
(add-hook 'text-mode-hook 'turn-on-evil-mc-mode))))
(defun multiple-cursors/init-multiple-cursors ()
(use-package multiple-cursors
:defer t
:init
(progn
(spacemacs/declare-prefix "sm" "multiple-cursors")
(spacemacs/declare-prefix "sms" "specials")
(spacemacs/set-leader-keys
"smm" 'mc/mark-more-like-this-extended
"smr" 'mc/edit-lines
"smb" 'mc/mark-all-like-this
"sma" 'mc/mark-all-dwim
"smss" 'mc/sort-regions
"smsr" 'set-rectangular-region-anchor
"smsm" 'mc/mark-sgml-tag-pair
"smsn" 'mc/insert-numbers
"smsl" 'mc/insert-letters
"smst" 'mc/reverse-regions)
(setq mc/always-run-for-all t)
(with-eval-after-load 'multiple-cursors-core
(add-to-list 'mc/cmds-to-run-once 'helm-M-x)
(add-to-list 'mc/cmds-to-run-once 'counsel-M-x)
(add-to-list 'mc/cmds-to-run-once 'spacemacs/default-pop-shell)
))))