From fbbf501f8fb234dcc6e86a7f6bccc8233baa5d0b Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@telfort.nl>
Date: Sun, 9 Jul 2017 21:07:38 +0200
Subject: [PATCH] tweaks: rename four functions, to be more distinct

---
 src/cut.c    |  2 +-
 src/files.c  |  2 +-
 src/move.c   | 18 +++++++++---------
 src/nano.c   | 10 +++++-----
 src/proto.h  |  8 ++++----
 src/search.c |  2 +-
 src/text.c   |  4 ++--
 src/winio.c  | 48 +++++++++++++++++++++++-------------------------
 8 files changed, 46 insertions(+), 48 deletions(-)

diff --git a/src/cut.c b/src/cut.c
index be1791ff..f6036b59 100644
--- a/src/cut.c
+++ b/src/cut.c
@@ -270,7 +270,7 @@ void do_uncut_text(void)
     add_undo(PASTE);
 
     if (ISSET(SOFTWRAP))
-	was_leftedge = get_chunk_leftedge(openfile->current, xplustabs());
+	was_leftedge = leftedge_for(xplustabs(), openfile->current);
 #endif
 
     /* Add a copy of the text in the cutbuffer to the current buffer
diff --git a/src/files.c b/src/files.c
index 6383ca57..3ef71470 100644
--- a/src/files.c
+++ b/src/files.c
@@ -777,7 +777,7 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable,
 	add_undo(INSERT);
 
     if (ISSET(SOFTWRAP))
-	was_leftedge = get_chunk_leftedge(openfile->current, xplustabs());
+	was_leftedge = leftedge_for(xplustabs(), openfile->current);
 #endif
 
     /* Create an empty buffer. */
diff --git a/src/move.c b/src/move.c
index ff479cfc..5f6ad6e8 100644
--- a/src/move.c
+++ b/src/move.c
@@ -53,7 +53,7 @@ void get_edge_and_target(size_t *leftedge, size_t *target_column)
 {
 #ifndef NANO_TINY
     if (ISSET(SOFTWRAP)) {
-	*leftedge = get_chunk_leftedge(openfile->current, xplustabs());
+	*leftedge = leftedge_for(xplustabs(), openfile->current);
 	*target_column = openfile->placewewant - *leftedge;
     } else
 #endif
@@ -348,7 +348,7 @@ void do_home(bool be_clever)
     size_t leftedge = 0, leftedge_x = 0;
 
     if (ISSET(SOFTWRAP)) {
-	leftedge = get_chunk_leftedge(openfile->current, was_column);
+	leftedge = leftedge_for(was_column, openfile->current);
 	leftedge_x = actual_x(openfile->current->data, leftedge);
     }
 
@@ -414,7 +414,7 @@ void do_end(bool be_clever)
 #ifndef NANO_TINY
     if (ISSET(SOFTWRAP)) {
 	bool last_chunk = FALSE;
-	size_t leftedge = get_chunk_leftedge(openfile->current, was_column);
+	size_t leftedge = leftedge_for(was_column, openfile->current);
 	size_t rightedge = get_softwrap_breakpoint(openfile->current->data,
 						leftedge, &last_chunk);
 	size_t rightedge_x;
@@ -572,7 +572,7 @@ void do_left(void)
     size_t was_column = xplustabs();
 #ifndef NANO_TINY
     filestruct *was_current = openfile->current;
-    size_t was_chunk = get_chunk_row(was_current, was_column);
+    size_t was_chunk = chunk_for(was_column, was_current);
 #endif
 
     if (openfile->current_x > 0)
@@ -591,8 +591,8 @@ void do_left(void)
      * we're now above the first line of the edit window, so scroll up. */
     if (ISSET(SOFTWRAP) && openfile->current_y == 0 &&
 		openfile->current == was_current &&
-		get_chunk_row(openfile->current,
-				openfile->placewewant) != was_chunk) {
+		chunk_for(openfile->placewewant,
+				openfile->current) != was_chunk) {
 	edit_scroll(UPWARD, ISSET(SMOOTH_SCROLL) ? 1 : editwinrows / 2 + 1);
 	return;
     }
@@ -609,7 +609,7 @@ void do_right(void)
     size_t was_column = xplustabs();
 #ifndef NANO_TINY
     filestruct *was_current = openfile->current;
-    size_t was_chunk = get_chunk_row(was_current, was_column);
+    size_t was_chunk = chunk_for(was_column, was_current);
 #endif
 
     if (openfile->current->data[openfile->current_x] != '\0')
@@ -628,8 +628,8 @@ void do_right(void)
      * we're now below the first line of the edit window, so scroll down. */
     if (ISSET(SOFTWRAP) && openfile->current_y == editwinrows - 1 &&
 		openfile->current == was_current &&
-		get_chunk_row(openfile->current,
-				openfile->placewewant) != was_chunk) {
+		chunk_for(openfile->placewewant,
+				openfile->current) != was_chunk) {
 	edit_scroll(DOWNWARD, ISSET(SMOOTH_SCROLL) ? 1 : editwinrows / 2 + 1);
 	return;
     }
diff --git a/src/nano.c b/src/nano.c
index afc36586..dc538d8b 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1762,7 +1762,7 @@ int do_mouse(void)
 	    /* Whether the click was on the row where the cursor is. */
 
 	if (ISSET(SOFTWRAP))
-	    leftedge = get_chunk_leftedge(openfile->current, xplustabs());
+	    leftedge = leftedge_for(xplustabs(), openfile->current);
 	else
 #endif
 	    leftedge = get_page_start(xplustabs());
@@ -1812,8 +1812,8 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
 
     if (ISSET(SOFTWRAP)) {
 	if (openfile->current_y == editwinrows - 1)
-	    original_row = get_chunk_row(openfile->current, xplustabs());
-	orig_rows = get_last_chunk_row(openfile->current);
+	    original_row = chunk_for(xplustabs(), openfile->current);
+	orig_rows = number_of_chunks_in(openfile->current);
     }
 #endif
 
@@ -1878,9 +1878,9 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
      * of the edit window, and we moved one screen row, we're now below
      * the last line of the edit window, so we need a full refresh too. */
     if (ISSET(SOFTWRAP) && refresh_needed == FALSE &&
-		(get_last_chunk_row(openfile->current) != orig_rows ||
+		(number_of_chunks_in(openfile->current) != orig_rows ||
 		(openfile->current_y == editwinrows - 1 &&
-		get_chunk_row(openfile->current, xplustabs()) != original_row)))
+		chunk_for(xplustabs(), openfile->current) != original_row)))
 	refresh_needed = TRUE;
 #endif
 
