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

发布于 2024-07-23 07:43:25 字数 342 浏览 5 评论 0原文

假设我有以下情况:

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

如何对齐参数,使其如下所示?

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

[我可以使用 Mxalign-regex 来对齐第一个参数,但我无法使用合适的正则表达式来对齐其余参数。 如果答案也考虑到某些参数是带有逗号的字符串的情况,那就加分了。]

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.]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白馒头 2024-07-30 07:43:25

选择区域,然后:

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

正则表达式表示将逗号与其后面的空格对齐。 括号组修改默认值1表示在\(\s-*\)所在位置插入空格,调整空格默认值1表示最长扩展后有一个空格,并且您希望它在整行中重复。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文