完整的 emacs 新手在这里。
我在 Ubuntu 上使用 emacs 23.1.1emacs 入门套件 https://github.com/technomancy/emacs-starter-kit。我主要在 lua 模式下工作(安装了package-install lua-mode
).
我需要调整缩进的工作方式,以便它符合我的编码指南。
指导方针是:
- 制表符到空格;
- 每个缩进两个空格;
- 每行最多 80 个字符,无尾随空格。
Example:
local foo = function()
print("Hello, world!")
end
如果我不尝试使用 emacs 的自动缩进,我会得到什么:
local foo = function()
print("Hello, world")
end
Update:
(这属于评论,但由于它需要额外的格式,所以我必须将其放在这里。)
如果我尝试托马斯的解决方案,我会得到这个:
local foo = function()
print("Hello, world")
end
注意end
缩进一个tab和四个空格。
不太行得通...
更新2:
这件事也以错误的方式缩进:
local bar = foo(
"one",
"two",
baz(), -- Note three spaces
"quo"
)
它应该是:
local bar = foo(
"one",
"two",
baz(),
"quo"
)
更新3:
错误缩进的第三种情况:
local bar = foo(
"one",
"two"
)
local t = 5 -- This line should not be indented,
-- also note tab between local and t.
更新4:
以下是我从托马斯那里得到的当前版本的信息:
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.
它应该如下所示:
local foo = function()
print("Hello, world")
end
local bar = 5
local zzz = foo(
"one",
"two",
three(),
"four"
)
更新5:
还有一种错误缩进的情况:
local foo =
{
bar(); -- Did press a TAB here, but closing brace killed it
baz;
}
应该:
local foo =
{
bar();
baz;
}
更新6:
为了完整起见,这是我得到的lua-mode 当前的 Git HEAD https://github.com/rrthomas/lua-mode/blob/master/lua-mode.el,没有托马斯的配置调整:
local foo = function()
print("Hello, world!")
end
local bar = 5
local foo = bar(
bar,
baz(),
quo(),
aaa
)
local t =
{
"one",
two(),
}
通过调整:
local foo = function()
print("Hello, world!")
end
local bar = 5
local foo = bar(
bar,
baz(),
quo(),
aaa
)
local t =
{
"one",
two(),
}
为了符合我的编码指南,它应该如下所示:
local foo = function()
print("Hello, world!")
end
local bar = 5
local foo = bar(
bar,
baz(),
quo(),
aaa
)
local t =
{
"one",
two(),
}