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 关于大棚监测的pcb板设计
  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计