Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
emacs垂直对齐函数参数_Emacs_Text Alignment - Fatal编程技术网

emacs垂直对齐函数参数

emacs垂直对齐函数参数,emacs,text-alignment,Emacs,Text Alignment,我正在努力实现以下目标: void foo( int one, int const & two, Bar three) 到 使用带有我们的无前缀的align regex函数可以做到这一点吗 更一般地说,正则表达式中的分组表示什么?它是被视为“列”的部分吗?什么是“如果为负数,则要修改的括号组”呢 谢谢请参阅C-hf align REGEP RET,特别是链接的C-hv align rules list RET,它提供了一些最佳的对齐文档 要修改的组是指阵列中在对齐时将缩小或扩大的组。为

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

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

使用带有我们的无前缀的align regex函数可以做到这一点吗

更一般地说,正则表达式中的分组表示什么?它是被视为“列”的部分吗?什么是“如果为负数,则要修改的括号组”呢

谢谢

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

要修改的组是指阵列中在对齐时将缩小或扩大的组。为了避免删除实际内容,您几乎总是希望该组为纯空白

GROUP参数(交互式地将GROUP括起来,以便在为负数时修改justify)是regexp中有问题的组的数目,从1开始计数

对正部分有点棘手。如果提供负数,则使用相同的组,如同该数字为正数一样,但也会触发align rules list变量的“justify”行为:

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

依我看,在这种情况下,regexp的使用变得越来越复杂。使用语法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))))))

没错,对于align regexp来说,这是一个相当棘手的问题。我可能会使用一个自定义的对齐规则列表规则,这样您就可以指定多个组来对齐,这简化了事情,但是这种方法看起来很有趣。我真的需要记住语法PPS是存在的+1@Andreas罗勒,你能更详细地解释一下如何使用这个功能吗?我已经将它放在init.el中,重新运行emacs,选择函数并按tablation,看不到任何效果。@klm123这只是一个示例,演示了在第二个参数处使用point调用算法。扩展了它,所以它也应该从第一个参数内部起作用。@Andreas Röhler,好吧,也许我离这个太远了。但是谢谢。很抱歉耽搁了,我在emacs regexs上遇到了问题。我的emacs版本21.4和22.4都没有关于对齐规则列表的文档。因此,如果您有多个括号组,为了对齐,只有“要修改的组”指示的括号组与align regexp相关,这是正确的。此外,Emacs 21和22都非常旧。您不妨考虑升级。
(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))))))