GNU bug report logs - #60454
30.0.50; `format-message' does not allow displaying "`" and "'" verbatim

Previous Next

Package: emacs;

Reported by: Ihor Radchenko <yantar92 <at> posteo.net>

Date: Sat, 31 Dec 2022 15:05:01 UTC

Severity: wishlist

Found in version 30.0.50

To reply to this bug, email your comments to 60454 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org:
bug#60454; Package emacs. (Sat, 31 Dec 2022 15:05:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Ihor Radchenko <yantar92 <at> posteo.net>:
New bug report received and forwarded. Copy sent to monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org. (Sat, 31 Dec 2022 15:05:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Ihor Radchenko <yantar92 <at> posteo.net>
To: bug-gnu-emacs <at> gnu.org
Subject: 30.0.50; `format-message' does not allow displaying "`" and "'"
 verbatim
Date: Sat, 31 Dec 2022 15:04:36 +0000
Hi,

Following up https://list.orgmode.org/87k027af5x.fsf <at> localhost/T/#t
and https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=62dc49509c8962bd2a19c4c4475fc616eebdfde8

`format-message' and thus also `warn' unconditionally replace _all_ the
instances of "`" and "'" in the message:

    This acts like ‘format’, except it also replaces each grave accent (`)
    by a left quote, and each apostrophe (') by a right quote.

However, sometimes, it is desired to keep these chars literal.
For example, `org-assert-version' displays a warning that suggests Elisp
code:

(warn "...
   It is recommended to put
    (straight-use-package 'org)
...")

Replacing "'" is undesired here and will make copy-pasted Elisp code
incorrect.

Would it be possible to introduce some kind of escape mechanism in
`format-message' to produce literal "'" and "`" when needed?

In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.35, cairo version 1.17.6) of 2022-12-26 built on localhost
Repository revision: cc29fab3a66c59e77d0ff67c0f3e2e34ec80a03c
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101004
System Description: Gentoo Linux

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60454; Package emacs. (Sat, 31 Dec 2022 15:42:02 GMT) Full text and rfc822 format available.

Message #8 received at 60454 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Schwab <schwab <at> linux-m68k.org>
To: Ihor Radchenko <yantar92 <at> posteo.net>
Cc: 60454 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#60454: 30.0.50; `format-message' does not allow displaying
 "`" and "'" verbatim
Date: Sat, 31 Dec 2022 16:41:09 +0100
On Dez 31 2022, Ihor Radchenko wrote:

> However, sometimes, it is desired to keep these chars literal.
> For example, `org-assert-version' displays a warning that suggests Elisp
> code:
>
> (warn "...
>    It is recommended to put
>     (straight-use-package 'org)
> ...")

The mangling only happens in the format string.  Pass the text as
argument and substitute it with %s.

(warn "...
   It is recommended to put
    %s
..." "(straight-use-package 'org)")

-- 
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60454; Package emacs. (Sat, 31 Dec 2022 15:43:01 GMT) Full text and rfc822 format available.

Message #11 received at 60454 <at> debbugs.gnu.org (full text, mbox):

From: Gregory Heytings <gregory <at> heytings.org>
To: Ihor Radchenko <yantar92 <at> posteo.net>
Cc: 60454 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#60454: 30.0.50; `format-message' does not allow displaying
 "`" and "'" verbatim
Date: Sat, 31 Dec 2022 15:42:44 +0000
>
> Would it be possible to introduce some kind of escape mechanism in 
> `format-message' to produce literal "'" and "`" when needed?
>

Just let-bind text-quoting-style:

(let ((text-quoting-style 'grave))
  (format-message "foo `bar' baz"))





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60454; Package emacs. (Sat, 31 Dec 2022 16:40:02 GMT) Full text and rfc822 format available.

Message #14 received at 60454 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Andreas Schwab <schwab <at> linux-m68k.org>
Cc: Ihor Radchenko <yantar92 <at> posteo.net>, 60454 <at> debbugs.gnu.org
Subject: Re: bug#60454: 30.0.50; `format-message' does not allow displaying
 "`" and "'" verbatim
Date: Sat, 31 Dec 2022 11:39:35 -0500
>> However, sometimes, it is desired to keep these chars literal.
>> For example, `org-assert-version' displays a warning that suggests Elisp
>> code:
>>
>> (warn "...
>>    It is recommended to put
>>     (straight-use-package 'org)
>> ...")
>
> The mangling only happens in the format string.  Pass the text as
> argument and substitute it with %s.
>
> (warn "...
>    It is recommended to put
>     %s
> ..." "(straight-use-package 'org)")

That's rather cumbersome.
I think it would make a lot of sense to offer escapes like %' and %`


        Stefan





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60454; Package emacs. (Sat, 31 Dec 2022 17:07:01 GMT) Full text and rfc822 format available.

Message #17 received at 60454 <at> debbugs.gnu.org (full text, mbox):

From: Ihor Radchenko <yantar92 <at> posteo.net>
To: Gregory Heytings <gregory <at> heytings.org>
Cc: 60454 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#60454: 30.0.50; `format-message' does not allow displaying
 "`" and "'" verbatim
Date: Sat, 31 Dec 2022 17:06:36 +0000
Gregory Heytings <gregory <at> heytings.org> writes:

>> Would it be possible to introduce some kind of escape mechanism in 
>> `format-message' to produce literal "'" and "`" when needed?
>>
>
> Just let-bind text-quoting-style:
>
> (let ((text-quoting-style 'grave))
>    (format-message "foo `bar' baz"))

This won't work when I sometimes actually want the replacement to
happen:

(format-message "This is variable `foo', and the code 'bar")

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60454; Package emacs. (Sat, 31 Dec 2022 19:30:02 GMT) Full text and rfc822 format available.

Message #20 received at 60454 <at> debbugs.gnu.org (full text, mbox):

From: Gregory Heytings <gregory <at> heytings.org>
To: Ihor Radchenko <yantar92 <at> posteo.net>
Cc: 60454 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#60454: 30.0.50; `format-message' does not allow displaying
 "`" and "'" verbatim
Date: Sat, 31 Dec 2022 19:29:48 +0000
[Message part 1 (text/plain, inline)]
>> Just let-bind text-quoting-style:
>>
>> (let ((text-quoting-style 'grave))
>>    (format-message "foo `bar' baz"))
>
> This won't work when I sometimes actually want the replacement to 
> happen:
>
> (format-message "This is variable `foo', and the code 'bar")
>

Indeed.  If you want both literal ` ' and interpreted ` ', until Stefan's 
suggestion is implemented, you can either use what Andreas suggested, or 
use a variant of format-message such as:

(defun format-message-alt (format &rest objects)
  "Format a string out of a format-string and arguments.

This acts like `format-message', which see, except that the grave
accent (\\=`) and apostrophe (\\=') can be escaped with `\\\\​=',
in which case they are not replaced by the left and right quote
replacement characters specified by `text-quoting-style'."
  (let* ((fq
	  (replace-regexp-in-string
	   "\\\\=`" "\uE001"
	   (replace-regexp-in-string
	    "\\\\='" "\uE000" format)))
	 (fm (format-message fq objects))
	 (fu
	  (replace-regexp-in-string
	   "\uE001" "`"
	   (replace-regexp-in-string
	    "\uE000" "'" fm))))
    fu))

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60454; Package emacs. (Sat, 31 Dec 2022 20:18:02 GMT) Full text and rfc822 format available.

Message #23 received at 60454 <at> debbugs.gnu.org (full text, mbox):

From: Gregory Heytings <gregory <at> heytings.org>
To: Ihor Radchenko <yantar92 <at> posteo.net>
Cc: 60454 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#60454: 30.0.50; `format-message' does not allow displaying
 "`" and "'" verbatim
Date: Sat, 31 Dec 2022 20:17:14 +0000
And of course, if all you need is copy-pasteable code, you can use (quote 
...) instead of a literal quote: (use-package (quote foo)).





Severity set to 'wishlist' from 'normal' Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Mon, 04 Sep 2023 15:03:01 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 284 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.