bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#23425: master branch: `message' wrongly corrupts ' to curly quote.


From: Paul Eggert
Subject: bug#23425: master branch: `message' wrongly corrupts ' to curly quote.
Date: Mon, 5 Jun 2017 17:14:37 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0

>> Elisp code needed to use
>> (message "%s" STR) even before the change you're objecting to,
>
> Did it?  When and why?

Yes, because one can’t pass arbitrary strings to the message function and expect them to be displayed as-is. This has been true for years. For example, lisp/ChangeLog.8 says this:

  1999-02-23  Richard M. Stallman  <address@hidden>

    * subr.el (with-temp-message): Use %s so % in old msg won't fool us.

This use of (message "%s" ...) is still in master, and would still be needed even if we went back to Emacs 24-style message formatting.

> Somebody using message to output Lisp will use ' just as I did - and suffer the
> same horrendous problems

Sure, like the “horrendous” problems with %. For example, in Emacs 24 your example, when used with data involving %:

  (setq c-parse-state-state '((a '%%)))
  (message
   (concat "(setq "
    (mapconcat
     (lambda (arg)
       (format "%s %s%s" (car arg)
           (if (atom (cdr arg)) "" "'")
           (if (markerp (cdr arg))
           (format "(copy-marker %s)" (marker-position (cdr arg)))
         (cdr arg))))
     c-parse-state-state "  ")
    ")"))

returns "(setq a '((quote %)))", which is obviously wrong and which results in silent data corruption.

> Do you, perhaps, have another strategem for preventing this problem?

Sure: don’t pass arbitrary strings to the message function.

> How do you propose to prevent such puzzlement and anger in the future

Not by this:

>>           (error "Can't find `%s' in %s" thing where)))
>>   =>      (error "Can%'t find %`%s%' in %s" thing where)))

For Emacs code this would likely be a cure worse than the disease, by causing more puzzlement and anger than it would prevent. It would make formats significantly harder to read. And as Clément mentioned, it would introduce compatibility problems of its own.

There is a better way if the primary goal is to avoid quote translation:

           (error "Can't find `%s' in %s" thing where)))
   =>      (error "Can’t find ‘%s’ in %s" thing where)))

Compared to %` and %', this is simpler, easier to read, and more compatible with current and older Emacs versions. A downside, though, is that it would involve changing hundreds or thousands of strings in the Emacs source (just as %` and %' would).

> You're not seriously
> telling me that any of your students who've written a message call with
> a "%s" in the format string remain unaware of the role of %, are you?

Sure, they learn about % after the message function doesn’t work the way they naively expected. In that respect, % is like ` and '.

> There are around 275 calls to message which have a non-literal
> format argument.

Each one stands for possibly many other calls, and we don’t know how many of these other calls might cause a problem.

> The consequences of surreptitious unwanted translation ...
>> It's not surreptitious: it's documented.
> And this documentation is useless for preventing the problems.

True, documentation by itself does not prevent programming problems. However, this doesn’t change the fact that quote translation is documented. It is not “surreptitious” or “implicit” or “vague” or “stealthy” or “fuzzy”.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]