From f01dd29f48064d2476a5cab2ada43b7a30ec0b43 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sun, 24 Jan 2016 20:36:02 +0000 Subject: [PATCH] Bundling four statements (that in total occur seven times) into a separate function. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5586 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 1 + src/prompt.c | 61 ++++++++++++++++------------------------------------ src/proto.h | 1 + 3 files changed, 20 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index ad61e942..8f3ad146 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ * src/prompt.c (do_statusbar_prev_word, do_statusbar_next_word): Chop an always-FALSE parameter and delete an unused return value. * src/prompt.c (do_prompt): Remove a superfluous free. + * src/prompt.c (update_the_bar): Bundle some statements. 2016-01-22 Benno Schulenberg * src/utils.c (get_homedir): Don't use $HOME when we're root, because diff --git a/src/prompt.c b/src/prompt.c index 326d9176..4d9e9165 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -240,15 +240,10 @@ int do_statusbar_mouse(void) /* Move to where the click occurred. */ if (mouse_x >= start_col && mouse_y == 0) { - size_t pww_save = statusbar_pww; - statusbar_x = actual_x(answer, get_statusbar_page_start(start_col, start_col + statusbar_xplustabs()) + mouse_x - start_col); - statusbar_pww = statusbar_xplustabs(); - - if (need_statusbar_update(pww_save)) - update_statusbar_line(answer, statusbar_x); + update_the_bar(); } } @@ -329,8 +324,6 @@ void do_statusbar_output(char *output, size_t output_len, bool * are. */ void do_statusbar_home(void) { - size_t pww_save = statusbar_pww; - #ifndef NANO_TINY if (ISSET(SMART_HOME)) { size_t statusbar_x_save = statusbar_x; @@ -340,42 +333,26 @@ void do_statusbar_home(void) if (statusbar_x == statusbar_x_save || statusbar_x == strlen(answer)) statusbar_x = 0; - - statusbar_pww = statusbar_xplustabs(); } else #endif - { statusbar_x = 0; - statusbar_pww = statusbar_xplustabs(); - } - if (need_statusbar_update(pww_save)) - update_statusbar_line(answer, statusbar_x); + update_the_bar(); } /* Move to the end of the prompt text. */ void do_statusbar_end(void) { - size_t pww_save = statusbar_pww; - statusbar_x = strlen(answer); - statusbar_pww = statusbar_xplustabs(); - - if (need_statusbar_update(pww_save)) - update_statusbar_line(answer, statusbar_x); + update_the_bar(); } /* Move left one character. */ void do_statusbar_left(void) { if (statusbar_x > 0) { - size_t pww_save = statusbar_pww; - statusbar_x = move_mbleft(answer, statusbar_x); - statusbar_pww = statusbar_xplustabs(); - - if (need_statusbar_update(pww_save)) - update_statusbar_line(answer, statusbar_x); + update_the_bar(); } } @@ -383,13 +360,8 @@ void do_statusbar_left(void) void do_statusbar_right(void) { if (statusbar_x < strlen(answer)) { - size_t pww_save = statusbar_pww; - statusbar_x = move_mbright(answer, statusbar_x); - statusbar_pww = statusbar_xplustabs(); - - if (need_statusbar_update(pww_save)) - update_statusbar_line(answer, statusbar_x); + update_the_bar(); } } @@ -447,7 +419,6 @@ void do_statusbar_cut_text(void) /* Move to the next word in the prompt text. */ void do_statusbar_next_word(void) { - size_t pww_save = statusbar_pww; char *char_mb; int char_mb_len; bool end_line = FALSE; @@ -494,16 +465,12 @@ void do_statusbar_next_word(void) free(char_mb); - statusbar_pww = statusbar_xplustabs(); - - if (need_statusbar_update(pww_save)) - update_statusbar_line(answer, statusbar_x); + update_the_bar(); } /* Move to the previous word in the prompt text. */ void do_statusbar_prev_word(void) { - size_t pww_save = statusbar_pww; char *char_mb; int char_mb_len; bool begin_line = FALSE; @@ -580,10 +547,7 @@ void do_statusbar_prev_word(void) free(char_mb); - statusbar_pww = statusbar_xplustabs(); - - if (need_statusbar_update(pww_save)) - update_statusbar_line(answer, statusbar_x); + update_the_bar(); } #endif /* !NANO_TINY */ @@ -693,6 +657,17 @@ bool need_statusbar_update(size_t pww_save) get_statusbar_page_start(start_col, start_col + statusbar_pww); } +/* Update the statusbar line /if/ the placewewant changes page. */ +void update_the_bar(void) +{ + size_t was_pww = statusbar_pww; + + statusbar_pww = statusbar_xplustabs(); + + if (need_statusbar_update(was_pww)) + update_statusbar_line(answer, statusbar_x); +} + /* Unconditionally redraw the entire screen, and then refresh it using * refresh_func(). */ void total_statusbar_refresh(void (*refresh_func)(void)) diff --git a/src/proto.h b/src/proto.h index 984aec8f..4f737df2 100644 --- a/src/proto.h +++ b/src/proto.h @@ -537,6 +537,7 @@ size_t get_statusbar_page_start(size_t start_col, size_t column); void reset_statusbar_cursor(void); void update_statusbar_line(const char *curranswer, size_t index); bool need_statusbar_update(size_t pww_save); +void update_the_bar(void); void total_statusbar_refresh(void (*refresh_func)(void)); functionptrtype get_prompt_string(int *value, bool allow_tabs, #ifndef DISABLE_TABCOMP -- 2.39.5