update mc
[emacs.git] / .emacs.d / elisp / multiple-cursors / multiple-cursors-core.el
1 ;;; multiple-cursors-core.el --- An experiment in multiple cursors for emacs.
2
3 ;; Copyright (C) 2012 Magnar Sveen
4
5 ;; Author: Magnar Sveen <magnars@gmail.com>
6 ;; Keywords: editing cursors
7
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
12
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21 ;;; Commentary:
22
23 ;; This file contains the core functionality of multiple-cursors.
24 ;; Please see multiple-cursors.el for more commentary.
25
26 ;;; Code:
27
28 (require 'cl)
29
30 (require 'rect)
31
32 (defface mc/cursor-face
33 '((t (:inverse-video t)))
34 "The face used for fake cursors"
35 :group 'multiple-cursors)
36
37 (defface mc/region-face
38 '((t :inherit region))
39 "The face used for fake regions"
40 :group 'multiple-cursors)
41
42 (defmacro mc/add-fake-cursor-to-undo-list (&rest forms)
43 "Make sure point is in the right place when undoing"
44 (let ((uc (make-symbol "undo-cleaner")))
45 `(let ((,uc (cons 'apply (cons 'deactivate-cursor-after-undo (list id)))))
46 (setq buffer-undo-list (cons ,uc buffer-undo-list))
47 ,@forms
48 (if (eq ,uc (car buffer-undo-list)) ;; if nothing has been added to the undo-list
49 (setq buffer-undo-list (cdr buffer-undo-list)) ;; then pop the cleaner right off again
50 (setq buffer-undo-list ;; otherwise add a function to activate this cursor
51 (cons (cons 'apply (cons 'activate-cursor-for-undo (list id))) buffer-undo-list))))))
52
53 (defun mc/all-fake-cursors (&optional start end)
54 (remove-if-not 'mc/fake-cursor-p
55 (overlays-in (or start (point-min))
56 (or end (point-max)))))
57
58 (defmacro mc/for-each-fake-cursor (&rest forms)
59 "Runs the body for each fake cursor, bound to the name cursor"
60 `(mapc #'(lambda (cursor) ,@forms)
61 (mc/all-fake-cursors)))
62
63 (defmacro mc/save-excursion (&rest forms)
64 "Saves and restores all the state that multiple-cursors cares about."
65 (let ((cs (make-symbol "current-state")))
66 `(let ((,cs (mc/store-current-state-in-overlay
67 (make-overlay (point) (point) nil nil t))))
68 (overlay-put ,cs 'type 'original-cursor)
69 (save-excursion ,@forms)
70 (mc/pop-state-from-overlay ,cs))))
71
72 (defun mc--compare-by-overlay-start (o1 o2)
73 (< (overlay-start o1) (overlay-start o2)))
74
75 (defmacro mc/for-each-cursor-ordered (&rest forms)
76 "Runs the body for each cursor, fake and real, bound to the name cursor"
77 (let ((rci (make-symbol "real-cursor-id")))
78 `(let ((,rci (overlay-get (mc/create-fake-cursor-at-point) 'mc-id)))
79 (mapc #'(lambda (cursor)
80 (when (mc/fake-cursor-p cursor)
81 ,@forms))
82 (sort (overlays-in (point-min) (point-max)) 'mc--compare-by-overlay-start))
83 (mc/pop-state-from-overlay (mc/cursor-with-id ,rci)))))
84
85 (defmacro mc/save-window-scroll (&rest forms)
86 "Saves and restores the window scroll position"
87 (let ((p (make-symbol "p"))
88 (s (make-symbol "start"))
89 (h (make-symbol "hscroll")))
90 `(let ((,p (set-marker (make-marker) (point)))
91 (,s (set-marker (make-marker) (window-start)))
92 (,h (window-hscroll)))
93 ,@forms
94 (goto-char ,p)
95 (set-window-start nil ,s t)
96 (set-window-hscroll nil ,h)
97 (set-marker ,p nil)
98 (set-marker ,s nil))))
99
100 (defun mc/make-cursor-overlay-at-eol (pos)
101 "Create overlay to look like cursor at end of line."
102 (let ((overlay (make-overlay pos pos nil nil nil)))
103 (overlay-put overlay 'after-string (propertize " " 'face 'mc/cursor-face))
104 overlay))
105
106 (defun mc/make-cursor-overlay-inline (pos)
107 "Create overlay to look like cursor inside text."
108 (let ((overlay (make-overlay pos (1+ pos) nil nil nil)))
109 (overlay-put overlay 'face 'mc/cursor-face)
110 overlay))
111
112 (defun mc/make-cursor-overlay-at-point ()
113 "Create overlay to look like cursor.
114 Special case for end of line, because overlay over a newline
115 highlights the entire width of the window."
116 (if (eolp)
117 (mc/make-cursor-overlay-at-eol (point))
118 (mc/make-cursor-overlay-inline (point))))
119
120 (defun mc/make-region-overlay-between-point-and-mark ()
121 "Create overlay to look like active region."
122 (let ((overlay (make-overlay (mark) (point) nil nil t)))
123 (overlay-put overlay 'face 'mc/region-face)
124 (overlay-put overlay 'type 'additional-region)
125 overlay))
126
127 (defvar mc/cursor-specific-vars '(transient-mark-mode
128 kill-ring
129 kill-ring-yank-pointer
130 mark-ring
131 mark-active
132 yank-undo-function
133 kill-ring-yank-pointer
134 autopair-action
135 autopair-wrap-action
136 er/history)
137 "A list of vars that need to be tracked on a per-cursor basis.")
138
139 (defun mc/store-current-state-in-overlay (o)
140 "Store relevant info about point and mark in the given overlay."
141 (overlay-put o 'point (set-marker (make-marker) (point)))
142 (overlay-put o 'mark (set-marker (make-marker) (mark)))
143 (dolist (var mc/cursor-specific-vars)
144 (when (boundp var) (overlay-put o var (symbol-value var))))
145 o)
146
147 (defun mc/restore-state-from-overlay (o)
148 "Restore point and mark from stored info in the given overlay."
149 (goto-char (overlay-get o 'point))
150 (set-marker (mark-marker) (overlay-get o 'mark))
151 (dolist (var mc/cursor-specific-vars)
152 (when (boundp var) (set var (overlay-get o var)))))
153
154 (defun mc/remove-fake-cursor (o)
155 "Delete overlay with state, including dependent overlays and markers."
156 (set-marker (overlay-get o 'point) nil)
157 (set-marker (overlay-get o 'mark) nil)
158 (mc/delete-region-overlay o)
159 (delete-overlay o))
160
161 (defun mc/pop-state-from-overlay (o)
162 "Restore the state stored in given overlay and then remove the overlay."
163 (mc/restore-state-from-overlay o)
164 (mc/remove-fake-cursor o))
165
166 (defun mc/delete-region-overlay (o)
167 "Remove the dependent region overlay for a given cursor overlay."
168 (ignore-errors
169 (delete-overlay (overlay-get o 'region-overlay))))
170
171 (defvar mc--current-cursor-id 0
172 "Var to store increasing id of fake cursors, used to keep track of them for undo.")
173
174 (defun mc/create-cursor-id ()
175 "Returns a unique cursor id"
176 (incf mc--current-cursor-id))
177
178 (defun mc/create-fake-cursor-at-point (&optional id)
179 "Add a fake cursor and possibly a fake active region overlay based on point and mark.
180 Saves the current state in the overlay to be restored later."
181 (let ((overlay (mc/make-cursor-overlay-at-point)))
182 (overlay-put overlay 'mc-id (or id (mc/create-cursor-id)))
183 (overlay-put overlay 'type 'fake-cursor)
184 (overlay-put overlay 'priority 100)
185 (mc/store-current-state-in-overlay overlay)
186 (when (use-region-p)
187 (overlay-put overlay 'region-overlay
188 (mc/make-region-overlay-between-point-and-mark)))
189 overlay))
190
191 (defun mc/execute-command (cmd)
192 "Run command, simulating the parts of the command loop that makes sense for fake cursors."
193 (setq this-command cmd)
194 (run-hooks 'pre-command-hook)
195 (unless (eq this-command 'ignore)
196 (call-interactively cmd))
197 (run-hooks 'post-command-hook)
198 (when deactivate-mark (deactivate-mark)))
199
200 (defvar mc--executing-command-for-fake-cursor nil)
201
202 (defun mc/execute-command-for-fake-cursor (cmd cursor)
203 (let ((mc--executing-command-for-fake-cursor t)
204 (id (overlay-get cursor 'mc-id))
205 (annoying-arrows-mode nil)
206 (smooth-scroll-margin 0))
207 (mc/add-fake-cursor-to-undo-list
208 (mc/pop-state-from-overlay cursor)
209 (ignore-errors
210 (mc/execute-command cmd)
211 (mc/create-fake-cursor-at-point id)))))
212
213 (defun mc/execute-command-for-all-fake-cursors (cmd)
214 "Calls CMD interactively for each cursor.
215 It works by moving point to the fake cursor, setting
216 up the proper environment, and then removing the cursor.
217 After executing the command, it sets up a new fake
218 cursor with updated info."
219 (mc/save-excursion
220 (mc/save-window-scroll
221 (mc/for-each-fake-cursor
222 (save-excursion
223 (mc/execute-command-for-fake-cursor cmd cursor)))))
224 (mc--reset-read-prompts))
225
226 (defun mc/execute-command-for-all-cursors (cmd)
227 "Calls CMD interactively for the real cursor and all fakes."
228 (call-interactively cmd)
229 (mc/execute-command-for-all-fake-cursors cmd))
230
231 ;; Intercept some reading commands so you won't have to
232 ;; answer them for every single cursor
233
234 (defadvice read-char (around mc-support activate)
235 (if (not multiple-cursors-mode)
236 ad-do-it
237 (unless mc--read-char
238 (setq mc--read-char ad-do-it))
239 (setq ad-return-value mc--read-char)))
240
241 (defadvice read-quoted-char (around mc-support activate)
242 (if (not multiple-cursors-mode)
243 ad-do-it
244 (unless mc--read-quoted-char
245 (setq mc--read-quoted-char ad-do-it))
246 (setq ad-return-value mc--read-quoted-char)))
247
248 (defun mc--reset-read-prompts ()
249 (setq mc--read-char nil)
250 (setq mc--read-quoted-char nil))
251
252 (mc--reset-read-prompts)
253
254 (defun mc/fake-cursor-p (o)
255 "Predicate to check if an overlay is a fake cursor"
256 (eq (overlay-get o 'type) 'fake-cursor))
257
258 (defun mc/cursor-with-id (id)
259 "Find the first cursor with the given id, or nil"
260 (find-if #'(lambda (o) (and (mc/fake-cursor-p o)
261 (= id (overlay-get o 'mc-id))))
262 (overlays-in (point-min) (point-max))))
263
264 (defvar mc--stored-state-for-undo nil
265 "Variable to keep the state of the real cursor while undoing a fake one")
266
267 (defun activate-cursor-for-undo (id)
268 "Called when undoing to temporarily activate the fake cursor which action is being undone."
269 (let ((cursor (mc/cursor-with-id id)))
270 (when cursor
271 (setq mc--stored-state-for-undo (mc/store-current-state-in-overlay
272 (make-overlay (point) (point) nil nil t)))
273 (mc/pop-state-from-overlay cursor))))
274
275 (defun deactivate-cursor-after-undo (id)
276 "Called when undoing to reinstate the real cursor after undoing a fake one."
277 (when mc--stored-state-for-undo
278 (mc/create-fake-cursor-at-point id)
279 (mc/pop-state-from-overlay mc--stored-state-for-undo)
280 (setq mc--stored-state-for-undo nil)))
281
282 (defun mc/prompt-for-inclusion-in-whitelist (original-command)
283 "Asks the user, then adds the command either to the once-list or the all-list."
284 (let ((all-p (y-or-n-p (format "Do %S for all cursors?" original-command))))
285 (if all-p
286 (add-to-list 'mc/cmds-to-run-for-all original-command)
287 (add-to-list 'mc/cmds-to-run-once original-command))
288 (mc/save-lists)
289 all-p))
290
291 (defun mc/num-cursors ()
292 "The number of cursors (real and fake) in the buffer."
293 (1+ (count-if 'mc/fake-cursor-p
294 (overlays-in (point-min) (point-max)))))
295
296 (defvar mc--this-command nil
297 "Used to store the original command being run.")
298 (make-variable-buffer-local 'mc--this-command)
299
300 (defun mc/make-a-note-of-the-command-being-run ()
301 "Used with pre-command-hook to store the original command being run.
302 Since that cannot be reliably determined in the post-command-hook.
303
304 Specifically, this-original-command isn't always right, because it could have
305 been remapped. And certain modes (cua comes to mind) will change their
306 remapping based on state. So a command that changes the state will afterwards
307 not be recognized through the command-remapping lookup."
308 (unless mc--executing-command-for-fake-cursor
309 (let ((cmd (or (command-remapping this-original-command)
310 this-original-command)))
311 (setq mc--this-command (and (not (eq cmd 'god-mode-self-insert))
312 cmd)))))
313
314 (defun mc/execute-this-command-for-all-cursors ()
315 "Wrap around `mc/execute-this-command-for-all-cursors-1' to protect hook."
316 (condition-case error
317 (mc/execute-this-command-for-all-cursors-1)
318 (error
319 (message "[mc] problem in `mc/execute-this-command-for-all-cursors': %s"
320 (error-message-string error)))))
321
322 ;; execute-kbd-macro should never be run for fake cursors. The real cursor will
323 ;; execute the keyboard macro, resulting in new commands in the command loop,
324 ;; and the fake cursors can pick up on those instead.
325 (defadvice execute-kbd-macro (around skip-fake-cursors activate)
326 (unless mc--executing-command-for-fake-cursor
327 ad-do-it))
328
329 (defun mc/execute-this-command-for-all-cursors-1 ()
330 "Used with post-command-hook to execute supported commands for all cursors.
331
332 It uses two lists of commands to know what to do: the run-once
333 list and the run-for-all list. If a command is in neither of these lists,
334 it will prompt for the proper action and then save that preference.
335
336 Some commands are so unsupported that they are even prevented for
337 the original cursor, to inform about the lack of support."
338 (unless mc--executing-command-for-fake-cursor
339
340 (if (eq 1 (mc/num-cursors)) ;; no fake cursors? disable mc-mode
341 (multiple-cursors-mode 0)
342 (when this-original-command
343 (let ((original-command (or mc--this-command
344 (command-remapping this-original-command)
345 this-original-command)))
346
347 ;; skip keyboard macros, since they will generate actual commands that are
348 ;; also run in the command loop - we'll handle those later instead.
349 (when (functionp original-command)
350
351 ;; if it's a lambda, we can't know if it's supported or not
352 ;; - so go ahead and assume it's ok, because we're just optimistic like that
353 (if (or (not (symbolp original-command))
354 ;; lambda registered by smartrep
355 (string-prefix-p "(" (symbol-name original-command)))
356 (mc/execute-command-for-all-fake-cursors original-command)
357
358 ;; smartrep `intern's commands into own obarray to help
359 ;; `describe-bindings'. So, let's re-`intern' here to
360 ;; make the command comparable by `eq'.
361 (setq original-command (intern (symbol-name original-command)))
362
363 ;; otherwise it's a symbol, and we can be more thorough
364 (if (get original-command 'mc--unsupported)
365 (message "%S is not supported with multiple cursors%s"
366 original-command
367 (get original-command 'mc--unsupported))
368 (when (and original-command
369 (not (memq original-command mc--default-cmds-to-run-once))
370 (not (memq original-command mc/cmds-to-run-once))
371 (or (memq original-command mc--default-cmds-to-run-for-all)
372 (memq original-command mc/cmds-to-run-for-all)
373 (mc/prompt-for-inclusion-in-whitelist original-command)))
374 (mc/execute-command-for-all-fake-cursors original-command))))))))))
375
376 (defun mc/remove-fake-cursors ()
377 "Remove all fake cursors.
378 Do not use to conclude editing with multiple cursors. For that
379 you should disable multiple-cursors-mode."
380 (mc/for-each-fake-cursor
381 (mc/remove-fake-cursor cursor)))
382
383 (defun mc/keyboard-quit ()
384 "Deactivate mark if there are any active, otherwise exit multiple-cursors-mode."
385 (interactive)
386 (if (not (use-region-p))
387 (multiple-cursors-mode 0)
388 (deactivate-mark)))
389
390 (defvar mc/keymap nil
391 "Keymap while multiple cursors are active.
392 Main goal of the keymap is to rebind C-g and <return> to conclude
393 multiple cursors editing.")
394 (unless mc/keymap
395 (setq mc/keymap (make-sparse-keymap))
396 (define-key mc/keymap (kbd "C-g") 'mc/keyboard-quit)
397 (define-key mc/keymap (kbd "<return>") 'multiple-cursors-mode)
398 (when (fboundp 'phi-search)
399 (define-key mc/keymap (kbd "C-s") 'phi-search))
400 (when (fboundp 'phi-search-backward)
401 (define-key mc/keymap (kbd "C-r") 'phi-search-backward)))
402
403 (defun mc--all-equal (list)
404 "Are all the items in LIST equal?"
405 (let ((first (car list))
406 (all-equal t))
407 (while (and all-equal list)
408 (setq all-equal (equal first (car list)))
409 (setq list (cdr list)))
410 all-equal))
411
412 (defun mc--kill-ring-entries ()
413 "Return the latest kill-ring entry for each cursor.
414 The entries are returned in the order they are found in the buffer."
415 (let (entries)
416 (mc/for-each-cursor-ordered
417 (setq entries (cons (car (overlay-get cursor 'kill-ring)) entries)))
418 (reverse entries)))
419
420 (defun mc--maybe-set-killed-rectangle ()
421 "Add the latest kill-ring entry for each cursor to killed-rectangle.
422 So you can paste it in later with `yank-rectangle'."
423 (let ((entries (mc--kill-ring-entries)))
424 (unless (mc--all-equal entries)
425 (setq killed-rectangle entries))))
426
427 (defvar mc/unsupported-minor-modes '(auto-complete-mode flyspell-mode)
428 "List of minor-modes that does not play well with multiple-cursors.
429 They are temporarily disabled when multiple-cursors are active.")
430
431 (defvar mc/temporarily-disabled-minor-modes nil
432 "The list of temporarily disabled minor-modes.")
433 (make-variable-buffer-local 'mc/temporarily-disabled-minor-modes)
434
435 (defun mc/temporarily-disable-minor-mode (mode)
436 "If MODE is available and turned on, remember that and turn it off."
437 (when (and (boundp mode) (eval mode))
438 (add-to-list 'mc/temporarily-disabled-minor-modes mode)
439 (funcall mode -1)))
440
441 (defun mc/temporarily-disable-unsupported-minor-modes ()
442 (mapc 'mc/temporarily-disable-minor-mode mc/unsupported-minor-modes))
443
444 (defun mc/enable-minor-mode (mode)
445 (funcall mode 1))
446
447 (defun mc/enable-temporarily-disabled-minor-modes ()
448 (mapc 'mc/enable-minor-mode mc/temporarily-disabled-minor-modes)
449 (setq mc/temporarily-disabled-minor-modes nil))
450
451 (defcustom mc/mode-line
452 `(" mc:" (:eval (format ,(propertize "%d" 'face 'font-lock-warning-face)
453 (mc/num-cursors))))
454 "What to display in the mode line while multiple-cursors-mode is active."
455 :group 'multiple-cursors)
456 (put 'mc/mode-line 'risky-local-variable t)
457
458 (define-minor-mode multiple-cursors-mode
459 "Mode while multiple cursors are active."
460 nil mc/mode-line mc/keymap
461 (if multiple-cursors-mode
462 (progn
463 (mc/temporarily-disable-unsupported-minor-modes)
464 (add-hook 'pre-command-hook 'mc/make-a-note-of-the-command-being-run nil t)
465 (add-hook 'post-command-hook 'mc/execute-this-command-for-all-cursors t t)
466 (run-hooks 'multiple-cursors-mode-enabled-hook))
467 (remove-hook 'post-command-hook 'mc/execute-this-command-for-all-cursors t)
468 (remove-hook 'pre-command-hook 'mc/make-a-note-of-the-command-being-run t)
469 (setq mc--this-command nil)
470 (mc--maybe-set-killed-rectangle)
471 (mc/remove-fake-cursors)
472 (mc/enable-temporarily-disabled-minor-modes)
473 (run-hooks 'multiple-cursors-mode-disabled-hook)))
474
475 (add-hook 'after-revert-hook #'(lambda () (multiple-cursors-mode 0)))
476
477 (defun mc/maybe-multiple-cursors-mode ()
478 "Enable multiple-cursors-mode if there is more than one currently active cursor."
479 (if (> (mc/num-cursors) 1)
480 (multiple-cursors-mode 1)
481 (multiple-cursors-mode 0)))
482
483 (defmacro unsupported-cmd (cmd msg)
484 "Adds command to list of unsupported commands and prevents it
485 from being executed if in multiple-cursors-mode."
486 `(progn
487 (put (quote ,cmd) 'mc--unsupported ,msg)
488 (defadvice ,cmd (around unsupported-advice activate)
489 "command isn't supported with multiple cursors"
490 (unless (and multiple-cursors-mode (called-interactively-p 'any))
491 ad-do-it))))
492
493 ;; Commands that does not work with multiple-cursors
494 (unsupported-cmd isearch-forward ". Feel free to add a compatible version.")
495 (unsupported-cmd isearch-backward ". Feel free to add a compatible version.")
496
497 ;; Make sure pastes from other programs are added to all kill-rings when yanking
498 (defadvice current-kill (before interprogram-paste-for-all-cursors activate)
499 (let ((interprogram-paste (and (= n 0)
500 interprogram-paste-function
501 (funcall interprogram-paste-function))))
502 (when interprogram-paste
503 ;; Add interprogram-paste to normal kill ring, just
504 ;; like current-kill usually does for itself.
505 ;; We have to do the work for it tho, since the funcall only returns
506 ;; something once. It is not a pure function.
507 (let ((interprogram-cut-function nil))
508 (if (listp interprogram-paste)
509 (mapc 'kill-new (nreverse interprogram-paste))
510 (kill-new interprogram-paste))
511 ;; And then add interprogram-paste to the kill-rings
512 ;; of all the other cursors too.
513 (mc/for-each-fake-cursor
514 (let ((kill-ring (overlay-get cursor 'kill-ring))
515 (kill-ring-yank-pointer (overlay-get cursor 'kill-ring-yank-pointer)))
516 (if (listp interprogram-paste)
517 (mapc 'kill-new (nreverse interprogram-paste))
518 (kill-new interprogram-paste))
519 (overlay-put cursor 'kill-ring kill-ring)
520 (overlay-put cursor 'kill-ring-yank-pointer kill-ring-yank-pointer)))))))
521
522 (defvar mc/list-file "~/.emacs.d/.mc-lists.el"
523 "The position of the file that keeps track of your preferences
524 for running commands with multiple cursors.")
525
526 (defun mc/dump-list (list-symbol)
527 "Insert (setq 'LIST-SYMBOL LIST-VALUE) to current buffer."
528 (symbol-macrolet ((value (symbol-value list-symbol)))
529 (insert "(setq " (symbol-name list-symbol) "\n"
530 " '(")
531 (newline-and-indent)
532 (set list-symbol
533 (sort value (lambda (x y) (string-lessp (symbol-name x)
534 (symbol-name y)))))
535 (mapc #'(lambda (cmd) (insert (format "%S" cmd)) (newline-and-indent))
536 value)
537 (insert "))")
538 (newline)))
539
540 (defun mc/save-lists ()
541 "Saves preferences for running commands with multiple cursors to `mc/list-file'"
542 (with-temp-file mc/list-file
543 (emacs-lisp-mode)
544 (insert ";; This file is automatically generated by the multiple-cursors extension.")
545 (newline)
546 (insert ";; It keeps track of your preferences for running commands with multiple cursors.")
547 (newline)
548 (newline)
549 (mc/dump-list 'mc/cmds-to-run-for-all)
550 (newline)
551 (mc/dump-list 'mc/cmds-to-run-once)))
552
553 (defvar mc/cmds-to-run-once nil
554 "Commands to run only once in multiple-cursors-mode.")
555
556 (defvar mc--default-cmds-to-run-once nil
557 "Default set of commands to run only once in multiple-cursors-mode.")
558
559 (setq mc--default-cmds-to-run-once '(mc/edit-lines
560 mc/edit-ends-of-lines
561 mc/edit-beginnings-of-lines
562 mc/mark-next-like-this
563 mc/mark-next-word-like-this
564 mc/mark-next-symbol-like-this
565 mc/mark-previous-like-this
566 mc/mark-previous-word-like-this
567 mc/mark-previous-symbol-like-this
568 mc/mark-all-like-this
569 mc/mark-all-words-like-this
570 mc/mark-all-symbols-like-this
571 mc/mark-more-like-this-extended
572 mc/mark-all-like-this-in-defun
573 mc/mark-all-words-like-this-in-defun
574 mc/mark-all-symbols-like-this-in-defun
575 mc/mark-all-like-this-dwim
576 mc/mark-all-dwim
577 mc/mark-sgml-tag-pair
578 mc/insert-numbers
579 mc/sort-regions
580 mc/reverse-regions
581 mc/cycle-forward
582 mc/cycle-backward
583 mc/add-cursor-on-click
584 mc/mark-pop
585 mc/add-cursors-to-all-matches
586 mc/mmlte--left
587 mc/mmlte--right
588 mc/mmlte--up
589 mc/mmlte--down
590 mc/unmark-next-like-this
591 mc/unmark-previous-like-this
592 mc/skip-to-next-like-this
593 mc/skip-to-previous-like-this
594 rrm/switch-to-multiple-cursors
595 save-buffer
596 ido-exit-minibuffer
597 exit-minibuffer
598 minibuffer-complete-and-exit
599 execute-extended-command
600 undo
601 redo
602 undo-tree-undo
603 undo-tree-redo
604 universal-argument
605 universal-argument-more
606 universal-argument-other-key
607 negative-argument
608 digit-argument
609 top-level
610 recenter-top-bottom
611 describe-mode
612 describe-key-1
613 describe-function
614 describe-bindings
615 describe-prefix-bindings
616 view-echo-area-messages
617 other-window
618 kill-buffer-and-window
619 split-window-right
620 split-window-below
621 delete-other-windows
622 toggle-window-split
623 mwheel-scroll
624 scroll-up-command
625 scroll-down-command
626 mouse-set-point
627 mouse-drag-region
628 quit-window
629 toggle-read-only
630 windmove-left
631 windmove-right
632 windmove-up
633 windmove-down))
634
635 (defvar mc--default-cmds-to-run-for-all nil
636 "Default set of commands that should be mirrored by all cursors")
637
638 (setq mc--default-cmds-to-run-for-all '(mc/keyboard-quit
639 self-insert-command
640 quoted-insert
641 previous-line
642 next-line
643 newline
644 newline-and-indent
645 open-line
646 delete-blank-lines
647 transpose-chars
648 transpose-lines
649 transpose-paragraphs
650 transpose-regions
651 join-line
652 right-char
653 right-word
654 forward-char
655 forward-word
656 left-char
657 left-word
658 backward-char
659 backward-word
660 forward-paragraph
661 backward-paragraph
662 upcase-word
663 downcase-word
664 capitalize-word
665 forward-list
666 backward-list
667 hippie-expand
668 hippie-expand-lines
669 yank
670 yank-pop
671 append-next-kill
672 kill-word
673 kill-line
674 kill-whole-line
675 backward-kill-word
676 backward-delete-char-untabify
677 delete-char delete-forward-char
678 delete-backward-char
679 py-electric-backspace
680 c-electric-backspace
681 org-delete-backward-char
682 paredit-backward-delete
683 autopair-backspace
684 just-one-space
685 zap-to-char
686 end-of-line
687 set-mark-command
688 exchange-point-and-mark
689 cua-set-mark
690 cua-replace-region
691 move-end-of-line
692 beginning-of-line
693 move-beginning-of-line
694 kill-ring-save
695 back-to-indentation
696 subword-forward
697 subword-backward
698 subword-mark
699 subword-kill
700 subword-backward-kill
701 subword-transpose
702 subword-capitalize
703 subword-upcase
704 subword-downcase
705 er/expand-region
706 er/contract-region
707 smart-forward
708 smart-backward
709 smart-up
710 smart-down))
711
712 (defvar mc/cmds-to-run-for-all nil
713 "Commands to run for all cursors in multiple-cursors-mode")
714
715 (load mc/list-file t) ;; load, but no errors if it does not exist yet please
716
717 (provide 'multiple-cursors-core)
718
719 ;; Local Variables:
720 ;; coding: utf-8
721 ;; byte-compile-warnings: (not cl-functions)
722 ;; End:
723
724 ;;; multiple-cursors-core.el ends here