[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] funny feature: make Alt+< and Alt+> scroll the help lines sidewa
From: |
Benno Schulenberg |
Subject: |
[PATCH] funny feature: make Alt+< and Alt+> scroll the help lines sideways |
Date: |
Sun, 29 Aug 2021 14:23:20 +0200 |
This allows the user to get reminders on the screen also for the
less common functions, without having to access the ^G help text.
---
src/definitions.h | 2 ++
src/global.c | 34 +++++++++++++++++++++++++++++++---
src/nano.c | 8 ++++++++
src/prototypes.h | 3 +++
src/winio.c | 4 ++++
5 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/src/definitions.h b/src/definitions.h
index 2ce72260..02ee08cf 100644
--- a/src/definitions.h
+++ b/src/definitions.h
@@ -111,6 +111,8 @@
#define BLIND FALSE
#define VISIBLE TRUE
+#define HELPLINE_ITEMS (((COLS + 40) / 20) * 2)
+
#define JUSTFIND 0
#define REPLACING 1
#define INREGION 2
diff --git a/src/global.c b/src/global.c
index 0e9b0618..066a28af 100644
--- a/src/global.c
+++ b/src/global.c
@@ -141,6 +141,11 @@ ssize_t stripe_column = 0;
/* The column at which a vertical bar will be drawn. */
#endif
+size_t entries_in_main = 2;
+ /* The total number of items in the main menu -- calculated
later. */
+int show_from = 0;
+ /* Display help items in the main menu starting from this
index. */
+
linestruct *cutbuffer = NULL;
/* The buffer where we store cut text. */
linestruct *cutbottom = NULL;
@@ -470,7 +475,7 @@ const keystruct *first_sc_for(int menu, void (*func)(void))
size_t shown_entries_for(int menu)
{
funcstruct *item = allfuncs;
- size_t maximum = ((COLS + 40) / 20) * 2;
+ size_t maximum = HELPLINE_ITEMS;
size_t count = 0;
while (count < maximum && item != NULL) {
@@ -560,6 +565,29 @@ functionptrtype interpret(int *keycode)
}
#endif /* ENABLE_BROWSER || ENABLE_HELP */
+#ifndef NANO_TINY
+/* Make the "bar" of help items scroll to the left. */
+void roll_left(void)
+{
+ if (show_from > 0)
+ show_from -= HELPLINE_ITEMS;
+ else
+ show_from = entries_in_main - (entries_in_main %
HELPLINE_ITEMS);
+
+ currmenu = MMOST;
+}
+
+/* Make the "bar" of help items scroll to the right. */
+void roll_right(void)
+{
+ show_from += HELPLINE_ITEMS;
+ if (show_from > entries_in_main)
+ show_from = 0;
+
+ currmenu = MMOST;
+}
+#endif
+
/* These two tags are used elsewhere too, so they are global. */
/* TRANSLATORS: Try to keep the next two strings at most 10 characters. */
const char *exit_tag = N_("Exit");
@@ -1366,13 +1394,13 @@ void shortcut_init(void)
add_to_sclist(MMAIN|MHELP, "M-=", 0, do_scroll_down, 0);
#endif
#ifdef ENABLE_MULTIBUFFER
- add_to_sclist(MMAIN, "M-<", 0, switch_to_prev_buffer, 0);
add_to_sclist(MMAIN, "M-,", 0, switch_to_prev_buffer, 0);
- add_to_sclist(MMAIN, "M->", 0, switch_to_next_buffer, 0);
add_to_sclist(MMAIN, "M-.", 0, switch_to_next_buffer, 0);
#endif
add_to_sclist(MMOST, "M-V", 0, do_verbatim_input, 0);
#ifndef NANO_TINY
+ add_to_sclist(MMAIN, "M-<", 0, roll_left, 0);
+ add_to_sclist(MMAIN, "M->", 0, roll_right, 0);
add_to_sclist(MMAIN, "M-T", 0, cut_till_eof, 0);
add_to_sclist(MEXECUTE, "^V", 0, cut_till_eof, 0);
add_to_sclist(MMAIN, "M-D", 0, do_wordlinechar_count, 0);
diff --git a/src/nano.c b/src/nano.c
index 3dd9f917..6af45c24 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -433,6 +433,13 @@ void window_init(void)
keypad(bottomwin, TRUE);
}
+ entries_in_main = 0;
+
+ /* Determine the total number of presentable items in the main menu. */
+ for (funcstruct *item = allfuncs; item != NULL; item = item->next)
+ if (item->menus & MMAIN)
+ entries_in_main++;
+
#ifdef ENABLED_WRAPORJUSTIFY
/* Set up the wrapping point, accounting for screen width when
negative. */
if (COLS + fill < 0)
@@ -1048,6 +1055,7 @@ void regenerate_screen(void)
* recreate the subwindows with their (new) sizes. */
terminal_init();
window_init();
+ show_from = 0;
/* If we have an open buffer, redraw the contents of the subwindows. */
if (openfile) {
diff --git a/src/prototypes.h b/src/prototypes.h
index 07f8f75e..44c8ba32 100644
--- a/src/prototypes.h
+++ b/src/prototypes.h
@@ -99,6 +99,9 @@ extern int *bardata;
extern ssize_t stripe_column;
#endif
+extern size_t entries_in_main;
+extern int show_from;
+
extern linestruct *cutbuffer;
extern linestruct *cutbottom;
extern bool keep_cutbuffer;
diff --git a/src/winio.c b/src/winio.c
index 6984a247..b713db5f 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -2388,6 +2388,7 @@ void post_one_key(const char *keystroke, const char *tag,
int width)
void bottombars(int menu)
{
size_t index, number, itemwidth;
+ int skip = show_from;
const keystruct *s;
funcstruct *f;
@@ -2422,6 +2423,9 @@ void bottombars(int menu)
if (s == NULL)
continue;
+ if (menu == MMAIN && skip-- > 0)
+ continue;
+
wmove(bottomwin, 1 + index % 2, (index / 2) * itemwidth);
/* When the number is uneven, the penultimate item can be
double wide. */
--
2.29.3
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] funny feature: make Alt+< and Alt+> scroll the help lines sideways,
Benno Schulenberg <=