emacs-devel
[Top][All Lists]
Advanced

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

Re: buffer-substring vs. buffer-substring-no-properties


From: Stefan Monnier
Subject: Re: buffer-substring vs. buffer-substring-no-properties
Date: Thu, 15 Nov 2001 12:35:00 -0500

> >> > >>     (format "%s" ...) in emacs 20.7 removes font info.  In 21.1 it 
> >> > >> does
> >> > >>     not.  This, not buffer-substring, is hosing me.
> >> > >> 
> >> > >> We made this change deliberately, thinking of it as repairing 
> >> > >> something
> >> > >> broken.  The idea is that colors, fonts, etc. should not be lost.
> >> > 
> >> > I said in a later reply that I thought format was more for human
> >> > readable formatted output, and if this is the case (that's a big
> >> > `if'), then the change doesn't make sense to me.
> >> 
> >> Printing of a string as #("blabla" blibli) is only done by format
> >> if you used `%S' rather than `%s'.  That kind of format argument
> >> is not really meant for human consumption.
> 
> x
> #("(defun fo" 0 9 (fontified nil))
> (format "%s" x)
> #("(defun fo" 0 9 (fontified nil))
> (format "%S" x)
> "#(\"(defun fo\" 0 9 (fontified nil))"

How do you think you went from `x' to `#("(defun fo" 0 9 (fontified nil))'
in the first place ?
It went through some kind of "pretty printer".
I.e. it is unrelated to what happens inside your program because the
content of `x' will not be sent to this pretty printer for you to see but
will be sent to your backend process instead.

In the first case (i.e. `x') the backend process will see the
string `defun fo'.  In the second case as well.
In the third case, it will see `#("(defun fo" 0 9 (fontified nil))'.

If the string had no properties the three behaviors would have been
1 - send `defun fo'
2 - send `defun fo'
3 - send `"defun fo"'

Now if `x' had no properties and had a \ instead of a space, the
results would have been:
1 - `defun\fo'
2 - `defun\fo'
3 - `"defun\\fo"'


        Stefan

PS: by the way all of the above works the same in Emacs-20 as in Emacs-21.




reply via email to

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