Commit fbbf501f authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

tweaks: rename four functions, to be more distinct

parent ac7a0718
Showing with 46 additions and 48 deletions
+46 -48
...@@ -270,7 +270,7 @@ void do_uncut_text(void) ...@@ -270,7 +270,7 @@ void do_uncut_text(void)
add_undo(PASTE); add_undo(PASTE);
if (ISSET(SOFTWRAP)) if (ISSET(SOFTWRAP))
was_leftedge = get_chunk_leftedge(openfile->current, xplustabs()); was_leftedge = leftedge_for(xplustabs(), openfile->current);
#endif #endif
/* Add a copy of the text in the cutbuffer to the current buffer /* Add a copy of the text in the cutbuffer to the current buffer
......
...@@ -777,7 +777,7 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, ...@@ -777,7 +777,7 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable,
add_undo(INSERT); add_undo(INSERT);
if (ISSET(SOFTWRAP)) if (ISSET(SOFTWRAP))
was_leftedge = get_chunk_leftedge(openfile->current, xplustabs()); was_leftedge = leftedge_for(xplustabs(), openfile->current);
#endif #endif
/* Create an empty buffer. */ /* Create an empty buffer. */
......
...@@ -53,7 +53,7 @@ void get_edge_and_target(size_t *leftedge, size_t *target_column) ...@@ -53,7 +53,7 @@ void get_edge_and_target(size_t *leftedge, size_t *target_column)
{ {
#ifndef NANO_TINY #ifndef NANO_TINY
if (ISSET(SOFTWRAP)) { if (ISSET(SOFTWRAP)) {
*leftedge = get_chunk_leftedge(openfile->current, xplustabs()); *leftedge = leftedge_for(xplustabs(), openfile->current);
*target_column = openfile->placewewant - *leftedge; *target_column = openfile->placewewant - *leftedge;
} else } else
#endif #endif
...@@ -348,7 +348,7 @@ void do_home(bool be_clever) ...@@ -348,7 +348,7 @@ void do_home(bool be_clever)
size_t leftedge = 0, leftedge_x = 0; size_t leftedge = 0, leftedge_x = 0;
if (ISSET(SOFTWRAP)) { 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); leftedge_x = actual_x(openfile->current->data, leftedge);
} }
...@@ -414,7 +414,7 @@ void do_end(bool be_clever) ...@@ -414,7 +414,7 @@ void do_end(bool be_clever)
#ifndef NANO_TINY #ifndef NANO_TINY
if (ISSET(SOFTWRAP)) { if (ISSET(SOFTWRAP)) {
bool last_chunk = FALSE; 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, size_t rightedge = get_softwrap_breakpoint(openfile->current->data,
leftedge, &last_chunk); leftedge, &last_chunk);
size_t rightedge_x; size_t rightedge_x;
...@@ -572,7 +572,7 @@ void do_left(void) ...@@ -572,7 +572,7 @@ void do_left(void)
size_t was_column = xplustabs(); size_t was_column = xplustabs();
#ifndef NANO_TINY #ifndef NANO_TINY
filestruct *was_current = openfile->current; 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 #endif
if (openfile->current_x > 0) if (openfile->current_x > 0)
...@@ -591,8 +591,8 @@ void do_left(void) ...@@ -591,8 +591,8 @@ void do_left(void)
* we're now above the first line of the edit window, so scroll up. */ * we're now above the first line of the edit window, so scroll up. */
if (ISSET(SOFTWRAP) && openfile->current_y == 0 && if (ISSET(SOFTWRAP) && openfile->current_y == 0 &&
openfile->current == was_current && openfile->current == was_current &&
get_chunk_row(openfile->current, chunk_for(openfile->placewewant,
openfile->placewewant) != was_chunk) { openfile->current) != was_chunk) {
edit_scroll(UPWARD, ISSET(SMOOTH_SCROLL) ? 1 : editwinrows / 2 + 1); edit_scroll(UPWARD, ISSET(SMOOTH_SCROLL) ? 1 : editwinrows / 2 + 1);
return; return;
} }
...@@ -609,7 +609,7 @@ void do_right(void) ...@@ -609,7 +609,7 @@ void do_right(void)
size_t was_column = xplustabs(); size_t was_column = xplustabs();
#ifndef NANO_TINY #ifndef NANO_TINY
filestruct *was_current = openfile->current; 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 #endif
if (openfile->current->data[openfile->current_x] != '\0') if (openfile->current->data[openfile->current_x] != '\0')
...@@ -628,8 +628,8 @@ void do_right(void) ...@@ -628,8 +628,8 @@ void do_right(void)
* we're now below the first line of the edit window, so scroll down. */ * we're now below the first line of the edit window, so scroll down. */
if (ISSET(SOFTWRAP) && openfile->current_y == editwinrows - 1 && if (ISSET(SOFTWRAP) && openfile->current_y == editwinrows - 1 &&
openfile->current == was_current && openfile->current == was_current &&
get_chunk_row(openfile->current, chunk_for(openfile->placewewant,
openfile->placewewant) != was_chunk) { openfile->current) != was_chunk) {
edit_scroll(DOWNWARD, ISSET(SMOOTH_SCROLL) ? 1 : editwinrows / 2 + 1); edit_scroll(DOWNWARD, ISSET(SMOOTH_SCROLL) ? 1 : editwinrows / 2 + 1);
return; return;
} }
......
...@@ -1762,7 +1762,7 @@ int do_mouse(void) ...@@ -1762,7 +1762,7 @@ int do_mouse(void)
/* Whether the click was on the row where the cursor is. */ /* Whether the click was on the row where the cursor is. */
if (ISSET(SOFTWRAP)) if (ISSET(SOFTWRAP))
leftedge = get_chunk_leftedge(openfile->current, xplustabs()); leftedge = leftedge_for(xplustabs(), openfile->current);
else else
#endif #endif
leftedge = get_page_start(xplustabs()); leftedge = get_page_start(xplustabs());
...@@ -1812,8 +1812,8 @@ void do_output(char *output, size_t output_len, bool allow_cntrls) ...@@ -1812,8 +1812,8 @@ void do_output(char *output, size_t output_len, bool allow_cntrls)
if (ISSET(SOFTWRAP)) { if (ISSET(SOFTWRAP)) {
if (openfile->current_y == editwinrows - 1) if (openfile->current_y == editwinrows - 1)
original_row = get_chunk_row(openfile->current, xplustabs()); original_row = chunk_for(xplustabs(), openfile->current);
orig_rows = get_last_chunk_row(openfile->current); orig_rows = number_of_chunks_in(openfile->current);
} }
#endif #endif
...@@ -1878,9 +1878,9 @@ void do_output(char *output, size_t output_len, bool allow_cntrls) ...@@ -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 * 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. */ * the last line of the edit window, so we need a full refresh too. */
if (ISSET(SOFTWRAP) && refresh_needed == FALSE && 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 && (openfile->current_y == editwinrows - 1 &&
get_chunk_row(openfile->current, xplustabs()) != original_row))) chunk_for(xplustabs(), openfile->current) != original_row)))
refresh_needed = TRUE; refresh_needed = TRUE;
#endif #endif
......
...@@ -665,10 +665,10 @@ void edit_scroll(scroll_dir direction, int nrows); ...@@ -665,10 +665,10 @@ void edit_scroll(scroll_dir direction, int nrows);
#ifndef NANO_TINY #ifndef NANO_TINY
size_t get_softwrap_breakpoint(const char *text, size_t leftedge, size_t get_softwrap_breakpoint(const char *text, size_t leftedge,
bool *end_of_line); bool *end_of_line);
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 get_chunk_row(filestruct *line, size_t column); size_t chunk_for(size_t column, filestruct *line);
size_t get_chunk_leftedge(filestruct *line, size_t column); size_t leftedge_for(size_t column, filestruct *line);
size_t get_last_chunk_row(filestruct *line); size_t number_of_chunks_in(filestruct *line);
void ensure_firstcolumn_is_aligned(void); void ensure_firstcolumn_is_aligned(void);
#endif #endif
size_t actual_last_column(size_t leftedge, size_t column); size_t actual_last_column(size_t leftedge, size_t column);
......
...@@ -900,7 +900,7 @@ void do_gotolinecolumn(ssize_t line, ssize_t column, bool use_answer, ...@@ -900,7 +900,7 @@ void do_gotolinecolumn(ssize_t line, ssize_t column, bool use_answer,
#ifndef NANO_TINY #ifndef NANO_TINY
if (ISSET(SOFTWRAP)) { if (ISSET(SOFTWRAP)) {
filestruct *line = openfile->current; 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) - rows_from_tail = (editwinrows / 2) -
go_forward_chunks(editwinrows / 2, &line, &leftedge); go_forward_chunks(editwinrows / 2, &line, &leftedge);
......
...@@ -112,7 +112,7 @@ void do_deletion(undo_type action) ...@@ -112,7 +112,7 @@ void do_deletion(undo_type action)
update_undo(action); update_undo(action);
if (ISSET(SOFTWRAP)) if (ISSET(SOFTWRAP))
orig_rows = get_last_chunk_row(openfile->current); orig_rows = number_of_chunks_in(openfile->current);
#endif #endif
/* Move the remainder of the line "in", over the current character. */ /* Move the remainder of the line "in", over the current character. */
...@@ -181,7 +181,7 @@ void do_deletion(undo_type action) ...@@ -181,7 +181,7 @@ void do_deletion(undo_type action)
/* If the number of screen rows that a softwrapped line occupies /* If the number of screen rows that a softwrapped line occupies
* has changed, we need a full refresh. */ * has changed, we need a full refresh. */
if (ISSET(SOFTWRAP) && refresh_needed == FALSE && 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; refresh_needed = TRUE;
#endif #endif
......
...@@ -2296,16 +2296,16 @@ void place_the_cursor(bool forreal) ...@@ -2296,16 +2296,16 @@ void place_the_cursor(bool forreal)
filestruct *line = openfile->edittop; filestruct *line = openfile->edittop;
size_t leftedge; 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. */ /* Calculate how many rows the lines from edittop to current use. */
while (line != NULL && line != openfile->current) { while (line != NULL && line != openfile->current) {
row += get_last_chunk_row(line) + 1; row += number_of_chunks_in(line) + 1;
line = line->next; line = line->next;
} }
/* Add the number of wraps in the current line before the cursor. */ /* 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; col = xpt - leftedge;
} else } else
#endif #endif
...@@ -2748,11 +2748,11 @@ int update_softwrapped_line(filestruct *fileptr) ...@@ -2748,11 +2748,11 @@ int update_softwrapped_line(filestruct *fileptr)
if (fileptr == openfile->edittop) if (fileptr == openfile->edittop)
from_col = openfile->firstcolumn; from_col = openfile->firstcolumn;
else 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. */ /* Find out on which screen row the target line should be shown. */
while (line != fileptr && line != NULL) { while (line != fileptr && line != NULL) {
row += get_last_chunk_row(line) + 1; row += number_of_chunks_in(line) + 1;
line = line->next; line = line->next;
} }
...@@ -2825,8 +2825,7 @@ int go_back_chunks(int nrows, filestruct **line, size_t *leftedge) ...@@ -2825,8 +2825,7 @@ int go_back_chunks(int nrows, filestruct **line, size_t *leftedge)
/* Recede through the requested number of chunks. */ /* Recede through the requested number of chunks. */
for (i = nrows; i > 0; i--) { for (i = nrows; i > 0; i--) {
if (current_leftedge > 0) { if (current_leftedge > 0) {
current_leftedge = get_chunk_leftedge(*line, current_leftedge = leftedge_for(current_leftedge - 1, *line);
current_leftedge - 1);
continue; continue;
} }
...@@ -2834,7 +2833,7 @@ int go_back_chunks(int nrows, filestruct **line, size_t *leftedge) ...@@ -2834,7 +2833,7 @@ int go_back_chunks(int nrows, filestruct **line, size_t *leftedge)
break; break;
*line = (*line)->prev; *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. */ /* 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) ...@@ -2900,7 +2899,7 @@ bool less_than_a_screenful(size_t was_lineno, size_t was_leftedge)
#ifndef NANO_TINY #ifndef NANO_TINY
if (ISSET(SOFTWRAP)) { if (ISSET(SOFTWRAP)) {
filestruct *line = openfile->current; 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); int rows_left = go_back_chunks(editwinrows - 1, &line, &leftedge);
return (rows_left > 0 || line->lineno < was_lineno || return (rows_left > 0 || line->lineno < was_lineno ||
...@@ -2966,11 +2965,11 @@ void edit_scroll(scroll_dir direction, int nrows) ...@@ -2966,11 +2965,11 @@ void edit_scroll(scroll_dir direction, int nrows)
#ifndef NANO_TINY #ifndef NANO_TINY
/* Compensate for the earlier chunks of a softwrapped line. */ /* 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. */ /* Don't compensate for the chunks that are offscreen. */
if (line == openfile->edittop) if (line == openfile->edittop)
nrows -= get_chunk_row(line, openfile->firstcolumn); nrows -= chunk_for(openfile->firstcolumn, line);
#endif #endif
/* Draw new content on the blank rows inside the scrolled region /* 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, ...@@ -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, /* 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 * relative to the first row (zero-based), and return it. If leftedge isn't
* NULL, return the leftmost column of the chunk in it. */ * 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; size_t current_chunk = 0, start_col = 0, end_col;
bool end_of_line = FALSE; bool end_of_line = FALSE;
...@@ -3072,27 +3071,27 @@ size_t get_chunk(filestruct *line, size_t column, size_t *leftedge) ...@@ -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, /* Return the row of the softwrapped chunk of the given line that column is on,
* relative to the first row (zero-based). */ * 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 /* Return the leftmost column of the softwrapped chunk of the given line that
* column is on. */ * 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; size_t leftedge;
get_chunk(line, column, &leftedge); get_chunk_and_edge(column, line, &leftedge);
return leftedge; return leftedge;
} }
/* Return the row of the last softwrapped chunk of the given line, relative to /* Return the row of the last softwrapped chunk of the given line, relative to
* the first row (zero-based). */ * 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 /* Ensure that firstcolumn is at the starting column of the softwrapped chunk
...@@ -3100,8 +3099,8 @@ size_t get_last_chunk_row(filestruct *line) ...@@ -3100,8 +3099,8 @@ size_t get_last_chunk_row(filestruct *line)
* has changed, because then the width of softwrapped chunks has changed. */ * has changed, because then the width of softwrapped chunks has changed. */
void ensure_firstcolumn_is_aligned(void) void ensure_firstcolumn_is_aligned(void)
{ {
openfile->firstcolumn = get_chunk_leftedge(openfile->edittop, openfile->firstcolumn = leftedge_for(openfile->firstcolumn,
openfile->firstcolumn); openfile->edittop);
/* If smooth scrolling is on, make sure the viewport doesn't center. */ /* If smooth scrolling is on, make sure the viewport doesn't center. */
focusing = FALSE; focusing = FALSE;
...@@ -3164,8 +3163,8 @@ bool current_is_below_screen(void) ...@@ -3164,8 +3163,8 @@ bool current_is_below_screen(void)
return (go_forward_chunks(editwinrows - 1, &line, &leftedge) == 0 && return (go_forward_chunks(editwinrows - 1, &line, &leftedge) == 0 &&
(line->lineno < openfile->current->lineno || (line->lineno < openfile->current->lineno ||
(line->lineno == openfile->current->lineno && (line->lineno == openfile->current->lineno &&
leftedge < get_chunk_leftedge(openfile->current, leftedge < leftedge_for(xplustabs(),
xplustabs())))); openfile->current))));
} else } else
#endif #endif
return (openfile->current->lineno >= return (openfile->current->lineno >=
...@@ -3284,8 +3283,7 @@ void adjust_viewport(update_type manner) ...@@ -3284,8 +3283,7 @@ void adjust_viewport(update_type manner)
openfile->edittop = openfile->current; openfile->edittop = openfile->current;
#ifndef NANO_TINY #ifndef NANO_TINY
if (ISSET(SOFTWRAP)) if (ISSET(SOFTWRAP))
openfile->firstcolumn = get_chunk_leftedge(openfile->current, openfile->firstcolumn = leftedge_for(xplustabs(), openfile->current);
xplustabs());
#endif #endif
/* Move edittop back goal rows, starting at current[current_x]. */ /* 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) ...@@ -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) void spotlight_softwrapped(bool active, size_t from_col, size_t to_col)
{ {
ssize_t row = openfile->current_y; 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; size_t break_col;
bool end_of_line = FALSE; bool end_of_line = FALSE;
char *word; char *word;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment