-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stored registers are removed on multi cursor creation #83
Comments
Same spotted on Linux Emacs 26.1. |
If someone has a good elisp fu, then perhaps an easy solution would be to make a copy of all text registers before the multiple cursors are made. Then when the cursors are killed the registers are restored...food for thought. EDIT: |
UpdateNo, the "fix" below only works when creating additional cursors with A to limited solutionI might have found a possible solution that doesn't remove the named registers. (defun evil-mc-run-cursors-before ()
"Runs `evil-mc-cursors-before' if there are no cursors created yet."
(when (not (evil-mc-has-cursors-p))
(let (register-alist)
(evil-mc-cursors-before)))) The optimal solution would be to be able to paste from a register at every cursor, but with this "fix" it only pastes from a register at the main cursor. But the major issue of not removing the named registers is probably enough for now. |
(setq ~+multiple-cursors--evil-mc-registers-copy '())
(defun ~+multiple-cursors*evil-mc-run-cursors-before (&rest r)
(cl-loop for reg from 97 to 122 do
(setq ~+multiple-cursors--evil-mc-registers-copy (nconc ~+multiple-cursors--evil-mc-registers-copy (cons (get-register reg) nil)))))
(defun ~+multiple-cursors*evil-mc-run-cursors-after (&rest r)
(cl-loop for reg in ~+multiple-cursors--evil-mc-registers-copy
for i from 97 do
(when reg
(set-register i reg)))
(setq ~+multiple-cursors--evil-mc-registers-copy nil))
(advice-add #'evil-mc-run-cursors-before :before #'~+multiple-cursors*evil-mc-run-cursors-before)
(advice-add #'evil-mc-run-cursors-after :after #'~+multiple-cursors*evil-mc-run-cursors-after) |
@sooqua It doesn't work with: And there might be an off by one issue, because while I was storing text in the |
The author of this Spacemacs issue: Says:
That might be why the alphabetic registers are erased when evil-mc cursors are created. |
Quick fix: (defun ~+multiple-cursors*evil-mc-write-cursor-state (state)
"Write the state of the real cursor with values from STATE."
(let ((names (evil-mc-get-cursor-variables)))
(dolist (name names)
(when (boundp name)
(let ((p (evil-mc-get-cursor-property state name)))
(when (not (and (string= name "register-alist") (null p)))
(set name (evil-mc-get-cursor-property state name))))))))
(advice-add #'evil-mc-write-cursor-state :override #'~+multiple-cursors*evil-mc-write-cursor-state) |
That seems to work for all evil-mc cursor creation commands 👍 It seems to also keep the |
Could that solution or something similar be implemented to also prevent the position markers from being removed when evil-mc cursors are created? Position markers (I might not be the correct name), can be store with
|
Yeah. I'm not sure why (defun ~+multiple-cursors-evil-mc-write-cursor-state-a (state)
"Write the state of the real cursor with values from STATE."
(let ((names (evil-mc-get-cursor-variables)))
(dolist (name names)
(when (boundp name)
(let ((p (evil-mc-get-cursor-property state name)))
(when (not
(or
(eq name 'register-alist)
(eq name 'evil-markers-alist)))
(set name p)))))))
(advice-add #'evil-mc-write-cursor-state :override #'~+multiple-cursors-evil-mc-write-cursor-state-a) |
You could probably just remove (when (featurep! :editor multiple-cursors)
(after! evil-mc
(setq evil-mc-cursor-variables (mapcar
(lambda (s)
(remove 'register-alist (remove 'evil-markers-alist s)))
evil-mc-cursor-variables)))) I'm using Doom Emacs, you will have to modify everything before and including |
This seems to work to prevent the removal of:
(with-eval-after-load 'evil-mc
(setq evil-mc-cursor-variables
(mapcar
(lambda (s)
(remove 'register-alist
(remove 'evil-markers-alist
(remove evil-was-yanked-without-register s))))
evil-mc-cursor-variables))) Thanks |
Observed behavior
Stored registers are removed when multiple cursors are created.
Expected behavior
That stored registers remained after cursor creation.
Steps to reproduce
abc
abc
in register a:"ayiw
:reg
RET
, there an entry for:C-w w
grh
a
is gone.Notes
Any registers that were stored while multiple cursors were active. Remain after pausing, resuming or undoing the cursors.
System information
The text was updated successfully, but these errors were encountered: