nano-devel
[Top][All Lists]
Advanced

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

[Nano-devel] [PATCH] input: allow using <Tab> and <Shift+Tab> to (un)ind


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH] input: allow using <Tab> and <Shift+Tab> to (un)indent selected region
Date: Sun, 10 Dec 2017 21:51:34 +0100

When the mark is on, instead of letting a <Tab> simply insert a Tab
character at the cursor position, let it indent the marked region.
---
 src/global.c |  1 +
 src/winio.c  | 16 +++++++++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/global.c b/src/global.c
index 606dc3c9..74b20a06 100644
--- a/src/global.c
+++ b/src/global.c
@@ -1147,6 +1147,7 @@ void shortcut_init(void)
     add_to_sclist(MMAIN, "M-^", 0, do_copy_text, 0);
     add_to_sclist(MMAIN, "M-}", 0, do_indent, 0);
     add_to_sclist(MMAIN, "M-{", 0, do_unindent, 0);
+    add_to_sclist(MMAIN, "S-Tab", KEY_BTAB, do_unindent, 0);
     add_to_sclist(MMAIN, "M-:", 0, record_macro, 0);
     add_to_sclist(MMAIN, "M-;", 0, run_macro, 0);
     add_to_sclist(MMAIN, "M-U", 0, do_undo, 0);
diff --git a/src/winio.c b/src/winio.c
index e59cd7e6..da1b18ed 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -621,8 +621,12 @@ int parse_kbinput(WINDOW *win)
     if (console && ioctl(0, TIOCLINUX, &modifiers) >= 0) {
 #ifndef NANO_TINY
        /* Is Shift being held? */
-       if (modifiers & 0x01)
+       if (modifiers & 0x01) {
+           /* A shifted <Tab> is a back tab. */
+           if (retval == TAB_CODE)
+               return KEY_BTAB;
            shift_held = TRUE;
+       }
 #endif
        /* Is Ctrl being held? */
        if (modifiers & 0x04) {
@@ -655,6 +659,16 @@ int parse_kbinput(WINDOW *win)
     }
 #endif /* __linux__ */
 
+#ifndef NANO_TINY
+    /* When <Tab> is pressed while the mark is on, do an indent. */
+    if (retval == TAB_CODE && openfile->mark && currmenu == MMAIN) {
+       const sc *command = first_sc_for(MMAIN, do_indent);
+
+       meta_key = command->meta;
+       return command->keycode;
+    }
+#endif
+
     switch (retval) {
 #ifdef KEY_SLEFT
        /* Slang doesn't support KEY_SLEFT. */
-- 
2.14.3




reply via email to

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