title: How to configure indentation in emacs lua-mode?
body: <p>Complete emacs newbie here.</p>
  
  <p>I'm using emacs 23.1.1 on Ubuntu with <a href="https://github.com/technomancy/emacs-starter-kit" rel="noreferrer">emacs starter kit</a>. I primarily work in the lua-mode (installed with <code>package-install lua-mode</code>).</p>
  
  <p>I need to tune how indentation works, so it would match my coding guidelines.</p>
  
  <p>The guidelines are:</p>
  
  <ul>
  <li>tabs-to-spaces;</li>
  <li>two spaces per indent;</li>
  <li>80 chars per line maximum, without trailing spaces.</li>
  </ul>
  
  <p>Example:</p>
  
  <pre>
  local foo = function()
    print("Hello, world!")
  end
  </pre>
  
  <p>What I get with emacs if I don't try to fight with its auto-indent:</p>
  
  <pre>
  local foo = function()
                 print("Hello, world")
  end
  </pre>
  
  <p><strong>Update:</strong></p>
  
  <p>(This belongs to a comment, but since it needs extra formatting, I have to place it here.)</p>
  
  <p>If I try solution by Thomas, I get this:</p>
  
  <pre>
  local foo = function()
                 print("Hello, world")
          end
  </pre>
  
  <p>Note that <code>end</code> is indented with a <strong>tab</strong> and four spaces.
  Does not quite work...</p>
  
  <p><strong>Update 2:</strong></p>
  
  <p>This thing is also gets indented in the wrong way:</p>
  
  <pre>
  local bar = foo(
      "one",
      "two",
     baz(), -- Note three spaces
     "quo"
  )  
  </pre>
  
  <p>It should be:</p>
  
  <pre>
  local bar = foo(
      "one",
      "two",
      baz(),
      "quo"
    )
  </pre>
  
  <p><strong>Update 3:</strong></p>
  
  <p>Third case of the wrong indentation:</p>
  
  <pre>
  local bar = foo(
      "one",
      "two"
    )
  
    local t = 5 -- This line should not be indented, 
                -- also note tab between local and t.
  </pre>
  
  <p><strong>Update 4:</strong></p>
  
  <p>Here is what I get with the current version from Thomas:</p>
  
  <pre>
  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
                  "two",
                 three(),
                 "four"
              )
  </pre>
  
  <p>Except where explicitly noted, I did not do anything for indentation, only typed in the code and pressed <kbd>RETURN</kbd> at the end of each line. I did not actually type any comments.</p>
  
  <p>It should look as follows:</p>
  
  <pre>
  local foo = function()
    print("Hello, world")
  end
  
  local bar = 5
  
  local zzz = foo(
      "one",
      "two",
      three(),
      "four"
    )
  </pre>
  
  <p><strong>Update 5:</strong></p>
  
  <p>One more wrong indentation case:</p>
  
  <pre>
  local foo =
  {
  bar(); -- Did press a TAB here, but closing brace killed it
  baz;
  }
  </pre>
  
  <p>Should be:</p>
  
  <pre>
  local foo =
  {
    bar();
    baz;
  }
  </pre>
  
  <p><strong>Update 6:</strong></p>
  
  <p>For the sake of completeness, here is what I get with the <a href="https://github.com/rrthomas/lua-mode/blob/master/lua-mode.el" rel="noreferrer">current Git HEAD of lua-mode</a>, without Thomas's configuration tuning:</p>
  
  <pre>
  local foo = function()
                 print("Hello, world!")
              end
  
  local bar = 5
  
  local foo = bar(
  bar,
     baz(),
     quo(),
  aaa
  )
  
  local t =
  {
  "one",
  two(),
  }
  </pre>
  
  <p>With tuning:</p>
  
  <pre>
  local foo = function()
             print("Hello, world!")
              end
  
              local bar = 5
  
              local foo = bar(
              bar,
                 baz(),
                 quo(),
                 aaa
              )
  
              local t =
              {
              "one",
              two(),
           }
  </pre>
  
  <p>To match my coding guidelines, it should look as follows:</p>
  
  <pre>
  local foo = function()
    print("Hello, world!")
  end
  
  local bar = 5
  
  local foo = bar(
      bar,
      baz(),
      quo(),
      aaa
    )
  
  local t =
  {
    "one",
    two(),
  }
  </pre>