martes, 6 de noviembre de 2018

e{vil,macs} macros

Macros are a powerful tool. I personally prefer vim-style macros although they're less powerful than emacs'(as I don't usually need anything on the surplus of emacs' macros features, I'm good with that).

Here's something I noticed today when using evil macros.

In vim, when you record a macro, you do it specifying a register where you want it to be stored. And registers are used for both copying/pasting text and storing macros (it stores the keypresses, so it's all text!).

On the other hand, a nice thing about emacs macros is that you can fine tune a macro in a very user-friendly way with kmacro-edit-macro.
Evil macros are a kind of hybrid between the two, and stored in an evil register and also as an emacs macro, so kmacro-edit-macro will give you the last macro you created, even if you created it with evil. The "problem" is that it doesn't update the evil register, so once the macro is defined for the first time, both macros (emacs kmacro and the evil register) are completely detached, and modifying one, does not modify the other.

I guess this is the right thing to do, because entangling one with the other could have many unexpected effects.

Along this experimentation, It's worth noting that editing the macro "the vim way" works great. kudos to evil devs again.

 So given we have stored the evil macro in register 'q':

  1. "qp to paste the register q. 
  2. edit the line - select the characters of the macro. 
  3. "qy 
  4. @q

No hay comentarios: