如何将参数对齐到emacs中的函数? [英] how to align arguments to functions in emacs?

查看:127
本文介绍了如何将参数对齐到emacs中的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有以下条件:

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

调整参数,这样就像下面的那样?

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

[我可以使用Mx align-regex对齐第一个参数,但是我不能用适当的正则表达式来调整其余的参数。奖金点,如果答案也关心的情况下,一些参数是用逗号分隔的字符串。]

解决方案

选择区域,然后:

  Cu Mx align-regexp RET,\(\s- * \)RET RET RET y 

正则表达式表示将逗号与其后面的空格对齐。默认值为1,为了更改括号组,意味着插入空格,其中 \(\s- * \)是,空格的默认值为1调整手段在最长展开后有一个空格,您希望在整个行中重复。


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.

这篇关于如何将参数对齐到emacs中的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