简体   繁体   English

如何将参数与emacs中的函数对齐?

[英]how to align arguments to functions in emacs?

Say if I have the following: 如果我有以下内容:

func(arg1, arg2, arg3...)
func(longargarg1, longerarg2, arg3,...)
...

How do I align the arguments so that it's like following? 如何对齐参数以便跟随它?

func(arg1       , arg2      , arg3...)
func(longargarg1, longerarg2, arg3,...)
...

[I can use Mx align-regex to align the first argument, but I cannot cook up with a suitable regex to align the rest of the arguments. [我可以使用Mx align-regex来对齐第一个参数,但我不能用合适的正则表达式来对齐其余的参数。 Bonus point if the answer also take cares of the case when some arguments are strings with commas in them.] 如果某些参数是带有逗号的字符串,则答案也会考虑到这一点。

Select the region, then: 选择区域,然后:

C-u M-x align-regexp RET ,\(\s-*\) RET RET RET y

The regexp says to align commas with spaces following them. 正则表达式将逗号与跟随它们的空格对齐。 The default value of 1 for the paren group to modify means insert spaces where the \\(\\s-*\\) is, the default value of 1 for spaces to adjust means have one space after the longest expansion, and you want it repeated throughout the line. 要修改的paren组的默认值为1意味着在\\(\\s-*\\)所在的位置插入空格,对于要调整的空格,默认值为1表示在最长扩展后有一个空格,并且您希望它在整个过程中重复这条线。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM