# Remarks on EmacsGolf Challenge 1

Apparently I was a bit sloppy with my wording because everyone missed the fact that there was a second part to this challenge. Every line that started with an “open figure” was supposed to be deleted. That was just a matter of deleting every other line and is easily done with a macro in 5 keystrokes.

My original solution was

 【F3】 start macro 【Ctrl+f】 move to “puthash” 【Meta+Shift+f】 select “puthash” xmsi-add-cycle replace 【Ctrl+f】 move after space [ 【Ctrl+7 Ctrl+f】 move after strings ] 【Meta+d Meta+d】 delete “xmsi-abrvs” 【Ctrl+n】 move to next line 【Ctrl+Shift+Delete】 delete entire line 【Meta+0 F4】 end macro and execute

That's 28 keystrokes (not 29; I think I shaved off another by combining the end macro and execute). Notice that deleting the extra lines takes only two additional keystrokes. If you don't worry about deleting the lines, you can do a bit better with multiple-cursors but then you have to use a macro to get rid of those lines. At least I couldn't figure out a way to do it from within multiple-cursors.

Magnar Sveen had a nice trick to shave off two more keystrokes by using hippie-expand. I tried to integrate that into my solution but after the first time it picked up xmsi-add-cycle instead of xmsi-abrvs which resulted in cascading -adds on subsequent lines. Magnar uses a custom function that looks for the nearest match so his hippie-expand trick might have worked with a macro for him.

Fuco had a nice approach using his smartparens package. If anyone else has some good tricks it's not too late to leave a comment.

If you want to contribute a challenge (please do!) you can mail it to challenges at the domain of this blog.

This entry was posted in General and tagged , . Bookmark the permalink.
• I think magnars' solution with hippie expand worked because it was executed for each cursor "in parallel" not as a macro in sequence. I run into the same problem with my first macro solution.

• Sure, it works fine when you do "everything at once." I was just speculating that maybe the macro method would have worked if I were using Magnar's try-expand-dabbrev-closest-first function as the first thing to try for hippie-expand instead of try-expand-dabbrev.

• hard to beat you guys. I tried. After several tries, best is about 30, and counting the typing of xmsi-add-cycle as single key stroke. haha.

my setup is also quite customized, with many conveniences, but still, couldn't do it.

the primary method i tried is regex replace, with about 8 of $.+$
replace it with (tt [\2 \3])
I have some abbrevs or copy/paste that saves me typing regex patterns, brackets, and copy without needing to select.

• Hey guys maybe some of you - Emacs gurus - could write some mode for counting keystrokes for this challange. I think that it should encourage other people to join to this challange.

• Tim Visher, of the original VimGolf in Emacs videos fame, wrote a mode that does that and more. He says that it could easily be tweaked to support an EmacsGolf type site. If there's enough interest in the whole EmacsGolf enterprise, we'll probably do something with that.