From 2de84c1c8d8c000e986af35a28be8aed03014640 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Mon, 24 Oct 2005 02:12:09 +0000 Subject: [PATCH] add the ability to scroll up or down single lines without scrolling the cursor, via Meta-- and Meta-+; note that this is disabled when NANO_SMALL is defined git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3049 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 6 ++++++ src/global.c | 12 ++++++++++++ src/move.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/nano.h | 8 ++++++++ src/proto.h | 6 ++++++ 5 files changed, 82 insertions(+) diff --git a/ChangeLog b/ChangeLog index aac77e5c..5ecdd1e6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,10 @@ CVS code - +- General: + - Add the ability to scroll up or down single lines without + scrolling the cursor, via Meta-- and Meta-+. Note that this + is disabled when NANO_SMALL is defined. New functions + do_scroll_up() and do_scroll_down(); changes to + shortcut_init(). (DLR, suggested by Mike Frysinger) GNU nano 1.3.9 - 2005.10.23 - General: diff --git a/src/global.c b/src/global.c index 56835bd5..fbd02ed0 100644 --- a/src/global.c +++ b/src/global.c @@ -291,6 +291,10 @@ void shortcut_init(bool unjustify) const char *nano_prevword_msg = N_("Move backward one word"); const char *nano_wordcount_msg = N_("Count the number of words, lines, and characters"); + const char *nano_scrollprev_msg = + N_("Scroll up one line without scrolling the cursor"); + const char *nano_scrollnext_msg = + N_("Scroll down one line without scrolling the cursor"); #endif #ifndef DISABLE_JUSTIFY const char *nano_parabegin_msg = @@ -543,6 +547,14 @@ void shortcut_init(bool unjustify) sc_init_one(&main_list, NANO_NO_KEY, N_("Word Count"), IFHELP(nano_wordcount_msg, NANO_WORDCOUNT_KEY), NANO_NO_KEY, NANO_NO_KEY, VIEW, do_wordlinechar_count); + + sc_init_one(&main_list, NANO_NO_KEY, N_("ScrollPrev"), + IFHELP(nano_scrollprev_msg, NANO_SCROLLPREV_KEY), NANO_NO_KEY, + NANO_SCROLLPREV_ALTKEY, VIEW, do_scroll_up); + + sc_init_one(&main_list, NANO_NO_KEY, N_("ScrollNext"), + IFHELP(nano_scrollnext_msg, NANO_SCROLLNEXT_KEY), NANO_NO_KEY, + NANO_SCROLLNEXT_ALTKEY, VIEW, do_scroll_down); #endif #ifndef DISABLE_JUSTIFY diff --git a/src/move.c b/src/move.c index ae432999..00bafa70 100644 --- a/src/move.c +++ b/src/move.c @@ -512,6 +512,31 @@ void do_up(void) } } +#ifndef NANO_SMALL +void do_scroll_up(void) +{ + check_statusblank(); + +#ifndef DISABLE_WRAPPING + wrap_reset(); +#endif + + /* If the top of the file is onscreen, get out. */ + if (openfile->edittop == openfile->fileage) + return; + + assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno); + + /* Move the current line of the edit window up. */ + openfile->current = openfile->current->prev; + openfile->current_x = actual_x(openfile->current->data, + openfile->placewewant); + + /* Scroll the edit window up one line. */ + edit_scroll(UP, 1); +} +#endif /* !NANO_SMALL */ + void do_down(void) { check_statusblank(); @@ -550,6 +575,31 @@ void do_down(void) } } +#ifndef NANO_SMALL +void do_scroll_down(void) +{ + check_statusblank(); + +#ifndef DISABLE_WRAPPING + wrap_reset(); +#endif + + /* If we're at the bottom of the file, get out. */ + if (openfile->current->next == NULL) + return; + + assert(openfile->current_y == openfile->current->lineno - openfile->edittop->lineno); + + /* Move the current line of the edit window down. */ + openfile->current = openfile->current->next; + openfile->current_x = actual_x(openfile->current->data, + openfile->placewewant); + + /* Scroll the edit window down one line. */ + edit_scroll(DOWN, 1); +} +#endif /* !NANO_SMALL */ + void do_left(void) { size_t pww_save = openfile->placewewant; diff --git a/src/nano.h b/src/nano.h index 97ecd6db..e2c35f20 100644 --- a/src/nano.h +++ b/src/nano.h @@ -360,13 +360,17 @@ typedef struct rcoption { #define NANO_ALT_SPACE ' ' #define NANO_ALT_LPAREN '(' #define NANO_ALT_RPAREN ')' +#define NANO_ALT_PLUS '+' #define NANO_ALT_COMMA ',' +#define NANO_ALT_MINUS '-' #define NANO_ALT_PERIOD '.' #define NANO_ALT_9 '9' #define NANO_ALT_0 '0' #define NANO_ALT_LCARAT '<' +#define NANO_ALT_EQUALS '=' #define NANO_ALT_RCARAT '>' #define NANO_ALT_RBRACKET ']' +#define NANO_ALT_USCORE '_' #define NANO_ALT_A 'a' #define NANO_ALT_B 'b' #define NANO_ALT_C 'c' @@ -473,6 +477,10 @@ typedef struct rcoption { #define NANO_NEXTWORD_KEY NANO_CONTROL_SPACE #define NANO_PREVWORD_KEY NANO_ALT_SPACE #define NANO_WORDCOUNT_KEY NANO_ALT_D +#define NANO_SCROLLPREV_KEY NANO_ALT_MINUS +#define NANO_SCROLLNEXT_KEY NANO_ALT_PLUS +#define NANO_SCROLLPREV_ALTKEY NANO_ALT_USCORE +#define NANO_SCROLLNEXT_ALTKEY NANO_ALT_EQUALS #define NANO_CUTTILLEND_KEY NANO_CONTROL_X #define NANO_CUTTILLEND_ALTKEY NANO_ALT_T #define NANO_PARABEGIN_KEY NANO_CONTROL_W diff --git a/src/proto.h b/src/proto.h index dfc9ba16..871a684c 100644 --- a/src/proto.h +++ b/src/proto.h @@ -333,7 +333,13 @@ void do_prev_word_void(void); void do_home(void); void do_end(void); void do_up(void); +#ifndef NANO_SMALL +void do_scroll_up(void); +#endif void do_down(void); +#ifndef NANO_SMALL +void do_scroll_down(void); +#endif void do_left(void); void do_right(void);