2018-08-05 22:10:36 +02:00
|
|
|
;;; editor/multiple-cursors/config.el -*- lexical-binding: t; -*-
|
|
|
|
|
2019-12-20 00:47:21 -05:00
|
|
|
(defvar +multiple-cursors-evil-mc-ex-global t
|
|
|
|
"TODO")
|
|
|
|
|
|
|
|
(defvar +multiple-cursors-evil-mc-ex-case nil
|
|
|
|
"TODO")
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;;; Packages
|
|
|
|
|
2019-10-26 21:34:44 -04:00
|
|
|
(use-package! evil-multiedit
|
|
|
|
:when (featurep! :editor evil)
|
|
|
|
:defer t
|
|
|
|
:config
|
|
|
|
(map! :map (evil-multiedit-state-map evil-multiedit-insert-state-map)
|
|
|
|
"C-n" #'evil-multiedit-next
|
|
|
|
"C-p" #'evil-multiedit-prev))
|
|
|
|
|
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(use-package! evil-mc
|
2019-04-21 19:59:44 -04:00
|
|
|
:when (featurep! :editor evil)
|
2019-07-22 19:11:12 +02:00
|
|
|
:commands (evil-mc-make-cursor-here
|
|
|
|
evil-mc-make-all-cursors
|
|
|
|
evil-mc-undo-all-cursors
|
|
|
|
evil-mc-pause-cursors
|
|
|
|
evil-mc-resume-cursors
|
|
|
|
evil-mc-make-and-goto-first-cursor
|
2018-08-05 22:10:36 +02:00
|
|
|
evil-mc-make-and-goto-last-cursor
|
2019-10-15 13:56:16 +02:00
|
|
|
evil-mc-make-cursor-in-visual-selection-beg
|
|
|
|
evil-mc-make-cursor-in-visual-selection-end
|
2018-08-05 22:10:36 +02:00
|
|
|
evil-mc-make-cursor-move-next-line
|
2019-07-22 19:11:12 +02:00
|
|
|
evil-mc-make-cursor-move-prev-line
|
|
|
|
evil-mc-make-cursor-at-pos
|
|
|
|
evil-mc-has-cursors-p
|
|
|
|
evil-mc-make-and-goto-next-cursor
|
|
|
|
evil-mc-skip-and-goto-next-cursor
|
|
|
|
evil-mc-make-and-goto-prev-cursor
|
|
|
|
evil-mc-skip-and-goto-prev-cursor
|
|
|
|
evil-mc-make-and-goto-next-match
|
|
|
|
evil-mc-skip-and-goto-next-match
|
|
|
|
evil-mc-skip-and-goto-next-match
|
|
|
|
evil-mc-make-and-goto-prev-match
|
|
|
|
evil-mc-skip-and-goto-prev-match)
|
2018-08-05 22:10:36 +02:00
|
|
|
:init
|
2019-10-26 21:34:44 -04:00
|
|
|
;; The included keybindings are too imposing and are likely to cause
|
|
|
|
;; conflicts, so we'll set them ourselves.
|
2018-08-05 22:10:36 +02:00
|
|
|
(defvar evil-mc-key-map (make-sparse-keymap))
|
2019-10-26 21:34:44 -04:00
|
|
|
|
2018-08-05 22:10:36 +02:00
|
|
|
:config
|
|
|
|
(global-evil-mc-mode +1)
|
2019-10-26 02:12:47 -04:00
|
|
|
|
|
|
|
;; REVIEW This is tremendously slow on macos and windows for some reason.
|
2019-03-16 14:13:47 +08:00
|
|
|
(setq evil-mc-enable-bar-cursor (not (or IS-MAC IS-WINDOWS)))
|
2018-08-05 22:10:36 +02:00
|
|
|
|
|
|
|
(after! smartparens
|
|
|
|
;; Make evil-mc cooperate with smartparens better
|
|
|
|
(let ((vars (cdr (assq :default evil-mc-cursor-variables))))
|
|
|
|
(unless (memq (car sp--mc/cursor-specific-vars) vars)
|
|
|
|
(setcdr (assq :default evil-mc-cursor-variables)
|
|
|
|
(append vars sp--mc/cursor-specific-vars)))))
|
|
|
|
|
2019-10-26 02:12:47 -04:00
|
|
|
;; Whitelist more commands
|
|
|
|
(dolist (fn '((delete-char)
|
|
|
|
(backward-kill-word)
|
|
|
|
(company-complete-common . evil-mc-execute-default-complete)
|
|
|
|
(doom/backward-to-bol-or-indent . evil-mc-execute-default-call)
|
|
|
|
(doom/forward-to-last-non-comment-or-eol . evil-mc-execute-default-call)
|
2020-08-02 19:21:31 -04:00
|
|
|
;; :emacs undo
|
|
|
|
(undo-fu-only-undo . evil-mc-execute-default-undo)
|
|
|
|
(undo-fu-only-redo . evil-mc-execute-default-redo)
|
2020-08-02 17:44:41 -04:00
|
|
|
;; :editor evil
|
2019-12-21 03:28:07 -05:00
|
|
|
(evil-delete-back-to-indentation . evil-mc-execute-default-call)
|
2020-08-02 17:44:41 -04:00
|
|
|
(evil-escape . evil-mc-execute-default-evil-normal-state) ; C-g
|
|
|
|
(evil-numbers/inc-at-pt-incremental)
|
|
|
|
(evil-numbers/dec-at-pt-incremental)
|
2020-08-02 19:21:31 -04:00
|
|
|
;; :tools eval
|
2020-08-02 17:44:41 -04:00
|
|
|
(+eval:replace-region . +multiple-cursors-execute-default-operator-fn)
|
2020-10-14 01:29:46 -04:00
|
|
|
;; :lang ess
|
|
|
|
(ess-smart-comma . evil-mc-execute-call)
|
2020-08-02 17:44:41 -04:00
|
|
|
;; :lang org
|
2020-08-02 19:21:31 -04:00
|
|
|
(evil-org-delete . evil-mc-execute-default-evil-delete)))
|
2020-08-02 17:44:41 -04:00
|
|
|
(setf (alist-get (car fn) evil-mc-custom-known-commands)
|
|
|
|
(list (cons :default
|
|
|
|
(or (cdr fn)
|
|
|
|
#'evil-mc-execute-default-call-with-count)))))
|
2018-08-05 22:10:36 +02:00
|
|
|
|
2020-04-11 19:08:54 -04:00
|
|
|
;; HACK Allow these commands to be repeated by prefixing them with a numerical
|
|
|
|
;; argument. See gabesoft/evil-mc#110
|
|
|
|
(defadvice! +multiple-cursors--make-repeatable-a (orig-fn)
|
|
|
|
:around '(evil-mc-make-and-goto-first-cursor
|
|
|
|
evil-mc-make-and-goto-last-cursor
|
|
|
|
evil-mc-make-and-goto-prev-cursor
|
|
|
|
evil-mc-make-and-goto-next-cursor
|
|
|
|
evil-mc-skip-and-goto-prev-cursor
|
|
|
|
evil-mc-skip-and-goto-next-cursor
|
|
|
|
evil-mc-make-and-goto-prev-match
|
|
|
|
evil-mc-make-and-goto-next-match
|
|
|
|
evil-mc-skip-and-goto-prev-match
|
|
|
|
evil-mc-skip-and-goto-next-match)
|
|
|
|
(dotimes (i (if (integerp current-prefix-arg) current-prefix-arg 1))
|
|
|
|
(funcall orig-fn)))
|
|
|
|
|
2019-10-26 02:12:47 -04:00
|
|
|
;; If we're entering insert mode, it's a good bet that we want to start using
|
|
|
|
;; our multiple cursors
|
2019-01-28 19:55:36 -05:00
|
|
|
(add-hook 'evil-insert-state-entry-hook #'evil-mc-resume-cursors)
|
2018-08-05 22:10:36 +02:00
|
|
|
|
2020-08-02 19:21:31 -04:00
|
|
|
(pushnew! evil-mc-incompatible-minor-modes
|
|
|
|
;; evil-escape's escape key leaves behind extraneous characters
|
|
|
|
'evil-escape-mode
|
|
|
|
;; Lispy commands don't register on more than 1 cursor. Lispyville
|
|
|
|
;; is fine though.
|
|
|
|
'lispy-mode)
|
2018-08-05 22:10:36 +02:00
|
|
|
|
2019-07-26 19:57:13 +02:00
|
|
|
(add-hook! 'doom-escape-hook
|
2019-07-18 15:27:20 +02:00
|
|
|
(defun +multiple-cursors-escape-multiple-cursors-h ()
|
|
|
|
"Clear evil-mc cursors and restore state."
|
|
|
|
(when (evil-mc-has-cursors-p)
|
|
|
|
(evil-mc-undo-all-cursors)
|
|
|
|
(evil-mc-resume-cursors)
|
|
|
|
t)))
|
2018-08-05 22:10:36 +02:00
|
|
|
|
2019-01-28 19:54:55 -05:00
|
|
|
;; Forward declare these so that ex completion and evil-mc support is
|
|
|
|
;; recognized before the autoloaded functions are loaded.
|
2018-08-05 22:10:36 +02:00
|
|
|
(evil-add-command-properties '+evil:align :evil-mc t)
|
2019-10-26 21:34:44 -04:00
|
|
|
(evil-add-command-properties '+multiple-cursors:evil-mc :evil-mc t)
|
|
|
|
|
|
|
|
(map! :map evil-mc-key-map
|
|
|
|
:nv "C-n" #'evil-mc-make-and-goto-next-cursor
|
|
|
|
:nv "C-N" #'evil-mc-make-and-goto-last-cursor
|
|
|
|
:nv "C-p" #'evil-mc-make-and-goto-prev-cursor
|
2019-10-27 14:01:49 -04:00
|
|
|
:nv "C-P" #'evil-mc-make-and-goto-first-cursor))
|
2018-08-05 22:10:36 +02:00
|
|
|
|
|
|
|
|
2019-03-13 14:17:29 +10:00
|
|
|
(after! multiple-cursors-core
|
2018-12-23 23:16:03 -05:00
|
|
|
(setq mc/list-file (concat doom-etc-dir "mc-lists.el"))
|
|
|
|
|
2020-07-24 02:13:19 -04:00
|
|
|
;; Can't use `mc/cmds-to-run-once' because mc-lists.el overwrites it
|
|
|
|
(add-to-list 'mc--default-cmds-to-run-once 'swiper-mc)
|
2020-07-23 00:57:00 -04:00
|
|
|
|
2018-08-05 22:10:36 +02:00
|
|
|
;; TODO multiple-cursors config for Emacs users?
|
|
|
|
|
|
|
|
;; mc doesn't play well with evil, this attempts to assuage some of its
|
|
|
|
;; problems so that any plugins that depend on multiple-cursors (which I have
|
|
|
|
;; no control over) can still use it in relative safety.
|
2019-04-21 19:59:44 -04:00
|
|
|
(when (featurep! :editor evil)
|
2018-08-05 22:10:36 +02:00
|
|
|
(evil-define-key* '(normal emacs) mc/keymap [escape] #'mc/keyboard-quit)
|
|
|
|
|
|
|
|
(defvar +mc--compat-evil-prev-state nil)
|
|
|
|
(defvar +mc--compat-mark-was-active nil)
|
|
|
|
|
2019-07-26 19:57:13 +02:00
|
|
|
(add-hook! 'multiple-cursors-mode-enabled-hook
|
2019-07-18 15:27:20 +02:00
|
|
|
(defun +multiple-cursors-compat-switch-to-emacs-state-h ()
|
|
|
|
(when (and (bound-and-true-p evil-mode)
|
|
|
|
(not (memq evil-state '(insert emacs))))
|
|
|
|
(setq +mc--compat-evil-prev-state evil-state)
|
|
|
|
(when (region-active-p)
|
|
|
|
(setq +mc--compat-mark-was-active t))
|
|
|
|
(let ((mark-before (mark))
|
|
|
|
(point-before (point)))
|
|
|
|
(evil-emacs-state 1)
|
|
|
|
(when (or +mc--compat-mark-was-active (region-active-p))
|
|
|
|
(goto-char point-before)
|
|
|
|
(set-mark mark-before))))))
|
|
|
|
|
2019-07-26 19:57:13 +02:00
|
|
|
(add-hook! 'multiple-cursors-mode-disabled-hook
|
2019-07-18 15:27:20 +02:00
|
|
|
(defun +multiple-cursors-compat-back-to-previous-state-h ()
|
|
|
|
(when +mc--compat-evil-prev-state
|
|
|
|
(unwind-protect
|
|
|
|
(case +mc--compat-evil-prev-state
|
|
|
|
((normal visual) (evil-force-normal-state))
|
|
|
|
(t (message "Don't know how to handle previous state: %S"
|
|
|
|
+mc--compat-evil-prev-state)))
|
|
|
|
(setq +mc--compat-evil-prev-state nil)
|
|
|
|
(setq +mc--compat-mark-was-active nil)))))
|
2018-08-05 22:10:36 +02:00
|
|
|
|
:boom: revise advice naming convention (1/2)
This is first of three big naming convention updates that have been a
long time coming. With 2.1 on the horizon, all the breaking updates will
batched together in preparation for the long haul.
In this commit, we do away with the asterix to communicate that a
function is an advice function, and we replace it with the '-a' suffix.
e.g.
doom*shut-up -> doom-shut-up-a
doom*recenter -> doom-recenter-a
+evil*static-reindent -> +evil--static-reindent-a
The rationale behind this change is:
1. Elisp's own formatting/indenting tools would occasionally struggle
with | and * (particularly pp and cl-prettyprint). They have no
problem with / and :, fortunately.
2. External syntax highlighters (like pygmentize, discord markdown or
github markdown) struggle with it, sometimes refusing to highlight
code beyond these symbols.
3. * and | are less expressive than - and -- in communicating the
intended visibility, versatility and stability of a function.
4. It complicated the regexps we must use to search for them.
5. They were arbitrary and over-complicated to begin with, decided
on haphazardly way back when Doom was simply "my private config".
Anyhow, like how predicate functions have the -p suffix, we'll adopt the
-a suffix for advice functions, -h for hook functions and -fn for
variable functions.
Other noteable changes:
- Replaces advice-{add,remove}! macro with new def-advice!
macro. The old pair weren't as useful. The new def-advice! saves on a
lot of space.
- Removed "stage" assertions to make sure you were using the right
macros in the right place. Turned out to not be necessary, we'll
employ better checks later.
2019-07-18 15:42:52 +02:00
|
|
|
;; When running edit-lines, point will return (position + 1) as a result of
|
|
|
|
;; how evil deals with regions
|
2019-07-23 17:24:56 +02:00
|
|
|
(defadvice! +multiple--cursors-adjust-mark-for-evil-a (&rest _)
|
:boom: revise advice naming convention (1/2)
This is first of three big naming convention updates that have been a
long time coming. With 2.1 on the horizon, all the breaking updates will
batched together in preparation for the long haul.
In this commit, we do away with the asterix to communicate that a
function is an advice function, and we replace it with the '-a' suffix.
e.g.
doom*shut-up -> doom-shut-up-a
doom*recenter -> doom-recenter-a
+evil*static-reindent -> +evil--static-reindent-a
The rationale behind this change is:
1. Elisp's own formatting/indenting tools would occasionally struggle
with | and * (particularly pp and cl-prettyprint). They have no
problem with / and :, fortunately.
2. External syntax highlighters (like pygmentize, discord markdown or
github markdown) struggle with it, sometimes refusing to highlight
code beyond these symbols.
3. * and | are less expressive than - and -- in communicating the
intended visibility, versatility and stability of a function.
4. It complicated the regexps we must use to search for them.
5. They were arbitrary and over-complicated to begin with, decided
on haphazardly way back when Doom was simply "my private config".
Anyhow, like how predicate functions have the -p suffix, we'll adopt the
-a suffix for advice functions, -h for hook functions and -fn for
variable functions.
Other noteable changes:
- Replaces advice-{add,remove}! macro with new def-advice!
macro. The old pair weren't as useful. The new def-advice! saves on a
lot of space.
- Removed "stage" assertions to make sure you were using the right
macros in the right place. Turned out to not be necessary, we'll
employ better checks later.
2019-07-18 15:42:52 +02:00
|
|
|
:before #'mc/edit-lines
|
2018-08-05 22:10:36 +02:00
|
|
|
(when (and (bound-and-true-p evil-mode)
|
|
|
|
(not (memq evil-state '(insert emacs))))
|
|
|
|
(if (> (point) (mark))
|
|
|
|
(goto-char (1- (point)))
|
|
|
|
(push-mark (1- (mark))))))
|
|
|
|
|
2019-07-26 19:57:13 +02:00
|
|
|
(add-hook! 'rectangular-region-mode-hook
|
2019-07-18 15:27:20 +02:00
|
|
|
(defun +multiple-cursors-evil-compat-rect-switch-state-h ()
|
|
|
|
(if rectangular-region-mode
|
|
|
|
(+multiple-cursors-compat-switch-to-emacs-state-h)
|
|
|
|
(setq +mc--compat-evil-prev-state nil))))
|
2018-08-05 22:10:36 +02:00
|
|
|
|
|
|
|
(defvar mc--default-cmds-to-run-once nil)))
|