Alex Rivera | Logout

How to configure indentation in emacs lua-mode?

Asked 2011-01-10T02:22:56.980
19

Complete emacs newbie here.

I'm using emacs 23.1.1 on Ubuntu with emacs starter kit. I primarily work in the lua-mode (installed with package-install lua-mode).

I need to tune how indentation works, so it would match my coding guidelines.

The guidelines are:

  • tabs-to-spaces;
  • two spaces per indent;
  • 80 chars per line maximum, without trailing spaces.

Example:

local foo = function()
  print("Hello, world!")
end

What I get with emacs if I don't try to fight with its auto-indent:

local foo = function()
               print("Hello, world")
end

Update:

(This belongs to a comment, but since it needs extra formatting, I have to place it here.)

If I try solution by Thomas, I get this:

local foo = function()
               print("Hello, world")
        end

Note that end is indented with a tab and four spaces. Does not quite work...

Update 2:

This thing is also gets indented in the wrong way:

local bar = foo(
    "one",
    "two",
   baz(), -- Note three spaces
   "quo"
)  

It should be:

local bar = foo(
    "one",
    "two",
    baz(),
    "quo"
  )

Update 3:

Third case of the wrong indentation:

local bar = foo(
    "one",
    "two"
  )

  local t = 5 -- This line should not be indented, 
              -- also note tab between local and t.

Update 4:

Here is what I get with the current version from Thomas:

local foo = function()
               print("Hello, world")
        end

            local bar = 5 -- Emacs put \t before 5

            local zzz = foo( -- Emacs put \t before foo
                "one", -- Pressed TAB here twice
Edit
Report

1 Answer

5

I know it's been a while since this was asked, but I just wanted to point out that this is still an issue, with lua-mode installed via the Emacs package system.

However, the latest version on GitHub works very well, didn't notice any indentation weirdness. All you have to do to conform with the Lua style guide is to set indent-tabs-mode to nil and lua-indent-level to 2.

answered 2013-06-09T10:45:08.773

Your Answer