例子:
local foo = function()
print("Hello, world!")
end
自动伸缩:
local foo = function()
print("Hello, world")
end
local foo = function()
print("Hello, world")
end
是以错误的方式缩进的:
local bar = foo(
"one",
"two",
baz(), -- Note three spaces
"quo"
)
应该是:
local bar = foo(
"one",
"two",
baz(),
"quo"
)
第三种错误的缩进:
local bar = foo(
"one",
"two"
)
local t = 5 -- This line should not be indented,
-- also note tab between local and t.
以下是我从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"
)
除了明确指出的地方,我没有为缩进做任何事情,只在代码中输入并按下每一行末尾的返回。我实际上没有输入任何评论。
它应如下所示:
local foo = function()
print("Hello, world")
end
local bar = 5
local zzz = foo(
"one",
"two",
three(),
"four"
)
还有一个错误的缩进情况:
local foo =
{
bar(); -- Did press a TAB here, but closing brace killed it
baz;
}
应:
local foo =
{
bar();
baz;
}
为了完整起见,下面是Lua模式:
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(),
}
发布于 2018-03-28 10:29:37
可以尝试下:
(defvar my-lua-indent 2
"The number of spaces to insert for indentation")
(defun my-lua-enter ()
"Inserts a newline and indents the line like the previous
non-empty line."
(interactive)
(newline)
(indent-relative-maybe))
(defun my-lua-indent ()
"Moves point to the first non-whitespace character of the
line if it is left of it. If point is already at that
position, or if it is at the beginning of an empty line,
inserts two spaces at point."
(interactive)
(when (looking-back "^\\s *")
(if (looking-at "[\t ]")
(progn (back-to-indentation)
(when (looking-at "$")
(kill-line 0)
(indent-relative-maybe)
(insert (make-string my-lua-indent ? ))))
(insert (make-string my-lua-indent ? )))))
(defun my-lua-setup ()
"Binds ENTER to my-lua-enter and configures indentation the way
I want it. Makes sure spaces are used for indentation, not tabs."
(setq indent-tabs-mode nil)
(local-set-key "\r" 'my-lua-enter)
(setq indent-line-function 'my-lua-indent))
;; add `my-lua-setup' as a call-back that is invoked whenever lua-mode
;; is activated.
(add-hook 'lua-mode-hook 'my-lua-setup)
https://stackoverflow.com/questions/-100007822
复制相似问题