-
Notifications
You must be signed in to change notification settings - Fork 37
/
evil-mc-vars.el
342 lines (267 loc) · 10.3 KB
/
evil-mc-vars.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
;;; evil-mc-vars.el --- Variables for evil-mc -*- lexical-binding: t; -*-
;;; Commentary:
;; This file contains variables used by evil-mc
(require 'evil-mc-known-commands)
(require 'evil-states)
;;; Code:
(defgroup evil-mc nil
"Multiple cursors implementation for evil mode."
:prefix "evil-mc-"
:group 'evil)
(defun evil-mc-cursor-color (state-cursor)
"Get the cursor color for a STATE-CURSOR"
(cond ((and (listp state-cursor) (stringp (car state-cursor)))
(car state-cursor))
((not (eq (face-attribute 'cursor :background) 'unspecified))
(face-attribute 'cursor :background))
(t "gray")))
(defface evil-mc-cursor-default-face
'((t (:inherit cursor :inverse-video nil)))
"The face used for fake cursors."
:group 'evil-mc)
(defface evil-mc-region-face
'((t :inherit region))
"The face used for fake regions"
:group 'evil-mc)
(defface evil-mc-cursor-bar-face
`((t (:height 1 :background ,(evil-mc-cursor-color evil-insert-state-cursor))))
"The face used for fake cursors if the cursor-type is bar"
:group 'evil-mc)
(defface evil-mc-cursor-hbar-face
`((t (:underline (:color ,(evil-mc-cursor-color evil-replace-state-cursor)))))
"The face used for fake cursors if the cursor-type is horizontal bar"
:group 'evil-mc)
(defcustom evil-mc-cursor-overlay-priority 201
"The priority of the fake cursors overlay."
:type 'integer
:group 'evil-mc)
(defcustom evil-mc-region-overlay-priority 99
"The priority of the fake regions overlay."
:type 'integer
:group 'evil-mc)
(defcustom evil-mc-cursors-keymap-prefix "gr"
"The keybinding that is going to be used in normal and visual mode for
moving and manipulating cursors."
:type 'string
:group 'evil-mc)
(defvar evil-mc-cursor-variables
'((:default . (evil-exchange--overlays
evil-exchange--position
evil-jumper--window-jumps
evil-jumper--jumping
evil-jump-list
evil-last-paste
evil-last-register
evil-last-repeat
evil-markers-alist
evil-recording-repeat
evil-repeat-count
evil-repeat-info
evil-repeat-keys
evil-repeat-pos
evil-repeat-ring
evil-this-register
evil-was-yanked-without-register
kill-ring
kill-ring-yank-pointer
mark-evil-active
mark-ring
last-position
region
register-alist
undo-stack
undo-stack-pointer
temporary-goal-column))
(:replace . (evil-replace-alist))
(:dabbrev . (dabbrev--friend-buffer-list
dabbrev--last-buffer
dabbrev--last-buffer-found
dabbrev--last-table
dabbrev--last-abbrev-location
dabbrev--last-abbreviation
dabbrev--last-expansion
dabbrev--last-expansion-location
dabbrev--last-direction)))
"Names of variables tracked per cursor during the execution of a command.")
(evil-define-local-var evil-mc-cursor-state nil
"The state of the real cursor saved while there are active cursors.")
(evil-define-local-var evil-mc-executing-command nil
"True when executing a command for all cursors.")
(evil-define-local-var evil-mc-recording-command nil
"True when recording `this-command' data.")
(evil-define-local-var evil-mc-cursor-current-face nil
"The face to use when making fake cursors.")
(evil-define-local-var evil-mc-cursor-list nil
"The list of current fake cursors.")
(evil-define-local-var evil-mc-frozen nil
"If true the fake cursors are frozen.")
(evil-define-local-var evil-mc-pattern nil
"The current pattern.")
(evil-define-local-var evil-mc-command nil
"The current command to be executed.")
(evil-define-local-var evil-mc-command-count nil
"The count for the current command")
(evil-define-local-var evil-mc-temporary-undo nil
"Variable for saving the `buffer-undo-list' temporarily.")
(evil-define-local-var evil-mc-executing-debug nil
"If true display debug messages during the execution of a command.")
(evil-define-local-var evil-mc-recording-debug nil
"If true display debug messages during the recording of a command.")
(evil-define-local-var evil-mc-silence-errors t
"If true don't display messages when failing to execute a command.")
(evil-define-local-var evil-mc-paused-modes nil
"List of temporarily disabled minor modes.")
(evil-define-local-var evil-mc-one-cursor-show-mode-line-text t
"Show mode line text when there's only one cursor.")
(evil-define-local-var evil-mc-mode-line-text-paused t
"Show (paused) text in the mode line.")
(evil-define-local-var evil-mc-mode-line-text-inverse-colors t
"Show mode line text with inverse colors.")
(evil-define-local-var evil-mc-mode-line-text-cursor-color t
"Show mode line text with the cursor color.")
(defun evil-mc-known-command-p (cmd)
"True if CMD is a supported command."
(or (not (null (assq cmd evil-mc-known-commands)))
(not (null (assq cmd evil-mc-custom-known-commands)))
(eq (evil-get-command-property cmd :repeat) 'motion)))
(defun evil-mc-has-cursors-p ()
"True if there are any fake cursors."
(not (null evil-mc-cursor-list)))
(defun evil-mc-has-command-p ()
"True if there is data saved for the current command."
(not (null evil-mc-command)))
(defun evil-mc-has-pattern-p ()
"True if there is a saved pattern."
(not (null evil-mc-pattern)))
(defun evil-mc-silence-errors-p ()
"True if logging of command execution errors is disabled."
(eq evil-mc-silence-errors t))
(defun evil-mc-silence-errors-on ()
"Silence command failure errors."
(interactive)
(setq evil-mc-silence-errors t))
(defun evil-mc-silence-errors-off ()
"Display command failure errors."
(interactive)
(setq evil-mc-silence-errors nil))
(defun evil-mc-executing-command-p ()
"True when executing a command for all fake cursors."
(eq evil-mc-executing-command t))
(defun evil-mc-recording-command-p ()
"True when recording a command."
(eq evil-mc-recording-command t))
(defun evil-mc-executing-debug-p ()
"True if debugging is enabled during the execution of a command."
(eq evil-mc-executing-debug t))
(defun evil-mc-recording-debug-p ()
"True if debugging is enabled during the recording of a command."
(eq evil-mc-recording-debug t))
(defun evil-mc-debug (state executing recording)
"Enable debugging according to STATE for command EXECUTING or RECORDING or both."
(when recording (setq evil-mc-recording-debug state))
(when executing (setq evil-mc-executing-debug state)))
(defun evil-mc-executing-debug-on ()
"Turn debug on while executing a command."
(interactive)
(evil-mc-debug t t nil))
(defun evil-mc-executing-debug-off ()
"Turn debug off while executing a command."
(interactive)
(evil-mc-debug nil t nil))
(defun evil-mc-recording-debug-on ()
"Turn debug on while recording a command."
(interactive)
(evil-mc-debug t nil t))
(defun evil-mc-recording-debug-off ()
"Turn debug off while recording a command."
(interactive)
(evil-mc-debug nil nil t))
(defun evil-mc-all-debug-on ()
"Turn all debug on."
(interactive)
(evil-mc-debug t t t))
(defun evil-mc-all-debug-off ()
"Turn all debug off."
(interactive)
(evil-mc-debug nil t t))
(defun evil-mc-print-pattern ()
"Print the curent pattern."
(interactive)
(evil-mc-message "%s" evil-mc-pattern))
(defun evil-mc-print-cursor-list ()
"Return the cursor list."
(interactive)
(if evil-mc-cursor-list
(evil-mc-message "%s: %s" (length evil-mc-cursor-list) evil-mc-cursor-list)
(evil-mc-message "No cursors found")))
(defun evil-mc-print-command ()
"Print the information saved for the current command."
(interactive)
(evil-mc-message "%s" evil-mc-command))
(defun evil-mc-frozen-p ()
"True if the fake cursors are frozen."
(eq evil-mc-frozen t))
(defun evil-mc-pause-cursors ()
"Freeze the fake cursors."
(interactive)
(setq evil-mc-frozen t)
(force-mode-line-update))
(defun evil-mc-resume-cursors ()
"Unfreeze the fake cursors."
(interactive)
(setq evil-mc-frozen nil)
(force-mode-line-update))
(defun evil-mc-clear-pattern ()
"Clear the currently saved pattern."
(setq evil-mc-pattern nil))
(defun evil-mc-clear-command ()
"Clear the current command."
(setq evil-mc-command nil))
(defun evil-mc-clear-command-count ()
"Clear the current command count."
(setq evil-mc-command-count nil))
(defun evil-mc-clear-cursor-list ()
"Clear the cursor list."
(setq evil-mc-cursor-list nil))
(defun evil-mc-update-cursor-list (cursors)
"Updates the `evil-mc-cursor-list' to CURSORS."
(setq evil-mc-cursor-list cursors))
(defun evil-mc-clear-executing-command ()
"Clear the `evil-mc-executing-command' variable."
(setq evil-mc-executing-command nil))
(defun evil-mc-clear-recording-command ()
"Clear the `evil-mc-recording-command' variable."
(setq evil-mc-recording-command nil))
(defun evil-mc-clear-executing-debug ()
"Clear the `evil-mc-executing-debug' variable."
(setq evil-mc-executing-debug nil))
(defun evil-mc-clear-recording-debug ()
"Clear the `evil-mc-recording-debug' variable."
(setq evil-mc-recording-debug nil))
(defun evil-mc-clear-paused-modes ()
"Clear the `evil-mc-paused-modes' variable."
(setq evil-mc-paused-modes nil))
(defun evil-mc-clear-cursor-state ()
"Clear the `evil-mc-cursor-state' variable."
(setq evil-mc-cursor-state nil))
(defun evil-mc-get-pattern ()
"Return the current pattern."
(when evil-mc-pattern (car evil-mc-pattern)))
(defun evil-mc-get-pattern-text ()
"Return the current pattern text."
(when evil-mc-pattern (car (evil-mc-get-pattern))))
(defun evil-mc-get-pattern-start ()
"Return the current pattern start position."
(when evil-mc-pattern (nth 1 evil-mc-pattern)))
(defun evil-mc-get-pattern-end ()
"Return the current pattern end position."
(when evil-mc-pattern (nth 2 evil-mc-pattern)))
(defun evil-mc-get-pattern-length ()
"Return the current pattern length."
(when evil-mc-pattern
(- (evil-mc-get-pattern-end) (evil-mc-get-pattern-start))))
(defun evil-mc-get-cursor-count ()
"Return the count of active cursors."
(1+ (length evil-mc-cursor-list)))
(provide 'evil-mc-vars)
;;; evil-mc-vars.el ends here