unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* [prettify-symbols-mode] Two consecutive matches don't work?
@ 2022-05-18  9:32 Joost
  2022-05-18 10:07 ` Robert Pluim
  2022-05-18 11:56 ` Eli Zaretskii
  0 siblings, 2 replies; 8+ messages in thread
From: Joost @ 2022-05-18  9:32 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I'm dealing with some `.xml` files that contain data which uses the sequence `<<!` as some sort of operator. Because it's XML, the LESS-THAN sign needs to be encoded as `&lt;`, yielding `&lt;&lt;!`.

So I thought this would be the ideal use case for `prettify-symbols-mode`. I added `("&lt;" . ?<)` to `prettify-symbols-alist` and activated the mode.

Unfortunately, only the first `&lt;` in each sequence is prettified. This seems to be due to the fact that the second `&lt;` is followed by the exclamation mark: if I insert a space in between, prettification works.

Is there any way to remedy this?

TIA

-- 
Joost Kremers
Life has its moments



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

* Re: [prettify-symbols-mode] Two consecutive matches don't work?
  2022-05-18  9:32 [prettify-symbols-mode] Two consecutive matches don't work? Joost
@ 2022-05-18 10:07 ` Robert Pluim
  2022-05-18 10:54   ` Tassilo Horn
  2022-05-18 11:56 ` Eli Zaretskii
  1 sibling, 1 reply; 8+ messages in thread
From: Robert Pluim @ 2022-05-18 10:07 UTC (permalink / raw)
  To: Joost; +Cc: help-gnu-emacs

>>>>> On Wed, 18 May 2022 11:32:07 +0200, Joost <joostkremers@fastmail.fm> said:

    Joost> Hi,
    Joost> I'm dealing with some `.xml` files that contain data which uses the
    Joost> sequence `<<!` as some sort of operator. Because it's XML, the
    Joost> LESS-THAN sign needs to be encoded as `&lt;`, yielding `&lt;&lt;!`.

    Joost> So I thought this would be the ideal use case for
    Joost> `prettify-symbols-mode`. I added `("&lt;" . ?<)` to
    Joost> `prettify-symbols-alist` and activated the mode.

    Joost> Unfortunately, only the first `&lt;` in each sequence is
    Joost> prettified. This seems to be due to the fact that the second `&lt;` is
    Joost> followed by the exclamation mark: if I insert a space in between,
    Joost> prettification works.

    Joost> Is there any way to remedy this?

Looks like a bug to me. I tried "&lt;&lt;", but exhibits the same
behaviour.

Robert
-- 



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

* Re: [prettify-symbols-mode] Two consecutive matches don't work?
  2022-05-18 10:07 ` Robert Pluim
@ 2022-05-18 10:54   ` Tassilo Horn
  2022-05-19 17:46     ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 8+ messages in thread
From: Tassilo Horn @ 2022-05-18 10:54 UTC (permalink / raw)
  To: Robert Pluim; +Cc: Joost, help-gnu-emacs

Robert Pluim <rpluim@gmail.com> writes:

>     Joost> I'm dealing with some `.xml` files that contain data which uses the
>     Joost> sequence `<<!` as some sort of operator. Because it's XML, the
>     Joost> LESS-THAN sign needs to be encoded as `&lt;`, yielding `&lt;&lt;!`.
>
>     Joost> So I thought this would be the ideal use case for
>     Joost> `prettify-symbols-mode`. I added `("&lt;" . ?<)` to
>     Joost> `prettify-symbols-alist` and activated the mode.
>
>     Joost> Unfortunately, only the first `&lt;` in each sequence is
>     Joost> prettified. This seems to be due to the fact that the second `&lt;` is
>     Joost> followed by the exclamation mark: if I insert a space in between,
>     Joost> prettification works.
>
>     Joost> Is there any way to remedy this?
>
> Looks like a bug to me. I tried "&lt;&lt;", but exhibits the same
> behaviour.

The problem is that in <a>&lt;&lt;</a> (symbol-at-point) on the first
&lt says "<a>&lt" and on the second "&lt".  I think there might be even
two bugs:

  1. nxml-mode: It feels wrong that <a>&lt is considered a symbol.  And
     that the closing ; isn't part of the symbol &lt; seems also not
     correct.  And why do < and > have symbol syntax.  Wouldn't
     open/close paren be more appropriate?

  2. prettify-symbols: It seems wrong that the second &lt; is prettified
     because its not a single symbol but a symbol &lt plus the character
     ; which as punctuation syntax.

Bye,
Tassilo



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

* Re: [prettify-symbols-mode] Two consecutive matches don't work?
  2022-05-18  9:32 [prettify-symbols-mode] Two consecutive matches don't work? Joost
  2022-05-18 10:07 ` Robert Pluim
