* prin1-to-string noescape parameter
@ 2014-10-31 16:15 Oleh Krehel
2014-10-31 19:11 ` Andreas Schwab
2014-10-31 19:54 ` Stefan Monnier
0 siblings, 2 replies; 9+ messages in thread
From: Oleh Krehel @ 2014-10-31 16:15 UTC (permalink / raw)
To: emacs-devel
Hi all,
I'm trying to write some code that formats/restructures Elisp source
files (a la Paredit). But instead of using text manipulation,
I want to read the object in, manipulate it and print it
out.
One issue that I'm facing is:
(prin1-to-string (read "(foo.bar baz?)"))
=> "(foo\\.bar baz\\?)"
I tried to overcome this with:
(prin1-to-string (read "(foo.bar baz?)") t)
=> "(foo.bar baz?)"
But another problem resurfaces instead:
(prin1-to-string (read "(foo \"bar\")") t)
=> "(foo bar)"
Even worse:
(prin1-to-string (read "(foo \";bar\")") t)
=> "(foo ;bar)"
I think a fix to the issue would be to split the `escapeflag'
parameter of the `print_object' C function into two parts. Currently a
single bool flag decides if to escape strings or not, and if to escape
certain characters or not.
Any other suggestions to overcome this issue are welcome as well, so
far I've tried setting `print-quoted', `print-escape-multibyte', and
`print-escape-nonascii'.
regards,
Oleh
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: prin1-to-string noescape parameter
2014-10-31 16:15 prin1-to-string noescape parameter Oleh Krehel
@ 2014-10-31 19:11 ` Andreas Schwab
2014-10-31 20:11 ` Oleh Krehel
2014-10-31 19:54 ` Stefan Monnier
1 sibling, 1 reply; 9+ messages in thread
From: Andreas Schwab @ 2014-10-31 19:11 UTC (permalink / raw)
To: Oleh Krehel; +Cc: emacs-devel
Oleh Krehel <oleh.krehel@gmail.com> writes:
> One issue that I'm facing is:
>
> (prin1-to-string (read "(foo.bar baz?)"))
> => "(foo\\.bar baz\\?)"
Why is that an issue? The strings represent objects that will compare
equal.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: prin1-to-string noescape parameter
2014-10-31 16:15 prin1-to-string noescape parameter Oleh Krehel
2014-10-31 19:11 ` Andreas Schwab
@ 2014-10-31 19:54 ` Stefan Monnier
1 sibling, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2014-10-31 19:54 UTC (permalink / raw)
To: Oleh Krehel; +Cc: emacs-devel
> (prin1-to-string (read "(foo.bar baz?)"))
> => "(foo\\.bar baz\\?)"
BTW, for that kind of reason, "." and "?" are not recommended in
Elisp identifiers.
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: prin1-to-string noescape parameter
2014-10-31 19:11 ` Andreas Schwab
@ 2014-10-31 20:11 ` Oleh Krehel
2014-10-31 20:51 ` Andreas Schwab
0 siblings, 1 reply; 9+ messages in thread
From: Oleh Krehel @ 2014-10-31 20:11 UTC (permalink / raw)
To: Andreas Schwab; +Cc: emacs-devel
Hi Andreas,
>> One issue that I'm facing is:
>>
>> (prin1-to-string (read "(foo.bar baz?)"))
>> => "(foo\\.bar baz\\?)"
>
> Why is that an issue? The strings represent objects that will compare
> equal.
The issue is that if I have `foo.bar` in the code, and then I re-format
my code by:
- read text
- delete text
- manipulate lisp object
- insert manipulated lisp object
And now my code contains `foo\.bar`, although I don't want it.
regards,
Oleh
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: prin1-to-string noescape parameter
2014-10-31 20:11 ` Oleh Krehel
@ 2014-10-31 20:51 ` Andreas Schwab
2014-10-31 21:24 ` Oleh Krehel
0 siblings, 1 reply; 9+ messages in thread
From: Andreas Schwab @ 2014-10-31 20:51 UTC (permalink / raw)
To: Oleh Krehel; +Cc: emacs-devel
Oleh Krehel <o.krehel@tue.nl> writes:
> The issue is that if I have `foo.bar` in the code, and then I re-format
> my code by:
>
> - read text
> - delete text
> - manipulate lisp object
> - insert manipulated lisp object
>
> And now my code contains `foo\.bar`, although I don't want it.
By passing the text through the lisp reading you are discarding all
redundancy, so it is impossible in general to get back the original
representation.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: prin1-to-string noescape parameter
2014-10-31 20:51 ` Andreas Schwab
@ 2014-10-31 21:24 ` Oleh Krehel
2014-11-01 7:34 ` Andreas Schwab
0 siblings, 1 reply; 9+ messages in thread
From: Oleh Krehel @ 2014-10-31 21:24 UTC (permalink / raw)
To: Andreas Schwab; +Cc: emacs-devel
>> The issue is that if I have `foo.bar` in the code, and then I re-format
>> my code by:
>>
>> - read text
>> - delete text
>> - manipulate lisp object
>> - insert manipulated lisp object
>>
>> And now my code contains `foo\.bar`, although I don't want it.
>
> By passing the text through the lisp reading you are discarding all
> redundancy, so it is impossible in general to get back the original
> representation.
Not possible in general, but the thing that I want can be done
by changing slightly the condition at line 240 of print.c
There are already `print_escape_newlines', `print_escape_multibyte' etc.,
so I propose to add one more that makes these tricky chars in symbols be
not quoted.
regards,
Oleh
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: prin1-to-string noescape parameter
2014-10-31 21:24 ` Oleh Krehel
@ 2014-11-01 7:34 ` Andreas Schwab
2014-11-01 8:28 ` Oleh Krehel
0 siblings, 1 reply; 9+ messages in thread
From: Andreas Schwab @ 2014-11-01 7:34 UTC (permalink / raw)
To: Oleh Krehel; +Cc: emacs-devel
Oleh Krehel <o.krehel@tue.nl> writes:
>>> The issue is that if I have `foo.bar` in the code, and then I re-format
>>> my code by:
>>>
>>> - read text
>>> - delete text
>>> - manipulate lisp object
>>> - insert manipulated lisp object
>>>
>>> And now my code contains `foo\.bar`, although I don't want it.
>>
>> By passing the text through the lisp reading you are discarding all
>> redundancy, so it is impossible in general to get back the original
>> representation.
>
> Not possible in general, but the thing that I want can be done
> by changing slightly the condition at line 240 of print.c
No, you can't. You have already discarded all necessary information.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: prin1-to-string noescape parameter
2014-11-01 7:34 ` Andreas Schwab
@ 2014-11-01 8:28 ` Oleh Krehel
2014-11-01 10:03 ` Andreas Schwab
0 siblings, 1 reply; 9+ messages in thread
From: Oleh Krehel @ 2014-11-01 8:28 UTC (permalink / raw)
To: Andreas Schwab; +Cc: emacs-devel
>>>> The issue is that if I have `foo.bar` in the code, and then I re-format
>>>> my code by:
>>>>
>>>> - read text
>>>> - delete text
>>>> - manipulate lisp object
>>>> - insert manipulated lisp object
>>>>
>>>> And now my code contains `foo\.bar`, although I don't want it.
>>>
>>> By passing the text through the lisp reading you are discarding all
>>> redundancy, so it is impossible in general to get back the original
>>> representation.
>>
>> Not possible in general, but the thing that I want can be done
>> by changing slightly the condition at line 240 of print.c
>
> No, you can't. You have already discarded all necessary information.
Of course it's possible.
Since `foo.bar' and `foo\.bar' is the same symbol, why not
print it as "foo.bar" always? It looks better like this
in the source code anyway, and the reader has no problem with it.
regards,
Oleh
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: prin1-to-string noescape parameter
2014-11-01 8:28 ` Oleh Krehel
@ 2014-11-01 10:03 ` Andreas Schwab
0 siblings, 0 replies; 9+ messages in thread
From: Andreas Schwab @ 2014-11-01 10:03 UTC (permalink / raw)
To: Oleh Krehel; +Cc: emacs-devel
Oleh Krehel <o.krehel@tue.nl> writes:
> Since `foo.bar' and `foo\.bar' is the same symbol, why not
> print it as "foo.bar" always?
That will not solve your problem.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2014-11-01 10:03 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-31 16:15 prin1-to-string noescape parameter Oleh Krehel
2014-10-31 19:11 ` Andreas Schwab
2014-10-31 20:11 ` Oleh Krehel
2014-10-31 20:51 ` Andreas Schwab
2014-10-31 21:24 ` Oleh Krehel
2014-11-01 7:34 ` Andreas Schwab
2014-11-01 8:28 ` Oleh Krehel
2014-11-01 10:03 ` Andreas Schwab
2014-10-31 19:54 ` Stefan Monnier
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).