在Emacs中定义多字符括号

kit*_*key 7 emacs verilog parentheses

在Verilog中,您可以在"begin"和"end"之间包含代码块,如下所示:

if(foo) begin
   x <= 1'b0;
   y <= 1'b0;
end else begin
   x <= x_d;
   y <= y_d;
end
Run Code Online (Sandbox Code Playgroud)

有没有办法在Emacs中将begin和end设置为括号,以便您可以使用check-parens或类似的方法来查找不匹配的任何内容?

我已经尝试将此(以及变体)添加到我的〜/ .emacs文件中,但它不喜欢它...

(modify-syntax-entry ?begin "(end" )
(modify-syntax-entry ?end ")begin" )
Run Code Online (Sandbox Code Playgroud)

谢谢.

Ste*_*fan 3

遗憾的是,Emacs 的括号匹配基础结构不能理解太多的多字符标记。Emacs-23.4 中添加的新库 SMIE 部分是为了解决这个问题。它让主要模式描述语言的语法(以非常有限的语法类型),之后像 CMf 和 CMb 这样的东西将知道如何跳过逻辑元素,例如从 a 跳转begin到其匹配end。正如 LindyDancer 所指出的,缩进通常需要这些东西,实际上 SMIE 背后的主要动机是提供一个通用的缩进引擎。

现在 Verilog 不使用 SMIE,但它确实实现了类似的导航命令。所以你可能可以尝试类似的事情

(defun sm-verilog-check-parens ()
  (save-excursion
    (goto-char (point-min))
    (while (not (eobp))
      (verilog-forward-sexp))))
Run Code Online (Sandbox Code Playgroud)

不过,我不知道如果verilog-forward-sexp它在意外时刻撞到缓冲区末尾是否会给您适当的警告/错误。