source file, and adjust related variables accordingly. New
file help.c; changes to help_init(), help_line_len(), and
do_help() (all moved to help.c). (DLR)
+ - Tweak a few functions to remove the assumption that the file
+ always ends in a magicline. Changes to do_cut_till_end(),
+ do_next_word(), and do_wordlinechar_count(). (DLR)
+ - Tweak a few functions to rely on fileage and filebot instead
+ of NULL for their checks to detect the top or bottom of the
+ file. Changes to cut_line(), cut_to_eol(), do_page_up(),
+ do_page_down(), do_para_end(), do_next_word(), do_prev_word(),
+ do_up(), do_down(), do_scroll_down(), do_right(), do_mouse(),
+ do_gotolinecolumn(), do_delete(), and find_paragraph(). (DLR)
- nano.h:
- Readd MIN_EDITOR_COLS #define. (DLR)
- winio.c:
keep_cutbuffer = FALSE;
}
-/* If we're not on the magicline, move all the text of the 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. */
+/* 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
+ * the current place we want to where the line used to start. */
void cut_line(void)
{
- if (openfile->current->next != NULL) {
+ if (openfile->current != openfile->filebot) {
move_to_filestruct(&cutbuffer, &cutbottom, openfile->current, 0,
openfile->current->next, 0);
openfile->placewewant = xplustabs();
/* If we're not 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 we're not on the magicline, move the newline at the end to the
- * cutbuffer, and set the current place we want to where the newline
- * used to be. */
+ * 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
+ * newline used to be. */
void cut_to_eol(void)
{
size_t data_len = strlen(openfile->current->data);
* the end, to the cutbuffer. */
move_to_filestruct(&cutbuffer, &cutbottom, openfile->current,
openfile->current_x, openfile->current, data_len);
- else if (openfile->current->next != NULL) {
- /* If we're at the end of the line, and it isn't the magicline,
- * 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. */
+ 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. */
move_to_filestruct(&cutbuffer, &cutbottom, openfile->current,
openfile->current_x, openfile->current->next, 0);
openfile->placewewant = xplustabs();
check_statusblank();
move_to_filestruct(&cutbuffer, &cutbottom, openfile->current,
- openfile->current_x, openfile->filebot, 0);
+ openfile->current_x, openfile->filebot,
+ strlen(openfile->filebot->data));
edit_refresh();
set_modified();
}
#endif
- for (i = editwinrows - 2; i > 0 && openfile->current->prev != NULL;
- i--)
+ for (i = editwinrows - 2; i > 0 && openfile->current !=
+ openfile->fileage; i--)
openfile->current = openfile->current->prev;
openfile->current_x = actual_x(openfile->current->data,
}
#endif
- for (i = editwinrows - 2; i > 0 && openfile->current->next != NULL;
- i--)
+ for (i = editwinrows - 2; i > 0 && openfile->current !=
+ openfile->filebot; i--)
openfile->current = openfile->current->next;
openfile->current_x = actual_x(openfile->current->data,
openfile->current_x = 0;
openfile->placewewant = 0;
- if (openfile->current->prev != NULL) {
+ if (openfile->current != openfile->fileage) {
do {
openfile->current = openfile->current->prev;
openfile->current_y--;
openfile->current_x = 0;
openfile->placewewant = 0;
- while (openfile->current->next != NULL && !inpar(openfile->current))
+ while (openfile->current != openfile->filebot &&
+ !inpar(openfile->current))
openfile->current = openfile->current->next;
- while (openfile->current->next != NULL &&
+ while (openfile->current != openfile->filebot &&
inpar(openfile->current->next) &&
!begpar(openfile->current->next)) {
openfile->current = openfile->current->next;
openfile->current_y++;
}
- if (openfile->current->next != NULL)
+ if (openfile->current != openfile->filebot)
openfile->current = openfile->current->next;
if (allow_update)
if (!end_line)
break;
- if (openfile->current->next != NULL) {
+ if (openfile->current != openfile->filebot) {
end_line = FALSE;
openfile->current_x = 0;
}
/* If we haven't found it, leave the cursor at the end of the
* file. */
- if (openfile->current == NULL)
+ if (openfile->current == NULL) {
openfile->current = openfile->filebot;
+ openfile->current_x = strlen(openfile->filebot->data);
+ }
openfile->placewewant = xplustabs();
if (!begin_line)
break;
- if (openfile->current->prev != NULL) {
+ if (openfile->current != openfile->fileage) {
begin_line = FALSE;
openfile->current_x = strlen(openfile->current->prev->data);
}
#endif
/* If we're at the top of the file, get out. */
- if (openfile->current->prev == NULL)
+ if (openfile->current == openfile->fileage)
return;
assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);
#endif
/* If we're at the bottom of the file, get out. */
- if (openfile->current->next == NULL)
+ if (openfile->current == openfile->filebot)
return;
assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);
#endif
/* If we're at the bottom of the file, get out. */
- if (openfile->current->next == NULL)
+ if (openfile->current == openfile->filebot)
return;
assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno);
if (openfile->current->data[openfile->current_x] != '\0')
openfile->current_x = move_mbright(openfile->current->data,
openfile->current_x);
- else if (openfile->current->next != NULL) {
+ else if (openfile->current != openfile->filebot) {
do_down();
openfile->current_x = 0;
}
}
/* Unpartition a filestruct so it begins at (fileage, 0) and ends at
- * (filebot, strlen(filebot)) again. */
+ * (filebot, strlen(filebot->data)) again. */
void unpartition_filestruct(partition **p)
{
char *tmp;
/* Move to where the click occurred. */
for (; openfile->current_y < mouse_y &&
- openfile->current->next != NULL; openfile->current_y++)
+ openfile->current != openfile->filebot;
+ openfile->current_y++)
openfile->current = openfile->current->next;
for (; openfile->current_y > mouse_y &&
- openfile->current->prev != NULL; openfile->current_y--)
+ openfile->current != openfile->fileage;
+ openfile->current_y--)
openfile->current = openfile->current->prev;
openfile->current_x = actual_x(openfile->current->data,
}
for (openfile->current = openfile->fileage;
- openfile->current->next != NULL && line > 1; line--)
+ openfile->current != openfile->filebot && line > 1; line--)
openfile->current = openfile->current->next;
openfile->current_x = actual_x(openfile->current->data, column - 1);
openfile->mark_begin_x -= char_buf_len;
#endif
openfile->totsize--;
- } else if (openfile->current != openfile->filebot &&
- (openfile->current->next != openfile->filebot ||
- openfile->current->data[0] == '\0')) {
- /* We can delete the line before filebot only if it is blank: it
- * becomes the new magicline then. */
+ } else if (openfile->current != openfile->filebot) {
filestruct *foo = openfile->current->next;
assert(openfile->current_x == strlen(openfile->current->data));
#ifndef DISABLE_WRAPPING
wrap_reset();
#endif
+
+ /* If we deleted the line before filebot, and the resulting
+ * line at filebot isn't blank, add a new magicline. */
+ if (openfile->current == openfile->filebot &&
+ openfile->current->data[0] != '\0')
+ new_magicline();
} else
return;
if (openfile->current == current_save ||
!inpar(openfile->current->prev))
return FALSE;
- if (openfile->current->prev != NULL)
+ if (openfile->current != openfile->fileage)
openfile->current = openfile->current->prev;
}
if (!begpar(openfile->current))
size_t pww_save = openfile->placewewant;
filestruct *current_save = openfile->current;
bool old_mark_set = openfile->mark_set;
- bool added_magicline = FALSE;
- /* Whether we added a magicline after filebot. */
filestruct *top, *bot;
size_t top_x, bot_x;
if (old_mark_set) {
/* If the mark is on, partition the filestruct so that it
- * contains only the marked text, keep track of whether the text
- * will need a magicline added while we're counting words, add
- * the magicline if necessary, and turn the mark off. */
+ * contains only the marked text, and turn the mark off. */
mark_order((const filestruct **)&top, &top_x,
(const filestruct **)&bot, &bot_x, NULL);
filepart = partition_filestruct(top, top_x, bot, bot_x);
- if ((added_magicline = (openfile->filebot->data[0] != '\0')))
- new_magicline();
openfile->mark_set = FALSE;
}
* until we reach the end of the file, incrementing the total word
* count whenever we're on a word just before moving. */
while (openfile->current != openfile->filebot ||
- openfile->current_x != 0) {
+ openfile->current->data[openfile->current_x] != '\0') {
if (do_next_word(TRUE, FALSE))
words++;
}
/* Get the total line and character counts, as "wc -l" and "wc -c"
* do, but get the latter in multibyte characters. */
if (old_mark_set) {
- /* If the mark was on and we added a magicline, remove it
- * now. */
- if (added_magicline)
- remove_magicline();
-
lines = openfile->filebot->lineno -
openfile->fileage->lineno + 1;
chars = get_totsize(openfile->fileage, openfile->filebot);