BBEdit's Handling of line breaks

892 views
Skip to first unread message

Steve Hodgson

unread,
Aug 7, 2013, 6:47:08 AM8/7/13
to bbe...@googlegroups.com
In an earlier discussion I asked about searching for and changing line break types. The discussion that followed was very useful, thanks to all who participated and took the time to answer.

After further digging it turns out what I was seeing was the result of a mixture of line endings in the same file. Text snippets were being inserted by Typinator using CR format while the text I was entering was using LF format line endings. BBEdit was doing exactly whet is described on page 120 of the current user manual. I'm assuming in those circumstances reports the line endings based on the first line break in the file. Any other line breaks are displayed as the infamous red '¿' character.

So what I was seeing as MC Classic (CR) files was actually a mixture and this is probably why they failed to display correctly when posted to scriptogr.am. As an aside Typinator should translate all line breaks to LF, as this is the standard representation on OS X.

Normalize Line Breaks appears to fix this using the format of the first line break rather than the line break preference set in the prefs.

Cheers,

Steve

John Delacour

unread,
Aug 7, 2013, 3:16:58 PM8/7/13
to bbe...@googlegroups.com
On 7/8/13 at 11:47, st...@shodgson.org.uk (Steve Hodgson) wrote:

>Normalize Line Breaks appears to fix this using the format of the
>first line break rather than the line break preference set in the
>prefs.

Yes, that does work, but you have the extra step of manually
changing the line endings to lf in the pop-up menu afterwards.
For example, if you run the script below you will get a document
which gives a ¿ for the Mac line endings instead of a new
line. Running “Text::Normalize Line Endings” will change
these to Windows line endings.

#!/usr/bin/perl
use strict;
my $f = "/tmp/test_line_endings.txt";
open my $fh, ">$f" or die $!;
print $fh "§\015\012§\015§\012§\012§\015§\015\012§";
close $fh;
`open -a bbedit $f`;

You can do the whole thing in one go with an AppleScript script
and optional key shortcut:

tell application "BBEdit"
tell front document
normalize line endings
set line breaks to Unix
end tell
end tell

JD



Reply all
Reply to author
Forward
0 new messages