I would like to align the comments/inline comments in this verilog code example. I plan on aligning each section separately by highlighting the regions and doing 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. 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:
(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). Additionally when I apply the same regexp to the 'align' function above it doesn't work.
This using 'align-regexp' works:
(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
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).
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. Seems to confuse emacs regexp's which is strange because it looks valid. Anyways I found a nice tool called Mx re-builder
which really helped visualize what the hell was going on. Hope this helps someone in the future!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.