tweaks: reshuffle a bit of common code, moving it to an existing function

master
Benno Schulenberg 2017-12-23 21:32:47 +01:00
parent ee5b250b66
commit c22fef18e4
3 changed files with 17 additions and 26 deletions

View File

@ -609,7 +609,7 @@ void remove_magicline(void);
#ifndef NANO_TINY
void mark_order(const filestruct **top, size_t *top_x, const filestruct
**bot, size_t *bot_x, bool *right_side_up);
void get_region(const filestruct **top, const filestruct **bot);
void get_range(const filestruct **top, const filestruct **bot);
#endif
size_t get_totsize(const filestruct *begin, const filestruct *end);
#ifndef NANO_TINY

View File

@ -298,12 +298,7 @@ void do_indent(void)
filestruct *top, *bot, *line;
/* Use either all the marked lines or just the current line. */
if (openfile->mark)
get_region((const filestruct **)&top, (const filestruct **)&bot);
else {
top = openfile->current;
bot = top;
}
get_range((const filestruct **)&top, (const filestruct **)&bot);
/* Go through the lines to see if there's a non-empty one. */
for (line = top; line != bot->next; line = line->next) {
@ -401,12 +396,7 @@ void do_unindent(void)
filestruct *top, *bot, *line;
/* Use either all the marked lines or just the current line. */
if (openfile->mark)
get_region((const filestruct **)&top, (const filestruct **)&bot);
else {
top = openfile->current;
bot = top;
}
get_range((const filestruct **)&top, (const filestruct **)&bot);
/* Check if there is a line that can be unindented. */
for (line = top; line != bot->next; line = line->next) {
@ -503,12 +493,7 @@ void do_comment(void)
#endif
/* Determine which lines to work on. */
if (openfile->mark)
get_region((const filestruct **)&top, (const filestruct **)&bot);
else {
top = openfile->current;
bot = top;
}
get_range((const filestruct **)&top, (const filestruct **)&bot);
/* If only the magic line is selected, don't do anything. */
if (top == bot && bot == openfile->filebot && !ISSET(NO_NEWLINES)) {

View File

@ -532,16 +532,22 @@ void mark_order(const filestruct **top, size_t *top_x, const filestruct
}
}
/* Get the start and end points of the marked region, but
* push the end point back if it's at the start of a line. */
void get_region(const filestruct **top, const filestruct **bot)
/* Get the set of lines to work on -- either just the current line, or the
* first to last lines of the marked region. When the cursor (or mark) is
* at the start of the last line of the region, exclude that line. */
void get_range(const filestruct **top, const filestruct **bot)
{
size_t top_x, bot_x;
if (!openfile->mark) {
*top = openfile->current;
*bot = openfile->current;
} else {
size_t top_x, bot_x;
mark_order(top, &top_x, bot, &bot_x, NULL);
mark_order(top, &top_x, bot, &bot_x, NULL);
if (bot_x == 0 && *bot != *top)
*bot = (*bot)->prev;
if (bot_x == 0 && *bot != *top)
*bot = (*bot)->prev;
}
}
/* Given a line number, return a pointer to the corresponding struct. */