Skip to content

Commit

Permalink
ed: buffer is dirty unless all lines were written (#932)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mknos authored Jan 27, 2025
1 parent 28dcd04 commit b5df2a2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions bin/ed
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,12 @@ sub edWrite {
warn "$filename: $!\n";
return E_CLOSE;
}

$NeedToSave = $UserHasBeenWarned = 0;
unless ($do_pipe) {
my $lcount = $adrs[1] - $adrs[0] + 1;
if ($lcount == maxline()) {
$NeedToSave = $UserHasBeenWarned = 0;
}
}
print "$chars\n" unless $Scripted;
exit getrc() if $qflag;
return;
Expand Down

0 comments on commit b5df2a2

Please sign in to comment.