From 906257932fecdd4f45e51e855b7aabee99dab877 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Fri, 30 Jul 2004 20:21:34 +0000 Subject: [PATCH] add my display tweak to do_replace(), my efficiency tweaks to do_gotoline(), and DB's efficiency tweaks to do_gotopos() git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1875 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 10 ++++++++++ src/proto.h | 2 +- src/search.c | 38 ++++++++++++++++++++++---------------- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index b4e7a20b..99fb6d81 100644 --- a/ChangeLog +++ b/ChangeLog @@ -144,6 +144,16 @@ CVS code - placewewant when a new match is found, so that edit_redraw() will redraw the screen properly when only placewewant changes. (DLR, found by Mike Frysinger) + do_replace() + - Instead of using edit_update() to redraw the screen with + edittop at the top, set edittop beforehand and call + edit_refresh(). (DLR) + do_gotoline() + - Use parse_num() to interpret a line entered by the user, and + start the search for a line from current instead of fileage. + (DLR) + do_gotopos() + - Tweak for efficiency. (David Benbennick) - utils.c: parse_num() - New function to parse numeric values, so that we don't have to diff --git a/src/proto.h b/src/proto.h index 37252c73..43a77c84 100644 --- a/src/proto.h +++ b/src/proto.h @@ -402,7 +402,7 @@ char *replace_line(const char *needle); int do_replace_loop(const char *needle, const filestruct *real_current, size_t *real_current_x, int wholewords); void do_replace(void); -void do_gotoline(ssize_t line, int save_pos); +void do_gotoline(int line, int save_pos); void do_gotoline_void(void); #if defined (ENABLE_MULTIBUFFER) || !defined (DISABLE_SPELLER) void do_gotopos(int line, int pos_x, int pos_y, size_t pos_pww); diff --git a/src/search.c b/src/search.c index 4d153c2d..fc4a7820 100644 --- a/src/search.c +++ b/src/search.c @@ -822,10 +822,11 @@ void do_replace(void) numreplaced = do_replace_loop(last_search, begin, &beginx, FALSE); /* Restore where we were. */ + edittop = edittop_save; current = begin; current_x = beginx; renumber_all(); - edit_update(edittop_save, TOP); + edit_refresh(); if (numreplaced >= 0) statusbar(P_("Replaced %d occurrence", "Replaced %d occurrences", @@ -834,11 +835,11 @@ void do_replace(void) replace_abort(); } -void do_gotoline(ssize_t line, int save_pos) +void do_gotoline(int line, int save_pos) { - if (line <= 0) { /* Ask for it */ + if (line <= 0) { /* Ask for it. */ char *ans = mallocstrcpy(NULL, answer); - int st = statusq(FALSE, goto_list, line != 0 ? ans : "", + int st = statusq(FALSE, goto_list, line < 0 ? ans : "", #ifndef NANO_SMALL NULL, #endif @@ -854,18 +855,23 @@ void do_gotoline(ssize_t line, int save_pos) return; } - line = (ssize_t)atol(answer); - /* Bounds check. */ - if (line <= 0) { + if (parse_num(answer, &line) == -1 || line < 0) { statusbar(_("Come on, be reasonable")); display_main_list(); return; } } - for (current = fileage; current->next != NULL && line > 1; line--) - current = current->next; + if (current->lineno > line) { + for (; current->prev != NULL && current->lineno > line; + current = current->prev) + ; + } else { + for (; current->next != NULL && current->lineno < line; + current = current->next) + ; + } current_x = 0; @@ -885,17 +891,17 @@ void do_gotoline_void(void) #if defined(ENABLE_MULTIBUFFER) || !defined(DISABLE_SPELLER) void do_gotopos(int line, int pos_x, int pos_y, size_t pos_pww) { - /* since do_gotoline() resets the x-coordinate but not the - y-coordinate, set the coordinates up this way */ + /* Since do_gotoline() resets the x-coordinate but not the + * y-coordinate, set the coordinates up this way. */ current_y = pos_y; do_gotoline(line, TRUE); - /* make sure that the x-coordinate is sane here */ - if (pos_x > strlen(current->data)) - pos_x = strlen(current->data); + /* Make sure that the x-coordinate is sane here. */ + current_x = strlen(current->data); + if (pos_x < current_x) + current_x = pos_x; - /* set the rest of the coordinates up */ - current_x = pos_x; + /* Set the rest of the coordinates up. */ placewewant = pos_pww; update_line(current, pos_x); } -- 2.39.5