-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for alignment of user defined types. #1803
Conversation
We cannot require eval: in local variables, and verilog-typedef-regexp is extremely commonly used with the existing definition, so please use it as-is without adding the identifier regexp. (Just add the identifier regexp where used or in a function that merges it with typedef regexp)
Doesn't verilog-typedef-regexp allow the exact same thing? Also generally most organizations I know use a naming convention and maintaining a specific list would be very painful. |
Hi @wsnyder , thanks for the review,
Things will work as they did before with the existing definition. The only place where (defun verilog-typedef-name-p (variable-name)
"Return true if the VARIABLE-NAME is a type definition."
(when verilog-typedef-regexp
(verilog-string-match-fold verilog-typedef-regexp variable-name))) Any valid type identifier ending in (defun verilog-get-declaration-typedef-re ()
"Return regexp of a user defined typedef.
See `verilog-typedef-regexp' and `verilog-typedef-words'."
(let (typedef-re words words-re re)
(when (verilog-align-typedef-enabled-p)
(setq typedef-re verilog-typedef-regexp)
(setq words verilog-typedef-words)
(setq words-re (verilog-regexp-words verilog-typedef-words))
(cond ((and typedef-re (not words))
(setq re typedef-re))
((and (not typedef-re) words)
(setq re words-re))
((and typedef-re words)
(setq re (concat verilog-typedef-regexp "\\|" words-re))))
(concat "\\s-*" "\\(" verilog-declaration-prefix-re "\\s-*\\(" verilog-range-re "\\)?" "\\s-*\\)?"
(concat "\\(" re "\\)")
"\\(\\s-*" verilog-range-re "\\)?\\s-+")))) I tried to figure out a way of obtaining the whole regexp for declaration matching from existing definition but I do not think its simple (i.e. obtaining In 999498e I did the same but adding the variable
Why? It seems to work fine. Anyway, any line containing: // eval: (setq verilog-typedef-regexp (concat "\\<" verilog-identifier-re "_t\\>")) Can be rewritten as: // verilog-typedef-regexp: "\\<[a-zA-Z_][a-zA-Z_0-9]*_t\\>"
This is the purpose of current PR: any type matching Thanks! |
* verilog-mode.el (Line#781, Line#787, verilog-align-typedef-enabled-p, verilog-align-typedef-regexp, verilog-align-typedef-words, verilog-get-declaration-re, verilog-get-declaration-typedef-re, verilog-looking-at-decl-to-align, verilog-mode, verilog-submit-bug-report): Add support for alignment of user defined types. Signed-off-by: Gonzalo Larumbe <[email protected]>
e7c2766
to
3ed94f4
Compare
Current force-pushed commit replaces |
How is this intended to work? I have attached a test case align_test.v I want mystruct_t to be recognized as part of the type and treated for the purposes of alignment the same way as "logic" is treated in "output logic out;". I thought this is what verilog-align-typedef-regexp was added to handle, but it doesn't work as I expect. If I instead add the whole type name "mystruct_t" to the verilog-align-typedef-words list, it skips alignment entirely for that line. |
Hi @thomase00 , You can check #1823 (comment). For your particular case:
I tried both locally and worked fine with the latest |
This causes it to not perform any alignment at all for declarations of the type "mystruct_t". Is this as intended? The syntax highlighting (not shown in my align_test.txt file) seems to to still be recognizing "mystruct_t" as a port name rather than as part of the type. The actual port name "in" has no highlighting at all, unlike the other port names. I was expecting the port name "in" to be aligned with the other port names, but the alignment of the type name "mystruct_t" to be left alone. |
Is the type name even really needed to do this correctly? Why not just have the alignment be anchored to the begging of the last identifier or the begging of the first of a list of comma-delimited identifiers at the end of the line. |
I am not sure what is the result you get after running
Syntax highlighting of variables through |
Thanks! I've never used verilog-pretty-declarations before, I've only ever used TAB while editing on-the-fly. I'm guessing this a workaround to avoid doing a pass over the buffer after every line, due to there not being a good way to maintain the "state" of indentation and alignment on-the-fly... |
Hi,
This PR adds support for alignment of user defined types when running
verilog-pretty-declarations
.Related issues: #308 #386 #920
To perform alignment two variables are used:
verilog-typedef-regexp
: already existing variable, string that matches user types."\\<[a-zA-Z_][a-zA-Z_0-9]*_t\\>"
or(concat "\\<" verilog-identifier-re "_t\\>")
."_t$"
) alignment is not supported but AUTO functions still work as they did before.verilog-typedef-words
: new variable, list of strings that match user types, e.g.'("my_type" "custom_if" "my_enum")
. Defaults tonil
.Thanks!