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 M-x align-regex to align the first argument, but I cannot cook up with a suitable regex to align the rest of the arguments. 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.
来源:https://stackoverflow.com/questions/970759/how-to-align-arguments-to-functions-in-emacs