domingo, 18 de marzo de 2018

fixing indentation of lua (busted) in emacs. A nasty hack

In general, indentation is not an issue in emacs.

But there are some exceptions.  For example, in Lua, one of the de facto testing libraries is busted, which tries to mimick rspec in many aspects.

A typical busted test looks like this:
Lua mode tends to indent code in a very lisp-y way (which I personally like) by aligning parameters to the same function using as a "starting point" the offset of the first parameter.  In this case, there's also an opened function that gets indented in addition to that base column.
This is unacceptable in most codebases, so I had to write some hack for those particular cases.

As the indentation code for lua-mode is quite complex and this is an exception to the general rule, I wrote this very ugly hack, that seems to solve my problem at hand.
As with all defadvice uses, it looks like a hack because it is a big ugly hack, but at least it lets me deal with it, and move on with my tasks without manually reindenting stuff.

Another +1 for emacs hackability :)

3 comentarios:

hs0ucy dijo...


Thanks for your hack. Unfortunately it's not working for me :S

Raimon Grau dijo...


Any other info about "not working for you"?

I'd debug it by:
1) check you have lua-mode installed and required
2) making sure the advice is working.
3) try do use edebug to see what's happening under the hood.


hs0ucy dijo...

Hi Raimon,

Thanks for your help.

1) Done
2) How I can do that?
3) Returs no error.

Here's my file .

Ciao, have a nice day!