diff --git a/ChangeLog b/ChangeLog index 253cf79b..8175f2d4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -93,6 +93,16 @@ CVS code - - Rename variable editline to line, for consistency. (DLR) - Change variable i from an int to a size_t in order to match selected, which it's compared against. (DLR) +- cut.c: + cut_to_eof() + - New function, containing the main functionality of + do_cut_till_end(). (DLR) + do_cut_text() + - Add parameter cut_till_end, to indicate when we're cutting + from the current cursor position to the end of the file, and + call cut_to_eof() when it's TRUE. (DLR) + do_cut_till_end() + - Convert to a wrapper for do_cut_text(). (DLR) - files.c: open_file() - Remove redundant wording in the error message when we try to @@ -180,6 +190,10 @@ CVS code - do_input() - Remove redundant check for allow_funcs' being TRUE when we get KEY_MOUSE. (DLR) + - Don't blow away the cutbuffer when we get a shortcut and the + function associated with it is do_cut_till_end(). (DLR) + - Simplify the routine to preserve the cutbuffer when we call a + cutting or copying function associated with a shortcut. (DLR) - nano.h: - Reorder the toggle #defines to match their corresponding order in toggle_init(). (DLR) @@ -199,10 +213,6 @@ CVS code - do_yesno_prompt() - Handle the keys in a switch statement instead of a long if block, for simplicity. (DLR) -- nano.c: - do_input() - - Don't blow away the cutbuffer when the shortcut we get is - do_cut_till_end(). (DLR) - rcfile.c: parse_argument() - Rename variable ptr_bak to ptr_save, for consistency. (DLR) diff --git a/src/cut.c b/src/cut.c index 9cbf4d64..ff3e399f 100644 --- a/src/cut.c +++ b/src/cut.c @@ -39,8 +39,8 @@ void cutbuffer_reset(void) } /* If we aren't on the last line of the file, move all the text of the - * current line, plus the newline at the end, to the cutbuffer. If we - * are, move all of the text of the current line to the cutbuffer. In + * current line, plus the newline at the end, into the cutbuffer. If we + * are, move all of the text of the current line into the cutbuffer. In * both cases, set the current place we want to the beginning of the * current line. */ void cut_line(void) @@ -55,8 +55,8 @@ void cut_line(void) } #ifndef NANO_TINY -/* Move all currently marked text to the cutbuffer, and set the current - * place we want to where the text used to start. */ +/* Move all currently marked text into the cutbuffer, and set the + * current place we want to where the text used to start. */ void cut_marked(void) { filestruct *top, *bot; @@ -71,9 +71,9 @@ void cut_marked(void) /* If we aren't at the end of the current line, move all the text from * the current cursor position to the end of the current line, not - * counting the newline at the end, to the cutbuffer. If we are, and + * counting the newline at the end, into the cutbuffer. If we are, and * we're not on the last line of the file, move the newline at the end - * to the cutbuffer, and set the current place we want to where the + * into the cutbuffer, and set the current place we want to where the * newline used to be. */ void cut_to_eol(void) { @@ -84,27 +84,37 @@ void cut_to_eol(void) if (openfile->current_x < data_len) /* If we're not at the end of the line, move all the text from * the current position up to it, not counting the newline at - * the end, to the cutbuffer. */ + * the end, into the cutbuffer. */ move_to_filestruct(&cutbuffer, &cutbottom, openfile->current, openfile->current_x, openfile->current, data_len); else if (openfile->current != openfile->filebot) { /* If we're at the end of the line, and it isn't the last line * of the file, move all the text from the current position up * to the beginning of the next line, i.e, the newline at the - * end, to the cutbuffer. */ + * end, into the cutbuffer. */ move_to_filestruct(&cutbuffer, &cutbottom, openfile->current, openfile->current_x, openfile->current->next, 0); openfile->placewewant = xplustabs(); } } + +/* Move all the text from the current cursor position to the end of the + * file into the cutbuffer. */ +void cut_to_eof(void) +{ + move_to_filestruct(&cutbuffer, &cutbottom, openfile->current, + openfile->current_x, openfile->filebot, + strlen(openfile->filebot->data)); +} #endif /* !NANO_TINY */ /* Move text from the current filestruct into the cutbuffer. If - * copy_text is TRUE, copy the text back into the filestruct - * afterward. */ + * copy_text is TRUE, copy the text back into the filestruct afterward. + * If cut_till_end is TRUE, move all text from the current cursor + * position to the end of the file into the cutbuffer. */ void do_cut_text( #ifndef NANO_TINY - bool copy_text + bool copy_text, bool cut_till_end #else void #endif @@ -156,7 +166,11 @@ void do_cut_text( keep_cutbuffer = TRUE; #ifndef NANO_TINY - if (openfile->mark_set) { + if (cut_till_end) { + /* If cut_till_end is TRUE, move all text up to the end of the + * file into the cutbuffer. */ + cut_to_eof(); + } else if (openfile->mark_set) { /* If the mark is on, move the marked text to the cutbuffer, and * turn the mark off. */ cut_marked(); @@ -211,7 +225,7 @@ void do_cut_text_void(void) { do_cut_text( #ifndef NANO_TINY - FALSE + FALSE, FALSE #endif ); } @@ -221,30 +235,13 @@ void do_cut_text_void(void) * back into the filestruct afterward. */ void do_copy_text(void) { - do_cut_text(TRUE); + do_cut_text(TRUE, FALSE); } /* Cut from the current cursor position to the end of the file. */ void do_cut_till_end(void) { - assert(openfile->current != NULL && openfile->current->data != NULL); - - check_statusblank(); - - move_to_filestruct(&cutbuffer, &cutbottom, openfile->current, - openfile->current_x, openfile->filebot, - strlen(openfile->filebot->data)); - - /* Leave the text in the cutbuffer, and mark the file as - * modified. */ - set_modified(); - - /* Update the screen. */ - edit_refresh(); - -#ifdef DEBUG - dump_filestruct(cutbuffer); -#endif + do_cut_text(FALSE, TRUE); } #endif /* !NANO_TINY */ diff --git a/src/nano.c b/src/nano.c index ccdac751..406b1fe6 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1247,6 +1247,8 @@ int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool /* The input buffer. */ static size_t kbinput_len = 0; /* The length of the input buffer. */ + bool cut_copy = FALSE; + /* Are we cutting or copying text? */ const shortcut *s; bool have_shortcut; #ifndef NANO_TINY @@ -1359,15 +1361,15 @@ int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool * that we're done after running or trying to run their * associated functions. */ default: - /* Blow away the text in the cutbuffer if we aren't - * cutting or copying text. */ - if (s->func != do_cut_text_void + /* If the function associated with this shortcut is + * cutting or copying text, indicate this. */ + if (s->func == do_cut_text_void #ifndef NANO_TINY - && s->func != do_copy_text && s->func != + || s->func == do_copy_text || s->func == do_cut_till_end #endif ) - cutbuffer_reset(); + cut_copy = TRUE; if (s->func != NULL) { *ran_func = TRUE; @@ -1382,20 +1384,18 @@ int do_input(bool *meta_key, bool *func_key, bool *s_or_t, bool } #ifndef NANO_TINY else if (have_toggle) { - /* Blow away the text in the cutbuffer, since we aren't - * cutting or copying text. */ - cutbuffer_reset(); /* Toggle the flag associated with this shortcut. */ if (allow_funcs) do_toggle(t); } #endif - else - /* Blow away the text in the cutbuffer, since we aren't - * cutting or copying text. */ - cutbuffer_reset(); } + /* If we aren't cutting or copying text, blow away the text in the + * cutbuffer. */ + if (!cut_copy) + cutbuffer_reset(); + return input; } diff --git a/src/proto.h b/src/proto.h index 4eccffa7..138b371a 100644 --- a/src/proto.h +++ b/src/proto.h @@ -254,10 +254,11 @@ void cut_line(void); #ifndef NANO_TINY void cut_marked(void); void cut_to_eol(void); +void cut_to_eof(void); #endif void do_cut_text( #ifndef NANO_TINY - bool copy_text + bool copy_text, bool cut_till_end #else void #endif