Closed korayal closed 7 years ago
You could also add a check for dotspacemacs-enable-paste-transient-state
when re-defining the keys just to account for the case that it could change after the hooks get initialized. Just replace the if state
line with if (and state dotspacemacs-enable-paste-transient-state)
. Other than that this should be fine. Are you adding it to spacemacs?
Thanks for the suggestion, I'll update my version.
I haven't thought about adding it there but yeah, I think that's a good idea since anyone using evil-mc would need this.
One more suggestion, maybe rename state
to enable-paste-transient-state
just to make that parameter a bit more descriptive
There was a suggestion to use a different method to implement this feature in spacemacs, so I tried to update the PR as I wrote at the comment there: https://github.com/syl20bnr/spacemacs/pull/8620#issuecomment-291612119
But I guess it seems this somehow breaks the use of evil-mc-execute-default-evil-paste
and even though evil-paste-after
is executed, we get the paste command applied to only one of the multiple cursors.
(defun spacemacs-evil/evil-mc-paste-after (&optional arg)
(interactive "p")
(if (and (eq (evil-mc-get-cursor-count) 1) dotspacemacs-enable-paste-transient-state)
(spacemacs/paste-transient-state/evil-paste-after)
(evil-paste-after)))
(defun spacemacs-evil/evil-mc-paste-before (&optional arg)
(interactive "p")
(if (and (eq (evil-mc-get-cursor-count) 1) dotspacemacs-enable-paste-transient-state)
(spacemacs/paste-transient-state/evil-paste-before)
(evil-paste-before)))
(define-key evil-normal-state-map "p" 'spacemacs-evil/evil-mc-paste-after)
(define-key evil-normal-state-map "P" 'spacemacs-evil/evil-mc-paste-before)
Could be because evil-mc
doesn't know about spacemacs-evil/evil-mc-paste-after
and spacemacs-evil/evil-mc-paste-before
. See evil-mc-known-commands.el
. You could add them there to see if that fixes it. Should be similar to the other paste entries.
That didn't help either.
Before adding lines for known commands, I was getting no errors but was only getting paste in the first cursor. After adding it I started getting a number-of-arguments error:
evil-mc Failed to execute spacemacs-evil/evil-mc-paste-before with error: Wrong number of arguments: (lambda nil (interactive) (if (and (eq (evil-mc-get-cursor-count) 1) dotspacemacs-enable-paste-transient-state) (spacemacs/paste-transient-state/evil-paste-before) (evil-paste-before))), 2
btw the updated version is as below:
(defun spacemacs-evil/evil-mc-paste-after ()
(interactive)
(if (and (eq (evil-mc-get-cursor-count) 1) dotspacemacs-enable-paste-transient-state)
(call-interactively 'spacemacs/paste-transient-state/evil-paste-after)
(call-interactively 'evil-paste-after)))
(defun spacemacs-evil/evil-mc-paste-before ()
(interactive)
(if (and (eq (evil-mc-get-cursor-count) 1) dotspacemacs-enable-paste-transient-state)
(call-interactively 'spacemacs/paste-transient-state/evil-paste-before)
(call-interactively 'evil-paste-before)))
(define-key evil-normal-state-map "p" 'spacemacs-evil/evil-mc-paste-after)
(define-key evil-normal-state-map "P" 'spacemacs-evil/evil-mc-paste-before)
I don't think that you need call-interactively
but both evil-paste-before
and evil-paste-after
take a count
parameter. You should accept that parameter (like you had before) and pass it on to the paste functions. Otherwise, paste commands preceded by a count will not work properly. Make sure that commands such as 3p
or 4P
work properly both when the cursors are on and off.
thanks for the help! I just sent a PR complimented with the PR at spacemacs.
So that we can use the paste mode that 'is' supported when evil-mc-mode is active. But when it's not in use, there isn't any reason to abandon the nice features of the paste-transient-state.
I wanted to know if I did this correctly. I'm not so good at writing elisp code (except setting up my config file I guess :) ) so below was my take on this issue:
Only issue I can think of is when
dotspacemacs-enable-paste-transient-state
changes (fromt
tonil
) after cursors are created. in that case we would probably get a state where transient-state is enabled (when the desired state was it being disabled). But since the only place I have seen this variable being used is 'at the boot of spacemacs', I don't think it's currently possible to toggle this afterwards anyway.