diff --git a/src/proto.h b/src/proto.h
index 098a2c67..a444f7ab 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -665,10 +665,10 @@ void edit_scroll(scroll_dir direction, int nrows);
 #ifndef NANO_TINY
 size_t get_softwrap_breakpoint(const char *text, size_t leftedge,
 				bool *end_of_line);
-size_t get_chunk(filestruct *line, size_t column, size_t *leftedge);
-size_t get_chunk_row(filestruct *line, size_t column);
-size_t get_chunk_leftedge(filestruct *line, size_t column);
-size_t get_last_chunk_row(filestruct *line);
+size_t get_chunk_and_edge(size_t column, filestruct *line, size_t *leftedge);
+size_t chunk_for(size_t column, filestruct *line);
+size_t leftedge_for(size_t column, filestruct *line);
+size_t number_of_chunks_in(filestruct *line);
 void ensure_firstcolumn_is_aligned(void);
 #endif
 size_t actual_last_column(size_t leftedge, size_t column);
diff --git a/src/search.c b/src/search.c
index 2c36a5b5..2af1d766 100644
--- a/src/search.c
+++ b/src/search.c
@@ -900,7 +900,7 @@ void do_gotolinecolumn(ssize_t line, ssize_t column, bool use_answer,
 #ifndef NANO_TINY
 	if (ISSET(SOFTWRAP)) {
 	    filestruct *line = openfile->current;
-	    size_t leftedge = get_chunk_leftedge(openfile->current, xplustabs());
+	    size_t leftedge = leftedge_for(xplustabs(), openfile->current);
 
 	    rows_from_tail = (editwinrows / 2) -
 			go_forward_chunks(editwinrows / 2, &line, &leftedge);
diff --git a/src/text.c b/src/text.c
index 4a8d38cf..b7e9f299 100644
--- a/src/text.c
+++ b/src/text.c
@@ -112,7 +112,7 @@ void do_deletion(undo_type action)
 	update_undo(action);
 
 	if (ISSET(SOFTWRAP))
-	    orig_rows = get_last_chunk_row(openfile->current);
+	    orig_rows = number_of_chunks_in(openfile->current);
 #endif
 
 	/* Move the remainder of the line "in", over the current character. */
@@ -181,7 +181,7 @@ void do_deletion(undo_type action)
     /* If the number of screen rows that a softwrapped line occupies
      * has changed, we need a full refresh. */
     if (ISSET(SOFTWRAP) && refresh_needed == FALSE &&
-		get_last_chunk_row(openfile->current) != orig_rows)
+		number_of_chunks_in(openfile->current) != orig_rows)
 	refresh_needed = TRUE;
 #endif
 
diff --git a/src/winio.c b/src/winio.c
index 39f6c8d6..17b258bd 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -2296,16 +2296,16 @@ void place_the_cursor(bool forreal)
 	filestruct *line = openfile->edittop;
 	size_t leftedge;
 
-	row -= get_chunk_row(openfile->edittop, openfile->firstcolumn);
+	row -= chunk_for(openfile->firstcolumn, openfile->edittop);
 
 	/* Calculate how many rows the lines from edittop to current use. */
 	while (line != NULL && line != openfile->current) {
-	    row += get_last_chunk_row(line) + 1;
+	    row += number_of_chunks_in(line) + 1;
 	    line = line->next;
 	}
 
 	/* Add the number of wraps in the current line before the cursor. */
-	row += get_chunk(openfile->current, xpt, &leftedge);
+	row += get_chunk_and_edge(xpt, openfile->current, &leftedge);
 	col = xpt - leftedge;
     } else
 #endif
