2

我正在努力实现以下目标:

void foo( int one,
int const & two,
Bar three)

void foo( int          one,
          inst const & two,
          Bar          three)

是否可以使用该align-regex函数(使用我们的不带前缀)来做到这一点?

更一般地说,正则表达式中的分组表示什么(它是被认为是“列”的部分)?什么是“要修改的括号组(如果为负则证明)”?

谢谢

4

2 回答 2

2

IMO 就是这种情况,正则表达式的使用变得越来越复杂。使用 syntax-ppss 的函数更容易:

(defun my-arguments-indent()
  "When called from inside an arguments list, indent it. "
  (interactive "*")
  (save-excursion
    (let* ((pps (syntax-ppss))
           (orig (point)) 
           indent)
      (while (and (nth 1 pps)(not (eobp)))
        (setq indent (save-excursion
                       (when (nth 1 pps)
                         (goto-char (nth 1 pps))
                         (forward-char 1)
                         (skip-chars-forward " \t")
                         (current-column))))
        (when (and (< orig (line-beginning-position)) indent)
          (beginning-of-line)
          (fixup-whitespace)
          (indent-to indent))
        (forward-line 1)
        (back-to-indentation)
        (setq pps (syntax-ppss))))))
于 2013-05-07T08:06:35.823 回答
1

请参阅C-hf align-regexp RET,特别是链接C-hv align-rules-list RET,它提供了一些最佳的对齐文档。

“要修改的组”是指图案中对齐时要缩小或扩大的组。您几乎总是希望该组是纯空白,以避免删除实际内容。

GROUP 参数——交互地“要修改的括号组(如果为负则证明)”——是正则表达式中相关组的编号,从 1 开始计数。

理由部分有点棘手。如果您提供负数,则使用相同的组,就好像该数字为正数一样,但align-rules-list也会触发变量的“调整”行为:

`justify'
It is possible with `regexp' and `group' to identify a
character group that contains more than just whitespace
characters.  By default, any non-whitespace characters in
that group will also be deleted while aligning the
alignment character.  However, if the `justify' attribute
is set to a non-nil value, only the initial whitespace
characters within that group will be deleted.  This has
the effect of right-justifying the characters that remain,
and can be used for outdenting or just plain old right-
justification.
于 2013-05-07T05:00:37.473 回答