简体   繁体   English

Emacs对齐方式将不对齐注释/嵌入式注释

[英]Emacs align mode will not align comments/inline comments

I would like to align the comments/inline comments in this verilog code example. 我想在此Verilog代码示例中对齐注释/内嵌注释。 I plan on aligning each section separately by highlighting the regions and doing Mx align . 我计划通过突出显示区域并进行Mx align分别对齐每个部分。 I found lisp code to align verilog code and I have it working fine, but I can't get comments to align for the life of me. 我发现Lisp代码可以对齐Verilog代码,并且可以正常工作,但是我无法获得注释以使我一生都可以对齐。 I'm beginning to think its disabled somehow in align mode. 我开始认为它在对齐模式下已禁用。

module spi_jstk ( 
                  input        clk, // System Clock (40MHz)
                  input        reset, // Async Reset
                  input        START, // Initialize SPI Transfer
                  input [39:0] DATA, // Input Data to Transfer
                  input        SS, // Chip Select
                  output       SCLK, // Serial Clock
                  output       NEW, // NEW SIGNAL
                  input        MISO, // Master In Slave Out
                  output       MOSI );  // Master Out Slave In

   test0  = signal; // comment
   test   = signal;   // comment
   test1  = signal;  // comment
   test11 = signal; // comment

   //
    //
   //
endmodule

Here's the elisp: 这是elisp:

(defcustom align-verilog-rules-list
    `(
         (verilog-declaration
             (regexp . "\\(logic\\|input\\|output\\|inout\\|wire\\|reg\\)\\s-*\\(\\s-+[[][^]]+[]]\\|reg\\|\\)\\(\\s-+\\)")
             (group . (3)))

         (verilog-asgn_param
             (regexp . "\\(assign\\|parameter\\)\\(\\s-+\\)\\S-")
             (group . (2)))

         (verilog-assign
             (regexp . "\\S-+\\(\\s-*\\)[!=><]+\\(\\s-*\\)\\S-")
             (group . (1 2)))

         (verilog-ports-no-comment
             (regexp . "[.][a-zA-Z0-9_]+\\(\\s-+\\)\\S-")
             (group . (1)))

;; Want to add code to align comments here.

         )
    "Verilog alignment rules."
    :type  'align-rules-list-type
    :group 'align)

(put 'align-verilog-rules-list 'risky-local-variable t)

(defun verilog-extras-hook ()
    (setq align-mode-rules-list align-verilog-rules-list))

(add-hook 'verilog-mode-hook 'verilog-extras-hook t)

;; Align with spaces
(setq-default indent-tabs-mode nil)

What would I need to add to align the comments? 我需要添加什么来对齐注释?

Here's the weird part, I can add a function that calls 'align-regexp' to make this work (see below). 这是一个很奇怪的部分,我可以添加一个调用“ align-regexp”的函数来完成这项工作(见下文)。 Additionally when I apply the same regexp to the 'align' function above it doesn't work. 另外,当我将相同的正则表达式应用于上方的“ align”功能时,它将不起作用。

This using 'align-regexp' works: 这使用'align-regexp'起作用:

(defun align-comments (beg end)
    (interactive "r")
    (align-regexp beg end "\\(\\s-*\\)//\\(\\s-*\\)" 1 1 t))

I seem to be missing something because I can't understand regexps or how to apply them to these functions for the life of me. 我似乎遗漏了一些东西,因为我不了解正则表达式或如何在我的一生中将其应用于这些功能。 I've been struggling with this for some time now. 我已经为此苦了一段时间了。

Also, if it helps anyone, here's the original code this is based off of: https://groups.google.com/forum/#!topic/gnu.emacs.help/odgMEJGd6Os 另外,如果它可以帮助任何人,那么这是基于以下内容的原始代码: https : //groups.google.com/forum/#!topic/gnu.emacs.help/odgMEJGd6Os

So far I have come up with this (outdated, see below): 到目前为止,我已经提出了这一点(已过时,请参见下文):

     (verilog-comment
         (regexp . "\\S-+\\(\\s-*\\)[/]+\\(\\s-*\\)\\S-")
         (group . (1 2)))

Which seems to almost do what I want, but doesn't work for non-inline comments (third set of comments at very bottom of verilog code). 这似乎几乎可以满足我的要求,但不适用于非内联注释(第三组注释位于verilog代码的最底部)。

Updated (latest!): 更新(最新!):

     (verilog-comment
         (regexp . "\\(\\s-*\\)[/]+\\(\\s-*\\)\\S-")
         (group . (1 2)))

Looks like I needed to get rid of the whitespace expression \\S-+ in the very beginning for some reason. 看起来由于某种原因,我一开始需要摆脱空格表达式\\ S- +。 Seems to confuse emacs regexp's which is strange because it looks valid. 似乎使emacs regexp混淆了,这很奇怪,因为它看起来有效。 Anyways I found a nice tool called Mx re-builder which really helped visualize what the hell was going on. 无论如何,我找到了一个名为Mx re-builder的好工具,它确实有助于可视化到底发生了什么。 Hope this helps someone in the future! 希望这对以后的人有所帮助!

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

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