more fixes for files that don't end in magiclines: make cut_line() cut

the text of the current line (if any), minus the nonexistent newline,
when we're on the last line of the file, and make sure again that the
file isn't marked as modified if the magicline is deleted and we're
supposed to have one, as it's more consistent that way (a marked cut of
the magicline adds a newline to the cutbuffer, while deleting the
magicline adds nothing)


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3114 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2005-11-08 23:59:29 +00:00
parent 0ed7171138
commit c9820ac098
3 changed files with 25 additions and 9 deletions

View File

@ -38,9 +38,10 @@ CVS code -
file help.c; changes to help_init(), help_line_len(), and file help.c; changes to help_init(), help_line_len(), and
do_help() (all moved to help.c). (DLR) do_help() (all moved to help.c). (DLR)
- Tweak a few functions to remove the assumption that the file - Tweak a few functions to remove the assumption that the file
always ends in a magicline. Changes to do_cut_till_end(), always ends in a magicline. Changes to cut_line(),
open_buffer(), read_file(), write_file(), do_last_line(), do_cut_till_end(), open_buffer(), read_file(), write_file(),
do_alt_speller(), and do_wordlinechar_count(). (DLR) do_last_line(), do_alt_speller(), and do_wordlinechar_count().
(DLR)
- Tweak a few functions to rely on fileage and filebot instead - Tweak a few functions to rely on fileage and filebot instead
of NULL for their checks to detect the top or bottom of the of NULL for their checks to detect the top or bottom of the
file. Changes to cut_line(), cut_to_eol(), do_page_up(), file. Changes to cut_line(), cut_to_eol(), do_page_up(),

View File

@ -40,15 +40,25 @@ void cutbuffer_reset(void)
/* If we're not on the last line of the file, move all the text of the /* If we're not on the last line of the file, move all the text of the
* current line, plus the newline at the end, to the cutbuffer, and set * current line, plus the newline at the end, to the cutbuffer, and set
* the current place we want to where the line used to start. */ * the current place we want to where the line used to start. If we
* are, and the last line of the file isn't blank, move all of the text
* of the current line to the cutbuffer, and set the current place we
* want to where the now-blank line starts. */
void cut_line(void) void cut_line(void)
{ {
if (openfile->current != openfile->filebot) { size_t data_len = strlen(openfile->current->data);
assert(openfile->current_x <= data_len);
if (openfile->current != openfile->filebot)
move_to_filestruct(&cutbuffer, &cutbottom, openfile->current, 0, move_to_filestruct(&cutbuffer, &cutbottom, openfile->current, 0,
openfile->current->next, 0); openfile->current->next, 0);
else if (data_len > 0)
move_to_filestruct(&cutbuffer, &cutbottom, openfile->current, 0,
openfile->current, data_len);
openfile->placewewant = xplustabs(); openfile->placewewant = xplustabs();
} }
}
#ifndef NANO_SMALL #ifndef NANO_SMALL
/* Move all currently marked text to the cutbuffer, and set the current /* Move all currently marked text to the cutbuffer, and set the current

View File

@ -96,6 +96,8 @@ void do_delete(void)
openfile->mark_begin_x -= char_buf_len; openfile->mark_begin_x -= char_buf_len;
#endif #endif
openfile->totsize--; openfile->totsize--;
set_modified();
} else if (openfile->current != openfile->filebot) { } else if (openfile->current != openfile->filebot) {
filestruct *foo = openfile->current->next; filestruct *foo = openfile->current->next;
@ -130,14 +132,17 @@ void do_delete(void)
/* If the NO_NEWLINES flag isn't set, and text has been added to /* If the NO_NEWLINES flag isn't set, and text has been added to
* the magicline as a result of deleting at the end of the line * the magicline as a result of deleting at the end of the line
* before filebot, add a new magicline. */ * before filebot, add a new magicline. This effectively leaves
* the text unchanged, so don't mark the file as modified after
* doing this. */
if (!ISSET(NO_NEWLINES) && openfile->current == if (!ISSET(NO_NEWLINES) && openfile->current ==
openfile->filebot && openfile->current->data[0] != '\0') openfile->filebot && openfile->current->data[0] != '\0')
new_magicline(); new_magicline();
else
set_modified();
} else } else
return; return;
set_modified();
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
/* If color syntaxes are available and turned on, we need to call /* If color syntaxes are available and turned on, we need to call