evil icon indicating copy to clipboard operation
evil copied to clipboard

Can't run a macro a second time

Open juacq97 opened this issue 4 years ago • 6 comments

Issue type

  • Bug report

Environment

Emacs version: GNU Emacs 26.3 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20) of 2020-05-19 Operating System: Arch Linux Evil version: 1.14.0 Evil installation type: Melpa Graphical/Terminal: Graphical Tested in a make emacs session (see CONTRIBUTING.md): No

Reproduction steps

  • Start Emacs
  • Record a macro with Q-, example Q-1
  • Play the marco with @-, example @-1 -Play the macro again

Expected behavior

The macro is played again

Actual behavior

The macro isn't played and I get an error After 0 kbd macro iterations: evil-execute-macro: Keyboard macro terminated by a command ringing the bell

juacq97 avatar Jul 07 '20 20:07 juacq97

I don't understand your reproduction steps. Q-1? Q isn't how you record a macro and - is not a valid register.

Tested in a make emacs session (see CONTRIBUTING.md): No

We have this question for a reason.

TheBB avatar Jul 07 '20 20:07 TheBB

My bad, I mean q-1, a lowercase q and the any character.

I ran make emacs. I get the next error:

F evil-test-flyspell-motions
    Test flyspell motions
    Info: Simple
    (ert-test-failed
     ((should
       (string=
	(buffer-substring
	 (max ... ...)
	 (point))
	before))
      :form
      (string= "I cannt tpye " "I cannt tpye for ")
      :value nil))

juacq97 avatar Jul 07 '20 21:07 juacq97

Sorry, I still can't reproduce. Is the hyphen supposed to be 'any' character? This is what I tried:

  • qa1xq record a macro in register a that deletes a character
  • @a@a replay macro, works fine

q followed by any character followed by 1 is an incomplete macro.

I ran make emacs. I get the next error:

I'm not sure why the tests are failing for you, but when asked whether you want to run the tests you can safely answer no. The point is just to reproduce the error in a make emacs instance.

TheBB avatar Jul 07 '20 21:07 TheBB

I tried tpo reproduce the error on the make emacs instance, I tried two macros:

  • q1ihello<ESC>q: write the word "hello". I can reproduce it at many times I want, just as expected. -df"i[[<ESC>f"a][<ESC>ldf>f<Da]] (<ESC> means press the ESC key): This is the one that trigger my error: I have a list of links like this <DT><A HREF="https://doc.opensuse.org/" ADD_DATE="1543974418" LAST_MODIFIED="1590776675">openSUSE Documentation</A> on a html file and I want to transform it to org-mode links with that macro. I can reproduce the macro just one time, the second time I get the error. This happens both the normal emacs and the make emacs instance

juacq97 avatar Jul 07 '20 21:07 juacq97

I've run into something like this a few times but could never reproduce it intentionally so I never made an issue.

mohkale avatar Oct 14 '20 10:10 mohkale

This happens when you save a macro to registers between "1 and "9. Those registers get overwritten whenever you delete text (see http://vimdoc.sourceforge.net/htmldoc/change.html#registers), so if your macro contains x or d, executing it will overwrite the register "1, and executing it again won't work because "1 is not a macro anymore, it's your deleted content.

You can display the registers on Emacs with M-x evil-show-registers, and on Vim with :registers (to compare).

It's more difficult to reproduce with Vim, because of this:

Numbered register 1 contains the text deleted by the most recent delete or change command, unless the command specified another register or the text is less than one line (the small delete register is used then).

So on Vim you need to delete at least one full line (e.g. with dd) to break a macro saved in the register "1.

I think evil-mode saving small deletes in numbered registers ("1 to "9) is the bug. It should only save them in the small delete register ("-). See https://github.com/emacs-evil/evil/pull/1049#issuecomment-424513846.

I don't think it's a good idea to save macros in numbered registers, regardless. You should save them in named registers: "a to "z. (Or "A to "Z if you want to append to an existing macro.)

classieur avatar Jun 17 '22 14:06 classieur