vi: Ensure that the edit buffer ends in a newline
Currently vi assumes that the edit buffer ends in a newline. This may not be the case. For example: $ printf test > test $ vi test <press 'o'> We fix this by inserting a newline to the end during initialization. Signed-off-by: Petja Patjas <pp01415943@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
0af28b84e5
commit
05e5d6a381
1 changed files with 4 additions and 3 deletions
|
@ -2315,9 +2315,10 @@ static int init_text_buffer(char *fn)
|
||||||
|
|
||||||
update_filename(fn);
|
update_filename(fn);
|
||||||
rc = file_insert(fn, text, 1);
|
rc = file_insert(fn, text, 1);
|
||||||
if (rc < 0) {
|
if (rc <= 0 || *(end - 1) != '\n') {
|
||||||
// file doesnt exist. Start empty buf with dummy line
|
// file doesn't exist or doesn't end in a newline.
|
||||||
char_insert(text, '\n', NO_UNDO);
|
// insert a newline to the end
|
||||||
|
char_insert(end, '\n', NO_UNDO);
|
||||||
}
|
}
|
||||||
|
|
||||||
flush_undo_data();
|
flush_undo_data();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue