all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Reza Nikoopour <rnikoopour@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Help Understanding syntax-propertize-function
Date: Mon, 15 Mar 2021 21:42:38 -0400	[thread overview]
Message-ID: <jwvtupbridu.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <CAKesZq1bgL81p9no_wrQuM8GZ6rbXF8Ro6d9ahvcXUR7O+i47w@mail.gmail.com> (Reza Nikoopour's message of "Mon, 15 Mar 2021 16:58:41 -0700")

> I'm struggling to understand what `hcl--syntax-propertize-heredoc` is
> doing.
> Could you provide a high level explanation like you did with
> `hcl--syntax-propertize-function`.
> That helped me a lot.

> (defun hcl--syntax-propertize-heredoc (end)

The purpose of the function is to do the "syntax-propertize" of the
inside of a heredoc.  It presumes that point *may* be in a heredoc but
not necessarily.

>   (let ((ppss (syntax-ppss)))
>     (when (eq t (nth 3 ppss))

Here we fetched the syntax state at point and then we checked that we
are indeed inside a heredoc (or at least a "string like thing" that was
opened using the `|` syntax category; in this mode should should only
ever happen if we have placed this syntax because we found a heredoc
marker).

>       (let ((key (get-text-property (nth 8 ppss) 'hcl-here-doc-marker))

This fetches the string that was used in the heredoc opener and which
has to be used as heredoc closer.  It's been placed on the opening char
at position (nth 8 ppss) by the same code that placed the `|` syntax
property on that same character.

>             (case-fold-search nil))

I guess here that the code does that because HCL defines the heredoc
marker to be case-significant.

>         (when (re-search-forward
>                (concat "^\\(?:[ \t]*\\)" (regexp-quote key) "\\(\n\\)")
>                end 'move)

Here we look for the heredoc end marker.  If we can't find one before
`end`, it just means that the heredoc extends further and hence we have
nothing to do (we could actually remove/override any `|` syntax that
might appear before `end` in case such a thing is possible, but
apparently the rest of code is arranged so that this is not needed).

>           (let ((eol (match-beginning 1)))
>             (put-text-property eol (1+ eol)
>                                'syntax-table (string-to-syntax "|"))))))))

If we did find the heredoc end marker before `end`, then we mark it as
being the end by adding the `|` syntax to the ending character.


        Stefan




  reply	other threads:[~2021-03-16  1:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-15 22:48 Help Understanding syntax-propertize-function Reza Nikoopour
2021-03-15 23:30 ` Stefan Monnier
2021-03-15 23:58   ` Reza Nikoopour
2021-03-16  1:42     ` Stefan Monnier [this message]
2021-03-16 15:37       ` Reza Nikoopour
2021-03-16 17:29         ` Stefan Monnier
2021-03-16 17:50           ` Reza Nikoopour
2021-03-24 20:29   ` Filipp Gunbin
2021-03-24 22:10     ` Stefan Monnier
2021-03-24 22:54       ` Filipp Gunbin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvtupbridu.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=rnikoopour@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.