假设我定义了一个m4宏FOOBAR,其中包含一段任意文本,可能包含逗号字符。请创建一个m4宏,添加5个空格的左边距
问题很简单(只需使用patsubst w/"^"正则表达式),如果文本不包含任何逗号。但是我需要处理逗号
谢谢!
需要润色,但这是一个开始:
m4_divert(-1)
I changed the m4 quoting to use [<{}>]
m4_define(_spaces,[<{m4_format([<{%}>]$1[<{s}>],)}>])
m4_define(_indent,[<{m4_patsubst($1,[<{^}>],_spaces($2))}>])
m4_define(_Comma_and_Paren_Safe,[<{m4_patsubst([<{[<{Some. arbitrary text,with unbalanced parentheses like:
((()((((
and several commas ,,,, and a few, more , of those
commas,,.
}>]}>],[<{,}>],[<{[<{,}>]}>])}>])
m4_divert(0)m4_dnl
_indent([<{_Comma_and_Paren_Safe}>],7)
示例运行(_m42是简单的m4包装脚本):
$ _m42 < ~/tmp/2v.STDIN.m4-margin.SatMay16.2052.190
Some. arbitrary text,with unbalanced parentheses like:
((()((((
and several commas ,,,, and a few, more , of those
commas,,.
比之前的尝试更简单:保存到宏FOOBAR -任意文本嵌套在四引号内以保护逗号的段落,和不平衡的括号:
m4_divert(-1)
m4_define(_spaces,[<{m4_format([<{%}>]$1[<{s}>],)}>])
m4_define(_indent,[<{m4_patsubst($1,[<{^}>],_spaces($2))}>])
--
Simpler than prior attempt: save arbitrary text paragraph nested inside
quadruple quote to protect commas, and unbalanced parentheses:
m4_define(FOOBAR,[<{[<{[<{[<{Some. arbitrary text,with unbalanced parentheses like:
((()((((
and several commas ,,,, and a few, more , of those
commas,,.
}>]}>] }>]}>])
m4_divert(0)m4_dnl
_indent(FOOBAR,15)
示例运行:
$ _m42 < ~/tmp/2v.STDIN.m4-margin.SatMay16.2052.190
Some. arbitrary text,with unbalanced parentheses like:
((()((((
and several commas ,,,, and a few, more , of those
commas,,.