Defining multi-character parentheses in Emacs

In Verilog, you enclose blocks of code between the words "begin" and "end" as follows:

if(foo) begin x <= 1'b0; y <= 1'b0; end else begin x <= x_d; y <= y_d; end 

Is there a way to set the start and end as brackets in Emacs so you can use check-parens or the like to find inappropriate ones?

I tried adding this (and options) to the ~ / .emacs file, but he doesn't like it ...

 (modify-syntax-entry ?begin "(end" ) (modify-syntax-entry ?end ")begin" ) 

Thanks.

+7
source share
1 answer

Unfortunately, the Emacs bracket matching framework does not understand many multi-valued tokens. The new SMIE library, added in Emacs-23.4, is partly designed to solve this problem. It allows the main modes to describe the syntax of the language (in a very limited form of grammar), after which things like CMf and CMb will know how to jump over logical elements, for example. skip from begin to its end match. As LindyDancer notes, such things are usually necessary for indentation, and in fact, the main motivation for SMIE was to provide a common indentation mechanism.

Verilog now does not use SMIE, but it implements similar navigation commands. So you could try something like

 (defun sm-verilog-check-parens () (save-excursion (goto-char (point-min)) (while (not (eobp)) (verilog-forward-sexp)))) 

Tho I do not know if verilog-forward-sexp will give appropriate warnings / errors if it encounters at the end of the buffer at an unexpected moment.

+2
source

All Articles