nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 1075de1222e90c03020a0b2e19ca22737c201740
parent 3457039ceed7529e6e6b23eca879b16ada6a8429
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Sun,  9 Jun 2019 19:37:56 +0200

tweaks: rename two functions, to get rid of the "mb" abbreviation

Also, for me "move" is about moving the cursor.  But these functions
are about moving an index in a text, which is more general.

Diffstat:
Msrc/chars.c | 10+++++-----
Msrc/color.c | 2+-
Msrc/help.c | 2+-
Msrc/move.c | 10+++++-----
Msrc/prompt.c | 12++++++------
Msrc/proto.h | 4++--
Msrc/search.c | 8++++----
Msrc/text.c | 16++++++++--------
Msrc/utils.c | 4++--
Msrc/winio.c | 8++++----
10 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/src/chars.c b/src/chars.c @@ -340,7 +340,7 @@ int parse_mbchar(const char *buf, char *chr, size_t *col) /* Return the index in buf of the beginning of the multibyte character * before the one at pos. */ -size_t move_mbleft(const char *buf, size_t pos) +size_t step_left(const char *buf, size_t pos) { #ifdef ENABLE_UTF8 if (use_utf8) { @@ -379,7 +379,7 @@ size_t move_mbleft(const char *buf, size_t pos) /* Return the index in buf of the beginning of the multibyte character * after the one at pos. */ -size_t move_mbright(const char *buf, size_t pos) +size_t step_right(const char *buf, size_t pos) { return pos + char_length(buf + pos); } @@ -508,7 +508,7 @@ char *mbrevstrcasestr(const char *haystack, const char *needle, if (pointer == haystack) return NULL; - pointer = haystack + move_mbleft(haystack, pointer - haystack); + pointer = haystack + step_left(haystack, pointer - haystack); } } else #endif @@ -597,7 +597,7 @@ char *mbrevstrpbrk(const char *head, const char *accept, const char *pointer) if (*pointer == '\0') { if (pointer == head) return NULL; - pointer = head + move_mbleft(head, pointer - head); + pointer = head + step_left(head, pointer - head); } while (TRUE) { @@ -608,7 +608,7 @@ char *mbrevstrpbrk(const char *head, const char *accept, const char *pointer) if (pointer == head) return NULL; - pointer = head + move_mbleft(head, pointer - head); + pointer = head + step_left(head, pointer - head); } } #endif /* !NANO_TINY */ diff --git a/src/color.c b/src/color.c @@ -387,7 +387,7 @@ void precalc_multicolorinfo(void) /* When at end-of-line, we're done. */ if (line->data[index] == '\0') break; - index = move_mbright(line->data, index); + index = step_right(line->data, index); } continue; } diff --git a/src/help.c b/src/help.c @@ -590,7 +590,7 @@ size_t help_line_len(const char *ptr) /* Get the length of the entire line up to a null or a newline. */ while (*(ptr + length) != '\0' && *(ptr + length) != '\n') - length = move_mbright(ptr, length); + length = step_right(ptr, length); /* If the entire line will just fit the screen, don't wrap it. */ if (wideness(ptr, length) <= wrapping_point + 1) diff --git a/src/move.c b/src/move.c @@ -278,7 +278,7 @@ void do_prev_word(bool allow_punct) } /* Step back one character. */ - openfile->current_x = move_mbleft(openfile->current->data, + openfile->current_x = step_left(openfile->current->data, openfile->current_x); if (is_word_mbchar(openfile->current->data + openfile->current_x, @@ -296,7 +296,7 @@ void do_prev_word(bool allow_punct) if (step_forward) /* Move one character forward again to sit on the start of the word. */ - openfile->current_x = move_mbright(openfile->current->data, + openfile->current_x = step_right(openfile->current->data, openfile->current_x); } @@ -324,7 +324,7 @@ bool do_next_word(bool after_ends, bool allow_punct) seen_space = TRUE; } else { /* Step forward one character. */ - openfile->current_x = move_mbright(openfile->current->data, + openfile->current_x = step_right(openfile->current->data, openfile->current_x); } @@ -570,7 +570,7 @@ void do_left(void) linestruct *was_current = openfile->current; if (openfile->current_x > 0) - openfile->current_x = move_mbleft(openfile->current->data, + openfile->current_x = step_left(openfile->current->data, openfile->current_x); else if (openfile->current != openfile->filetop) { openfile->current = openfile->current->prev; @@ -586,7 +586,7 @@ void do_right(void) linestruct *was_current = openfile->current; if (openfile->current->data[openfile->current_x] != '\0') - openfile->current_x = move_mbright(openfile->current->data, + openfile->current_x = step_right(openfile->current->data, openfile->current_x); else if (openfile->current != openfile->filebot) { openfile->current = openfile->current->next; diff --git a/src/prompt.c b/src/prompt.c @@ -239,14 +239,14 @@ void do_statusbar_end(void) void do_statusbar_left(void) { if (typing_x > 0) - typing_x = move_mbleft(answer, typing_x); + typing_x = step_left(answer, typing_x); } /* Move right one character. */ void do_statusbar_right(void) { if (answer[typing_x] != '\0') - typing_x = move_mbright(answer, typing_x); + typing_x = step_right(answer, typing_x); } /* Delete one character. */ @@ -264,7 +264,7 @@ void do_statusbar_delete(void) void do_statusbar_backspace(void) { if (typing_x > 0) { - typing_x = move_mbleft(answer, typing_x); + typing_x = step_left(answer, typing_x); do_statusbar_delete(); } } @@ -288,7 +288,7 @@ void do_statusbar_next_word(void) /* Move forward until we reach either the end or the start of a word, * depending on whether the AFTER_ENDS flag is set or not. */ while (answer[typing_x] != '\0') { - typing_x = move_mbright(answer, typing_x); + typing_x = step_right(answer, typing_x); if (ISSET(AFTER_ENDS)) { /* If this is a word character, continue; else it's a separator, @@ -315,7 +315,7 @@ void do_statusbar_prev_word(void) /* Move backward until we pass over the start of a word. */ while (typing_x != 0) { - typing_x = move_mbleft(answer, typing_x); + typing_x = step_left(answer, typing_x); if (is_word_mbchar(answer + typing_x, FALSE)) seen_a_word = TRUE; @@ -328,7 +328,7 @@ void do_statusbar_prev_word(void) if (step_forward) /* Move one character forward again to sit on the start of the word. */ - typing_x = move_mbright(answer, typing_x); + typing_x = step_right(answer, typing_x); } #endif /* !NANO_TINY */ diff --git a/src/proto.h b/src/proto.h @@ -215,8 +215,8 @@ int mbwidth(const char *c); char *make_mbchar(long chr, int *chr_mb_len); int char_length(const char *pointer); int parse_mbchar(const char *buf, char *chr, size_t *col); -size_t move_mbleft(const char *buf, size_t pos); -size_t move_mbright(const char *buf, size_t pos); +size_t step_left(const char *buf, size_t pos); +size_t step_right(const char *buf, size_t pos); int mbstrcasecmp(const char *s1, const char *s2); int mbstrncasecmp(const char *s1, const char *s2, size_t n); char *mbstrcasestr(const char *haystack, const char *needle); diff --git a/src/search.c b/src/search.c @@ -223,7 +223,7 @@ int findnextstr(const char *needle, bool whole_word_only, int modus, if (skipone) { skipone = FALSE; if (ISSET(BACKWARDS_SEARCH) && from != line->data) { - from = line->data + move_mbleft(line->data, from - line->data); + from = line->data + step_left(line->data, from - line->data); found = strstrwrapper(line->data, needle, from); } else if (!ISSET(BACKWARDS_SEARCH) && *from != '\0') { from += char_length(from); @@ -871,9 +871,9 @@ bool find_a_bracket(bool reverse, const char *bracket_pair) return FALSE; pointer = line->data + strlen(line->data); } else - pointer = line->data + move_mbleft(line->data, openfile->current_x); + pointer = line->data + step_left(line->data, openfile->current_x); } else - pointer = line->data + move_mbright(line->data, openfile->current_x); + pointer = line->data + step_right(line->data, openfile->current_x); /* Now seek for any of the two brackets, either backwards or forwards. */ while (TRUE) { @@ -952,7 +952,7 @@ void do_find_bracket(void) wanted_ch = ch; while (charcount-- > 0) { if (reverse) - wanted_ch = matchbrackets + move_mbleft(matchbrackets, + wanted_ch = matchbrackets + step_left(matchbrackets, wanted_ch - matchbrackets); else wanted_ch += char_length(wanted_ch); diff --git a/src/text.c b/src/text.c @@ -1413,7 +1413,7 @@ bool do_wrap(void) return FALSE; /* Step forward to the character just after the blank. */ - wrap_loc = move_mbright(line->data, wrap_loc); + wrap_loc = step_right(line->data, wrap_loc); /* When now at end-of-line, no need to wrap. */ if (line->data[wrap_loc] == '\0') @@ -1440,7 +1440,7 @@ bool do_wrap(void) openfile->current_x = line_len; /* If the remainder doesn't end in a blank, add a space. */ - if (!is_blank_mbchar(remainder + move_mbleft(remainder, rest_length))) { + if (!is_blank_mbchar(remainder + step_left(remainder, rest_length))) { #ifndef NANO_TINY add_undo(ADD); #endif @@ -1466,14 +1466,14 @@ bool do_wrap(void) /* When requested, snip trailing blanks off the wrapped line. */ if (ISSET(TRIM_BLANKS)) { - size_t tail_x = move_mbleft(line->data, wrap_loc); - size_t typed_x = move_mbleft(line->data, cursor_x); + size_t tail_x = step_left(line->data, wrap_loc); + size_t typed_x = step_left(line->data, cursor_x); while ((tail_x != typed_x || cursor_x >= wrap_loc) && is_blank_mbchar(line->data + tail_x)) { openfile->current_x = tail_x; do_delete(); - tail_x = move_mbleft(line->data, tail_x); + tail_x = step_left(line->data, tail_x); } } @@ -3093,7 +3093,7 @@ char *copy_completion(char *text) /* Find the end of the candidate word to get its length. */ while (is_word_mbchar(&text[length], FALSE)) - length = move_mbright(text, length); + length = step_right(text, length); /* Now copy this candidate to a new string. */ word = charalloc(length + 1); @@ -3145,7 +3145,7 @@ void complete_a_word(void) /* Find the start of the fragment that the user typed. */ start_of_shard = openfile->current_x; while (start_of_shard > 0) { - size_t oneleft = move_mbleft(openfile->current->data, start_of_shard); + size_t oneleft = step_left(openfile->current->data, start_of_shard); if (!is_word_mbchar(&openfile->current->data[oneleft], FALSE)) break; @@ -3192,7 +3192,7 @@ void complete_a_word(void) /* If the match is not a separate word, skip it. */ if (i > 0 && is_word_mbchar(&pletion_line->data[ - move_mbleft(pletion_line->data, i)], FALSE)) + step_left(pletion_line->data, i)], FALSE)) continue; /* If this match is the shard itself, ignore it. */ diff --git a/src/utils.c b/src/utils.c @@ -202,7 +202,7 @@ bool is_separate_word(size_t position, size_t length, const char *buf) size_t word_end = position + length; /* Get the characters before and after the word, if any. */ - parse_mbchar(buf + move_mbleft(buf, position), before, NULL); + parse_mbchar(buf + step_left(buf, position), before, NULL); parse_mbchar(buf + word_end, after, NULL); /* If the word starts at the beginning of the line OR the character before @@ -246,7 +246,7 @@ const char *strstrwrapper(const char *haystack, const char *needle, /* If this is the last possible match, don't try to advance. */ if (last_find == ceiling) break; - next_rung = move_mbright(haystack, last_find); + next_rung = step_right(haystack, last_find); regmatches[0].rm_so = next_rung; regmatches[0].rm_eo = far_end; if (regexec(&search_regexp, haystack, 1, regmatches, diff --git a/src/winio.c b/src/winio.c @@ -2001,7 +2001,7 @@ char *display_string(const char *buf, size_t column, size_t span, if (column > beyond || (*buf != '\0' && (isprompt || (isdata && !ISSET(SOFTWRAP))))) { do { - index = move_mbleft(converted, index); + index = step_left(converted, index); } while (mbwidth(converted + index) == 0); #ifdef ENABLE_UTF8 @@ -2494,7 +2494,7 @@ void edit_draw(linestruct *fileptr, const char *converted, /* If the match is of length zero, skip it. */ if (match.rm_so == match.rm_eo) { - index = move_mbright(fileptr->data, + index = step_right(fileptr->data, index + match.rm_eo); continue; } @@ -2581,7 +2581,7 @@ void edit_draw(linestruct *fileptr, const char *converted, endmatch.rm_so == endmatch.rm_eo) { if (start_line->data[index] == '\0') break; - index = move_mbright(start_line->data, index); + index = step_right(start_line->data, index); } /* If there is no later start on this line, next step. */ if (regexec(varnish->start, start_line->data + index, @@ -2663,7 +2663,7 @@ void edit_draw(linestruct *fileptr, const char *converted, endmatch.rm_so == endmatch.rm_eo) { if (fileptr->data[index] == '\0') break; - index = move_mbright(fileptr->data, index); + index = step_right(fileptr->data, index); } continue; }