emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to use Generic String Delimiter ("|")


From: Stefan Monnier
Subject: Re: How to use Generic String Delimiter ("|")
Date: Sun, 07 Nov 2021 15:57:14 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]