Emacs Key Macro and Elisp Exercise: Reformat XML

2012-07-02, Mihamina Rakotomandimby posted a interesting problem (Source groups.google.com):

I got a big one line XML file. I want to break the lines to make it more readable.

Replacing "><" with "C-j" then indenting is the most obvious solution, but would you know a more elegant solution?

This is a good exercise for emacs a keyboard macro. Record a key macro, save it, assign it a key. So, just press one key, and the file is indented and well-formatted.

to indent, just select all then call indent-regionCtrl+Alt+\】.

For key macro tutorial, see: Emacs: Using Keyboard Macro to Record/Playback Keystrokes.

or, if you are a emacs expert but never done any elisp, this is a great exercise. Write a command that does this. It's about 5 lines of elisp. (➲ Emacs Lisp Examples ₁)

Popular posts from this blog

Browser User Agent Strings 2012

11 Years of Writing About Emacs

does md5 creates more randomness?