Only in my-src: mark-end-in-currents-stead.patch diff -ur original-src/move.c my-src/move.c --- original-src/move.c 2016-01-10 12:23:04.000000000 +0530 +++ my-src/move.c 2016-02-07 00:42:01.979206368 +0530 @@ -375,7 +375,60 @@ /* If scroll_only is FALSE, move up one line. If scroll_only is TRUE, * scroll up one line without scrolling the cursor. */ -void do_up( +void do_mark_end_up( +#ifndef NANO_TINY + bool scroll_only +#else + void +#endif + ) +{ + /* If we're at the top of the file, or if scroll_only is TRUE and + * the top of the file is onscreen, get out. */ + if (openfile->mark_end == openfile->fileage +#ifndef NANO_TINY + || (scroll_only && openfile->edittop == openfile->fileage) +#endif + ) + return; + + assert(ISSET(SOFTWRAP) || openfile->mark_end_y == openfile->mark_end->lineno - openfile->edittop->lineno); + + /* Move the mark_end one line up in the edit window. */ + openfile->mark_end = openfile->mark_end->prev; + openfile->mark_end_x = actual_x(openfile->mark_end->data, + openfile->placewewant); + + /* If scroll_only is FALSE and if we're on the first line of the + * edit window, scroll the edit window up one line if we're in + * smooth scrolling mode, or up half a page if we're not. If + * scroll_only is TRUE, scroll the edit window up one line + * unconditionally. */ + if (openfile->mark_end_y == 0 +#ifndef NANO_TINY + || (ISSET(SOFTWRAP) && openfile->edittop->lineno == openfile->mark_end->next->lineno) || scroll_only +#endif + ) + edit_scroll(UPWARD, +#ifndef NANO_TINY + (ISSET(SMOOTH_SCROLL) || scroll_only) ? 1 : +#endif + editwinrows / 2 + 1); + + /* If we're below the first line of the edit window, update the + * line we were on before and the line we're on now. The former + * needs to be redrawn if we're not on the first page, and the + * latter needs to be drawn unconditionally. */ + if (openfile->mark_end_y > 0) { + if (need_screen_update(0)) + update_line(openfile->mark_end->next, 0); + update_line(openfile->mark_end, openfile->mark_end_x); + } +} + +/* If scroll_only is FALSE, move up one line. If scroll_only is TRUE, + * scroll up one line without scrolling the cursor. */ +void do_cursor_up( #ifndef NANO_TINY bool scroll_only #else @@ -394,7 +447,7 @@ assert(ISSET(SOFTWRAP) || openfile->current_y == openfile->current->lineno - openfile->edittop->lineno); - /* Move the current line of the edit window up. */ + /* Move the cursor one line up in the edit window. */ openfile->current = openfile->current->prev; openfile->current_x = actual_x(openfile->current->data, openfile->placewewant); @@ -426,6 +479,21 @@ } } +/* Do what up, cursor or mark_end? */ +void do_up( +#ifndef NANO_TINY + bool scroll_only +#else + void +#endif + ) +{ + if (!openfile->mark_set) + do_cursor_up(scroll_only); + else + do_mark_end_up(scroll_only); +} + /* Move up one line. */ void do_up_void(void) { @@ -446,7 +514,90 @@ /* If scroll_only is FALSE, move down one line. If scroll_only is TRUE, * scroll down one line without scrolling the cursor. */ -void do_down( +void do_mark_end_down( +#ifndef NANO_TINY + bool scroll_only +#else + void +#endif + ) +{ +#ifndef NANO_TINY + int amount = 0, enough; + filestruct *topline; +#endif + + /* If we're at the bottom of the file, get out. */ + if (openfile->mark_end == openfile->filebot) + return; + + assert(ISSET(SOFTWRAP) || openfile->mark_end_y == + openfile->mark_end->lineno - openfile->edittop->lineno); + assert(openfile->mark_end->next != NULL); + + /* Move the mark_end one line down in the edit window. */ + openfile->mark_end = openfile->mark_end->next; + openfile->mark_end_x = actual_x(openfile->mark_end->data, + openfile->placewewant); + +#ifndef NANO_TINY + if (ISSET(SOFTWRAP)) { + /* Compute the amount to scroll. */ + amount = (strlenpt(openfile->mark_end->data) / COLS + + openfile->mark_end_y + 2 + strlenpt(openfile->mark_end->prev->data) / + COLS - editwinrows); + topline = openfile->edittop; + /* Reduce the amount when there are overlong lines at the top. */ + for (enough = 1; enough < amount; enough++) { + amount -= strlenpt(topline->data) / COLS; + if (amount <= 0) { + amount = enough; + break; + } + topline = topline->next; + } + } +#endif + + /* If scroll_only is FALSE and if we're on the last line of the + * edit window, scroll the edit window down one line if we're in + * smooth scrolling mode, or down half a page if we're not. If + * scroll_only is TRUE, scroll the edit window down one line + * unconditionally. */ + if (openfile->mark_end_y == editwinrows - 1 +#ifndef NANO_TINY + || amount > 0 || scroll_only +#endif + ) { +#ifndef NANO_TINY + if (amount < 1 || scroll_only) + amount = 1; +#endif + edit_scroll(DOWNWARD, +#ifndef NANO_TINY + (ISSET(SMOOTH_SCROLL) || scroll_only) ? amount : +#endif + editwinrows / 2 + 1); + edit_refresh_needed = TRUE; + } + /* If we're above the last line of the edit window, update the line + * we were on before and the line we're on now. The former needs to + * be redrawn if we're not on the first page, and the latter needs + * to be drawn unconditionally. */ + if (openfile->mark_end_y < editwinrows - 1 +#ifndef NANO_TINY + || ISSET(SOFTWRAP) +#endif + ) { + if (need_screen_update(0)) + update_line(openfile->mark_end->prev, 0); + update_line(openfile->mark_end, openfile->mark_end_x); + } +} + +/* If scroll_only is FALSE, move down one line. If scroll_only is TRUE, + * scroll down one line without scrolling the cursor. */ +void do_cursor_down( #ifndef NANO_TINY bool scroll_only #else @@ -467,7 +618,7 @@ openfile->current->lineno - openfile->edittop->lineno); assert(openfile->current->next != NULL); - /* Move the current line of the edit window down. */ + /* Move the cursor one line down in the edit window. */ openfile->current = openfile->current->next; openfile->current_x = actual_x(openfile->current->data, openfile->placewewant); @@ -526,6 +677,21 @@ } } +/* Do what down, cursor or mark_end? */ +void do_down( +#ifndef NANO_TINY + bool scroll_only +#else + void +#endif + ) +{ + if (!openfile->mark_set) + do_cursor_down(scroll_only); + else + do_mark_end_down(scroll_only); +} + /* Move down one line. */ void do_down_void(void) { @@ -544,8 +710,27 @@ } #endif -/* Move left one character. */ -void do_left(void) +/* Move mark_end left by one character. */ +void do_mark_end_left(void) +{ + size_t pww_save = openfile->placewewant; + + if (openfile->mark_end_x > 0) + openfile->mark_end_x = move_mbleft(openfile->mark_end->data, + openfile->mark_end_x); + else if (openfile->mark_end != openfile->fileage) { + do_up_void(); + openfile->mark_end_x = strlen(openfile->mark_end->data); + } + + openfile->placewewant = xplustabs(); + + if (need_screen_update(pww_save)) + update_line(openfile->mark_end, openfile->mark_end_x); +} + +/* Move cursor left by one character. */ +void do_cursor_left(void) { size_t pww_save = openfile->placewewant; @@ -563,8 +748,38 @@ update_line(openfile->current, openfile->current_x); } -/* Move right one character. */ -void do_right(void) +/* Do what left, cursor or mark_end? */ +void do_left(void) +{ + if (!openfile->mark_set) + do_cursor_left(); + else + do_mark_end_left(); +} + +/* Move mark_end right by one character. */ +void do_mark_end_right(void) +{ + size_t pww_save = openfile->placewewant; + + assert(openfile->mark_end_x <= strlen(openfile->mark_end->data)); + + if (openfile->mark_end->data[openfile->mark_end_x] != '\0') + openfile->mark_end_x = move_mbright(openfile->mark_end->data, + openfile->mark_end_x); + else if (openfile->mark_end != openfile->filebot) { + do_down_void(); + openfile->mark_end_x = 0; + } + + openfile->placewewant = xplustabs(); + + if (need_screen_update(pww_save)) + update_line(openfile->mark_end, openfile->mark_end_x); +} + +/* Move cursor right by one character. */ +void do_cursor_right(void) { size_t pww_save = openfile->placewewant; @@ -583,3 +798,12 @@ if (need_screen_update(pww_save)) update_line(openfile->current, openfile->current_x); } + +/* Do what right, cursor or mark_end? */ +void do_right(void) +{ + if (!openfile->mark_set) + do_cursor_right(); + else + do_mark_end_right(); +} diff -ur original-src/nano.h my-src/nano.h --- original-src/nano.h 2015-12-06 10:30:29.000000000 +0530 +++ my-src/nano.h 2016-02-06 19:27:24.888878000 +0530 @@ -388,9 +388,15 @@ bool mark_set; /* Whether the mark is on in this file. */ filestruct *mark_begin; - /* The file's line where the mark is, if any. */ + /* The file's line where the first mark is, if any. */ size_t mark_begin_x; - /* The file's mark's x-coordinate position, if any. */ + /* The file's first mark's x-coordinate position, if any. */ + filestruct *mark_end; + /* The file's line where the second mark is, if any. */ + size_t mark_end_x; + /* The file's second mark's x-coordinate position, if any. */ + ssize_t mark_end_y; + /* The mark_end's y-coordinate position. */ file_format fmt; /* The file's format. */ struct stat *current_stat; diff -ur original-src/text.c my-src/text.c --- original-src/text.c 2016-01-10 12:23:04.000000000 +0530 +++ my-src/text.c 2016-02-06 21:49:22.786342000 +0530 @@ -54,10 +54,16 @@ statusbar(_("Mark Set")); openfile->mark_begin = openfile->current; openfile->mark_begin_x = openfile->current_x; + openfile->mark_end = openfile->current; + openfile->mark_end_x = openfile->current_x; + openfile->mark_end_y = openfile->current_y; } else { statusbar(_("Mark Unset")); openfile->mark_begin = NULL; openfile->mark_begin_x = 0; + openfile->mark_end = NULL; + openfile->mark_end_x = 0; + openfile->mark_end_y = 0; edit_refresh(); } } diff -ur original-src/utils.c my-src/utils.c --- original-src/utils.c 2015-12-05 10:36:09.000000000 +0530 +++ my-src/utils.c 2016-02-06 19:25:42.952878000 +0530 @@ -561,20 +561,20 @@ { assert(top != NULL && top_x != NULL && bot != NULL && bot_x != NULL); - if ((openfile->current->lineno == openfile->mark_begin->lineno && - openfile->current_x > openfile->mark_begin_x) || - openfile->current->lineno > openfile->mark_begin->lineno) { + if ((openfile->mark_end->lineno == openfile->mark_begin->lineno && + openfile->mark_end_x > openfile->mark_begin_x) || + openfile->mark_end->lineno > openfile->mark_begin->lineno) { *top = openfile->mark_begin; *top_x = openfile->mark_begin_x; - *bot = openfile->current; - *bot_x = openfile->current_x; + *bot = openfile->mark_end; + *bot_x = openfile->mark_end_x; if (right_side_up != NULL) *right_side_up = TRUE; } else { *bot = openfile->mark_begin; *bot_x = openfile->mark_begin_x; - *top = openfile->current; - *top_x = openfile->current_x; + *top = openfile->mark_end; + *top_x = openfile->mark_end_x; if (right_side_up != NULL) *right_side_up = FALSE; } diff -ur original-src/winio.c my-src/winio.c --- original-src/winio.c 2016-01-11 10:24:30.000000000 +0530 +++ my-src/winio.c 2016-02-06 18:08:31.444860000 +0530 @@ -2653,9 +2653,9 @@ /* If the mark is on, we need to display it. */ if (openfile->mark_set && (fileptr->lineno <= openfile->mark_begin->lineno || fileptr->lineno <= - openfile->current->lineno) && (fileptr->lineno >= + openfile->mark_end->lineno) && (fileptr->lineno >= openfile->mark_begin->lineno || fileptr->lineno >= - openfile->current->lineno)) { + openfile->mark_end->lineno)) { /* fileptr is at least partially selected. */ const filestruct *top; /* Either current or mark_begin, whichever is first. */