From 7ea09e540f1d36b36dd5bc9081b90cc4f32efad7 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Mon, 25 Jul 2005 02:41:59 +0000 Subject: [PATCH] move mark setting, deleting, backspacing, tabbing, and entering of newlines to text.c too git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2923 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 3 +- src/nano.c | 196 ---------------------------------------------------- src/proto.h | 14 ++-- src/text.c | 196 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 205 insertions(+), 204 deletions(-) diff --git a/ChangeLog b/ChangeLog index 471f3c42..89042846 100644 --- a/ChangeLog +++ b/ChangeLog @@ -92,7 +92,8 @@ CVS code - wrapping, spell checking, justifying, and word counting) to their own source file, and adjust related variables accordingly. New file text.c; changes to cancel_command(), - execute_command(), wrap_reset(), do_wrap(), + execute_command(), do_backspace(), do_delete(), do_tab(), + do_enter(), do_mark(), wrap_reset(), do_wrap(), do_int_spell_fix(), do_int_speller(), do_alt_speller(), do_spell(), break_line(), indent_length(), justify_format(), quote_length(), quotes_match(), indents_match(), begpar(), diff --git a/src/nano.c b/src/nano.c index b87fea07..d9e5d5ff 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1247,202 +1247,6 @@ void do_verbatim_input(void) free(output); } -void do_backspace(void) -{ - if (openfile->current != openfile->fileage || - openfile->current_x > 0) { - do_left(FALSE); - do_delete(); - } -} - -void do_delete(void) -{ - bool do_refresh = FALSE; - /* Do we have to call edit_refresh(), or can we get away with - * update_line()? */ - - assert(openfile->current != NULL && openfile->current->data != NULL && openfile->current_x <= strlen(openfile->current->data)); - - openfile->placewewant = xplustabs(); - - if (openfile->current->data[openfile->current_x] != '\0') { - int char_buf_len = parse_mbchar(openfile->current->data + - openfile->current_x, NULL, NULL, NULL); - size_t line_len = strlen(openfile->current->data + - openfile->current_x); - - assert(openfile->current_x < strlen(openfile->current->data)); - - /* Let's get dangerous. */ - charmove(&openfile->current->data[openfile->current_x], - &openfile->current->data[openfile->current_x + - char_buf_len], line_len - char_buf_len + 1); - - null_at(&openfile->current->data, openfile->current_x + - line_len - char_buf_len); -#ifndef NANO_SMALL - 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 && - (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. */ - filestruct *foo = openfile->current->next; - - assert(openfile->current_x == strlen(openfile->current->data)); - - /* If we're deleting at the end of a line, we need to call - * edit_refresh(). */ - if (openfile->current->data[openfile->current_x] == '\0') - do_refresh = TRUE; - - openfile->current->data = charealloc(openfile->current->data, - openfile->current_x + strlen(foo->data) + 1); - strcpy(openfile->current->data + openfile->current_x, - foo->data); -#ifndef NANO_SMALL - if (openfile->mark_set && openfile->mark_begin == - openfile->current->next) { - openfile->mark_begin = openfile->current; - openfile->mark_begin_x += openfile->current_x; - } -#endif - if (openfile->filebot == foo) - openfile->filebot = openfile->current; - - unlink_node(foo); - delete_node(foo); - renumber(openfile->current); - openfile->totlines--; - openfile->totsize--; -#ifndef DISABLE_WRAPPING - wrap_reset(); -#endif - } else - return; - - set_modified(); - -#ifdef ENABLE_COLOR - /* If color syntaxes are available and turned on, we need to call - * edit_refresh(). */ - if (openfile->colorstrings != NULL && !ISSET(NO_COLOR_SYNTAX)) - do_refresh = TRUE; -#endif - - if (do_refresh) - edit_refresh(); - else - update_line(openfile->current, openfile->current_x); -} - -void do_tab(void) -{ -#ifndef NANO_SMALL - if (ISSET(TABS_TO_SPACES)) { - char *output; - size_t output_len = 0, new_pww = openfile->placewewant; - - do { - new_pww++; - output_len++; - } while (new_pww % tabsize != 0); - - output = charalloc(output_len + 1); - - charset(output, ' ', output_len); - output[output_len] = '\0'; - - do_output(output, output_len, TRUE); - - free(output); - } else { -#endif - do_output("\t", 1, TRUE); -#ifndef NANO_SMALL - } -#endif -} - -/* Someone hits Return *gasp!* */ -void do_enter(void) -{ - filestruct *newnode = make_new_node(openfile->current); - size_t extra = 0; - - assert(openfile->current != NULL && openfile->current->data != NULL); - -#ifndef NANO_SMALL - /* Do auto-indenting, like the neolithic Turbo Pascal editor. */ - if (ISSET(AUTOINDENT)) { - /* If we are breaking the line in the indentation, the new - * indentation should have only current_x characters, and - * current_x should not change. */ - extra = indent_length(openfile->current->data); - if (extra > openfile->current_x) - extra = openfile->current_x; - } -#endif - newnode->data = charalloc(strlen(openfile->current->data + - openfile->current_x) + extra + 1); - strcpy(&newnode->data[extra], openfile->current->data + - openfile->current_x); -#ifndef NANO_SMALL - if (ISSET(AUTOINDENT)) { - strncpy(newnode->data, openfile->current->data, extra); - openfile->totsize += mbstrlen(newnode->data); - } -#endif - null_at(&openfile->current->data, openfile->current_x); -#ifndef NANO_SMALL - if (openfile->mark_set && openfile->current == - 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; - - if (openfile->current == openfile->filebot) - openfile->filebot = newnode; - splice_node(openfile->current, newnode, - openfile->current->next); - - renumber(openfile->current); - openfile->current = newnode; - - edit_refresh(); - - openfile->totlines++; - openfile->totsize++; - set_modified(); - openfile->placewewant = xplustabs(); -} - -#ifndef NANO_SMALL -void do_mark(void) -{ - openfile->mark_set = !openfile->mark_set; - if (openfile->mark_set) { - statusbar(_("Mark Set")); - openfile->mark_begin = openfile->current; - openfile->mark_begin_x = openfile->current_x; - } else { - statusbar(_("Mark UNset")); - openfile->mark_begin = NULL; - openfile->mark_begin_x = 0; - edit_refresh(); - } -} -#endif /* !NANO_SMALL */ - void do_exit(void) { int i; diff --git a/src/proto.h b/src/proto.h index b7d0414b..877a03dc 100644 --- a/src/proto.h +++ b/src/proto.h @@ -389,13 +389,6 @@ int no_more_space(void); int no_help(void); void nano_disabled_msg(void); void do_verbatim_input(void); -void do_backspace(void); -void do_delete(void); -void do_tab(void); -void do_enter(void); -#ifndef NANO_SMALL -void do_mark(void); -#endif void do_exit(void); void signal_init(void); void handle_hupterm(int signal); @@ -493,6 +486,13 @@ char *get_history_completion(filestruct **h, const char *s, size_t len); /* Public functions in text.c. */ #ifndef NANO_SMALL +void do_mark(void); +#endif +void do_delete(void); +void do_backspace(void); +void do_tab(void); +void do_enter(void); +#ifndef NANO_SMALL void cancel_command(int signal); bool execute_command(const char *command); #endif diff --git a/src/text.c b/src/text.c index a4dc220a..460225c7 100644 --- a/src/text.c +++ b/src/text.c @@ -47,6 +47,202 @@ static filestruct *jusbottom = NULL; /* Pointer to end of justify buffer. */ #endif +#ifndef NANO_SMALL +void do_mark(void) +{ + openfile->mark_set = !openfile->mark_set; + if (openfile->mark_set) { + statusbar(_("Mark Set")); + openfile->mark_begin = openfile->current; + openfile->mark_begin_x = openfile->current_x; + } else { + statusbar(_("Mark UNset")); + openfile->mark_begin = NULL; + openfile->mark_begin_x = 0; + edit_refresh(); + } +} +#endif /* !NANO_SMALL */ + +void do_delete(void) +{ + bool do_refresh = FALSE; + /* Do we have to call edit_refresh(), or can we get away with + * update_line()? */ + + assert(openfile->current != NULL && openfile->current->data != NULL && openfile->current_x <= strlen(openfile->current->data)); + + openfile->placewewant = xplustabs(); + + if (openfile->current->data[openfile->current_x] != '\0') { + int char_buf_len = parse_mbchar(openfile->current->data + + openfile->current_x, NULL, NULL, NULL); + size_t line_len = strlen(openfile->current->data + + openfile->current_x); + + assert(openfile->current_x < strlen(openfile->current->data)); + + /* Let's get dangerous. */ + charmove(&openfile->current->data[openfile->current_x], + &openfile->current->data[openfile->current_x + + char_buf_len], line_len - char_buf_len + 1); + + null_at(&openfile->current->data, openfile->current_x + + line_len - char_buf_len); +#ifndef NANO_SMALL + 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 && + (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. */ + filestruct *foo = openfile->current->next; + + assert(openfile->current_x == strlen(openfile->current->data)); + + /* If we're deleting at the end of a line, we need to call + * edit_refresh(). */ + if (openfile->current->data[openfile->current_x] == '\0') + do_refresh = TRUE; + + openfile->current->data = charealloc(openfile->current->data, + openfile->current_x + strlen(foo->data) + 1); + strcpy(openfile->current->data + openfile->current_x, + foo->data); +#ifndef NANO_SMALL + if (openfile->mark_set && openfile->mark_begin == + openfile->current->next) { + openfile->mark_begin = openfile->current; + openfile->mark_begin_x += openfile->current_x; + } +#endif + if (openfile->filebot == foo) + openfile->filebot = openfile->current; + + unlink_node(foo); + delete_node(foo); + renumber(openfile->current); + openfile->totlines--; + openfile->totsize--; +#ifndef DISABLE_WRAPPING + wrap_reset(); +#endif + } else + return; + + set_modified(); + +#ifdef ENABLE_COLOR + /* If color syntaxes are available and turned on, we need to call + * edit_refresh(). */ + if (openfile->colorstrings != NULL && !ISSET(NO_COLOR_SYNTAX)) + do_refresh = TRUE; +#endif + + if (do_refresh) + edit_refresh(); + else + update_line(openfile->current, openfile->current_x); +} + +void do_backspace(void) +{ + if (openfile->current != openfile->fileage || + openfile->current_x > 0) { + do_left(FALSE); + do_delete(); + } +} + +void do_tab(void) +{ +#ifndef NANO_SMALL + if (ISSET(TABS_TO_SPACES)) { + char *output; + size_t output_len = 0, new_pww = openfile->placewewant; + + do { + new_pww++; + output_len++; + } while (new_pww % tabsize != 0); + + output = charalloc(output_len + 1); + + charset(output, ' ', output_len); + output[output_len] = '\0'; + + do_output(output, output_len, TRUE); + + free(output); + } else { +#endif + do_output("\t", 1, TRUE); +#ifndef NANO_SMALL + } +#endif +} + +/* Someone hits Return *gasp!* */ +void do_enter(void) +{ + filestruct *newnode = make_new_node(openfile->current); + size_t extra = 0; + + assert(openfile->current != NULL && openfile->current->data != NULL); + +#ifndef NANO_SMALL + /* Do auto-indenting, like the neolithic Turbo Pascal editor. */ + if (ISSET(AUTOINDENT)) { + /* If we are breaking the line in the indentation, the new + * indentation should have only current_x characters, and + * current_x should not change. */ + extra = indent_length(openfile->current->data); + if (extra > openfile->current_x) + extra = openfile->current_x; + } +#endif + newnode->data = charalloc(strlen(openfile->current->data + + openfile->current_x) + extra + 1); + strcpy(&newnode->data[extra], openfile->current->data + + openfile->current_x); +#ifndef NANO_SMALL + if (ISSET(AUTOINDENT)) { + strncpy(newnode->data, openfile->current->data, extra); + openfile->totsize += mbstrlen(newnode->data); + } +#endif + null_at(&openfile->current->data, openfile->current_x); +#ifndef NANO_SMALL + if (openfile->mark_set && openfile->current == + 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; + + if (openfile->current == openfile->filebot) + openfile->filebot = newnode; + splice_node(openfile->current, newnode, + openfile->current->next); + + renumber(openfile->current); + openfile->current = newnode; + + edit_refresh(); + + openfile->totlines++; + openfile->totsize++; + set_modified(); + openfile->placewewant = xplustabs(); +} + #ifndef NANO_SMALL void cancel_command(int signal) {