nano-devel
[Top][All Lists]
Advanced

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

[Nano-devel] [PATCH 1/2] scrolling: add a function and key binding to ce


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH 1/2] scrolling: add a function and key binding to center the cursor line
Date: Wed, 4 May 2016 22:20:15 +0200

---
 doc/man/nanorc.5      |  5 ++++-
 doc/texinfo/nano.texi |  9 ++++++---
 src/global.c          | 10 ++++++++++
 src/move.c            |  7 +++++++
 src/proto.h           |  1 +
 5 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/doc/man/nanorc.5 b/doc/man/nanorc.5
index 6d61619..441537d 100644
--- a/doc/man/nanorc.5
+++ b/doc/man/nanorc.5
@@ -17,7 +17,7 @@
 .\"   Documentation License along with this program.  If not, see
 .\"   <http://www.gnu.org/licenses/>.
 .\"
-.TH NANORC 5 "version 2.5.3" "February 2016"
+.TH NANORC 5 "version 2.5.4" "May 2016"
 .\" Please adjust this date whenever revising the manpage.
 .\"
 .SH NAME
@@ -473,6 +473,9 @@ Scrolls up one line of text from the current position.
 .B scrolldown
 Scrolls down one line of text from the current position.
 .TP
+.B center
+Scrolls the line with the cursor to the middle of the screen.
+.TP
 .B prevword
 Moves the cursor to the beginning of the previous word.
 .TP
diff --git a/doc/texinfo/nano.texi b/doc/texinfo/nano.texi
index 3589f21..ed70f46 100644
--- a/doc/texinfo/nano.texi
+++ b/doc/texinfo/nano.texi
@@ -6,8 +6,8 @@
 
 @smallbook
 @set EDITION 0.3
address@hidden VERSION 2.5.2
address@hidden UPDATED February 2016
address@hidden VERSION 2.5.4
address@hidden UPDATED May 2016
 
 @dircategory Editors
 @direntry
@@ -21,7 +21,7 @@
 @titlepage
 @title GNU @code{nano}
 @subtitle a small and friendly text editor.
address@hidden version 2.5.2
address@hidden version 2.5.4
 
 @author Chris Allegretta
 @page
@@ -1061,6 +1061,9 @@ Scrolls up one line of text from the current position.
 @item scrolldown
 Scrolls down one line of text from the current position.
 
address@hidden center
+Scrolls the line with the cursor to the middle of the screen.
+
 @item prevword
 Moves the cursor to the beginning of the previous word.
 
diff --git a/src/global.c b/src/global.c
index 3421eca..3add8aa 100644
--- a/src/global.c
+++ b/src/global.c
@@ -576,6 +576,8 @@ void shortcut_init(void)
        N_("Scroll up one line without scrolling the cursor");
     const char *nano_scrolldown_msg =
        N_("Scroll down one line without scrolling the cursor");
+    const char *nano_center_msg =
+       N_("Center the line where the cursor is");
 #endif
 #ifndef DISABLE_MULTIBUFFER
     const char *nano_prevfile_msg = N_("Switch to the previous file buffer");
@@ -936,6 +938,9 @@ void shortcut_init(void)
     add_to_funcs(do_savefile, MMAIN,
        N_("Save"), IFSCHELP(nano_savefile_msg), BLANKAFTER, NOVIEW);
 
+    add_to_funcs(do_center, MMAIN,
+       N_("Center"), IFSCHELP(nano_center_msg), BLANKAFTER, VIEW);
+
     add_to_funcs(do_findprevious, MMAIN,
        N_("Previous"), IFSCHELP(nano_findprev_msg), TOGETHER, VIEW);
     add_to_funcs(do_findnext, MMAIN,
@@ -1134,6 +1139,9 @@ void shortcut_init(void)
     add_to_sclist(MMAIN, "^Z", do_suspend_void, 0);
 
 #ifndef NANO_TINY
+    add_to_sclist(MMAIN, "M-'", do_center, 0);
+    add_to_sclist(MMAIN, "M-\"", do_center, 0);
+
     /* Group of "Appearance" toggles. */
     add_to_sclist(MMAIN, "M-X", do_toggle_void, NO_HELP);
     add_to_sclist(MMAIN, "M-C", do_toggle_void, CONST_UPDATE);
@@ -1412,6 +1420,8 @@ sc *strtosc(const char *input)
        s->scfunc = do_scroll_up;
     else if (!strcasecmp(input, "scrolldown"))
        s->scfunc = do_scroll_down;
+    else if (!strcasecmp(input, "center"))
+       s->scfunc = do_center;
     else if (!strcasecmp(input, "prevword"))
        s->scfunc = do_prev_word_void;
     else if (!strcasecmp(input, "nextword"))
diff --git a/src/move.c b/src/move.c
index 8dfc476..b9429f8 100644
--- a/src/move.c
+++ b/src/move.c
@@ -533,6 +533,13 @@ void do_scroll_down(void)
 {
     do_down(TRUE);
 }
+
+/* Scroll the line with the cursor to the center of the screen. */
+void do_center(void)
+{
+    edit_update(CENTERING);
+    refresh_needed = TRUE;
+}
 #endif
 
 /* Move left one character. */
diff --git a/src/proto.h b/src/proto.h
index 0712942..fce5661 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -427,6 +427,7 @@ void do_down(
 void do_down_void(void);
 #ifndef NANO_TINY
 void do_scroll_down(void);
+void do_center(void);
 #endif
 void do_left(void);
 void do_right(void);
-- 
2.8.1




reply via email to

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