GNU bug report logs - #23425
master branch: `message' wrongly corrupts ' to curly quote.

Previous Next

Package: emacs;

Reported by: Alan Mackenzie <acm <at> muc.de>

Date: Mon, 2 May 2016 15:26:02 UTC

Severity: normal

Tags: notabug, wontfix

Done: Glenn Morris <rgm <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Alan Mackenzie <acm <at> muc.de>
Cc: Glenn Morris <rgm <at> gnu.org>, 23425 <at> debbugs.gnu.org, emacs-devel <at> gnu.org
Subject: bug#23425: master branch: `message' wrongly corrupts ' to curly quote.
Date: Mon, 5 Jun 2017 17:14:37 -0700
>> 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  <rms <at> gnu.org>

    * 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”.





This bug report was last modified 7 years and 338 days ago.

Previous Next


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