英文:
realign code for readbility
问题
我有一些代码,看起来像这样:
Id string // 由交换提供的唯一竞标请求ID
Fields []interface{} // 字段对象数组
User interface{} // 用户对象
Device interface{}
我知道align-regexp
函数,并且我使用它来对齐我的注释。这将输出类似于:
Id string // 由交换提供的唯一竞标请求ID
Fields []interface{} // 字段对象数组
User interface{} // 用户对象
Device interface{}
然而,我也希望类型能够正确对齐。我试图弄清楚如何使用align-regexp
来实现这一点。不幸的是,我的正则表达式技能有限。
我希望输出的结果如下所示:
Id string // 由交换提供的唯一竞标请求ID
Fields []interface{} // 字段对象数组
User interface{} // 用户对象
Device interface{}
如果这需要两个单独的函数调用,我也不介意,因为我可以编写一个函数来封装它们。
另外,如果解决方案最终使用align-regexp
,我也不在意。迄今为止,这是我用来处理这类问题的方法。
英文:
I have some code that looks like
Id string // uniq bid req id provided by the exchange
Fields []interface{} // array of field objects
User interface{} // user obj
Device interface{}
I know about the align-regexp
function, and I use this to align my comments. This would output something like
Id string // uniq bid req id provided by the exchange
Fields []interface{} // array of field objects
User interface{} // user obj
Device interface{}
However, I would also like the types to be aligned properly. I was trying to figure out how I would be able to use align-regexp
in order to accomplish this. Unfortunately, my regex skills are lacking.
I would like the output to look like
Id string // uniq bid req id provided by the exchange
Fields []interface{} // array of field objects
User interface{} // user obj
Device interface{}
I wouldn't mind if this was two separate function calls, as I could just write a function that could encapsulate them.
Also, I don't care if the solution ends up using align-regexp
. This is just what I have been using for things like this thus far.
答案1
得分: 1
这可能比你想象的要简单。
你的类型总是一个单词吗?那么你可以使用一个空格作为第一个正则表达式,然后在“//”上对齐。在这个例子中是有效的
英文:
It's maybe simpler than you think.
Are your types always one word ? Then you can use a space as the first regexp, and then align on the //
. It does work with this example
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论