I am trying to fix the regex for a highlight indentation module for emacs. The way it works currently is by highlighting once every %s spaces:
"\\( \\) \\{%s\\}"
And here's a sample result of the behavior for some Verilog code:
The current regex works well for the indentations in the beginning of each line. However, there is an undesirable artifact that sequences of spaces that are not at the beginning of the line are also matched by the regex. I would like to modify the regex to match the above behavior, but only at the beginning of the line. Here's what I want (I had to manually draw it):
Here's what I've tried. You can see from the result that the behavior isn't right.
"^\\(\\( \\) \\{%s\\}\\) \\{1,\\}"
Result:
Also tried
"^\\(\\( \\) \\{%s\\}\\)\\{1,\\}"
Result:
Here is the relevant code, but I apologize It is not a working example. Please use the above link for a working example.
(set (make-local-variable 'highlight-indentation-current-regex)
(format "\\( \\) \\{%s\\}" (- highlight-indentation-offset 1)))
(font-lock-add-keywords nil `((,highlight-indentation-current-regex
(1 'highlight-indentation-face))))
Assuming your current font-lock rule looks like:
(,highlight-indentation-current-regex (1 'highlight-indentation-face))
you could use
(,highlight-indentation-current-regex (1 (if (save-excursion (skip-chars-backward " \t") (bolp)) 'highlight-indentation-face)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With