我是一个完全的emacs新手。
我正在Ubuntu上使用emacs 23.1.1和emacs starter kit。我主要在lua-mode中工作(使用package-install lua-mode
安装)。
我需要调整缩进方式,使其符合我的编码规范。
规范如下:
- 制表符转换为空格;
- 每次缩进两个空格;
- 每行最多80个字符,不包括尾随空格。
例如:
local foo = function() print("Hello, world!") end
如果我不试图与其自动缩进抗争,我得到的emacs结果如下:
local foo = function() print("Hello, world") end
更新:
(这属于评论,但由于需要额外的格式化,我必须将其放在这里。)
如果我尝试Thomas的解决方案,我会得到以下结果:
local foo = function() print("Hello, world") end
请注意,end
缩进了制表符和四个空格。
还不太对...
更新2:
这个东西的缩进方式也不对:
local bar = foo( "one", "two", baz(), -- 注意三个空格 "quo" )
它应该是:
local bar = foo( "one", "two", baz(), "quo" )
更新3:
第三种错误的缩进情况:
local bar = foo( "one", "two" )
local t = 5 -- 这一行不应该缩进, -- 还要注意local和t之间的制表符。
更新4:
以下是我从Thomas的当前版本中得到的结果:
local foo = function() print("Hello, world") end
local bar = 5 -- Emacs在5前放了\t
local zzz = foo( -- Emacs在foo前放了\t "one", -- 在这里按两次TAB "two", three(), "four" )
除非明确说明,否则我没有做任何缩进,只是输入代码并在每行末按RETURN。我实际上没有输入任何注释。
它应该如下所示:
local foo = function() print("Hello, world") end local bar = 5 local zzz = foo( "one", "two", three(), "four" )
更新5:
另一个错误的缩进案例:
本应为:
local foo = { bar(); baz; }
更新6:
为了完整起见,以下是我使用lua-mode的最新Git HEAD得到的结果,未使用Thomas的配置调整:
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(), }
indent-line-function
的标准机制来进行缩进。 - ThomasC-h k
ENTER 会给你绑定到回车键的函数是什么? - Thomas