From: David Lawrence Ramsey Date: Tue, 12 Jul 2005 17:40:16 +0000 (+0000) Subject: fix marking breakage X-Git-Tag: v1.3.9~196 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=5128de830888b7ba9c1af3e16cde2b8bc75edc9c;p=nano.git fix marking breakage git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2850 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/src/files.c b/src/files.c index 2944cfd2..a134d890 100644 --- a/src/files.c +++ b/src/files.c @@ -134,8 +134,8 @@ void initialize_buffer(void) openfile->placewewant = 0; #ifndef NANO_SMALL - openfile->mark_beginbuf = NULL; - openfile->mark_beginx = 0; + openfile->mark_begin = NULL; + openfile->mark_begin_x = 0; #endif openfile->totlines = 1; diff --git a/src/nano.c b/src/nano.c index 37cbf21c..7fffdf64 100644 --- a/src/nano.c +++ b/src/nano.c @@ -320,14 +320,14 @@ void move_to_filestruct(filestruct **file_top, filestruct **file_bot, at_edittop = (openfile->fileage == openfile->edittop); #ifndef NANO_SMALL if (openfile->mark_set) - mark_inside = (openfile->mark_beginbuf->lineno >= + mark_inside = (openfile->mark_begin->lineno >= openfile->fileage->lineno && - openfile->mark_beginbuf->lineno <= + openfile->mark_begin->lineno <= openfile->filebot->lineno && - (openfile->mark_beginbuf != openfile->fileage || - openfile->mark_beginx >= top_x) && - (openfile->mark_beginbuf != openfile->filebot || - openfile->mark_beginx <= bot_x)); + (openfile->mark_begin != openfile->fileage || + openfile->mark_begin_x >= top_x) && + (openfile->mark_begin != openfile->filebot || + openfile->mark_begin_x <= bot_x)); #endif /* Get the number of characters in the text, and subtract it from @@ -371,8 +371,8 @@ void move_to_filestruct(filestruct **file_top, filestruct **file_bot, openfile->edittop = openfile->fileage; #ifndef NANO_SMALL if (mark_inside) { - openfile->mark_beginbuf = openfile->fileage; - openfile->mark_beginx = top_x; + openfile->mark_begin = openfile->fileage; + openfile->mark_begin_x = top_x; } #endif @@ -1311,10 +1311,10 @@ void do_delete(void) null_at(&openfile->current->data, openfile->current_x + line_len - char_buf_len); #ifndef NANO_SMALL - if (openfile->mark_set && openfile->current_x < - openfile->mark_beginx && openfile->mark_beginbuf == - openfile->current) - openfile->mark_beginx -= char_buf_len; + if (openfile->mark_set && openfile->mark_begin == + openfile->current && openfile->current_x < + openfile->mark_begin_x) + openfile->mark_begin_x -= char_buf_len; #endif openfile->totsize--; } else if (openfile->current != openfile->filebot && @@ -1336,10 +1336,10 @@ void do_delete(void) strcpy(openfile->current->data + openfile->current_x, foo->data); #ifndef NANO_SMALL - if (openfile->mark_set && openfile->mark_beginbuf == + if (openfile->mark_set && openfile->mark_begin == openfile->current->next) { - openfile->mark_beginx += openfile->current_x; - openfile->mark_beginbuf = openfile->current; + openfile->mark_begin = openfile->current; + openfile->mark_begin_x += openfile->current_x; } #endif if (openfile->filebot == foo) @@ -1431,10 +1431,10 @@ void do_enter(void) null_at(&openfile->current->data, openfile->current_x); #ifndef NANO_SMALL if (openfile->mark_set && openfile->current == - openfile->mark_beginbuf && openfile->current_x < - openfile->mark_beginx) { - openfile->mark_beginbuf = newnode; - openfile->mark_beginx += extra - openfile->current_x; + openfile->mark_begin && openfile->current_x < + openfile->mark_begin_x) { + openfile->mark_begin = newnode; + openfile->mark_begin_x += extra - openfile->current_x; } #endif openfile->current_x = extra; @@ -1747,15 +1747,15 @@ void do_word_count(void) void do_mark(void) { - openfile->mark_set = openfile->mark_set ? FALSE : TRUE; + openfile->mark_set = !openfile->mark_set; if (openfile->mark_set) { statusbar(_("Mark Set")); - openfile->mark_beginbuf = openfile->current; - openfile->mark_beginx = openfile->current_x; + openfile->mark_begin = openfile->current; + openfile->mark_begin_x = openfile->current_x; } else { statusbar(_("Mark UNset")); - openfile->mark_beginbuf = NULL; - openfile->mark_beginx = 0; + openfile->mark_begin = NULL; + openfile->mark_begin_x = 0; edit_refresh(); } } @@ -1969,12 +1969,14 @@ bool do_wrap(filestruct *line) /* If the mark was on this line after the wrap point, we move it * down. If it was on the next line and we wrapped onto that line, * we move it right. */ - if (openfile->mark_set && openfile->mark_beginbuf == line && - openfile->mark_beginx > wrap_loc) { - openfile->mark_beginbuf = line->next; - openfile->mark_beginx -= wrap_loc - indent_len + 1; - } else if (wrapping && openfile->mark_beginbuf == line->next) - openfile->mark_beginx += after_break_len; + if (openfile->mark_set) { + if (openfile->mark_begin == line && openfile->mark_begin_x > + wrap_loc) { + openfile->mark_begin = line->next; + openfile->mark_begin_x -= wrap_loc - indent_len + 1; + } else if (wrapping && openfile->mark_begin == line->next) + openfile->mark_begin_x += after_break_len; + } #endif return TRUE; @@ -2006,7 +2008,7 @@ bool do_int_spell_fix(const char *word) bool added_magicline = FALSE; /* Whether we added a magicline after filebot. */ bool right_side_up = FALSE; - /* TRUE if (mark_beginbuf, mark_beginx) is the top of the mark, + /* TRUE if (mark_begin, mark_begin_x) is the top of the mark, * FALSE if (current, current_x) is. */ filestruct *top, *bot; size_t top_x, bot_x; @@ -2101,11 +2103,11 @@ bool do_int_spell_fix(const char *word) if (openfile->fileage == openfile->filebot) bot_x += top_x; if (right_side_up) { - openfile->mark_beginx = top_x; + openfile->mark_begin_x = top_x; current_x_save = bot_x; } else { current_x_save = top_x; - openfile->mark_beginx = bot_x; + openfile->mark_begin_x = bot_x; } /* Unpartition the filestruct so that it contains all the text @@ -2347,15 +2349,15 @@ const char *do_alt_speller(char *tempfile_name) bool added_magicline = FALSE; /* Whether we added a magicline after filebot. */ bool right_side_up = FALSE; - /* TRUE if (mark_beginbuf, mark_beginx) is the top of the mark, + /* TRUE if (mark_begin, mark_begin_x) is the top of the mark, * FALSE if (current, current_x) is. */ filestruct *top, *bot; size_t top_x, bot_x; - ssize_t mbb_lineno_save = 0; + ssize_t mb_lineno_save = 0; /* We're going to close the current file, and open the output of - * the alternate spell command. The line that mark_beginbuf - * points to will be freed, so we save the line number and - * restore afterwards. */ + * the alternate spell command. The line that mark_begin points + * to will be freed, so we save the line number and restore it + * afterwards. */ size_t totsize_save = openfile->totsize; /* Our saved value of totsize, used when we spell-check a marked * selection. */ @@ -2363,7 +2365,7 @@ const char *do_alt_speller(char *tempfile_name) if (old_mark_set) { /* If the mark is on, save the number of the line it starts on, * and then turn the mark off. */ - mbb_lineno_save = openfile->mark_beginbuf->lineno; + mb_lineno_save = openfile->mark_begin->lineno; openfile->mark_set = FALSE; } #endif @@ -2479,11 +2481,11 @@ const char *do_alt_speller(char *tempfile_name) if (openfile->fileage == openfile->filebot) bot_x += top_x; if (right_side_up) { - openfile->mark_beginx = top_x; + openfile->mark_begin_x = top_x; current_x_save = bot_x; } else { current_x_save = top_x; - openfile->mark_beginx = bot_x; + openfile->mark_begin_x = bot_x; } /* Unpartition the filestruct so that it contains all the text @@ -2502,16 +2504,15 @@ const char *do_alt_speller(char *tempfile_name) totsize_save += openfile->totsize; openfile->totsize = totsize_save; - /* Assign mark_beginbuf to the line where the mark began - * before. */ - do_gotopos(mbb_lineno_save, openfile->mark_beginx, + /* Assign mark_begin to the line where the mark began before. */ + do_gotopos(mb_lineno_save, openfile->mark_begin_x, current_y_save, 0); - openfile->mark_beginbuf = openfile->current; + openfile->mark_begin = openfile->current; - /* Assign mark_beginx to the location in mark_beginbuf where the + /* Assign mark_begin_x to the location in mark_begin where the * mark began before, adjusted for any shortening of the * line. */ - openfile->mark_beginx = openfile->current_x; + openfile->mark_begin_x = openfile->current_x; /* Turn the mark back on. */ openfile->mark_set = TRUE; @@ -2722,8 +2723,8 @@ void justify_format(filestruct *paragraph, size_t skip) #ifndef NANO_SMALL /* Keep track of the change in the current line. */ - if (openfile->mark_set && openfile->mark_beginbuf == - paragraph && openfile->mark_beginx >= end - + if (openfile->mark_set && openfile->mark_begin == + paragraph && openfile->mark_begin_x >= end - paragraph->data) mark_shift += end_len; #endif @@ -2777,8 +2778,8 @@ void justify_format(filestruct *paragraph, size_t skip) #ifndef NANO_SMALL /* Keep track of the change in the current line. */ - if (openfile->mark_set && openfile->mark_beginbuf == - paragraph && openfile->mark_beginx >= end - + if (openfile->mark_set && openfile->mark_begin == + paragraph && openfile->mark_begin_x >= end - paragraph->data) mark_shift += end_len; #endif @@ -2817,11 +2818,10 @@ void justify_format(filestruct *paragraph, size_t skip) #ifndef NANO_SMALL /* Adjust the mark coordinates to compensate for the change in * the current line. */ - if (openfile->mark_set && openfile->mark_beginbuf == - paragraph) { - openfile->mark_beginx -= mark_shift; - if (openfile->mark_beginx > new_end - new_paragraph_data) - openfile->mark_beginx = new_end - new_paragraph_data; + if (openfile->mark_set && openfile->mark_begin == paragraph) { + openfile->mark_begin_x -= mark_shift; + if (openfile->mark_begin_x > new_end - new_paragraph_data) + openfile->mark_begin_x = new_end - new_paragraph_data; } #endif } else @@ -3031,12 +3031,12 @@ filestruct *backup_lines(filestruct *first_line, size_t par_len, size_t ssize_t current_lineno_save = openfile->current->lineno; #ifndef NANO_SMALL bool old_mark_set = openfile->mark_set; - ssize_t mbb_lineno_save = 0; - size_t mark_beginx_save = 0; + ssize_t mb_lineno_save = 0; + size_t mark_begin_x_save = 0; if (old_mark_set) { - mbb_lineno_save = openfile->mark_beginbuf->lineno; - mark_beginx_save = openfile->mark_beginx; + mb_lineno_save = openfile->mark_begin->lineno; + mark_begin_x_save = openfile->mark_begin_x; } #endif @@ -3054,9 +3054,9 @@ filestruct *backup_lines(filestruct *first_line, size_t par_len, size_t copy_from_filestruct(jusbuffer, jusbottom); /* Move upward from the last line of the paragraph to the first - * line, putting first_line, edittop, current, and mark_beginbuf at - * the same lines in the copied paragraph that they had in the - * original paragraph. */ + * line, putting first_line, edittop, current, and mark_begin at the + * same lines in the copied paragraph that they had in the original + * paragraph. */ top = openfile->current->prev; for (i = par_len; i > 0; i--) { if (top->lineno == fl_lineno_save) @@ -3066,9 +3066,9 @@ filestruct *backup_lines(filestruct *first_line, size_t par_len, size_t if (top->lineno == current_lineno_save) openfile->current = top; #ifndef NANO_SMALL - if (old_mark_set && top->lineno == mbb_lineno_save) { - openfile->mark_beginbuf = top; - openfile->mark_beginx = mark_beginx_save; + if (old_mark_set && top->lineno == mb_lineno_save) { + openfile->mark_begin = top; + openfile->mark_begin_x = mark_begin_x_save; } #endif top = top->prev; @@ -3179,8 +3179,8 @@ void do_justify(bool full_justify) filestruct *edittop_save = openfile->edittop; filestruct *current_save = openfile->current; #ifndef NANO_SMALL - filestruct *mark_beginbuf_save = openfile->mark_beginbuf; - size_t mark_beginx_save = openfile->mark_beginx; + filestruct *mark_begin_save = openfile->mark_begin; + size_t mark_begin_x_save = openfile->mark_begin_x; #endif int kbinput; bool meta_key, func_key, s_or_t, ran_func, finished; @@ -3318,10 +3318,10 @@ void do_justify(bool full_justify) #ifndef NANO_SMALL /* Adjust the mark coordinates to compensate for the change * in the next line. */ - if (openfile->mark_set && openfile->mark_beginbuf == + if (openfile->mark_set && openfile->mark_begin == next_line) { - openfile->mark_beginbuf = openfile->current; - openfile->mark_beginx += line_len - indent_len; + openfile->mark_begin = openfile->current; + openfile->mark_begin_x += line_len - indent_len; } #endif @@ -3398,11 +3398,11 @@ void do_justify(bool full_justify) #ifndef NANO_SMALL /* Adjust the mark coordinates to compensate for the change * in the current line. */ - if (openfile->mark_set && openfile->mark_beginbuf == - openfile->current && openfile->mark_beginx > + if (openfile->mark_set && openfile->mark_begin == + openfile->current && openfile->mark_begin_x > break_pos) { - openfile->mark_beginbuf = openfile->current->next; - openfile->mark_beginx -= break_pos - indent_len; + openfile->mark_begin = openfile->current->next; + openfile->mark_begin_x -= break_pos - indent_len; } #endif @@ -3504,8 +3504,8 @@ void do_justify(bool full_justify) openfile->totlines = openfile->filebot->lineno; #ifndef NANO_SMALL if (openfile->mark_set) { - openfile->mark_beginbuf = mark_beginbuf_save; - openfile->mark_beginx = mark_beginx_save; + openfile->mark_begin = mark_begin_save; + openfile->mark_begin_x = mark_begin_x_save; } #endif openfile->modified = modified_save; @@ -4137,9 +4137,9 @@ void do_output(char *output, size_t output_len, bool allow_cntrls) #ifndef NANO_SMALL /* Note that current_x has not yet been incremented. */ if (openfile->mark_set && openfile->current == - openfile->mark_beginbuf && openfile->current_x < - openfile->mark_beginx) - openfile->mark_beginx += char_buf_len; + openfile->mark_begin && openfile->current_x < + openfile->mark_begin_x) + openfile->mark_begin_x += char_buf_len; #endif do_right(FALSE); diff --git a/src/nano.h b/src/nano.h index b9ac25f1..73ab655a 100644 --- a/src/nano.h +++ b/src/nano.h @@ -172,10 +172,9 @@ typedef struct openfilestruct { * position. */ size_t placewewant; /* Current file's place we want. */ #ifndef NANO_SMALL - filestruct *mark_beginbuf; - /* Current file's beginning marked + filestruct *mark_begin; /* Current file's beginning marked * line. */ - size_t mark_beginx; /* Current file's beginning marked + size_t mark_begin_x; /* Current file's beginning marked * line's x-coordinate position. */ #endif size_t totlines; /* Current file's total number of diff --git a/src/proto.h b/src/proto.h index 1420fef5..ba6cb7bd 100644 --- a/src/proto.h +++ b/src/proto.h @@ -486,7 +486,7 @@ void search_init_globals(void); int search_init(bool replacing, bool use_answer); bool is_whole_word(size_t pos, const char *buf, const char *word); bool findnextstr(bool can_display_wrap, bool wholeword, bool - no_sameline, const filestruct *begin, size_t beginx, const char + no_sameline, const filestruct *begin, size_t begin_x, const char *needle, size_t *needle_len); void findnextstr_wrap_reset(void); void do_search(void); diff --git a/src/search.c b/src/search.c index 2ae55457..11f6f8c5 100644 --- a/src/search.c +++ b/src/search.c @@ -281,13 +281,13 @@ bool is_whole_word(size_t pos, const char *buf, const char *word) /* Look for needle, starting at (current, current_x). If no_sameline is * TRUE, skip over begin when looking for needle. begin is the line - * where we first started searching, at column beginx. If + * where we first started searching, at column begin_x. If * can_display_wrap is TRUE, we put messages on the statusbar, wrap * around the file boundaries. The return value specifies whether we * found anything. If we did, set needle_len to the length of the * string we found if it isn't NULL. */ bool findnextstr(bool can_display_wrap, bool wholeword, bool - no_sameline, const filestruct *begin, size_t beginx, const char + no_sameline, const filestruct *begin, size_t begin_x, const char *needle, size_t *needle_len) { filestruct *fileptr = openfile->current; @@ -404,10 +404,10 @@ bool findnextstr(bool can_display_wrap, bool wholeword, bool /* Ensure we haven't wrapped around again! */ if (search_last_line && #ifndef NANO_SMALL - ((!ISSET(BACKWARDS_SEARCH) && current_x_find > beginx) || - (ISSET(BACKWARDS_SEARCH) && current_x_find < beginx)) + ((!ISSET(BACKWARDS_SEARCH) && current_x_find > begin_x) || + (ISSET(BACKWARDS_SEARCH) && current_x_find < begin_x)) #else - current_x_find > beginx + current_x_find > begin_x #endif ) { if (can_display_wrap) @@ -691,7 +691,7 @@ ssize_t do_replace_loop(const char *needle, const filestruct filestruct *edittop_save = openfile->edittop, *top, *bot; size_t top_x, bot_x; bool right_side_up = FALSE; - /* TRUE if (mark_beginbuf, mark_beginx) is the top of the mark, + /* TRUE if (mark_begin, mark_begin_x) is the top of the mark, * FALSE if (current, current_x) is. */ if (old_mark_set) { @@ -795,17 +795,17 @@ ssize_t do_replace_loop(const char *needle, const filestruct strlen(openfile->current->data); #ifndef NANO_SMALL - /* If the mark was on and (mark_beginbuf, mark_begin_x) was - * the top of it, don't change mark_beginx. */ + /* If the mark was on and (mark_begin, mark_begin_x) was the + * top of it, don't change mark_begin_x. */ if (!old_mark_set || !right_side_up) { - /* Keep mark_beginx in sync with the text changes. */ - if (openfile->current == openfile->mark_beginbuf && - openfile->mark_beginx > openfile->current_x) { - if (openfile->mark_beginx < openfile->current_x + + /* Keep mark_begin_x in sync with the text changes. */ + if (openfile->current == openfile->mark_begin && + openfile->mark_begin_x > openfile->current_x) { + if (openfile->mark_begin_x < openfile->current_x + match_len) - openfile->mark_beginx = openfile->current_x; + openfile->mark_begin_x = openfile->current_x; else - openfile->mark_beginx += length_change; + openfile->mark_begin_x += length_change; } } @@ -878,7 +878,7 @@ void do_replace(void) { int i; filestruct *edittop_save, *begin; - size_t beginx, pww_save; + size_t begin_x, pww_save; ssize_t numreplaced; if (ISSET(VIEW_MODE)) { @@ -941,16 +941,16 @@ void do_replace(void) /* Save where we are. */ edittop_save = openfile->edittop; begin = openfile->current; - beginx = openfile->current_x; + begin_x = openfile->current_x; pww_save = openfile->placewewant; - numreplaced = do_replace_loop(last_search, begin, &beginx, FALSE, + numreplaced = do_replace_loop(last_search, begin, &begin_x, FALSE, NULL); /* Restore where we were. */ openfile->edittop = edittop_save; openfile->current = begin; - openfile->current_x = beginx; + openfile->current_x = begin_x; openfile->placewewant = pww_save; renumber(openfile->fileage); diff --git a/src/utils.c b/src/utils.c index 6a20a11e..423b032f 100644 --- a/src/utils.c +++ b/src/utils.c @@ -403,25 +403,25 @@ void remove_magicline(void) /* Set top_x and bot_x to the top and bottom x-coordinates of the mark, * respectively, based on the locations of top and bot. If * right_side_up isn't NULL, set it to TRUE If the mark begins with - * (mark_beginbuf, mark_beginx) and ends with (current, current_x), or + * (mark_begin, mark_begin_x) and ends with (current, current_x), or * FALSE otherwise. */ void mark_order(const filestruct **top, size_t *top_x, const filestruct **bot, size_t *bot_x, bool *right_side_up) { assert(top != NULL && top_x != NULL && bot != NULL && bot_x != NULL); - if ((openfile->current->lineno == openfile->mark_beginbuf->lineno && - openfile->current_x > openfile->mark_beginx) || - openfile->current->lineno > openfile->mark_beginbuf->lineno) { - *top = openfile->mark_beginbuf; - *top_x = openfile->mark_beginx; + if ((openfile->current->lineno == openfile->mark_begin->lineno && + openfile->current_x > openfile->mark_begin_x) || + openfile->current->lineno > openfile->mark_begin->lineno) { + *top = openfile->mark_begin; + *top_x = openfile->mark_begin_x; *bot = openfile->current; *bot_x = openfile->current_x; if (right_side_up != NULL) *right_side_up = TRUE; } else { - *bot = openfile->mark_beginbuf; - *bot_x = openfile->mark_beginx; + *bot = openfile->mark_begin; + *bot_x = openfile->mark_begin_x; *top = openfile->current; *top_x = openfile->current_x; if (right_side_up != NULL) diff --git a/src/winio.c b/src/winio.c index ea88d638..01d96dcd 100644 --- a/src/winio.c +++ b/src/winio.c @@ -3354,19 +3354,19 @@ void edit_add(const filestruct *fileptr, const char *converted, int #ifndef NANO_SMALL if (openfile->mark_set && (fileptr->lineno <= - openfile->mark_beginbuf->lineno || fileptr->lineno <= + openfile->mark_begin->lineno || fileptr->lineno <= openfile->current->lineno) && (fileptr->lineno >= - openfile->mark_beginbuf->lineno || fileptr->lineno >= + openfile->mark_begin->lineno || fileptr->lineno >= openfile->current->lineno)) { /* fileptr is at least partially selected. */ const filestruct *top; - /* Either current or mark_beginbuf, whichever is first. */ + /* Either current or mark_begin, whichever is first. */ size_t top_x; - /* current_x or mark_beginx, corresponding to top. */ + /* current_x or mark_begin_x, corresponding to top. */ const filestruct *bot; size_t bot_x; int x_start; - /* Starting column for mvwaddnstr. Zero-based. */ + /* Starting column for mvwaddnstr(). Zero-based. */ int paintlen; /* Number of chars to paint on this line. There are COLS * characters on a whole line. */