[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Help Understanding syntax-propertize-function
From: |
Stefan Monnier |
Subject: |
Re: Help Understanding syntax-propertize-function |
Date: |
Mon, 15 Mar 2021 19:30:08 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
> Could someone help explain the following code:
I'm not sure which part you don't understand, so I'll stick to
generic ideas:
> (defun hcl--syntax-propertize-function (start end)
> (goto-char start)
> (hcl--syntax-propertize-heredoc end)
> (funcall
> (syntax-propertize-rules
> (hcl--here-doc-beg-re
> (2 (hcl--font-lock-open-heredoc
> (match-beginning 0) (match-string 1) (match-beginning 2))))
> ("\\s|" (0 (prog1 nil (hcl--syntax-propertize-heredoc end)))))
> (point) end))
Since we don't know where `start` will be, it can be within a heredoc.
So we first call `hcl--syntax-propertize-heredoc` which should detect
when we're inside a heredoc and if so process it until its end and if not
do nothing.
Once that's done, we know we're not in a heredoc, hence we're in
"normal code" and we then use `syntax-propertize-rules` to try and
detect a few interesting conditions. One of them is when we find
a match for `hcl--here-doc-beg-re`, in that case we call
`hcl--font-lock-open-heredoc` to place some syntactic marker at the
beginning of the heredoc. The other is when we see a char of
syntactic category `|`, which doesn't occur in the wild but should
presumably be the result of `hcl--font-lock-open-heredoc` having placed
it there, so it announces the beginning of a heredoc, in which case we
can call `hcl--syntax-propertize-heredoc` to process it.
Stefan
Re: Help Understanding syntax-propertize-function, Filipp Gunbin, 2021/03/24