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
This commit is contained in:
Benno Schulenberg 2016-01-24 20:36:02 +00:00
parent 53c8ada24b
commit f01dd29f48
3 changed files with 20 additions and 43 deletions

View File

@ -6,6 +6,7 @@
* src/prompt.c (do_statusbar_prev_word, do_statusbar_next_word): * src/prompt.c (do_statusbar_prev_word, do_statusbar_next_word):
Chop an always-FALSE parameter and delete an unused return value. Chop an always-FALSE parameter and delete an unused return value.
* src/prompt.c (do_prompt): Remove a superfluous free. * src/prompt.c (do_prompt): Remove a superfluous free.
* src/prompt.c (update_the_bar): Bundle some statements.
2016-01-22 Benno Schulenberg <bensberg@justemail.net> 2016-01-22 Benno Schulenberg <bensberg@justemail.net>
* src/utils.c (get_homedir): Don't use $HOME when we're root, because * src/utils.c (get_homedir): Don't use $HOME when we're root, because

View File

@ -240,15 +240,10 @@ int do_statusbar_mouse(void)
/* Move to where the click occurred. */ /* Move to where the click occurred. */
if (mouse_x >= start_col && mouse_y == 0) { if (mouse_x >= start_col && mouse_y == 0) {
size_t pww_save = statusbar_pww;
statusbar_x = actual_x(answer, statusbar_x = actual_x(answer,
get_statusbar_page_start(start_col, start_col + get_statusbar_page_start(start_col, start_col +
statusbar_xplustabs()) + mouse_x - start_col); statusbar_xplustabs()) + mouse_x - start_col);
statusbar_pww = statusbar_xplustabs(); update_the_bar();
if (need_statusbar_update(pww_save))
update_statusbar_line(answer, statusbar_x);
} }
} }
@ -329,8 +324,6 @@ void do_statusbar_output(char *output, size_t output_len, bool
* are. */ * are. */
void do_statusbar_home(void) void do_statusbar_home(void)
{ {
size_t pww_save = statusbar_pww;
#ifndef NANO_TINY #ifndef NANO_TINY
if (ISSET(SMART_HOME)) { if (ISSET(SMART_HOME)) {
size_t statusbar_x_save = statusbar_x; size_t statusbar_x_save = statusbar_x;
@ -340,42 +333,26 @@ void do_statusbar_home(void)
if (statusbar_x == statusbar_x_save || if (statusbar_x == statusbar_x_save ||
statusbar_x == strlen(answer)) statusbar_x == strlen(answer))
statusbar_x = 0; statusbar_x = 0;
statusbar_pww = statusbar_xplustabs();
} else } else
#endif #endif
{
statusbar_x = 0; statusbar_x = 0;
statusbar_pww = statusbar_xplustabs();
}
if (need_statusbar_update(pww_save)) update_the_bar();
update_statusbar_line(answer, statusbar_x);
} }
/* Move to the end of the prompt text. */ /* Move to the end of the prompt text. */
void do_statusbar_end(void) void do_statusbar_end(void)
{ {
size_t pww_save = statusbar_pww;
statusbar_x = strlen(answer); statusbar_x = strlen(answer);
statusbar_pww = statusbar_xplustabs(); update_the_bar();
if (need_statusbar_update(pww_save))
update_statusbar_line(answer, statusbar_x);
} }
/* Move left one character. */ /* Move left one character. */
void do_statusbar_left(void) void do_statusbar_left(void)
{ {
if (statusbar_x > 0) { if (statusbar_x > 0) {
size_t pww_save = statusbar_pww;
statusbar_x = move_mbleft(answer, statusbar_x); statusbar_x = move_mbleft(answer, statusbar_x);
statusbar_pww = statusbar_xplustabs(); update_the_bar();
if (need_statusbar_update(pww_save))
update_statusbar_line(answer, statusbar_x);
} }
} }
@ -383,13 +360,8 @@ void do_statusbar_left(void)
void do_statusbar_right(void) void do_statusbar_right(void)
{ {
if (statusbar_x < strlen(answer)) { if (statusbar_x < strlen(answer)) {
size_t pww_save = statusbar_pww;
statusbar_x = move_mbright(answer, statusbar_x); statusbar_x = move_mbright(answer, statusbar_x);
statusbar_pww = statusbar_xplustabs(); update_the_bar();
if (need_statusbar_update(pww_save))
update_statusbar_line(answer, statusbar_x);
} }
} }
@ -447,7 +419,6 @@ void do_statusbar_cut_text(void)
/* Move to the next word in the prompt text. */ /* Move to the next word in the prompt text. */
void do_statusbar_next_word(void) void do_statusbar_next_word(void)
{ {
size_t pww_save = statusbar_pww;
char *char_mb; char *char_mb;
int char_mb_len; int char_mb_len;
bool end_line = FALSE; bool end_line = FALSE;
@ -494,16 +465,12 @@ void do_statusbar_next_word(void)
free(char_mb); free(char_mb);
statusbar_pww = statusbar_xplustabs(); update_the_bar();
if (need_statusbar_update(pww_save))
update_statusbar_line(answer, statusbar_x);
} }
/* Move to the previous word in the prompt text. */ /* Move to the previous word in the prompt text. */
void do_statusbar_prev_word(void) void do_statusbar_prev_word(void)
{ {
size_t pww_save = statusbar_pww;
char *char_mb; char *char_mb;
int char_mb_len; int char_mb_len;
bool begin_line = FALSE; bool begin_line = FALSE;
@ -580,10 +547,7 @@ void do_statusbar_prev_word(void)
free(char_mb); free(char_mb);
statusbar_pww = statusbar_xplustabs(); update_the_bar();
if (need_statusbar_update(pww_save))
update_statusbar_line(answer, statusbar_x);
} }
#endif /* !NANO_TINY */ #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); 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 /* Unconditionally redraw the entire screen, and then refresh it using
* refresh_func(). */ * refresh_func(). */
void total_statusbar_refresh(void (*refresh_func)(void)) void total_statusbar_refresh(void (*refresh_func)(void))

View File

@ -537,6 +537,7 @@ size_t get_statusbar_page_start(size_t start_col, size_t column);
void reset_statusbar_cursor(void); void reset_statusbar_cursor(void);
void update_statusbar_line(const char *curranswer, size_t index); void update_statusbar_line(const char *curranswer, size_t index);
bool need_statusbar_update(size_t pww_save); bool need_statusbar_update(size_t pww_save);
void update_the_bar(void);
void total_statusbar_refresh(void (*refresh_func)(void)); void total_statusbar_refresh(void (*refresh_func)(void));
functionptrtype get_prompt_string(int *value, bool allow_tabs, functionptrtype get_prompt_string(int *value, bool allow_tabs,
#ifndef DISABLE_TABCOMP #ifndef DISABLE_TABCOMP