5

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:

enter image description here

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):

enter image description here

Here's what I've tried. You can see from the result that the behavior isn't right.

"^\\(\\( \\) \\{%s\\}\\) \\{1,\\}"

Result:

enter image description here

Also tried

"^\\(\\( \\) \\{%s\\}\\)\\{1,\\}"

Result:

enter image description here

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))))
4

1 回答 1

1

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)))
于 2013-07-08T12:27:45.183 回答