Emacs Keyboard Macro Counter to the Rescue


So, I have to admit, I've been doing a lot of manual numbering/indexing in a particularly large auto generated Scala file.  An example of what I've been doing is parameterizing hardcoded values to be populated from a list.

val a = 2.0

val b = 10.0

val c = 1.7

val d = 8.2

val x = 1.2

val y = 10.5

val z = 1.1

 

Essentially what I was doing using emacs at this point was creating a macro which would template out the list that I would be pulling elements from.

 

val a = a(0)

val b = a(0)

val c = a(0)

val d = a(0)

val x = a(0)

val y = a(0)

val z = a(0)

 

The problem with this is that I still have to go back and manually change each of these values to be 1, 2, 3, and so on.  So in one of the cases I was working on, there was a number of values that was too large for me to get by with this technique, enter the keyboard macro counter.  The keyboard macro counter can be accessed when you are defining your macro using <F3> and everytime it is called the value is incremented.  This essentially solves my problem since I am just trying to number things.  

The macro I would create now would be, C-s "=", right arrow key, C-k, "a(", <F3>, ")", down arrow key, C-a.  Repeating this macro would go down the list and produce val b = a(1), val c = a(2), … until the end which is what I wanted.  

What I've explained here is just what I needed to solve my problem, you can find more information on how to use the keyboard macro counter in the documentation at http://www.gnu.org/software/emacs/manual/html_node/emacs/Keyboard-Macro-Counter.html.

Share this post:
  • RSS
  • Digg
  • Reddit
  • Twitter
  1. No comments yet.
(will not be published)