unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* How to use Generic String Delimiter ("|")
@ 2021-11-07 19:51 Reza Nikoopour
  2021-11-07 20:57 ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Reza Nikoopour @ 2021-11-07 19:51 UTC (permalink / raw)
  To: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 629 bytes --]

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


Or do I use one delimiter that spans the entire string body?

<<SYMBOL(delimiter start)
whatever
text(delimiter end)
SYMBOL


In my experiments using the single delimiter I've failed at getting the
highlighting to work properly so I think I'm going down the wrong path.

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]

Cheers,
Reza

[-- Attachment #1.2: Type: text/html, Size: 1235 bytes --]

[-- Attachment #2: image.png --]
[-- Type: image/png, Size: 26180 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to use Generic String Delimiter ("|")
  2021-11-07 19:51 How to use Generic String Delimiter ("|") Reza Nikoopour
@ 2021-11-07 20:57 ` Stefan Monnier
  2021-11-08  2:42   ` Reza Nikoopour
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2021-11-07 20:57 UTC (permalink / raw)
  To: Reza Nikoopour; +Cc: emacs-devel

> 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




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to use Generic String Delimiter ("|")
  2021-11-07 20:57 ` Stefan Monnier
@ 2021-11-08  2:42   ` Reza Nikoopour
  2021-11-08  2:54     ` Reza Nikoopour
  0 siblings, 1 reply; 4+ messages in thread
From: Reza Nikoopour @ 2021-11-08  2:42 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 682 bytes --]

Thank you so much for the explanation.  That helped me a lot.

> So depending on whether N is odd or even the rest of the text will be
> highlighted with `font-lock-string-face` ;-)

Well that explains the behavior I saw during my experimentation!

I've managed to find a solution for propertizing. However I've now I have a
new
issue that I don't understand. When editing a line inside the heredoc the
line
changes to white font then shortly after changes to green.  What would be
the
cause of that behavior? I'm not really sure where to begin debugging.

I can provide my syntax-propertize function and my
syntax-propertize-extend-region
function if they're needed.

Cheers,
Reza

[-- Attachment #2: Type: text/html, Size: 791 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to use Generic String Delimiter ("|")
  2021-11-08  2:42   ` Reza Nikoopour
@ 2021-11-08  2:54     ` Reza Nikoopour
  0 siblings, 0 replies; 4+ messages in thread
From: Reza Nikoopour @ 2021-11-08  2:54 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 195 bytes --]

Actually I'm sorry.  I just realized that the messages buffer was spelling
out my issue to me:

> Error during redisplay: (jit-lock-function 963) signaled (error "Odd
length text property list")

[-- Attachment #2: Type: text/html, Size: 283 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-11-08  2:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-07 19:51 How to use Generic String Delimiter ("|") Reza Nikoopour
2021-11-07 20:57 ` Stefan Monnier
2021-11-08  2:42   ` Reza Nikoopour
2021-11-08  2:54     ` Reza Nikoopour

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).