From: Daniel Carl Date: Sun, 29 Jun 2014 19:43:56 +0000 (+0200) Subject: Added new hint mode ;x (#65). X-Git-Url: https://git.owens.tech/assets/static/git-logo.png/assets/static/git-logo.png/git?a=commitdiff_plain;h=cf52a8b29aad205a4804c153b54324a7c07d23ad;p=vimb.git Added new hint mode ;x (#65). This hint modes calls a user defined vimb command if a hint was fired. The command can be change and set via ':set x-hint-command' on runtime. --- diff --git a/doc/vimb.1 b/doc/vimb.1 index 4d82b89..edcd6bb 100644 --- a/doc/vimb.1 +++ b/doc/vimb.1 @@ -285,6 +285,10 @@ Push the hint's URI to the beginning of the read it later queue like the `:qunshift' command. This is only available if vimb was compiled with QUEUE feature. .TP +.B ;x +Hints like ;o, but instead of opening the hinted URI, the +`x-hint-command' is run in vimb. +.TP .B ;y Yank hint's destination location into primary and secondary clipboard. .TP @@ -370,7 +374,7 @@ Moves the cursor after the char in inputbox. .B CTRL\-V Pass the next key press directly to gtk. .TP -.B CTRL\-R {a-z%:/} +.B CTRL\-R {a-z%:/;} Insert the content of given register at cursor position. See also section REGISTERS. .SS Command Line History @@ -625,6 +629,10 @@ Contains the most recent executed ex command. .TP .B \[char34]/ Contains the most recent search-pattern. +.TP +.B \[char34]; +Contains the last hinted URL. This can be used in `x-hint-command' to get the +URL of the hint. .SH COMPLETIONS The completions are triggered by pressing `` or `` in the activated inputbox. Depending of the current inserted content different @@ -933,6 +941,21 @@ If 'on' the user defined styles-sheet is used. .B timeoutlen (int) The time in milliseconds that is waited for a key code or mapped key sequence to complete. +.TP +.B x-hint-command (string) +Command used if hint mode ;x is fired. The command can be any vimb command +string. Note that the command is run through the mapping mechanism of vimb so +it might change the behaviour by adding or changing mappings. +.RS +.P +.PD 0 +.IP ":set x-hint-command=50G" +Not really useful. If the hint is fired, scroll to the middle of the page. +.IP ":set x-hint-command=:sh! curl -e % ;" +This fills the inputbox with the prefilled download command and replaces +`%' with the current URI and `;' with the URI of the hinted element. +.PD +.RE .SH FILES .TP .B $XDG_CONFIG_HOME/vimb/config @@ -962,7 +985,7 @@ Holds the read it later queue filled by `qpush' if vimb has been compiled with QUEUE feature. .TP .B $XDG_CONFIG_HOME/vimb/hsts -Holds the known hsts hosts if vimb is compliled with HTTP strict transport +Holds the known hsts hosts if vimb is compiled with HTTP strict transport security feature. .TP .B $XDG_CONFIG_HOME/vimb/scripts.js diff --git a/src/hints.c b/src/hints.c index eb22475..f4c85d2 100644 --- a/src/hints.c +++ b/src/hints.c @@ -218,10 +218,10 @@ gboolean hints_parse_prompt(const char *prompt, char *mode, gboolean *is_gmode) gboolean res; char pmode = '\0'; #ifdef FEATURE_QUEUE - static char *modes = "eiIoOpPstTyY"; + static char *modes = "eiIoOpPstTxyY"; static char *g_modes = "IpPstyY"; #else - static char *modes = "eiIoOstTyY"; + static char *modes = "eiIoOstTxyY"; static char *g_modes = "IstyY"; #endif @@ -296,8 +296,10 @@ static gboolean call_hints_function(const char *func, int count, JSValueRef para mode_enter('n'); } - char *v = (value + 5); - Arg a = {0}; + char *v = (value + 5); + Arg a = {0}; + /* put the hinted value into register "; */ + vb_register_add(';', v); switch (hints.mode) { /* used if images should be opened */ case 'i': @@ -321,6 +323,10 @@ static gboolean call_hints_function(const char *func, int count, JSValueRef para command_save(&a); break; + case 'x': + map_handle_string(GET_CHAR("x-hint-command"), true); + break; + case 'y': case 'Y': a.i = COMMAND_YANK_ARG; diff --git a/src/hints.js b/src/hints.js index e15d442..dfbf72a 100644 --- a/src/hints.js +++ b/src/hints.js @@ -513,17 +513,17 @@ Object.freeze((function(){ var prop, /* holds the xpaths for the different modes */ xpathmap = { - otY: "//*[@href] | //*[@onclick or @tabindex or @class='lk' or @role='link' or @role='button'] | //input[not(@type='hidden' or @disabled or @readonly)] | //textarea[not(@disabled or @readonly)] | //button | //select", - e: "//input[not(@type) or @type='text'] | //textarea", - iI: "//img[@src]", - OpPsTy: "//*[@href] | //img[@src and not(ancestor::a)] | //iframe[@src]" + otY: "//*[@href] | //*[@onclick or @tabindex or @class='lk' or @role='link' or @role='button'] | //input[not(@type='hidden' or @disabled or @readonly)] | //textarea[not(@disabled or @readonly)] | //button | //select", + e: "//input[not(@type) or @type='text'] | //textarea", + iI: "//img[@src]", + OpPsTxy: "//*[@href] | //img[@src and not(ancestor::a)] | //iframe[@src]" }, /* holds the actions to perform on hint fire */ actionmap = { - o: function(e) {open(e, false); return "DONE:";}, - t: function(e) {open(e, true); return "DONE:";}, - eiIOpPsTy: function(e) {return "DATA:" + getSrc(e);}, - Y: function(e) {return "DATA:" + (e.textContent || "");} + o: function(e) {open(e, false); return "DONE:";}, + t: function(e) {open(e, true); return "DONE:";}, + eiIOpPsTxy: function(e) {return "DATA:" + getSrc(e);}, + Y: function(e) {return "DATA:" + (e.textContent || "");} }; config = { diff --git a/src/main.h b/src/main.h index dd8d867..ef9c0d9 100644 --- a/src/main.h +++ b/src/main.h @@ -115,7 +115,7 @@ #define VB_MARK_SIZE (sizeof(VB_MARK_CHARS) - 1) #define VB_USER_REG "abcdefghijklmnopqrstuvwxyz" -#define VB_REG_CHARS VB_USER_REG "%:/" +#define VB_REG_CHARS VB_USER_REG "%:/;" #define VB_REG_SIZE (sizeof(VB_REG_CHARS) - 1) /* enums */ diff --git a/src/setting.c b/src/setting.c index c6cf54d..a97ec0c 100644 --- a/src/setting.c +++ b/src/setting.c @@ -140,6 +140,7 @@ void setting_init() #ifdef FEATURE_HSTS setting_add("hsts", TYPE_BOOLEAN, &on, hsts, NULL); #endif + setting_add("x-hint-command", TYPE_CHAR, &":o ;", NULL, NULL); /* initialize the shortcuts and set the default shortcuts */ shortcut_init();