【问题标题】:Right-justification of a column using align-regexp使用 align-regexp 对列进行右对齐
【发布时间】:2014-01-14 19:35:50
【问题描述】:

我尝试使用 align-regexp 对齐某些内容,但无法获得所需的行为。

这是我最初拥有的:

  [21:26] <Luke-Jr> btcNeverSleeps: no
  [21:26] <dmanderson> Not if it has to wait to make it into the block
  [21:26] <btcNeverSleeps> Luke-Jr: can you develop a bit?
  [21:26] <Luke-Jr> btcNeverSleeps: Bitcoin is a currency, not an authentication system
  [21:26] <dmanderson> your user could be waiting a LONG time for 1 Satoshi to who up
  [21:26] <Luke-Jr> btcNeverSleeps: you can use signed messages though

这就是我想要的:

  [21:26]        <Luke-Jr> btcNeverSleeps: no
  [21:26]     <dmanderson> Not if it has to wait to make it into the block
  [21:26] <btcNeverSleeps> Luke-Jr: can you develop a bit?
  [21:26]        <Luke-Jr> btcNeverSleeps: Bitcoin is a currency, not an authentication system
  [21:26]     <dmanderson> your user could be waiting a LONG time for 1 Satoshi to who up
  [21:26]        <Luke-Jr> btcNeverSleeps: you can use signed messages though

这是我使用“align-rexegp RET > RET”得到的结果:(这不是我想要的)

  [21:26] <Luke-Jr        > btcNeverSleeps: no
  [21:26] <dmanderson     > Not if it has to wait to make it into the block
  [21:26] <btcNeverSleeps > Luke-Jr: can you develop a bit?
  [21:26] <Luke-Jr        > btcNeverSleeps: Bitcoin is a currency, not an authentication system
  [21:26] <dmanderson     > your user could be waiting a LONG time for 1 Satoshi to who up
  [21:26] <Luke-Jr        > btcNeverSleeps: you can use signed messages though

我想用一个简单的align-regexp 来完成还是我应该研究更高级的东西? (例如,我知道我绝对可以使用宏来完成,但我首先想知道是否可以使用简单的正则表达式来完成)。

【问题讨论】:

  • 我不知道 emacs 正则表达式例程。但是,您要查找的对齐需要对源进行完整解析,然后才能使用正确的对齐偏移写入新源。试试&lt;[^&gt;]*&gt;,不知道RET是什么。
  • @sln: 'RET' 只是 Emacs 文档中使用的一种约定,这里的意思是“此时按回车键”:)(您可以在其中一个答案中看到一些格式很好的内容下面)

标签: regex emacs alignment


【解决方案1】:

align-regexp 函数没有很好的文档记录。在这种情况下你真正想做的是使用 C-u M-x align-regexp

然后,按照提示输入 -1 以证明捕获组的合理性。

使用正则表达式进行复杂对齐:(&lt;[^&gt;]*&gt;)

要修改的括号组(如果为负则证明):-1

间距量(或列,如果为负数):1

整行重复? (是或否):是

【讨论】:

  • 谢谢,太好了...遗憾的是我无法投票给任何人,因为我错过了 5 个声望点; (
  • +1 for The align-regexp function is not well documented. 我很想看到一些关于这方面的文档,但我并不认为我熟悉它的内部结构。
【解决方案2】:

您需要在捕获组中包含括号内的文本,然后通过提供 negative 组参数来打开对齐:

C-u M-xalign-regexpRET\( &lt;[^&gt;]+&gt;\)RETDEL@ 987654323@RETRETn

align-regexp 绝对是更神秘的 Emacs 命令之一。不过很强大。

【讨论】:

  • 我知道使用 align-regexp 将成为可能。我仍然需要研究那个说:)
【解决方案3】:

您可以将第三个文本样本转换为第二个使用 replace-regexp&lt;\([^ ]+\)\( +\)\2&lt;\1

【讨论】:

  • 啊,不能投票给你:没有足够的代表(需要 15 个代表)。是的,确实,这很好。但是用 align-regexp 一次性完成呢,可行吗?
  • 可能不会。即使是这样,将 align-regexp 和 replace-regexp 的调用包装在一个函数中也容易得多。没有参数或确认或前缀参数。
猜你喜欢
  • 2021-09-03
  • 2013-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-13
  • 2017-02-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多