Subject: Re: bug#52459: 28.0.90; prin1-to-string does not escape bidi control characters despite print-escape-control-characters=t

From: Daniel Mendler <[email-masked]>
Date: Sun, 12 Dec 2021 22:33:50 +0100

On 12/12/21 10:11 PM, Daniel Mendler wrote:
> Example packages which are affected by this issue are for example the
> Helpful package, which provides an enhanced Help buffer. Another package
> affected by the issue is the Marginalia package which adds annotations
> to `describe-variable` in the minibuffer. The annotations show the
> variable value. I would like to print the variable values in a safe way
> which does not mess up the display. Instead of "string" these packages
> show "str"gnandallthatfollowsisgarbage. How is this supposed to be done?
> 
> I propose the addition of an additional variable which configures
> prin1-string such that all control characters which affect the display
> in special ways are escaped. Is there an alternative approach to achieve
> this goal?

There is actually one function which comes close in functionality -
`bidi-string-mark-left-to-right`. However this function is not really a
pure string manipulation function since it adds display properties. So
this function can only be used if the string is directly displayed as
is. The function is not a good fit if the resulting string is
manipulated further, truncated, etc.