@@ -2748,11 +2748,11 @@ int update_softwrapped_line(filestruct *fileptr)
     if (fileptr == openfile->edittop)
 	from_col = openfile->firstcolumn;
     else
-	row -= get_chunk_row(openfile->edittop, openfile->firstcolumn);
+	row -= chunk_for(openfile->firstcolumn, openfile->edittop);
 
     /* Find out on which screen row the target line should be shown. */
     while (line != fileptr && line != NULL) {
-	row += get_last_chunk_row(line) + 1;
+	row += number_of_chunks_in(line) + 1;
 	line = line->next;
     }
 
@@ -2825,8 +2825,7 @@ int go_back_chunks(int nrows, filestruct **line, size_t *leftedge)
 	/* Recede through the requested number of chunks. */
 	for (i = nrows; i > 0; i--) {
 	    if (current_leftedge > 0) {
-		current_leftedge = get_chunk_leftedge(*line,
-							current_leftedge - 1);
+		current_leftedge = leftedge_for(current_leftedge - 1, *line);
 		continue;
 	    }
 
@@ -2834,7 +2833,7 @@ int go_back_chunks(int nrows, filestruct **line, size_t *leftedge)
 		break;
 
 	    *line = (*line)->prev;
-	    current_leftedge = get_chunk_leftedge(*line, (size_t)-1);
+	    current_leftedge = leftedge_for((size_t)-1, *line);
 	}
 
 	/* Only change leftedge when we actually could move. */
