Emacs Macro Counter!

Say you want to create the following HTML:

<div id="d0"></div>
<div id="d1"></div>
<div id="d2"></div>
<div id="d3"></div>
<div id="d4"></div>
<div id="d5"></div>
<div id="d6"></div>
<div id="d7"></div>
<div id="d8"></div>
<div id="d9"></div>

Doing this is simple using Emacs’ macros. Type C-x ( to start defining the macro. Then, when it comes time to insert the digit, enter C-x C-k C-i. The next time you run the macro, the number will be incremented.

Say you need to add a zero-padded number. Enter C-x C-k C-f and use the typical printf string formats like %03d.

When you need to reset the counter, use C-x C-k C-c and enter in the start value.

Finally, if you need to repeat a number, use C-u C-x C-k C-i.




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s