all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#60454: 30.0.50; `format-message' does not allow displaying "`" and "'" verbatim
@ 2022-12-31 15:04 Ihor Radchenko
  2022-12-31 15:41 ` Andreas Schwab
  2022-12-31 15:42 ` Gregory Heytings
  0 siblings, 2 replies; 7+ messages in thread
From: Ihor Radchenko @ 2022-12-31 15:04 UTC (permalink / raw)
  To: 60454; +Cc: Stefan Monnier

Hi,

Following up https://list.orgmode.org/87k027af5x.fsf@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>





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

* bug#60454: 30.0.50; `format-message' does not allow displaying "`" and "'" verbatim
  2022-12-31 15:04 bug#60454: 30.0.50; `format-message' does not allow displaying "`" and "'" verbatim Ihor Radchenko
@ 2022-12-31 15:41 ` Andreas Schwab
  2022-12-31 16:39   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-12-31 15:42 ` Gregory Heytings
  1 sibling, 1 reply; 7+ messages in thread
From: Andreas Schwab @ 2022-12-31 15:41 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: 60454, Stefan Monnier

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@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."





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

* bug#60454: 30.0.50; `format-message' does not allow displaying "`" and "'" verbatim
  2022-12-31 15:04 bug#60454: 30.0.50; `format-message' does not allow displaying "`" and "'" verbatim Ihor Radchenko
  2022-12-31 15:41 ` Andreas Schwab
@ 2022-12-31 15:42 ` Gregory Heytings
  2022-12-31 17:06   ` Ihor Radchenko
  1 sibling, 1 reply; 7+ messages in thread
From: Gregory Heytings @ 2022-12-31 15:42 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: 60454, Stefan Monnier


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






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

* bug#60454: 30.0.50; `format-message' does not allow displaying "`" and "'" verbatim
  2022-12-31 15:41 ` Andreas Schwab
@ 2022-12-31 16:39   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-12-31 16:39 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Ihor Radchenko, 60454

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






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

* bug#60454: 30.0.50; `format-message' does not allow displaying "`" and "'" verbatim
  2022-12-31 15:42 ` Gregory Heytings
@ 2022-12-31 17:06   ` Ihor Radchenko
  2022-12-31 19:29     ` Gregory Heytings
  0 siblings, 1 reply; 7+ messages in thread
From: Ihor Radchenko @ 2022-12-31 17:06 UTC (permalink / raw)
  To: Gregory Heytings; +Cc: 60454, Stefan Monnier

Gregory Heytings <gregory@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>





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

* bug#60454: 30.0.50; `format-message' does not allow displaying "`" and "'" verbatim
  2022-12-31 17:06   ` Ihor Radchenko
@ 2022-12-31 19:29     ` Gregory Heytings
  2022-12-31 20:17       ` Gregory Heytings
  0 siblings, 1 reply; 7+ messages in thread
From: Gregory Heytings @ 2022-12-31 19:29 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: 60454, Stefan Monnier

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


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

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

* bug#60454: 30.0.50; `format-message' does not allow displaying "`" and "'" verbatim
  2022-12-31 19:29     ` Gregory Heytings
@ 2022-12-31 20:17       ` Gregory Heytings
  0 siblings, 0 replies; 7+ messages in thread
From: Gregory Heytings @ 2022-12-31 20:17 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: 60454, Stefan Monnier


And of course, if all you need is copy-pasteable code, you can use (quote 
...) instead of a literal quote: (use-package (quote foo)).






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

end of thread, other threads:[~2022-12-31 20:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-31 15:04 bug#60454: 30.0.50; `format-message' does not allow displaying "`" and "'" verbatim Ihor Radchenko
2022-12-31 15:41 ` Andreas Schwab
2022-12-31 16:39   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-31 15:42 ` Gregory Heytings
2022-12-31 17:06   ` Ihor Radchenko
2022-12-31 19:29     ` Gregory Heytings
2022-12-31 20:17       ` Gregory Heytings

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.