@@ -2900,7 +2899,7 @@ bool less_than_a_screenful(size_t was_lineno, size_t was_leftedge)
 #ifndef NANO_TINY
     if (ISSET(SOFTWRAP)) {
 	filestruct *line = openfile->current;
-	size_t leftedge = get_chunk_leftedge(openfile->current, xplustabs());
+	size_t leftedge = leftedge_for(xplustabs(), openfile->current);
 	int rows_left = go_back_chunks(editwinrows - 1, &line, &leftedge);
 
 	return (rows_left > 0 || line->lineno < was_lineno ||
@@ -2966,11 +2965,11 @@ void edit_scroll(scroll_dir direction, int nrows)
 
 #ifndef NANO_TINY
     /* Compensate for the earlier chunks of a softwrapped line. */
-    nrows += get_chunk_row(line, leftedge);
+    nrows += chunk_for(leftedge, line);
 
     /* Don't compensate for the chunks that are offscreen. */
     if (line == openfile->edittop)
-	nrows -= get_chunk_row(line, openfile->firstcolumn);
+	nrows -= chunk_for(openfile->firstcolumn, line);
 #endif
 
     /* Draw new content on the blank rows inside the scrolled region
@@ -3050,7 +3049,7 @@ size_t get_softwrap_breakpoint(const char *text, size_t leftedge,
 /* Get the row of the softwrapped chunk of the given line that column is on,
  * relative to the first row (zero-based), and return it.  If leftedge isn't
  * NULL, return the leftmost column of the chunk in it. */
-size_t get_chunk(filestruct *line, size_t column, size_t *leftedge)
+size_t get_chunk_and_edge(size_t column, filestruct *line, size_t *leftedge)
 {
     size_t current_chunk = 0, start_col = 0, end_col;
     bool end_of_line = FALSE;
@@ -3072,27 +3071,27 @@ size_t get_chunk(filestruct *line, size_t column, size_t *leftedge)
 
 /* Return the row of the softwrapped chunk of the given line that column is on,
  * relative to the first row (zero-based). */
-size_t get_chunk_row(filestruct *line, size_t column)
+size_t chunk_for(size_t column, filestruct *line)
 {
-    return get_chunk(line, column, NULL);
+    return get_chunk_and_edge(column, line, NULL);
 }
 
 /* Return the leftmost column of the softwrapped chunk of the given line that
  * column is on. */
-size_t get_chunk_leftedge(filestruct *line, size_t column)
+size_t leftedge_for(size_t column, filestruct *line)
 {
     size_t leftedge;
 
-    get_chunk(line, column, &leftedge);
+    get_chunk_and_edge(column, line, &leftedge);
 
     return leftedge;
 }
 
 /* Return the row of the last softwrapped chunk of the given line, relative to
  * the first row (zero-based). */
-size_t get_last_chunk_row(filestruct *line)
+size_t number_of_chunks_in(filestruct *line)
 {
-    return get_chunk_row(line, (size_t)-1);
+    return chunk_for((size_t)-1, line);
 }
 
 /* Ensure that firstcolumn is at the starting column of the softwrapped chunk
@@ -3100,8 +3099,8 @@ size_t get_last_chunk_row(filestruct *line)
  * has changed, because then the width of softwrapped chunks has changed. */
 void ensure_firstcolumn_is_aligned(void)
 {
-    openfile->firstcolumn = get_chunk_leftedge(openfile->edittop,
-						openfile->firstcolumn);
+    openfile->firstcolumn = leftedge_for(openfile->firstcolumn,
+						openfile->edittop);
 
     /* If smooth scrolling is on, make sure the viewport doesn't center. */
     focusing = FALSE;
@@ -3164,8 +3163,8 @@ bool current_is_below_screen(void)
 	return (go_forward_chunks(editwinrows - 1, &line, &leftedge) == 0 &&
 			(line->lineno < openfile->current->lineno ||
 			(line->lineno == openfile->current->lineno &&
-			leftedge < get_chunk_leftedge(openfile->current,
-					xplustabs()))));
+			leftedge < leftedge_for(xplustabs(),
+						openfile->current))));
     } else
 #endif
 	return (openfile->current->lineno >=
@@ -3284,8 +3283,7 @@ void adjust_viewport(update_type manner)
     openfile->edittop = openfile->current;
 #ifndef NANO_TINY
     if (ISSET(SOFTWRAP))
-	openfile->firstcolumn = get_chunk_leftedge(openfile->current,
-							xplustabs());
+	openfile->firstcolumn = leftedge_for(xplustabs(), openfile->current);
 #endif
 
     /* Move edittop back goal rows, starting at current[current_x]. */
@@ -3462,7 +3460,7 @@ void spotlight(bool active, size_t from_col, size_t to_col)
 void spotlight_softwrapped(bool active, size_t from_col, size_t to_col)
 {
     ssize_t row = openfile->current_y;
-    size_t leftedge = get_chunk_leftedge(openfile->current, from_col);
+    size_t leftedge = leftedge_for(from_col, openfile->current);
     size_t break_col;
     bool end_of_line = FALSE;
     char *word;
-- 
GitLab