Added CTRL-A and CTRL-X commands.
authorDaniel Carl <danielcarl@gmx.de>
Sat, 9 Aug 2014 15:58:52 +0000 (17:58 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Sat, 9 Aug 2014 16:17:49 +0000 (18:17 +0200)
These commands allow to increment or decrement the last number in the current
url.

doc/vimb.1
src/hints.c
src/hints.h
src/hints.js
src/normal.c

index 7a1d53a..ae58bb7 100644 (file)
@@ -137,6 +137,14 @@ Go to the \fIN\fPth descendent directory of the current opened URI.
 .B gU
 Go to the domain of the current opened page.
 .TP
+.BI [ N ]CTRL\-A
+Increments the last number in URL by 1, or by \fIN\fP if given.
+.TP
+.BI [ N ]CTRL\-X
+Decrements the last number in URL by 1, or by \fIN\fP if given. Negative
+numbers are not supported as trailing numbers in URLs are often preceded by
+hyphens.
+.TP
 .B r
 Reload the website.
 .TP
index 2b8e15c..0917d97 100644 (file)
@@ -210,6 +210,15 @@ void hints_follow_link(const gboolean back, int count)
     call_hints_function("followLink", 3, arguments);
 }
 
+void hints_increment_uri(int count)
+{
+    JSValueRef arguments[] = {
+        JSValueMakeNumber(hints.ctx, count)
+    };
+
+    call_hints_function("incrementUri", 1, arguments);
+}
+
 /**
  * Checks if the given hint prompt belong to a known and valid hints mode and
  * parses the mode and is_gmode into given pointers.
index 9a786cb..5e2c947 100644 (file)
@@ -27,6 +27,7 @@ VbResult hints_keypress(int key);
 void hints_create(const char *input);
 void hints_fire(void);
 void hints_follow_link(const gboolean back, int count);
+void hints_increment_uri(int count);
 gboolean hints_parse_prompt(const char *prompt, char *mode, gboolean *is_gmode);
 void hints_clear(void);
 void hints_focus_next(const gboolean back);
index dfbf72a..f58c0ab 100644 (file)
@@ -499,6 +499,26 @@ Object.freeze((function(){
         return "ERROR:";
     }
 
+    function incrementUri(count) {
+        var oldnum, newnum, matches = location.href.match(/(.*?)(\d+)(\D*)$/);
+        if (matches) {
+            oldnum = matches[2];
+            newnum = String(Math.max(parseInt(oldnum) + count, 0));
+            /* keep prepending zeros */
+            if (/^0/.test(oldnum)) {
+                while (newnum.length < oldnum.length) {
+                    newnum = "0" + newnum;
+                }
+            }
+            matches[2] = newnum;
+
+            location.href = matches.slice(1).join("");
+
+            return "DONE:";
+        }
+        return "ERROR:";
+    }
+
     function allFrames(win) {
         var i, f, frames = [win];
         for (i = 0; i < win.frames.length; i++) {
@@ -570,10 +590,11 @@ Object.freeze((function(){
             }
             return "ERROR:";
         },
-        clear:      clear,
-        fire:       fire,
-        focus:      focus,
+        clear:        clear,
+        fire:         fire,
+        focus:        focus,
         /* not really hintings but uses similar logic */
-        followLink: followLink
+        followLink:   followLink,
+        incrementUri: incrementUri,
     };
 })());
index fa45d4a..f8b83a4 100644 (file)
@@ -62,6 +62,7 @@ static VbResult normal_focus_input(const NormalCmdInfo *info);
 static VbResult normal_g_cmd(const NormalCmdInfo *info);
 static VbResult normal_hint(const NormalCmdInfo *info);
 static VbResult normal_do_hint(const char *prompt);
+static VbResult normal_increment_decrement(const NormalCmdInfo *info);
 static VbResult normal_input_open(const NormalCmdInfo *info);
 static VbResult normal_mark(const NormalCmdInfo *info);
 static VbResult normal_navigate(const NormalCmdInfo *info);
@@ -83,7 +84,7 @@ static struct {
     NormalCommand func;
 } commands[] = {
 /* NUL 0x00 */ {NULL},
-/* ^A  0x01 */ {NULL},
+/* ^A  0x01 */ {normal_increment_decrement},
 /* ^B  0x02 */ {normal_scroll},
 /* ^C  0x03 */ {normal_navigate},
 /* ^D  0x04 */ {normal_scroll},
@@ -106,7 +107,7 @@ static struct {
 /* ^U  0x15 */ {normal_scroll},
 /* ^V  0x16 */ {NULL},
 /* ^W  0x17 */ {NULL},
-/* ^X  0x18 */ {NULL},
+/* ^X  0x18 */ {normal_increment_decrement},
 /* ^Y  0x19 */ {NULL},
 /* ^Z  0x1a */ {normal_pass},
 /* ^[  0x1b */ {normal_clear_input},
@@ -492,6 +493,14 @@ static VbResult normal_do_hint(const char *prompt)
     return RESULT_COMPLETE;
 }
 
+static VbResult normal_increment_decrement(const NormalCmdInfo *info)
+{
+    int count = info->count ? info->count : 1;
+    hints_increment_uri(info->key == CTRL('A') ? count : -count);
+
+    return RESULT_COMPLETE;
+}
+
 static VbResult normal_input_open(const NormalCmdInfo *info)
 {
     if (strchr("ot", info->key)) {