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: How to use Generic String Delimiter ("|")
Date: Sun, 07 Nov 2021 15:57:14 -0500	[thread overview]
Message-ID: <jwvk0hj4rpn.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <CAKesZq05X=uvGdxqs7b_7i1_ym-FdrSsRYkiKkaTxYVmjak5qQ@mail.gmail.com> (Reza Nikoopour's message of "Sun, 7 Nov 2021 11:51:09 -0800")

> Hello All,
>
> I'm trying to highlight a multiline construct.  It uses the here doc syntax
>
> <<SYMBOL
> whatever
> text
> SYMBOL
>
>
> Do I need two delimiters as follows:
>
>
> <<SYMBOL(1)
> whatever
> text(2)
> SYMBOL

Yes

> Or do I use one delimiter that spans the entire string body?
>
> <<SYMBOL(delimiter start)
> whatever
> text(delimiter end)
> SYMBOL

A string delimiter only occupies a single character.  When you apply
a text property to a range of text, it applies that property to every
char in the text.  So with your "delimiter that spans the entire string
body", Emacs interprets it as N consecutive string delimiters.
So depending on whether N is odd or even the rest of the text will be
highlighted with `font-lock-string-face` ;-)

> I'm trying to avoid how sh-mode and the current implementation
> of terraform-mode highlight the entirety of the closing SYMBOL.
> [image: image.png]

I recommend you consider the highlighting itself separately from the
placement of the string delimiters (the placement of the delimiters does
impact the default highlighting, obviously, but you can override that in
the `font-lock-keywords` rules).

The placement of the delimiters should be chosen based on the needs of
things like navigation (e.g. `C-M-f`) and indentation, or maybe to take
care of corner cases like empty here docs:

    <<SYMBOL
    SYMBOL


-- Stefan




  reply	other threads:[~2021-11-07 20:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-07 19:51 How to use Generic String Delimiter ("|") Reza Nikoopour
2021-11-07 20:57 ` Stefan Monnier [this message]
2021-11-08  2:42   ` Reza Nikoopour
2021-11-08  2:54     ` Reza Nikoopour

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=jwvk0hj4rpn.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.