Commit Diff


commit - 576ab1416c905d70529d5acc377e3f30594d39e5
commit + 8ecd98cc9ee4478187cb6adc0034ac75a5f2ce36
blob - 075e0cb33fa7a8bb82a397eb30f157422802bdd2
blob + 875dc80f18b234350303bf0c4c30b3e62c55e347
--- mymenu.1
+++ mymenu.1
@@ -75,6 +75,10 @@ The same as Enter
 Expand the prompt to the next possible completion
 .It Shift Tab
 Expand the prompt to the previous possible completion
+.It C-n
+The same as Tab
+.It C-p
+The same as Shift-Tab
 .It Backspace
 Delete the last character
 .It C-h
blob - 8cddbf4f3c1987106fd07523162753a844d3b88b
blob + 6a0042a6c04bda58dfac2e11d5b3a4c1697868a2
--- mymenu.c
+++ mymenu.c
@@ -47,6 +47,24 @@
     cs = filter(text, lines);                   \
   }
 
+#define complete(cs, nothing_selected, p, text, textlen, status) {      \
+    struct completions *n = p                                           \
+      ? compl_select_prev(cs, nothing_selected)                         \
+      : compl_select_next(cs, nothing_selected);                        \
+                                                                        \
+    if (n != nil) {                                                     \
+      nothing_selected = false;                                         \
+      free(text);                                                       \
+      text = strdup(n->completion);                                     \
+      if (text == nil) {                                                \
+        fprintf(stderr, "Memory allocation error!\n");                  \
+        status = ERR;                                                   \
+        break;                                                          \
+      }                                                                 \
+      textlen = strlen(text);                                           \
+    }                                                                   \
+  }
+
 #define INITIAL_ITEMS 64
 
 #define cannot_allocate_memory {                        \
@@ -977,19 +995,7 @@ int main() {
 
       if (ev->keycode == XKeysymToKeycode(d, XK_Tab)) {
         bool shift = (ev->state & ShiftMask);
-        struct completions *n = shift ? compl_select_prev(cs, nothing_selected)
-                                      : compl_select_next(cs, nothing_selected);
-        if (n != nil) {
-          nothing_selected = false;
-          free(text);
-          text = strdup(n->completion);
-          if (text == nil) {
-            fprintf(stderr, "Memory allocation error!\n");
-            status = ERR;
-            break;
-          }
-          textlen = strlen(text);
-        }
+        complete(cs, nothing_selected, shift, text, textlen, status);
         draw(&r, text, cs);
         break;
       }
@@ -1063,6 +1069,12 @@ int main() {
         if (!strcmp(str, "\r")) { // C-m
           status = OK;
         }
+        if (!strcmp(str, "")) {
+          complete(cs, nothing_selected, true, text, textlen, status);
+        }
+        if (!strcmp(str, "")) {
+          complete(cs, nothing_selected, false, text, textlen, status);
+        }
         draw(&r, text, cs);
         break;
       }