dtn43447 2014-09-19 13:54
浏览 39
已采纳

重新对齐代码以提高可读性

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条回答 默认 最新

  • douwei1921 2014-09-19 14:27
    关注

    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 :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效