首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在emacs Lua-模式下配置缩进?

如何在emacs Lua-模式下配置缩进?
EN

Stack Overflow用户
提问于 2018-03-28 00:41:05
回答 2查看 0关注 0票数 0

例子:

代码语言:txt
复制
local foo = function()
  print("Hello, world!")
end

自动伸缩:

代码语言:txt
复制
local foo = function()
               print("Hello, world")
end
代码语言:txt
复制
local foo = function()
               print("Hello, world")
        end

是以错误的方式缩进的:

代码语言:txt
复制
local bar = foo(
    "one",
    "two",
   baz(), -- Note three spaces
   "quo"
)  

应该是:

代码语言:txt
复制
local bar = foo(
    "one",
    "two",
    baz(),
    "quo"
  )

第三种错误的缩进:

代码语言:txt
复制
local bar = foo(
    "one",
    "two"
  )

  local t = 5 -- This line should not be indented, 
              -- also note tab between local and t.

以下是我从Thomas获得的最新版本:

代码语言:txt
复制
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"
            )

除了明确指出的地方,我没有为缩进做任何事情,只在代码中输入并按下每一行末尾的返回。我实际上没有输入任何评论。

它应如下所示:

代码语言:txt
复制
local foo = function()
  print("Hello, world")
end

local bar = 5

local zzz = foo(
    "one",
    "two",
    three(),
    "four"
  )

还有一个错误的缩进情况:

代码语言:txt
复制
local foo =
{
bar(); -- Did press a TAB here, but closing brace killed it
baz;
}

应:

代码语言:txt
复制
local foo =
{
  bar();
  baz;
}

为了完整起见,下面是Lua模式

代码语言:txt
复制
local foo = function()
               print("Hello, world!")
            end

local bar = 5

local foo = bar(
bar,
   baz(),
   quo(),
aaa
)

local t =
{
"one",
two(),
}

通过调整:

代码语言:txt
复制
local foo = function()
           print("Hello, world!")
            end

            local bar = 5

            local foo = bar(
            bar,
               baz(),
               quo(),
               aaa
            )

            local t =
            {
            "one",
            two(),
         }

如下所示:

代码语言:txt
复制
local foo = function()
  print("Hello, world!")
end

local bar = 5

local foo = bar(
    bar,
    baz(),
    quo(),
    aaa
  )

local t =
{
  "one",
  two(),
}
EN

Stack Overflow用户

发布于 2018-03-28 10:29:37

可以尝试下:

代码语言:txt
复制
(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)
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100007822

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档