[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nano-devel] [PATCH 1/2] scrolling: add a function and a key binding to
From: |
Benno Schulenberg |
Subject: |
[Nano-devel] [PATCH 1/2] scrolling: add a function and a key binding to center the cursor line |
Date: |
Sun, 11 Mar 2018 17:54:43 +0100 |
From: Benno Schulenberg <address@hidden>
---
doc/nano.texi | 3 +++
doc/nanorc.5 | 3 +++
src/global.c | 15 +++++++++++++--
src/move.c | 7 +++++++
src/proto.h | 1 +
5 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/doc/nano.texi b/doc/nano.texi
index 04dc5756..999f6e9b 100644
--- a/doc/nano.texi
+++ b/doc/nano.texi
@@ -1193,6 +1193,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/doc/nanorc.5 b/doc/nanorc.5
index 0e6198aa..a85d2d07 100644
--- a/doc/nanorc.5
+++ b/doc/nanorc.5
@@ -548,6 +548,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/src/global.c b/src/global.c
index 2d4d04f0..b86014c5 100644
--- a/src/global.c
+++ b/src/global.c
@@ -580,6 +580,8 @@ void shortcut_init(void)
N_("Scroll up one line without scrolling the cursor");
const char *scrolldown_gist =
N_("Scroll down one line without scrolling the cursor");
+ const char *center_gist =
+ N_("Center the line where the cursor is");
#endif
#ifdef ENABLE_MULTIBUFFER
const char *prevfile_gist = N_("Switch to the previous file buffer");
@@ -978,6 +980,9 @@ void shortcut_init(void)
add_to_funcs(do_savefile, MMAIN,
N_("Save"), WITHORSANS(savefile_gist), BLANKAFTER, NOVIEW);
+ add_to_funcs(do_center, MMAIN,
+ N_("Center"), WITHORSANS(center_gist), BLANKAFTER, VIEW);
+
#ifdef ENABLE_HISTORIES
add_to_funcs(get_history_older_void,
MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE,
N_("PrevHstory"), WITHORSANS(prevhistory_gist), TOGETHER, VIEW);
@@ -1225,10 +1230,14 @@ void shortcut_init(void)
#ifdef ENABLE_JUSTIFY
add_to_sclist(MMAIN|MWHEREIS, "M-J", 0, do_full_justify, 0);
#endif
- add_to_sclist(MMAIN|MHELP|MBROWSER, "^L", 0, total_refresh, 0);
add_to_sclist(MMAIN, "^Z", 0, do_suspend_void, 0);
-#ifndef NANO_TINY
+#ifdef NANO_TINY
+ add_to_sclist(MMAIN|MHELP|MBROWSER, "^L", 0, total_refresh, 0);
+#else
+ add_to_sclist(MMAIN, "^L", 0, do_center, 0);
+ add_to_sclist(MHELP|MBROWSER, "^L", 0, total_refresh, 0);
+
/* Group of "Appearance" toggles. */
add_to_sclist(MMAIN, "M-X", 0, do_toggle_void, NO_HELP);
add_to_sclist(MMAIN, "M-C", 0, do_toggle_void, CONSTANT_SHOW);
@@ -1528,6 +1537,8 @@ sc *strtosc(const char *input)
s->func = do_scroll_up;
else if (!strcasecmp(input, "scrolldown"))
s->func = do_scroll_down;
+ else if (!strcasecmp(input, "center"))
+ s->func = do_center;
else if (!strcasecmp(input, "cutwordleft"))
s->func = do_cut_prev_word;
else if (!strcasecmp(input, "cutwordright"))
diff --git a/src/move.c b/src/move.c
index f559fb41..2613fd20 100644
--- a/src/move.c
+++ b/src/move.c
@@ -558,6 +558,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)
+{
+ adjust_viewport(CENTERING);
+ total_refresh();
+}
#endif
/* Move left one character. */
diff --git a/src/proto.h b/src/proto.h
index 551aa650..9b179427 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -393,6 +393,7 @@ void do_down_void(void);
#ifndef NANO_TINY
void do_scroll_up(void);
void do_scroll_down(void);
+void do_center(void);
#endif
void do_left(void);
void do_right(void);
--
2.16.2
- [Nano-devel] [PATCH 1/2] scrolling: add a function and a key binding to center the cursor line,
Benno Schulenberg <=