@ 2022-05-18 11:56 ` Eli Zaretskii
  2022-05-18 12:28   ` Robert Pluim
  1 sibling, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2022-05-18 11:56 UTC (permalink / raw)
  To: help-gnu-emacs

> Feedback-ID: ie15541ac:Fastmail
> Date: Wed, 18 May 2022 11:32:07 +0200
> From: Joost <joostkremers@fastmail.fm>
> 
> I'm dealing with some `.xml` files that contain data which uses the sequence `<<!` as some sort of operator. Because it's XML, the LESS-THAN sign needs to be encoded as `&lt;`, yielding `&lt;&lt;!`.
> 
> So I thought this would be the ideal use case for `prettify-symbols-mode`. I added `("&lt;" . ?<)` to `prettify-symbols-alist` and activated the mode.
> 
> Unfortunately, only the first `&lt;` in each sequence is prettified. This seems to be due to the fact that the second `&lt;` is followed by the exclamation mark: if I insert a space in between, prettification works.
> 
> Is there any way to remedy this?

prettify-symbols-mode is not general-purpose enough, its defaults are
tailored to prettifying keywords of programming languages, not just
any arbitrary strings of characters.

I think you will need to tailor prettify-symbols-default-compose-p or
roll your own predicate and bind prettify-symbols-compose-predicate to
that predicate, if you want to support such sequences.



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

* Re: [prettify-symbols-mode] Two consecutive matches don't work?
  2022-05-18 11:56 ` Eli Zaretskii
@ 2022-05-18 12:28   ` Robert Pluim
  2022-05-18 20:01     ` Joost Kremers
  0 siblings, 1 reply; 8+ messages in thread
From: Robert Pluim @ 2022-05-18 12:28 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

>>>>> On Wed, 18 May 2022 14:56:53 +0300, Eli Zaretskii <eliz@gnu.org> said:

    >> Feedback-ID: ie15541ac:Fastmail
    >> Date: Wed, 18 May 2022 11:32:07 +0200
    >> From: Joost <joostkremers@fastmail.fm>
    >> 
    >> I'm dealing with some `.xml` files that contain data which uses the
    >> sequence `<<!` as some sort of operator. Because it's XML, the
    >> LESS-THAN sign needs to be encoded as `&lt;`, yielding `&lt;&lt;!`.
    >> 
    >> So I thought this would be the ideal use case for
    >> `prettify-symbols-mode`. I added `("&lt;" . ?<)` to
    >> `prettify-symbols-alist` and activated the mode.
    >> 
    >> Unfortunately, only the first `&lt;` in each sequence is
    >> prettified. This seems to be due to the fact that the second `&lt;`
    >> is followed by the exclamation mark: if I insert a space in between,
    >> prettification works.
    >> 
    >> Is there any way to remedy this?

    Eli> prettify-symbols-mode is not general-purpose enough, its defaults are
    Eli> tailored to prettifying keywords of programming languages, not just
    Eli> any arbitrary strings of characters.

Yes, it by default does a lot of stuff based on the syntax tables of
the buffer.

    Eli> I think you will need to tailor prettify-symbols-default-compose-p or
    Eli> roll your own predicate and bind prettify-symbols-compose-predicate to
    Eli> that predicate, if you want to support such sequences.

(setq prettify-symbols-alist '(("&lt;" . "<"))
      prettify-symbols-compose-predicate
      (lambda (s e m)
        (string-match-p "&lt;" m)))

seems to do the trick.

You could even generalize it to:

(setq prettify-symbols-alist '(("&lt;" . "<"))
      prettify-symbols-compose-predicate
      (lambda (s e m)
        t))

:-)

Robert
-- 



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

* Re: [prettify-symbols-mode] Two consecutive matches don't work?
  2022-05-18 12:28   ` Robert Pluim
