• $ cat "

    Emacs Kata #1: Name List

    "

    Working efficiently with a good text editor is something that takes deliberate practice. My editor of choice is Emacs, and to improve my emacs skills I found myself wanting a few simple katas which let you practice a bunch of every day text editing scenarios.

    So, here is the first in a series of text editor katas. The challenge is simply to transform the first block of text into the second block.


    Allen Key Bob Sled Clay Pigeon Cliff Edge
    Guy Ropes Jack Hammer Jerry Cann Jim Boot
    Jim Equipment Jock Strap Lou Paper Mike Stand
    Morris Minor Phillip Screwdriver Ray Gunn Roman Bath
    Stanley Knife Terry Towelling Walter Closet Catherine Wheel
    Joy Stick Kitty Litter Pearl Necklace Penny Farthing
    Jim Nazium Jack Pott Noah Zark Cain Basket
    Barb Dwyer Helmut Strap Jim Shorts Peg Basket
    Col Pitt Cec Pitt Mary Goround Annette Curtain
    Brandon Iron Mike Rowe-chip Lucy Lastic
    1.   Basket,       Cain
    2. Basket, Peg
    3. Bath, Roman
    4. Boot, Jim
    5. Cann, Jerry
    6. Closet, Walter
    7. Curtain, Annette
    8. Dwyer, Barb
    9. Edge, Cliff
    10. Equipment, Jim
    11. Farthing, Penny
    12. Goround, Mary
    13. Gunn, Ray
    14. Hammer, Jack
    15. Iron, Brandon
    16. Key, Allen
    17. Knife, Stanley
    18. Lastic, Lucy
    19. Litter, Kitty
    20. Minor, Morris
    21. Nazium, Jim
    22. Necklace, Pearl
    23. Paper, Lou
    24. Pigeon, Clay
    25. Pitt, Cec
    26. Pitt, Col
    27. Pott, Jack
    28. Ropes, Guy
    29. Rowe-chip, Mike
    30. Screwdriver, Phillip
    31. Shorts, Jim
    32. Sled, Bob
    33. Stand, Mike
    34. Stick, Joy
    35. Strap, Helmut
    36. Strap, Jock
    37. Towelling, Terry
    38. Wheel, Catherine
    39. Zark, Noah

    My personal solution to this kata is something along these lines:
    - Replace tab with newline (using C-q C-i and C-q C-j to input tab and newline in emacs)
    - Define a keyboard macro that cuts the last name, puts it first and inserts the comma and space.
    - Repeat the macro until the end of the file using C-u 0 F4
    - Sort the lines using M-x sort-lines
    - Define a keyboard macro that inserts the row number using F3 to insert a macro counter when defining the macro. Since the counter is zero based and the list is one based i start the macro at the row above the first name.
    - Run the macro until the end of the file
    - Align the names using M-x align-repeat (which can be found here)