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
"two",
three(),
"four"
)
Except where explicitly noted, I did not do anything for indentation, only typed in the code and pressed RETURN at the end of each line. I did not actually type any comments.
It should look as follows:
local foo = function()
print("Hello, world")
end
local bar = 5
local zzz = foo(
"one",
"two",
three(),
"four"
)
Update 5:
One more wrong indentation case:
local foo =
{
bar(); -- Did press a TAB here, but closing brace killed it
baz;
}
Should be:
local foo =
{
bar();
baz;
}
Update 6:
For the sake of completeness, here is what I get with the current Git HEAD of lua-mode, without Thomas's configuration tuning:
local foo = function()
print("Hello, world!")
end
local bar = 5
local foo = bar(
bar,
baz(),
quo(),
aaa
)
local t =
{
"one",
two(),
}
With tuning:
local foo = function()
print("Hello, world!")
end
local bar = 5
local foo = bar(
bar,
baz(),
quo(),
aaa
)
local t =
{
"one",
two(),
}
To match my coding guidelines, it should look as follows:
local foo = function()
print("Hello, world!")
end
local bar = 5
local foo = bar(
bar,
baz(),
quo(),
aaa
)
local t =
{
"one",
two(),
}
(Lua ...)? - Thomas-UU-:**--F1 test.lua Top L41 (Lua Abbrev)- Alexander Gladyshindent-line-function? You can find out by typingC-h v, then type "indent-line-function" ENTER. - Thomas