Skip to content

Commit 9ed47db

Browse files
authored
ed: buffer is dirty unless all lines were written
* I found a case where ed allowed unsaved changes to be lost * The default behaviour of "w" command is to write all lines from the editor buffer * In the case of 1w or 1,2w command, only the selected lines are written and there may be unsaved changes on other lines, so don't unset the "dirty" flag * The flag should be unmodified also in the case of "w !cat", where all buffer lines are written to a pipe * This patch makes ed consistent with BSD and GNU versions
1 parent 28dcd04 commit 9ed47db

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

bin/ed

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,12 @@ sub edWrite {
679679
warn "$filename: $!\n";
680680
return E_CLOSE;
681681
}
682-
683-
$NeedToSave = $UserHasBeenWarned = 0;
682+
unless ($do_pipe) {
683+
my $lcount = $adrs[1] - $adrs[0] + 1;
684+
if ($lcount == maxline()) {
685+
$NeedToSave = $UserHasBeenWarned = 0;
686+
}
687+
}
684688
print "$chars\n" unless $Scripted;
685689
exit getrc() if $qflag;
686690
return;

0 commit comments

Comments
 (0)