Re: [Parseperl-discuss] [PATCH] preserve newlines
Brought to you by:
adamkennedy
|
From: Adam K. <ad...@ph...> - 2006-10-05 06:16:10
|
Chris Dolan wrote:
> On Oct 5, 2006, at 12:40 AM, Adam Kennedy wrote:
>
>>>> That leaves us only with the case of mixed newlines. Personally,
>>>> outside of binary files I am not away of ANY cases in which mixed
>>>> newlines in a text file is allowed, even in __DATA__ segments.
>>> Well, certainly my goal is to get rid of the mixed newlines! That's
>>> why I was writing a Perl::Critic policy against that. :-)
>>
>> Well, you know it's possible to detect mixed newlines from the raw
>> source right?
>>
>> Does critic have access to the original file/string?
>
> In theory almost always yes, in practice no. We accept PPI::Document
> instances, so that's one case where I can't ever get the raw source. We
> also accept STDIN, so I'd have to explicitly save the source. In the
> most common case, we build a PPI::Document::File. I *could* of course
> use the filename() to get back to source.
Oh right, I forgot about the STDIN stuff... so yeah, practically
speaking you don't have access. Suck.
>> Emacs et al doing binary items inside a text file is one example of
>> what I mean by handling it wrong.
>
> Hmm... Maybe I've just been using Emacs so long that its behavior feels
> intuitive to me? :-)
Probably :)
I mean, it's a newline, and Perl doesn't have ANY binary (ignoring
unicode) content. The fact it isn't a newline for the current platform
(at least with respect for Perl) should be irrelevant.
> I think the correct behavior on insert is to convert to document newline
> by default, and possibly offer a way to preserve the mixed newlines if
> the generator requests it. The mechanism for that "request" can be a
> workaround (add_before() then set_newline()), or a flag to add_before(),
> or a sticky_newline flag on the node to be inserted.
I'm happy to go with "convert to the document default automatically" and
ignore any customization capability until someone actually asks for it :)
>> I don't think anyone ever really WANTs to make mixed newlines. As I
>> said, I don't know of any legitimate real-world cases of this.
>
> ... so probably the generator case is just to adopt the newline of the
> surrounding document.
>
> There are plenty of real world cases of mixed newlines, just none of
> them intentional!
Right :)
So I guess to start with, we need to take the input string, and detect
1. All Unix
2. All Win32
3. All Mac
4. Mixed Unix-dominant
5. Mixed Win32-dominant
6. Mixed Mac-dominant
:/
So... $doc->{newlines} = 'unix|win32|max' and $doc->{newlines_mixed} = 1|0
What do you think?
Adam K
Adam K
|