Index: src/global.c =================================================================== --- src/global.c (revision 4904) +++ src/global.c (working copy) @@ -1366,6 +1366,10 @@ s->scfunc = do_toggle_void; s->execute = FALSE; s->toggle = SMOOTH_SCROLL; + } else if (!strcasecmp(input, "align_page")) { + s->scfunc = do_toggle_void; + s->execute = FALSE; + s->toggle = SMOOTH_HORZ_SCROLL; } else if (!strcasecmp(input, "softwrap")) { s->scfunc = do_toggle_void; s->execute = FALSE; Index: src/move.c =================================================================== --- src/move.c (revision 4904) +++ src/move.c (working copy) @@ -93,6 +93,9 @@ (unsigned long) openfile->current->lineno, skipped); #endif + if(ISSET(SMOOTH_HORZ_SCROLL) ) + edit_refresh(); + else /* Scroll the edit window up a page. */ edit_update(NONE); } @@ -134,6 +137,9 @@ openfile->current_x = actual_x(openfile->current->data, openfile->placewewant); + if(ISSET(SMOOTH_HORZ_SCROLL) ) + edit_refresh(); + else /* Scroll the edit window down a page. */ edit_update(NONE); } @@ -222,8 +228,9 @@ size_t pww_save = openfile->placewewant; filestruct *current_save = openfile->current; char *char_mb; - int char_mb_len; - bool end_line = FALSE, started_on_word = FALSE; + int char_mb_len=0; + bool started_on_word = FALSE; + bool end_line = (openfile->current_x >= strlen(openfile->current->data)); assert(openfile->current != NULL && openfile->current->data != NULL); @@ -467,9 +474,13 @@ } #endif - if (need_horizontal_update(pww_save)) + if (need_horizontal_update(pww_save)){ + if(ISSET(SMOOTH_HORZ_SCROLL) ) + update_page(); + else update_line(openfile->current, openfile->current_x); } +} /* Move to the end of the current line. */ void do_end(void) @@ -479,9 +490,13 @@ openfile->current_x = strlen(openfile->current->data); openfile->placewewant = xplustabs(); - if (need_horizontal_update(pww_save)) + if (need_horizontal_update(pww_save)){ + if(ISSET(SMOOTH_HORZ_SCROLL) ) + update_page(); + else update_line(openfile->current, openfile->current_x); } +} /* If scroll_only is FALSE, move up one line. If scroll_only is TRUE, * scroll up one line without scrolling the cursor. */ @@ -530,11 +545,15 @@ * needs to be redrawn if we're not on the first page, and the * latter needs to be drawn unconditionally. */ if (openfile->current_y > 0) { + if(ISSET(SMOOTH_HORZ_SCROLL) ) + edit_refresh(); + else{ if (need_vertical_update(0)) update_line(openfile->current->next, 0); update_line(openfile->current, openfile->current_x); } } +} /* Move up one line. */ void do_up_void(void) @@ -624,11 +643,15 @@ * be redrawn if we're not on the first page, and the latter needs * to be drawn unconditionally. */ if (ISSET(SOFTWRAP) || openfile->current_y < editwinrows - 1) { + if(ISSET(SMOOTH_HORZ_SCROLL) ) + edit_refresh(); + else{ if (need_vertical_update(0)) update_line(openfile->current->prev, 0); update_line(openfile->current, openfile->current_x); } } +} /* Move down one line. */ void do_down_void(void) @@ -663,9 +686,13 @@ openfile->placewewant = xplustabs(); - if (need_horizontal_update(pww_save)) + if (need_horizontal_update(pww_save)){ + if(ISSET(SMOOTH_HORZ_SCROLL) ) + update_page(); + else update_line(openfile->current, openfile->current_x); } +} /* Move right one character. */ void do_right(void) @@ -684,6 +711,10 @@ openfile->placewewant = xplustabs(); - if (need_horizontal_update(pww_save)) + if (need_horizontal_update(pww_save)){ + if(ISSET(SMOOTH_HORZ_SCROLL) ) + update_page(); + else update_line(openfile->current, openfile->current_x); } +} Index: src/nano.c =================================================================== --- src/nano.c (revision 4904) +++ src/nano.c (working copy) @@ -2019,6 +2019,9 @@ openfile->current->data = charealloc(openfile->current->data, current_len + (char_buf_len * 2)); + if(openfile->current_x > current_len) + openfile->current_x = current_len; + assert(openfile->current_x <= current_len); charmove(openfile->current->data + openfile->current_x + @@ -2075,7 +2078,9 @@ #ifndef DISABLE_COLOR reset_multis(openfile->current, FALSE); #endif - if (edit_refresh_needed == TRUE) { + if (ISSET(SMOOTH_HORZ_SCROLL) ) + update_page(); + else if (edit_refresh_needed == TRUE) { edit_refresh(); edit_refresh_needed = FALSE; } else Index: src/nano.h =================================================================== --- src/nano.h (revision 4904) +++ src/nano.h (working copy) @@ -515,6 +515,7 @@ BACKWARDS_SEARCH, MULTIBUFFER, SMOOTH_SCROLL, + SMOOTH_HORZ_SCROLL, REBIND_DELETE, REBIND_KEYPAD, NO_CONVERT, @@ -540,6 +541,7 @@ NOREAD_MODE }; +#define EDITWIN_CURR_PG_START get_edit_pg_start() /* Flags for the menus in which a given function should be present. */ #define MMAIN (1<<0) #define MWHEREIS (1<<1) Index: src/proto.h =================================================================== --- src/proto.h (revision 4904) +++ src/proto.h (working copy) @@ -721,6 +721,8 @@ char *mallocstrcpy(char *dest, const char *src); char *mallocstrassn(char *dest, char *src); size_t get_page_start(size_t column); +size_t get_edit_pg_start(); +void set_edit_pg_start(size_t column); size_t xplustabs(void); size_t actual_x(const char *s, size_t column); size_t strnlenpt(const char *s, size_t maxlen); @@ -788,6 +790,7 @@ void edit_scroll(scroll_dir direction, ssize_t nlines); void edit_redraw(filestruct *old_current, size_t pww_save); void edit_refresh(void); +void update_page(void); void edit_update(update_type location); void total_redraw(void); void total_refresh(void); Index: src/rcfile.c =================================================================== --- src/rcfile.c (revision 4904) +++ src/rcfile.c (working copy) @@ -94,6 +94,7 @@ {"quickblank", QUICK_BLANK}, {"smarthome", SMART_HOME}, {"smooth", SMOOTH_SCROLL}, + {"align_page", SMOOTH_HORZ_SCROLL}, {"tabstospaces", TABS_TO_SPACES}, {"undo", UNDOABLE}, {"whitespace", 0}, Index: src/utils.c =================================================================== --- src/utils.c (revision 4904) +++ src/utils.c (working copy) @@ -457,12 +457,28 @@ return src; } +static size_t edit_pg_start=0; + +inline size_t get_edit_pg_start(){return edit_pg_start;} +inline void set_edit_pg_start(size_t column){edit_pg_start = column;} + /* nano scrolls horizontally within a line in chunks. Return the column * number of the first character displayed in the edit window when the * cursor is at the given column. Note that (0 <= column - * get_page_start(column) < COLS). */ size_t get_page_start(size_t column) { + if (ISSET(SMOOTH_HORZ_SCROLL) ){ + if(column <= 0) + return 0; + else if(column <= edit_pg_start) + return column-1; + else if( (column - edit_pg_start) > COLS-2 ) + return column - (COLS - 2); + else + return edit_pg_start; + } + else { if (column == 0 || column < COLS - 1) return 0; else if (COLS > 8) @@ -470,6 +486,7 @@ else return column - (COLS - 2); } +} /* Return the placewewant associated with current_x, i.e. the zero-based * column position of the cursor. The value will be no smaller than Index: src/winio.c =================================================================== --- src/winio.c (revision 4904) +++ src/winio.c (working copy) @@ -2841,6 +2841,21 @@ #endif /* !NANO_TINY */ } +void update_page(void) +{ + size_t curr_col =xplustabs(); + + size_t pg_start = get_page_start(curr_col); + size_t old_pg_start = EDITWIN_CURR_PG_START; + + if(pg_start != old_pg_start){ + set_edit_pg_start(pg_start); + edit_refresh(); + } + else + update_line(openfile->current, pg_start); +} + /* Just update one line in the edit buffer. This is basically a wrapper * for edit_draw(). The line will be displayed starting with * fileptr->data[index]. Likely arguments are current_x or zero. @@ -2853,7 +2868,7 @@ char *converted; /* fileptr->data converted to have tabs and control characters * expanded. */ - size_t page_start; + size_t page_start=0; filestruct *tmp; assert(fileptr != NULL); @@ -2875,9 +2890,13 @@ * positions in the expanded line. */ if (ISSET(SOFTWRAP)) index = 0; - else + else if (ISSET(SMOOTH_HORZ_SCROLL) ){ + index = EDITWIN_CURR_PG_START; + page_start = index; + } else{ index = strnlenpt(fileptr->data, index); page_start = get_page_start(index); + } /* Expand the line, replacing tabs with spaces, and control * characters with their displayed forms. */ @@ -3080,10 +3099,10 @@ if ((i == nlines && direction == DOWN_DIR) || (i == 1 && direction == UP_DIR)) { if (do_redraw) - update_line(foo, (foo == openfile->current) ? + update_line(foo, (foo == openfile->current || ISSET(SMOOTH_HORZ_SCROLL) ) ? openfile->current_x : 0); } else - update_line(foo, (foo == openfile->current) ? + update_line(foo, (foo == openfile->current || ISSET(SMOOTH_HORZ_SCROLL) ) ? openfile->current_x : 0); foo = foo->next; } @@ -3094,6 +3113,9 @@ * updated. Use this if we've moved without changing any text. */ void edit_redraw(filestruct *old_current, size_t pww_save) { + if(ISSET(SMOOTH_HORZ_SCROLL) ) + return update_page(); + bool do_redraw = need_vertical_update(0) || need_vertical_update(pww_save); filestruct *foo = NULL;