nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nano-devel] [request] quick scrolling


From: David Lawrence Ramsey
Subject: Re: [Nano-devel] [request] quick scrolling
Date: Sat, 01 Oct 2005 02:47:05 -0400
User-agent: Mozilla Thunderbird 1.0.6 (X11/20050716)

Mike Frysinger wrote:

<snip>

>what would be nice i think is to be able to use say alt+up and alt+down
>to force nano to scroll up or down a single line ... the simple
>attached patch shows what i mean (open up a multi-page file, enable
>smooth scrolling, then simply start hitting up/down and alt+up/down). >it doesnt work properly, but it gives you an idea of what i'm talking
>about :)

Interesting.  I'll look into this in detail after 1.3.9 is out.  One
minor point, though: I'd prefer not to use Alt (Meta)-Up and -Down for
this if possible.  I know it would be more intuitive, but it'd also be
much more difficult to parse properly.

(Rationale: If the keypad support for a terminal is broken, or if the -K
option is used, the sequence will be Escape-[arrow key escape sequence]. While the routine for converting ncurses function keys such as KEY_UP
and KEY_DOWN to their control-key equivalents can easily be tweaked to
work with a preceding Escape, the routine for converting escape
sequences to their control-key equivalents can't.  This is mainly due to
timing issues.  Over e.g. a slow remote connection, holding down Alt and
a key will eventually result in a problem where the Escape generated by
the Alt key will be lost, and since reading escape sequences involves
reading part of the sequence, putting it back, and then reading the
entire sequence, this will lead to even worse problems in the same
vein.)

I've whipped up a temporary patch against current CVS (attached) that I
believe properly implements what your above patch tries to implement,
using Meta-- and Meta-+ instead of Meta-Up and Meta-Down, and scrolling
single lines regardless of the smooth scrolling option (since scrolling
half a page puts the cursor offscreen if it isn't at the corresponding
vertical extreme).  Is it what you're thinking of?

diff -ur nano/src/global.c nano-fixed/src/global.c
--- nano/src/global.c   2005-09-13 00:53:44.000000000 -0400
+++ nano-fixed/src/global.c     2005-09-30 22:35:50.000000000 -0400
@@ -291,6 +291,10 @@
     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 @@
     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 -ur nano/src/move.c nano-fixed/src/move.c
--- nano/src/move.c     2005-09-13 00:53:44.000000000 -0400
+++ nano-fixed/src/move.c       2005-09-30 22:35:50.000000000 -0400
@@ -512,6 +512,31 @@
     }
 }
 
+#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 @@
     }
 }
 
+#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 -ur nano/src/nano.h nano-fixed/src/nano.h
--- nano/src/nano.h     2005-09-25 22:58:16.000000000 -0400
+++ nano-fixed/src/nano.h       2005-09-30 22:35:50.000000000 -0400
@@ -360,13 +360,17 @@
 #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'
@@ -472,6 +476,10 @@
 #define NANO_BRACKET_KEY       NANO_ALT_RBRACKET
 #define NANO_NEXTWORD_KEY      NANO_CONTROL_SPACE
 #define NANO_PREVWORD_KEY      NANO_ALT_SPACE
+#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_WORDCOUNT_KEY     NANO_ALT_D
 #define NANO_CUTTILLEND_KEY    NANO_CONTROL_X
 #define NANO_CUTTILLEND_ALTKEY NANO_ALT_T
diff -ur nano/src/proto.h nano-fixed/src/proto.h
--- nano/src/proto.h    2005-09-13 00:53:44.000000000 -0400
+++ nano-fixed/src/proto.h      2005-09-30 22:35:50.000000000 -0400
@@ -333,7 +333,13 @@
 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);
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]