有人用 Spacemacs 写 Lua 代码吗?

默认的lua layer 启用了compay-mode; 我使用ctags -e -R 生成TAGS, 之后company-mode不起作用(调用company-etags提示不能补全), 但是手动按tab键 HELM Completion At Point有补全选项.

不知道在spacemacs 中如何方便的补全lua?

这个是按tab后出现的结果, 不按tab键就什么都没有

user-config里面添加下列代码:

(spacemacs|defvar-company-backends lua-mode)
 (spacemacs|add-company-hook lua-mode)

如果想补全关键字,可以再加上这个:

    ;;; add lua language, basic, string and table keywords.
    (with-eval-after-load 'lua-mode
      (push '(lua-mode  "setmetatable" "local" "function" "and" "break" "do" "else" "elseif" "self" "resume" "yield"
                        "end" "false" "for" "function" "goto" "if" "nil" "not" "or" "repeat" "return" "then" "true"
                        "until" "while" "__index" "dofile" "getmetatable" "ipairs" "pairs" "print" "rawget" "status"
                        "rawset" "select" "_G" "assert" "collectgarbage" "error" "pcall" "coroutine"
                        "rawequal" "require" "load" "tostring" "tonumber" "xpcall" "gmatch" "gsub"
                        "rep" "reverse" "sub" "upper" "concat" "pack" "insert" "remove" "unpack" "sort"
                        "lower") company-keywords-alist))
1 个赞

.spacemacs 配置片段

测试环境: windows 10 spacemacs 0.105.19

company-mode仍然不能补全~

有重启编辑器试试么? 如果不能补全,能否用 C-h vcompany-backends 这个变量的值输出看一下。

重启编辑器了的, 下图是company-backends的截图, 正在编辑的是InitServer.lua文件

好像有company-etags, 使用这个company-mode是否还要安装其它软件? 像正则表达式支持那些?

你需要添加 auto-completion layer ,同时调用 (global-company-mode t) 在 user-config里面

仍然不行, 不过我手动调用company-other-backend 有补全列表了, 估计是backend后端配置有bug.

我这边都是可以的呀。。。你再查查 company backend 吧。

好像是空的

你的 lua 关键字能补全吗?

另外 已经写过的代码能补全吗?

打开过的文件中的单词都能补全, lua关键字不能补全, 没有添加关键字

TAG 不能补全么? 可以尝试换几个 tag,或者检查一下你的 tag 文件里面是否有这个 tag。。。

把你的 lua 文件和 tags 文件发给我试试。。 你这个代码贴得太丑了。。。 删掉吧。用 github gist 上传代码,然后在论坛里面放链接就行了。

你都可以用 Github Gist 上传你的 tags 和 lua 文件。