From: David Lawrence Ramsey Date: Wed, 20 Jul 2005 19:24:11 +0000 (+0000) Subject: move the paragraph-searching functions to move.c, as they're movement X-Git-Tag: v1.3.9~144 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=ca62f9fa2baf6db24925747abfe509ae7b4f200b;p=nano.git move the paragraph-searching functions to move.c, as they're movement functions, and make them call check_statusblank() too; also reorder some other movement functions git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2902 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index a2b8ad62..0c1377b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -94,6 +94,10 @@ CVS code - do_first_line(), do_last_line() - Simplify by only using edit_redraw(), and also make them call check_statusblank(). (DLR) + do_para_begin(), do_para_begin_void(), do_para_end(), + do_para_end_void() + - Move here from nano.c, as they're movement functions, and also + make them call check_statusblank(). do_page_up(), do_page_down() - If there's less than a page of text onscreen, just call do_(first|last)_line(). (DLR) diff --git a/src/move.c b/src/move.c index c9937759..d6c6ce32 100644 --- a/src/move.c +++ b/src/move.c @@ -59,48 +59,6 @@ void do_last_line(void) edit_redraw(current_save, pww_save); } -void do_home(void) -{ - size_t pww_save = openfile->placewewant; - - check_statusblank(); - -#ifndef NANO_SMALL - if (ISSET(SMART_HOME)) { - size_t current_x_save = openfile->current_x; - - openfile->current_x = indent_length(openfile->current->data); - - if (openfile->current_x == current_x_save || - openfile->current->data[openfile->current_x] == '\0') - openfile->current_x = 0; - - openfile->placewewant = xplustabs(); - } else { -#endif - openfile->current_x = 0; - openfile->placewewant = 0; -#ifndef NANO_SMALL - } -#endif - - if (need_horizontal_update(pww_save)) - update_line(openfile->current, openfile->current_x); -} - -void do_end(void) -{ - size_t pww_save = openfile->placewewant; - - check_statusblank(); - - openfile->current_x = strlen(openfile->current->data); - openfile->placewewant = xplustabs(); - - if (need_horizontal_update(pww_save)) - update_line(openfile->current, openfile->current_x); -} - void do_page_up(void) { int i; @@ -182,6 +140,114 @@ void do_page_down(void) edit_scroll(DOWN, editwinrows - 2); } +#ifndef DISABLE_JUSTIFY +/* Move up to the last beginning-of-paragraph line before the current + * line. */ +void do_para_begin(bool allow_update) +{ + const filestruct *current_save = openfile->current; + const size_t pww_save = openfile->placewewant; + + check_statusblank(); + + openfile->current_x = 0; + openfile->placewewant = 0; + + if (openfile->current->prev != NULL) { + do { + openfile->current = openfile->current->prev; + openfile->current_y--; + } while (!begpar(openfile->current)); + } + + if (allow_update) + edit_redraw(current_save, pww_save); +} + +void do_para_begin_void(void) +{ + do_para_begin(TRUE); +} + +/* Move down to the end of a paragraph, then one line farther. A line + * is the last line of a paragraph if it is in a paragraph, and the next + * line either is a beginning-of-paragraph line or isn't in a + * paragraph. */ +void do_para_end(bool allow_update) +{ + const filestruct *const current_save = openfile->current; + const size_t pww_save = openfile->placewewant; + + check_statusblank(); + + openfile->current_x = 0; + openfile->placewewant = 0; + + while (openfile->current->next != NULL && !inpar(openfile->current)) + openfile->current = openfile->current->next; + + while (openfile->current->next != NULL && + inpar(openfile->current->next) && + !begpar(openfile->current->next)) { + openfile->current = openfile->current->next; + openfile->current_y++; + } + + if (openfile->current->next != NULL) + openfile->current = openfile->current->next; + + if (allow_update) + edit_redraw(current_save, pww_save); +} + +void do_para_end_void(void) +{ + do_para_end(TRUE); +} +#endif /* !DISABLE_JUSTIFY */ + +void do_home(void) +{ + size_t pww_save = openfile->placewewant; + + check_statusblank(); + +#ifndef NANO_SMALL + if (ISSET(SMART_HOME)) { + size_t current_x_save = openfile->current_x; + + openfile->current_x = indent_length(openfile->current->data); + + if (openfile->current_x == current_x_save || + openfile->current->data[openfile->current_x] == '\0') + openfile->current_x = 0; + + openfile->placewewant = xplustabs(); + } else { +#endif + openfile->current_x = 0; + openfile->placewewant = 0; +#ifndef NANO_SMALL + } +#endif + + if (need_horizontal_update(pww_save)) + update_line(openfile->current, openfile->current_x); +} + +void do_end(void) +{ + size_t pww_save = openfile->placewewant; + + check_statusblank(); + + openfile->current_x = strlen(openfile->current->data); + openfile->placewewant = xplustabs(); + + if (need_horizontal_update(pww_save)) + update_line(openfile->current, openfile->current_x); +} + void do_up(void) { check_statusblank(); diff --git a/src/nano.c b/src/nano.c index 78bacb13..1f9bf20d 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2948,32 +2948,6 @@ bool begpar(const filestruct *const foo) return FALSE; } -/* We find the last beginning-of-paragraph line before the current - * line. */ -void do_para_begin(bool allow_update) -{ - const filestruct *current_save = openfile->current; - const size_t pww_save = openfile->placewewant; - - openfile->current_x = 0; - openfile->placewewant = 0; - - if (openfile->current->prev != NULL) { - do { - openfile->current = openfile->current->prev; - openfile->current_y--; - } while (!begpar(openfile->current)); - } - - if (allow_update) - edit_redraw(current_save, pww_save); -} - -void do_para_begin_void(void) -{ - do_para_begin(TRUE); -} - /* Is foo inside a paragraph? */ bool inpar(const filestruct *const foo) { @@ -2988,39 +2962,6 @@ bool inpar(const filestruct *const foo) quote_len)] != '\0'; } -/* A line is the last line of a paragraph if it is in a paragraph, and - * the next line isn't, or is the beginning of a paragraph. We move - * down to the end of a paragraph, then one line farther. */ -void do_para_end(bool allow_update) -{ - const filestruct *const current_save = openfile->current; - const size_t pww_save = openfile->placewewant; - - openfile->current_x = 0; - openfile->placewewant = 0; - - while (openfile->current->next != NULL && !inpar(openfile->current)) - openfile->current = openfile->current->next; - - while (openfile->current->next != NULL && - inpar(openfile->current->next) && - !begpar(openfile->current->next)) { - openfile->current = openfile->current->next; - openfile->current_y++; - } - - if (openfile->current->next != NULL) - openfile->current = openfile->current->next; - - if (allow_update) - edit_redraw(current_save, pww_save); -} - -void do_para_end_void(void) -{ - do_para_end(TRUE); -} - /* Put the next par_len lines, starting with first_line, into the * justify buffer, leaving copies of those lines in place. Assume there * are enough lines after first_line. Return the new copy of diff --git a/src/proto.h b/src/proto.h index dd643a94..f798a0e1 100644 --- a/src/proto.h +++ b/src/proto.h @@ -329,10 +329,16 @@ void thanks_for_all_the_fish(void); /* Public functions in move.c. */ void do_first_line(void); void do_last_line(void); -void do_home(void); -void do_end(void); void do_page_up(void); void do_page_down(void); +#ifndef DISABLE_JUSTIFY +void do_para_begin(bool allow_update); +void do_para_begin_void(void); +void do_para_end(bool allow_update); +void do_para_end_void(void); +#endif +void do_home(void); +void do_end(void); void do_up(void); void do_down(void); void do_left(bool allow_update); @@ -420,11 +426,7 @@ bool quotes_match(const char *a_line, size_t a_quote, const char bool indents_match(const char *a_line, size_t a_indent, const char *b_line, size_t b_indent); bool begpar(const filestruct *const foo); -void do_para_begin(bool allow_update); -void do_para_begin_void(void); bool inpar(const filestruct *const foo); -void do_para_end(bool allow_update); -void do_para_end_void(void); filestruct *backup_lines(filestruct *first_line, size_t par_len, size_t quote_len); bool find_paragraph(size_t *const quote, size_t *const par);