Lua中的Lua缩进代码 [英] Lua indentation code in Lua

查看:508
本文介绍了Lua中的Lua缩进代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在用于缩编Lua代码的Lua代码?

Does there exist Lua code to indent Lua code?

我有很多lua代码,在纯lua环境中,缩进会有所帮助.

I have a lot of lua code where indenting it would help, and its in a pure lua environment.

为我的问题辩护:对于这里的某些人来说,这里的情况听起来是不可能的.这与请求Emacs Lisp代码格式化文本非常相似.这是一个真正的实时工作(公司内部)Lua环境.这是一个纯粹的lua环境.我正在寻找可以缩进Lua代码的Lua工具,而不是对最佳编辑器的意见.保罗·库尔琴科(Paul Kulchenko)提供了一个了不起的解决方案,尤苏夫X(Yusuf X)也提供了.

In defence of my question: For some of you here the situation here sounds impossible. It is very similar to requesting for Emacs Lisp code to format text. This is a real live working (company internal) Lua environment. This is a pure lua environment. I am looking for a Lua tool which can indent Lua code, not an opinion about the best editor. Paul Kulchenko has provided an amazing solution and so has Yusuf X.

推荐答案

我写了

I have written a Lua beautifier and applied it to my project with a large group of Lua files (about 8k lines in total). The beautifier is in Perl (and yes, I saw that the question is about it being in Lua), but (1) it is only 55 lines and it should be easily translatable to Lua (I just haven't got time to do that yet), and (2) you can format your files somewhere else and transfer back to your environment (unless you need this re-formatting to be done on a regular basis).

此美化工具基于另一个基于Lua的插件(截止到3/11/的udead链接) 2013; 网络归档副本),但是最初的案例无法处理我感兴趣的所有案例,因此我最终重写了它.不过,它可能仍然对您有用.

This beautifier is based on another Lua-based one (udead link as of 3/11/2013; web archive copy), but the original one didn't handle all the cases that I was interested in, so I ended up re-writing it. It may still work for you though.

美化器不会更改行结构(这是要求之一),它很容易检查,但会更改缩进和格式(并处理嵌入式匿名函数和其他类似事物的复杂情况).该链接包含其功能的一些示例.您还可以使用大多数转换后的文件查看我为我们的项目所做的长期提交: https://github.com/pkulchenko/ZeroBraneStudio/commit/85be27559058ce085e95cef47de2c11185f9211a .

The beautifier doesn't change the line structure (it was one of the requirements), which makes it easy to check, but changes the indentation and formatting (and handles complex cases of embedded anonymous functions and other similar things). The link includes some examples of what it does. You can also review the long commit I did for our project with most of the converted files: https://github.com/pkulchenko/ZeroBraneStudio/commit/85be27559058ce085e95cef47de2c11185f9211a.

如果您只是在寻找一种简单的方法来缩进文件(而不是将缩进逻辑集成到您的应用程序中),则可以使用 ZeroBrane Studio IDE (Edit | Source | Correct IndentationCtrl-I).

If you are looking only for an easy way to indent your files (rather than to integrate the indentation logic into your application), then you can use ZeroBrane Studio IDE (Edit | Source | Correct Indentation or Ctrl-I).

这篇关于Lua中的Lua缩进代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