[PATCH] possible new feature: Alt+Left and Alt+Right scroll a tabsize sideways

Benno Schulenberg <[email protected]> Sun, 8 Mar 2026 12:41:07 +0100
Newsgroups gmane.editors.nano.devel
Message-ID <[email protected]>
Whenever there is now an overlong line onscreen, I feel the urge to tap
<Alt+Right> a few times to see what it is currently hidden offscreen.
So, humor this urge and make <Alt+Left> and <Alt+Right> scroll sideways.

This will inconvenience users (like myself) who have become accustomed
to using <Alt+Left> and <Alt+Right> for switching between buffers, so
it will probably be necessary to make it possible to rebind M-Left and
M-Right.  But first...

Who would like to have these keystrokes for scrolling sideways?
---
 src/global.c     | 12 ++++++------
 src/move.c       | 39 +++++++++++++++++++++++++++++++++++++++
 src/prototypes.h |  4 ++++
 3 files changed, 49 insertions(+), 6 deletions(-)

diff --git a/src/global.c b/src/global.c
index d602bd80..c2fc9d63 100644
--- a/src/global.c
+++ b/src/global.c
@@ -1365,10 +1365,10 @@ void shortcut_init(void)
 		add_to_sclist(MMOST|MBROWSER|MHELP, "\xE2\x96\xb8", KEY_RIGHT, do_right, 0);
 		add_to_sclist(MSOME, "^\xE2\x97\x82", CONTROL_LEFT, to_prev_word, 0);
 		add_to_sclist(MSOME, "^\xE2\x96\xb8", CONTROL_RIGHT, to_next_word, 0);
-#if defined(ENABLE_MULTIBUFFER) && !defined(NANO_TINY)
+#ifndef NANO_TINY
 		if (!on_a_vt) {
-			add_to_sclist(MMAIN, "M-\xE2\x97\x82", ALT_LEFT, switch_to_prev_buffer, 0);
-			add_to_sclist(MMAIN, "M-\xE2\x96\xb8", ALT_RIGHT, switch_to_next_buffer, 0);
+			add_to_sclist(MMAIN, "M-\xE2\x97\x82", ALT_LEFT, scroll_left, 0);
+			add_to_sclist(MMAIN, "M-\xE2\x96\xb8", ALT_RIGHT, scroll_right, 0);
 		}
 #endif
 	} else
@@ -1378,10 +1378,10 @@ void shortcut_init(void)
 		add_to_sclist(MMOST|MBROWSER|MHELP, "Right", KEY_RIGHT, do_right, 0);
 		add_to_sclist(MSOME, "^Left", CONTROL_LEFT, to_prev_word, 0);
 		add_to_sclist(MSOME, "^Right", CONTROL_RIGHT, to_next_word, 0);
-#if defined(ENABLE_MULTIBUFFER) && !defined(NANO_TINY)
+#ifndef NANO_TINY
 		if (!on_a_vt) {
-			add_to_sclist(MMAIN, "M-Left", ALT_LEFT, switch_to_prev_buffer, 0);
-			add_to_sclist(MMAIN, "M-Right", ALT_RIGHT, switch_to_next_buffer, 0);
+			add_to_sclist(MMAIN, "M-Left", ALT_LEFT, scroll_left, 0);
+			add_to_sclist(MMAIN, "M-Right", ALT_RIGHT, scroll_right, 0);
 		}
 #endif
 	}
diff --git a/src/move.c b/src/move.c
index 6fdaae82..322d0321 100644
--- a/src/move.c
+++ b/src/move.c
@@ -691,3 +691,42 @@ void do_right(void)
 
 	edit_redraw(was_current, FLOWING);
 }
+
+#ifndef NANO_TINY
+/* Scroll the viewport horizontally to the left, when possible. */
+void scroll_left(void)
+{
+	size_t frame_x;
+
+	if (openfile->brink < tabsize)
+		openfile->brink = 0;
+	else
+		openfile->brink -= tabsize;
+
+	frame_x = actual_x(openfile->current->data, openfile->brink + editwincols - CUSHION - 1);
+
+	if (openfile->current_x > frame_x) {
+		openfile->current_x = frame_x;
+		openfile->placewewant = xplustabs();
+	}
+
+	refresh_needed = TRUE;
+}
+
+/* Scroll the viewport horizontally to the right, when possible. */
+void scroll_right(void)
+{
+	size_t frame_x;
+
+	openfile->brink += tabsize;
+
+	frame_x = actual_x(openfile->current->data, openfile->brink + CUSHION + 1);
+
+	if (openfile->current_x < frame_x) {
+		openfile->current_x = frame_x;
+		openfile->placewewant = xplustabs();
+	}
+
+	refresh_needed = TRUE;
+}
+#endif /* !NANO_TINY */
diff --git a/src/prototypes.h b/src/prototypes.h
index 4759481e..701a3eba 100644
--- a/src/prototypes.h
+++ b/src/prototypes.h
@@ -394,6 +394,10 @@ void do_scroll_down(void);
 #endif
 void do_left(void);
 void do_right(void);
+#ifndef NANO_TINY
+void scroll_left(void);
+void scroll_right(void);
+#endif
 
 /* Most functions in nano.c. */
 linestruct *make_new_node(linestruct *prevnode);
-- 
2.53.0