@ 2022-05-18 20:01     ` Joost Kremers
  0 siblings, 0 replies; 8+ messages in thread
From: Joost Kremers @ 2022-05-18 20:01 UTC (permalink / raw)
  To: Robert Pluim; +Cc: Eli Zaretskii, help-gnu-emacs


On Wed, May 18 2022, Robert Pluim wrote:
>>>>>> On Wed, 18 May 2022 14:56:53 +0300, Eli Zaretskii <eliz@gnu.org> said:
[helpful info]

Thanks Eli & Robert. I didn't realise the importance of
prettify-symbols-compose-predicate. 

> You could even generalize it to:
>
> (setq prettify-symbols-alist '(("&lt;" . "<"))
>       prettify-symbols-compose-predicate
>       (lambda (s e m)
>         t))

  (setq prettify-symbols-compose-predicate #'always)

:-)


-- 
Joost Kremers
Life has its moments



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

* Re: [prettify-symbols-mode] Two consecutive matches don't work?
  2022-05-18 10:54   ` Tassilo Horn
@ 2022-05-19 17:46     ` Stefan Monnier via Users list for the GNU Emacs text editor
  2022-05-19 19:09       ` Tassilo Horn
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2022-05-19 17:46 UTC (permalink / raw)
  To: help-gnu-emacs

>   1. nxml-mode: It feels wrong that <a>&lt is considered a symbol.  And
>      that the closing ; isn't part of the symbol &lt; seems also not
>      correct.  And why do < and > have symbol syntax.  Wouldn't
>      open/close paren be more appropriate?

It all depends if your XML is mostly made of "tags" or mostly made of
text.  IIRC the syntax table used in XML/SGML/HTML buffers is usually
a variant of the text-mode syntax table (and then another syntax-table
is used while parsing the actual *ML structure).


        Stefan




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

* Re: [prettify-symbols-mode] Two consecutive matches don't work?
  2022-05-19 17:46     ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2022-05-19 19:09       ` Tassilo Horn
  0 siblings, 0 replies; 8+ messages in thread
From: Tassilo Horn @ 2022-05-19 19:09 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

Stefan Monnier via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> writes:

>>   1. nxml-mode: It feels wrong that <a>&lt is considered a symbol.  And
>>      that the closing ; isn't part of the symbol &lt; seems also not
>>      correct.  And why do < and > have symbol syntax.  Wouldn't
>>      open/close paren be more appropriate?
>
> It all depends if your XML is mostly made of "tags" or mostly made of
> text.  IIRC the syntax table used in XML/SGML/HTML buffers is usually
> a variant of the text-mode syntax table

Ok, I see the reasoning and it's probably the right thing at least for
HTML which usually contains a lot of prose.

> (and then another syntax-table is used while parsing the actual *ML
> structure).

Probably that's more like the one I had expected.

Bye,
Tassilo



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

end of thread, other threads:[~2022-05-19 19:09 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-18  9:32 [prettify-symbols-mode] Two consecutive matches don't work? Joost
2022-05-18 10:07 ` Robert Pluim
2022-05-18 10:54   ` Tassilo Horn
2022-05-19 17:46     ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-05-19 19:09       ` Tassilo Horn
2022-05-18 11:56 ` Eli Zaretskii
2022-05-18 12:28   ` Robert Pluim
2022-05-18 20:01     ` Joost Kremers

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).