Skip to content
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

Improve fontification of variables #1807

Merged
merged 2 commits into from
Sep 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 31 additions & 27 deletions verilog-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,12 @@ always be saved."
:type 'boolean)
(put 'verilog-auto-star-save 'safe-local-variable #'verilog-booleanp)

(defcustom verilog-fontify-variables t
"Non-nil means fontify declaration variables."
:group 'verilog-mode-actions
:type 'boolean)
(put 'verilog-fontify-variables 'safe-local-variable #'verilog-booleanp)

(defvar verilog-auto-update-tick nil
"Modification tick at which autos were last performed.")

Expand Down Expand Up @@ -3437,12 +3443,12 @@ See also `verilog-font-lock-extra-types'.")
;; Pre-form for this anchored matcher:
;; First, avoid declaration keywords written in comments,
;; which can also trigger this anchor.
'(if (not (verilog-in-comment-p))
'(if (and (not (verilog-in-comment-p))
(not (member (thing-at-point 'symbol) verilog-keywords)))
(verilog-single-declaration-end verilog-highlight-max-lookahead)
(point)) ;; => current declaration statement is of 0 length
nil ;; Post-form: nothing to be done
'(0 font-lock-variable-name-face nil t)))
)))
'(0 font-lock-variable-name-face))))))


(setq verilog-font-lock-keywords-2
Expand Down Expand Up @@ -3743,31 +3749,28 @@ This function moves POINT to the next variable within the same declaration (if
it exists).
LIMIT is expected to be the pos at which current single-declaration ends,
obtained using `verilog-single-declaration-end'."

(let (found-var old-point)

;; Remove starting whitespace
(verilog-forward-ws&directives limit)

(when (< (point) limit) ;; no matching if this is violated

;; Find the variable name (match-data is set here)
(setq found-var (re-search-forward verilog-identifier-sym-re limit t))

;; Walk to this variable's delimiter
(save-match-data
(verilog-forward-ws&directives limit)
(setq old-point nil)
(while (and (< (point) limit)
(not (member (char-after) '(?, ?\) ?\] ?\} ?\;)))
(not (eq old-point (point))))
(setq old-point (point))
(when (and verilog-fontify-variables
(not (member (thing-at-point 'symbol) verilog-keywords)))
(let (found-var old-point)
;; Remove starting whitespace
(verilog-forward-ws&directives limit)
(when (< (point) limit) ;; no matching if this is violated
;; Find the variable name (match-data is set here)
(setq found-var (re-search-forward verilog-identifier-sym-re limit t))
;; Walk to this variable's delimiter
(save-match-data
Copy link
Member

@wsnyder wsnyder Sep 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the save-match-data should be in verilog-forward-ws instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is already wrapping the last three verilog-forward-ws&directives. I am sorry this diff seems so confusing, it is caused by the indentation changes after adding this condition at the beginning of the function:

  (when (and verilog-fontify-variables
             (not (member (thing-at-point 'symbol) verilog-keywords)))

(verilog-forward-ws&directives limit)
(forward-sexp)
(verilog-forward-ws&directives limit))
;; Only a comma or semicolon expected at this point
(skip-syntax-forward "."))
found-var)))
(setq old-point nil)
(while (and (< (point) limit)
(not (member (char-after) '(?, ?\) ?\] ?\} ?\;)))
(not (eq old-point (point))))
(setq old-point (point))
(verilog-forward-ws&directives limit)
(forward-sexp)
(verilog-forward-ws&directives limit))
;; Only a comma or semicolon expected at this point
(skip-syntax-forward "."))
found-var))))

(defun verilog-point-text (&optional pointnum)
"Return text describing where POINTNUM or current point is (for errors).
Expand Down Expand Up @@ -15505,6 +15508,7 @@ Files are checked based on `verilog-library-flags'."
verilog-compiler
verilog-coverage
verilog-delete-auto-hook
verilog-fontify-variables
verilog-getopt-flags-hook
verilog-highlight-grouping-keywords
verilog-highlight-includes
Expand Down