- 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
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)
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)
}
/* 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)
}
#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;
/* 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)
{
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
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();
{
do_cut_text(
#ifndef NANO_TINY
- FALSE
+ FALSE, FALSE
#endif
);
}
* 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 */
/* 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
* 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;
}
#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;
}