简体   繁体   English

在Emacs Verilog模式中对齐代码?

[英]Align code in Emacs Verilog Mode?

I'm used to writing code in VHDL in emacs, which has the nice beautify functionality that will align signal assignments. 我习惯用emacs中的VHDL编写代码,它具有很好的美化功能,可以对齐信号分配。 Is there something similar with the Verilog Mode? 是否有与Verilog模式类似的东西?

Convert this: 转换这个:

r_Tx_Done <= 1'b1;
r_Clock_Count <= 0;
if (r_Done == 1'b1)
  begin
    r_SM_Main <= s_CLEANUP;
    o_Tx_Active <= 1'b0;
  end

To This: 对此:

r_Tx_Done     <= 1'b1;
r_Clock_Count <= 0;
if (r_Done == 1'b1)
  begin
    r_SM_Main   <= s_CLEANUP;
    o_Tx_Active <= 1'b0;
  end

Verilog mode does a good job keeping if else begin end aligned, but it doesn't align assignments like I want. Verilog的模式做得很好保持if else begin end一致,但像我想它不对齐分配。 Note that inside the if statement doesn't align to <= outside the if statement. 请注意,if语句内部未与if语句之外的<=对齐。 Essentially I want each begin/end block treated separately. 基本上我希望每个开始/结束块单独处理。

I use verilog mode, and I have found this works by default. 我使用verilog模式,我发现默认情况下这是有效的。

  1. Type Cx h to highlight the entire buffer. 键入Cx h以突出显示整个缓冲区。
  2. Then TAB to get it to beautify everything. 然后TAB让它美化一切。 Much easier and less tedious! 更简单,更乏味!

Based on this answer you can try to customize align-rules-list . 根据此答案,您可以尝试自定义align-rules-list

Something like this should help: 这样的事情应该有所帮助:

(eval-after-load "align"
  '(add-to-list 'align-rules-list
                '(verilog-assignment
                  (regexp . "\\(\\s-*\\)<=")
                  (mode   . '(verilog-mode))
                  (repeat . nil))))

Now Mx align should apply the new alignment rule. 现在Mx align应该应用新的对齐规则。

In Verilog mode for GNU Emacs 24.3.1 you can place the cursor on the non-blocking assignment operator "<=" in any of the assignment operations. 在GNU Emacs 24.3.1的Verilog模式中,您可以将光标放在任何赋值操作中的非阻塞赋值运算符“<=”上。 For instance, in the top portion of the code: 例如,在代码的顶部:

r_Tx_Done <= 1'b1;
r_Clock_Count <= 0;

place the cursor on either of the assignment operators and type Cc = . 将光标放在任一赋值运算符上并键入Cc = The code will now become 代码现在将成为

r_Tx_Done     <= 1'b1;
r_Clock_Count <= 0;

This operation will only be performed in that section of code. 此操作仅在该部分代码中执行。 This operation will not jump into any other statements: if-else, case, always, etc. In order to perform the same operation in another statement you would have to go inside that statement click on an assignment operator and type Cc = again. 此操作不会跳转到任何其他语句:if-else,case,always等。为了在另一个语句中执行相同的操作,您必须进入该语句,单击赋值运算符并再次键入Cc =

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM