summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Carl <danielcarl@gmx.de>2014-08-09 17:58:52 +0200
committerDaniel Carl <danielcarl@gmx.de>2014-08-09 18:17:49 +0200
commita9404c9fb8a63a14cfcd65c0c77dadd4be88767f (patch)
tree9ce0c0739af91ac03c862aec786af153f0db89c9
parent716d6d7c1b86eb7d440bad3f28c8c766eaabc4db (diff)
Added CTRL-A and CTRL-X commands.
These commands allow to increment or decrement the last number in the current url.
-rw-r--r--doc/vimb.18
-rw-r--r--src/hints.c9
-rw-r--r--src/hints.h1
-rw-r--r--src/hints.js29
-rw-r--r--src/normal.c13
5 files changed, 54 insertions, 6 deletions
diff --git a/doc/vimb.1 b/doc/vimb.1
index 7a1d53a..ae58bb7 100644
--- a/doc/vimb.1
+++ b/doc/vimb.1
@@ -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
diff --git a/src/hints.c b/src/hints.c
index 2b8e15c..0917d97 100644
--- a/src/hints.c
+++ b/src/hints.c
@@ -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.
diff --git a/src/hints.h b/src/hints.h
index 9a786cb..5e2c947 100644
--- a/src/hints.h
+++ b/src/hints.h
@@ -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);
diff --git a/src/hints.js b/src/hints.js
index dfbf72a..f58c0ab 100644
--- a/src/hints.js
+++ b/src/hints.js
@@ -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,
};
})());
diff --git a/src/normal.c b/src/normal.c
index fa45d4a..f8b83a4 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -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)) {