Hi,
I've found a problem concerning newlines and autoindent behaviour.
My environment:
- Padre 0.98, but issue is also present in current SVN trunk (rev 19766)
- Strawberry Perl 5.16.3.1-64bit on Windows 7
I'll start with a description of the symptoms:
1) Occasionally Padre enters 2 empty lines after hitting the return key.
2) The perl interpreter does not execute some function calls, which are
visible in Padre.
Since I'm using Windows, a newline consists of carriage return and
linefeed.
The 2 empty lines, that were added by hitting return, looked like this:
[CR][LF]
[CR]
While editing and restructuring perl code, it could happen, that the code
looks like this in Padre:
[CR][LF]
# comment[CR]
foo()[CR][LF]
In this case, the interpreter thought the foo function call was part of
the comment and didn't execute it, because they were only separated by
[CR].
You can imagine the amount of debugging I did here in my code to find out
what's wrong, since I didn't expect the editor to be at fault...
Anyway, after enabling View->"Show Newlines", the problem was obvious.
The attached patch file changes the function _auto_indent(). This change
fixes the above mentioned symptoms for me.
For instance, $self->document->newline contained only "\n" in my case,
which is deleted by the following regexp and thus leaves a single \r in the
editor.
I've changed the regexp to catch all combinations of carriage returns and
linefeed so using the wrong value from $self->document->newline is not
needed anymore.
But it seems, there are still some more inconsistencies regarding the
newlines and newline_type.
The function newline() in Document.pm checks $self->newline_type for the
cases WIN, MAC and returns "\n" for everything else.
But the everything else "branch" covers not only UNIX but also "Mixed",
which happened to be the value I had here. That's why I've got only "\n" in
_auto_indent().
I assume the "Mixed" type comes from using File->New->"Perl 5 Script",
because the automatically added file header lines have an eol with only
"\n".
So I first tried to change this newline() function, adding an if condition
for "Mixed" type and returning "\r\n", but this didn't solve the issue
completely, because sometimes the newline_type was set to "None"...?
Well, I stopped debugging at this point and decided to write a mail. I
hope this description is somewhat helpful.
Regards,
Marc
Index: Padre/lib/Padre/Wx/Editor.pm
===================================================================
--- Padre/lib/Padre/Wx/Editor.pm (revision 19766)
+++ Padre/lib/Padre/Wx/Editor.pm (working copy)
@@ -1278,8 +1278,7 @@
my $indent_style = $self->document->get_indentation_style;
my $content = $self->GetLine($prev_line);
- my $eol = $self->document->newline;
- $content =~ s/$eol$//;
+ $content =~ s/\r?\n?$//;
my $indent = ( $content =~ /^(\s+)/ ? $1 : '' );
if ( $config->editor_autoindent eq 'deep' and $content =~ /\{\s*$/ ) {
_______________________________________________
Padre-dev mailing list
Padre-dev@perlide.org
http://mail.perlide.org/mailman/listinfo/padre-dev