-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-multi-cursors.el
142 lines (133 loc) · 5.27 KB
/
init-multi-cursors.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
(use-package evil-multiedit
:demand t
;; :commands (evil-multiedit-match-all evil-multiedit-match-symbol-and-next evil-multiedit-match-symbol-and-prev)
:init
(setq evil-multiedit-use-symbols t)
;; Ex command that allows you to invoke evil-multiedit with a regular expression, e.g.
(evil-ex-define-cmd "ie[dit]" 'evil-multiedit-ex-match)
(general-define-key
:states '(normal visual)
"R" 'jester/evil-multiedit-match-all
"C-n" 'evil-multiedit-match-and-next
"C-p" 'evil-multiedit-match-and-prev)
(defun jester/evil-multiedit-match-all ()
"Match all occurences. with prefix arg, exclude those in comments or strings."
(interactive)
(evil-multiedit-match-all)
(when current-prefix-arg
(save-excursion
(let ((pos))
(iedit-goto-first-occurrence)
(setq pos (point))
(unless (jester/in-expression-area-p)
(evil-multiedit-toggle-or-restrict-region))
(while (evil-multiedit-next)
(unless (jester/in-expression-area-p)
(evil-multiedit-toggle-or-restrict-region)))))))
:config
(general-define-key
:states '(normal)
:keymaps 'evil-multiedit-mode-map
"<return>" 'evil-multiedit-toggle-or-restrict-region
"<tab>" 'evil-multiedit-next
"<S-tab>" 'evil-multiedit-prev
"C-n" 'evil-multiedit-match-and-next
"C-p" 'evil-multiedit-match-and-prev)
(general-define-key
:states '(insert emacs)
:keymaps 'evil-multiedit-mode-map
"<return>" 'newline
"<tab>" 'jester/start-complete
"C-a" 'evil-multiedit-beginning-of-line
"C-e" 'evil-multiedit-end-of-line)
)
(use-package evil-mc
:init
;; don't bind any keys
(setq evil-mc-key-map (make-sparse-keymap))
;; (general-define-key
;; :states '(normal visual)
;; "K" 'evil-mc-make-all-cursors
;; "M-n" 'evil-mc-make-and-goto-next-match
;; "M-p" 'evil-mc-make-and-goto-prev-match
;; "M-j" 'evil-mc-make-cursor-move-next-line
;; "M-k" 'evil-mc-make-cursor-move-prev-line
;; "<M-return>" 'jester/evil-mc-toggle-cursors-pause)
(defun jester/evil-mc-toggle-cursors-pause ()
"Toggle between pausing or resuming all cursors."
(interactive)
(if evil-mc-frozen
(evil-mc-resume-cursors)
(evil-mc-pause-cursors)))
:commands (evil-mc-make-all-cursors evil-mc-make-cursor-here
evil-mc-make-cursor-move-next-line evil-mc-make-cursor-move-prev-line
evil-mc-make-and-goto-next-match evil-mc-make-and-goto-prev-match)
:config
(advice-add 'evil-force-normal-state :after 'evil-mc-undo-all-cursors)
;; FIXME activate mode after using some command may be buggy, but it's the only way to lazy-load evil-mc now.
(global-evil-mc-mode 1)
;; Add custom commands to whitelisted commands
;; TODO not work
(dolist (fn '(string-inflection-kebab-case
string-inflection-camelcase string-inflection-lower-camelcase
jester/expand-yas-or-complete-company))
(push (cons fn '((:default . evil-mc-execute-default-call)))
evil-mc-custom-known-commands)))
;; https://github.com/abo-abo/hydra/wiki/multiple-cursors
(use-package multiple-cursors
:init
(general-define-key
:states '(emacs)
"M-j" 'mc/mark-next-like-this
"M-k" 'mc/mark-previous-like-this
"M-J" 'mc/skip-to-next-like-this
"M-K" 'mc/skip-to-previous-like-this
"M-n" 'mc/mark-next-like-this-symbol
"M-p" 'mc/mark-previous-like-this-symbol
"M-N" 'mc/skip-to-next-like-this
"M-P" 'mc/skip-to-previous-like-this)
(general-define-key
:states '(normal visual)
"M-j" 'jester/emacs-state-and-press
"M-k" 'jester/emacs-state-and-press
"M-n" 'jester/emacs-state-and-press
"M-p" 'jester/emacs-state-and-press)
(general-define-key
:states '(emacs)
:definer 'minor-mode
:keymaps 'multiple-cursors-mode
"<escape>" 'mc/keyboard-quit)
(general-define-key :keymaps 'mc/keymap "<return>" nil))
;; TODO kinda works, but not totally
(defun jester/emacs-state-and-press ()
"Enter emacs state, find the command for the pressed keys in emacs state, call it."
(interactive)
(evil-emacs-state)
(message "%s|%s" (evil-emacs-state-p) (this-command-keys))
(general-key (this-command-keys)))
(defhydra hydra-multiple-cursors (:hint nil :exit nil)
"
Up^^ Down^^ Miscellaneous % 2(mc/num-cursors) cursor%s(if (> (mc/num-cursors) 1) \"s\" \"\")
------------------------------------------------------------------
[_p_] Next [_n_] Next [_l_] Edit lines [_0_] Insert numbers
[_P_] Skip [_N_] Skip [_a_] Mark all [_A_] Insert letters
[_M-p_] Unmark [_M-n_] Unmark [_s_] Search [_q_] Quit
[_|_] Align with input CHAR [Click] Cursor at point"
("l" mc/edit-lines :exit t)
("a" mc/mark-all-like-this :exit t)
("n" mc/mark-next-like-this)
("N" mc/skip-to-next-like-this)
("M-n" mc/unmark-next-like-this)
("p" mc/mark-previous-like-this)
("P" mc/skip-to-previous-like-this)
("M-p" mc/unmark-previous-like-this)
("|" mc/vertical-align)
("s" mc/mark-all-in-region-regexp :exit t)
("0" mc/insert-numbers :exit t)
("A" mc/insert-letters :exit t)
("<mouse-1>" mc/add-cursor-on-click)
;; Help with click recognition in this hydra
("<down-mouse-1>" ignore)
("<drag-mouse-1>" ignore)
("q" nil))
(provide 'init-multi-cursors)