[Vimperator] Configurable hints for vimperator 0.6
Daniel Trstenjak
Daniel.Trstenjak at online.de
Wed Apr 30 12:09:46 PDT 2008
Hi Martin,
I have made the desired changes:
- added documentation to 'options.txt'
- changed the code style issues
- removed focusedhintstyle option
Also I changed 'char-hints.js' so that the options
'hintstyle/{activelink,link}{fg,bg}color' are considered.
> That's the biggest problem. While it probably would work, we decided
> against such a behavior months ago. The conclusion was, that we wanted
> to have:
>
> :highlight Hint bg=black fg=white
>
> and
>
> :colorscheme myscheme (which actually just sources
> ~/.vimperator/colors/myscheme.vim).
>
> So the question is, whether you (or somebody with time) is able to
> implement :colorscheme (easy) and :highlight (hard) commands or we
> should go with the more ugly design. IF we keep linkfgcolor, etc.
> options (temporarily at least), the patch would also need documentation
> for these options in options.txt. Documentation for all :highlight
> groups is not necassary.
I have to admit, I'm not proud of the color options. I just wanted to
get as fast as possible rid of the yellow background. It's okay if
it's just a temporary solution.
In terms of vim, a colorscheme is just a group of highlight definitions.
So I don't understand why the colorscheme command should be easier to
implement then the highlight command.
> Actually the future plan for hints would be to match hints with some
> heuristics. The plan is to prefer matches for shorter links where the
> hint text appears at the beginning or at least at the start of a word
> boundary. However, since I don't know when I find time for that, maybe
> this option would be a good start although I really think a good
> heuristics would be better than that option (but harder to code as well ;)).
Should the heuristics only choose the active link, or also execute it.
For example, if you have two links which match with the hintstring 'be'.
The frist link matches at the beginning, and the second in the middle.
If matching at the beginning is prefered, should then the first link
directly be executed, or should it only be activated? Directly executing
the link could induce unanticipated behavoir.
It's okay to have such a heuristics. But I think it's nice to have this
part of vimperator configurable. To try different approaches by just
replacing a javascript function.
Greetings,
Daniel
-------------- next part --------------
? downloads
? vimperator-0.6-20080430.patch
? src/build.0.6pre.Linux
? src/chrome/vimperator.jar
? src/locale/en-US/autocommands.html
? src/locale/en-US/browsing.html
? src/locale/en-US/buffer.html
? src/locale/en-US/developer.html
? src/locale/en-US/intro.html
? src/locale/en-US/marks.html
? src/locale/en-US/options.html
? src/locale/en-US/repeat.html
? src/locale/en-US/starting.html
? src/locale/en-US/tabs.html
? src/locale/en-US/various.html
Index: src/vimperator.vim
===================================================================
RCS file: /cvs/vimperator/src/vimperator.vim,v
retrieving revision 1.30
diff -u -r1.30 vimperator.vim
--- src/vimperator.vim 7 Apr 2008 14:28:18 -0000 1.30
+++ src/vimperator.vim 30 Apr 2008 18:42:27 -0000
@@ -38,10 +38,11 @@
syn match vimperatorCommandWrapper "\%(^\s*:\=\)\@<=\%(!\|\h\w*\>\)" contains=vimperatorCommand
syn region vimperatorSet matchgroup=vimperatorCommand start="\%(^\s*:\=\)\@<=\<set\=\>" end="$" keepend oneline contains=vimperatorOption
-syn keyword vimperatorOption activate act complete cpt defsearch ds editor extendedhinttags eht focusedhintstyle fhs fullscreen fs
- \ nofullscreen nofs guioptions go hintstyle hs hinttags ht hinttimeout hto history hi hlsearch hls nohlsearch nohls
- \ hlsearchstyle hlss nohlsearchstyle nohlss incsearch is noincsearch nois ignorecase ic noignorecase noic insertmode im
- \ noinsertmode noim laststatus ls linksearch lks nolinksearch nolks more nextpattern nomore pageinfo pa popups pps preload
+syn keyword vimperatorOption activate act activelinkfgcolor alfc activelinkbgcolor albc complete cpt defsearch ds editor extendedhinttags eht
+ \ fullscreen fs nofullscreen nofs guioptions go hintstyle hs hinttags ht hinttimeout hto history hi
+ \ hlsearch hls nohlsearch nohls hlsearchstyle hlss nohlsearchstyle nohlss incsearch is noincsearch nois ignorecase ic
+ \ noignorecase noic insertmode im noinsertmode noim laststatus ls linkbgcolor lbc linkfgcolor lfc linksearch lks linkmatching lm
+ \ nolinksearch nolks more nextpattern nomore pageinfo pa popups pps preload
\ nopreload previewheight pvh previouspattern scroll scr showmode smd noshowmode nosmd showstatuslinks ssli showtabline
\ stal smartcase scs nosmartcase noscs titlestring usermode um nousermode noum verbose vbs visualbell vb novisualbell novb
\ wildmode wim wildoptions wop
Index: src/content/hints.js
===================================================================
RCS file: /cvs/vimperator/src/content/hints.js,v
retrieving revision 1.55
diff -u -r1.55 hints.js
--- src/content/hints.js 30 Mar 2008 13:13:41 -0000 1.55
+++ src/content/hints.js 30 Apr 2008 18:42:28 -0000
@@ -89,15 +89,7 @@
var scrollY = doc.defaultView.scrollY;
var baseNodeAbsolute = doc.createElementNS("http://www.w3.org/1999/xhtml", "span");
- baseNodeAbsolute.style.backgroundColor = "red";
- baseNodeAbsolute.style.color = "white";
- baseNodeAbsolute.style.position = "absolute";
- baseNodeAbsolute.style.fontSize = "10px";
- baseNodeAbsolute.style.fontWeight = "bold";
- baseNodeAbsolute.style.lineHeight = "10px";
- baseNodeAbsolute.style.padding = "0px 1px 0px 0px";
- baseNodeAbsolute.style.zIndex = "10000001";
- baseNodeAbsolute.style.display = "none";
+ baseNodeAbsolute.style.cssText = liberator.options["hintstyle"];
baseNodeAbsolute.className = "liberator-hint";
var elem, tagname, text, span, rect;
@@ -155,11 +147,58 @@
{
var oldElem = validHints[oldID - 1];
if (oldElem)
- oldElem.style.backgroundColor = "yellow";
+ oldElem.style.backgroundColor = liberator.options["linkbgcolor"];
var newElem = validHints[newID - 1];
if (newElem)
- newElem.style.backgroundColor = "#88FF00";
+ newElem.style.backgroundColor = liberator.options["activelinkbgcolor"];
+ }
+
+ function containsTokensMatcher(hintString)
+ {
+ var tokens = hintString.split(/ +/);
+
+ function containsTokens(textOfLink)
+ {
+ for (var i = 0; i < tokens.length; i++)
+ {
+ if (textOfLink.indexOf(tokens[i]) < 0)
+ return false;
+ }
+
+ return true;
+ }
+
+ return containsTokens;
+ }
+
+ function startsWithMatcher(hintString)
+ {
+ var regex = new RegExp((hintString == "" ? ".*" : ("^\\s*" + hintString + ".*")));
+
+ function startsWith(textOfLink)
+ {
+ return (textOfLink.search(regex) == 0);
+ }
+
+ return startsWith;
+ }
+
+ function hintMatcher(hintString)
+ {
+ var hintMatching = liberator.options["hintmatching"];
+
+ if (hintMatching == "contains")
+ return containsTokensMatcher(hintString);
+ else if (hintMatching == "startswith")
+ return startsWithMatcher(hintString);
+ else
+ {
+ liberator.echoerr("Invalid hintmatching type: " + hintMatching);
+ return null;
+ }
+
+ return null;
}
function showHints()
@@ -169,11 +208,16 @@
var height = win.innerHeight;
var width = win.innerWidth;
- liberator.log("Show hints matching: " + hintString, 7);
+ liberator.log("Show hints matching: \"" + hintString + "\"", 7);
+
+ var linkfgcolor = liberator.options["linkfgcolor"];
+ var linkbgcolor = liberator.options["linkbgcolor"];
+ var activelinkfgcolor = liberator.options["activelinkfgcolor"];
+ var activelinkbgcolor = liberator.options["activelinkbgcolor"];
var elem, tagname, text, rect, span, imgspan;
var hintnum = 1;
- var findTokens = hintString.split(/ +/);
+ var validHint = hintMatcher(hintString);
var activeHint = hintNumber || 1;
validHints = [];
@@ -193,19 +237,16 @@
span = hints[i][2];
imgspan = hints[i][3];
- for (var k = 0; k < findTokens.length; k++)
+ if (! validHint(text))
{
- if (text.indexOf(findTokens[k]) < 0)
- {
- span.style.display = "none";
- if (imgspan)
- imgspan.style.display = "none";
-
- // reset background color
- elem.style.backgroundColor = hints[i][4];
- elem.style.color = hints[i][5];
- continue outer;
- }
+ span.style.display = "none";
+ if (imgspan)
+ imgspan.style.display = "none";
+
+ // reset background color
+ elem.style.backgroundColor = hints[i][4];
+ elem.style.color = hints[i][5];
+ continue outer;
}
if (text == "" && elem.firstChild && elem.firstChild.tagName == "IMG")
@@ -228,13 +269,13 @@
hints[i][3] = imgspan;
doc.body.appendChild(imgspan);
}
- imgspan.style.backgroundColor = (activeHint == hintnum) ? "#88FF00" : "yellow";
+ imgspan.style.backgroundColor = (activeHint == hintnum) ? activelinkbgcolor : linkbgcolor;
imgspan.style.display = "inline";
}
if (!imgspan)
- elem.style.backgroundColor = (activeHint == hintnum) ? "#88FF00" : "yellow";
- elem.style.color = "black";
+ elem.style.backgroundColor = (activeHint == hintnum) ? activelinkbgcolor : linkbgcolor;
+ elem.style.color = (activeHint == hintnum) ? activelinkfgcolor : linkfgcolor;
span.textContent = "" + (hintnum++);
span.style.display = "inline";
validHints.push(elem);
@@ -404,9 +445,6 @@
liberator.options.add(["extendedhinttags", "eht"],
"XPath string of hintable elements activated by ';'",
"string", DEFAULT_HINTTAGS);
- liberator.options.add(["focusedhintstyle", "fhs"],
- "CSS specification of focused hints",
- "string", "z-index:5000; font-family:monospace; font-size:12px; color:ButtonText; background-color:ButtonShadow; border-color:ButtonShadow; border-width:1px; border-style:solid; padding:0px 1px 0px 1px; position:absolute;");
liberator.options.add(["hintstyle", "hs"],
"CSS specification of unfocused hints",
"string", "z-index:5000; font-family:monospace; font-size:12px; color:white; background-color:red; border-color:ButtonShadow; border-width:0px; border-style:solid; padding:0px 1px 0px 1px; position:absolute;");
@@ -420,7 +458,27 @@
validator: function (value) { return value >= 0; }
});
- /////////////////////////////////////////////////////////////////////////////}}}
+ liberator.options.add(["linkfgcolor", "lfc"],
+ "Foreground color of a link during hint mode",
+ "string", "black")
+
+ liberator.options.add(["linkbgcolor", "lbc"],
+ "Background color of a link during hint mode",
+ "string", "yellow")
+
+ liberator.options.add(["activelinkfgcolor", "alfc"],
+ "Foreground color of the current active link during hint mode",
+ "string", "black")
+
+ liberator.options.add(["activelinkbgcolor", "albc"],
+ "Background color of the current active link during hint mode",
+ "string", "#88FF00")
+
+ liberator.options.add(["hintmatching", "lm"],
+ "How links are matched",
+ "string", "contains")
+
+ ///////////////////////////////////////////////////////////////////////////
////////////////////// MAPPINGS ////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
Index: src/locale/en-US/options.txt
===================================================================
RCS file: /cvs/vimperator/src/locale/en-US/options.txt,v
retrieving revision 1.9
diff -u -r1.9 options.txt
--- src/locale/en-US/options.txt 23 Apr 2008 18:00:53 -0000 1.9
+++ src/locale/en-US/options.txt 30 Apr 2008 18:42:28 -0000
@@ -172,12 +172,58 @@
The XPath string of hintable elements activated by [m];[m].
____
-|\'fhs'| |\'focusedhintstyle'|
-||'focusedhintstyle' 'fhs'|| string
+|\'hs'| |\'hintstyle'|
+||'hintstyle' 'hs'|| string
____
-(default: z-index:5000; font-family:monospace; font-size:12px; color:ButtonText; background-color:ButtonShadow; border-color:ButtonShadow; border-width:1px; border-style:solid; padding:0px 1px 0px 1px; position:absolute;)
+(default: z-index:5000; font-family:monospace; font-size:12px; color:white; background-color:red; border-color:ButtonShadow; border-width:0px; border-style:solid; padding:0px 1px 0px 1px; position:absolute;)
+
+CSS specification of hints
+____
+
+|\'lfc'| |\'linkfgcolor'|
+||'linkfgcolor' 'lfc'|| string
+____
+(default: black)
+
+Foreground color of a link during hint mode.
+____
+
+|\'lbc'| |\'linkbgcolor'|
+||'linkbgcolor' 'lbc'|| string
+____
+(default: yellow)
+
+Background color of a link during hint mode.
+____
+
+|\'alfc'| |\'activelinkfgcolor'|
+||'activelinkfgcolor' 'alfc'|| string
+____
+(default: black)
+
+Foreground color of the current active link during hint mode.
+____
+
+|\'albc'| |\'activelinkbgcolor'|
+||'activelinkbgcolor' 'albc'|| string
+____
+(default: ##88FF00)
+
+Background color of the current active link during hint mode.
+____
+
+|\'hm'| |\'hintmatching'|
+||'hintmatching' 'hm'|| string
+____
+(default: contains)
+
+How links are matched during hint mode (only for numeric hints). Available items:
+
+`------------`------------------------------------------------------------------------------------------------------------------------
+*contains* The typed characters are splitted by spaces, and these character groups have to be anywhere inside the text of the link.
+*startswith* The typed characters have to be in the typed order at the beginning of the text of the link.
+--------------------------------------------------------------------------------------------------------------------------------------
-CSS specification of focused hints
____
|\'nofs'| |\'nofullscreen'| |\'fs'| |\'fullscreen'|
Index: www/scripts/char-hints.js
===================================================================
RCS file: /cvs/vimperator/www/scripts/char-hints.js,v
retrieving revision 1.11
diff -u -r1.11 char-hints.js
--- www/scripts/char-hints.js 24 Mar 2008 23:19:41 -0000 1.11
+++ www/scripts/char-hints.js 30 Apr 2008 18:42:29 -0000
@@ -23,9 +23,10 @@
chh.showcapitals = true; // show capital letters, even with lowercase hintchars
chh.timeout = 500; // in 1/000sec; when set to 0, press <RET> to follow
-chh.fgcolor = "black"; // hints foreground color
-chh.bgcolor = "yellow"; // hints background color
-chh.selcolor = "#99FF00"; // selected/active hints background color
+chh.fgcolor = liberator.options["linkfgcolor"]; // hints foreground color
+chh.bgcolor = liberator.options["linkbgcolor"]; // hints background color
+chh.selfgcolor = liberator.options["activelinkfgcolor"]; // selected/active hints foreground color
+chh.selbgcolor = liberator.options["activelinkbgcolor"]; // selected/active hints background color
chh.mapNormal = "f"; // trigger normal mode with...
chh.mapNormalNewTab = "F"; // trigger and open in new tab
@@ -251,16 +252,8 @@
var scrollY = doc.defaultView.scrollY;
var baseNodeAbsolute = doc.createElementNS("http://www.w3.org/1999/xhtml", "span");
- baseNodeAbsolute.style.backgroundColor = "red";
- baseNodeAbsolute.style.color = "white";
- baseNodeAbsolute.style.position = "absolute";
- baseNodeAbsolute.style.fontSize = "10px";
- baseNodeAbsolute.style.fontWeight = "bold";
- baseNodeAbsolute.style.lineHeight = "10px";
- baseNodeAbsolute.style.padding = "0px 1px 0px 0px";
- baseNodeAbsolute.style.zIndex = "10000001";
- baseNodeAbsolute.style.display = "none";
- baseNodeAbsolute.className = "vimperator-hint";
+ baseNodeAbsolute.style.cssText = liberator.options["hintstyle"];
+ baseNodeAbsolute.className = "liberator-hint";
var elem, tagname, text, span, rect;
var res = liberator.buffer.evaluateXPath(chh.hinttags, doc, null, true);
@@ -306,11 +299,17 @@
{
var oldElem = chh.validHints[oldID - 1];
if (oldElem)
+ {
+ oldElem.style.color = chh.fgcolor;
oldElem.style.backgroundColor = chh.bgcolor;
+ }
var newElem = chh.validHints[newID - 1];
- if (newElem)
- newElem.style.backgroundColor = chh.selcolor;
+ if (newElem)
+ {
+ newElem.style.color = chh.selfgcolor;
+ newElem.style.backgroundColor = chh.selbgcolor;
+ }
}
//}}}
chh.showHints = function ()//{{{
@@ -363,13 +362,26 @@
chh.hints[i][3] = imgspan;
doc.body.appendChild(imgspan);
}
- imgspan.style.backgroundColor = (activeHint == hintnum) ? chh.selcolor : chh.bgcolor;
+
+ if (activeHint == hintnum)
+ {
+ imgspan.style.color = chh.selfgcolor;
+ imgspan.style.backgroundColor = chh.selbgcolor;
+ }
+ else
+ {
+ imgspan.style.color = chh.fgcolor;
+ imgspan.style.backgroundColor = chh.bgcolor;
+ }
+
imgspan.style.display = "inline";
}
- if (!imgspan)
- elem.style.backgroundColor = (activeHint == hintnum) ? chh.selcolor : chh.bgcolor;
- elem.style.color = chh.fgcolor;
+ if (! imgspan)
+ elem.style.backgroundColor = (activeHint == hintnum) ? chh.selbgcolor : chh.bgcolor;
+
+ elem.style.color = (activeHint == hintnum) ? chh.selfgcolor : chh.fgcolor;
+
if (chh.showcapitals)
span.textContent = chh.number2hintchars(hintnum++).toUpperCase();
else
Index: www/scripts/vimperator.vim
===================================================================
RCS file: /cvs/vimperator/www/scripts/vimperator.vim,v
retrieving revision 1.1
diff -u -r1.1 vimperator.vim
--- www/scripts/vimperator.vim 4 Jan 2008 12:30:32 -0000 1.1
+++ www/scripts/vimperator.vim 30 Apr 2008 18:42:29 -0000
@@ -31,12 +31,14 @@
syn match vimperatorCommandWrapper "\%(!\|\<\h\w*\>\)" contains=vimperatorCommand
syn region vimperatorSet matchgroup=vimperatorCommand start="\<set\=\>" end="$" keepend oneline contains=vimperatorOption
-syn keyword vimperatorOption activate act complete cpt defsearch ds extendedhinttags eht focusedhintstyle fhs fullscreen fs
- \ nofullscreen nofs guioptions go hintchars hc hintstyle hs hinttags ht hlsearch nohlsearch hls nohls hlsearchstyle hlss
- \ incsearch is noincsearch nois ignorecase ic noignorecase noic laststatus ls linksearch nolinksearch lks nolks maxhints
- \ mh more nomore preload nopreload popups pps previewheight pvh scroll scr showmode smd noshowmode nosmd showstatuslinks
- \ ssli showtabline stal smartcase scs nosmartcase noscs titlestring usermode um nousermode noum verbose vbs visualbell vb
- \ novisualbell novb visualbellstyle visualbellstyle t_vb wildmode wim wildoptions wop
+syn keyword vimperatorOption activate act activelinkfgcolor alfc activelinkbgcolor albc complete cpt defsearch ds editor extendedhinttags eht
+ \ fullscreen fs nofullscreen nofs guioptions go hintstyle hs hinttags ht hinttimeout hto history hi
+ \ hlsearch hls nohlsearch nohls hlsearchstyle hlss nohlsearchstyle nohlss incsearch is noincsearch nois ignorecase ic
+ \ noignorecase noic insertmode im noinsertmode noim laststatus ls linkbgcolor lbc linkfgcolor lfc linksearch lks linkmatching lm
+ \ nolinksearch nolks more nextpattern nomore pageinfo pa popups pps preload
+ \ nopreload previewheight pvh previouspattern scroll scr showmode smd noshowmode nosmd showstatuslinks ssli showtabline
+ \ stal smartcase scs nosmartcase noscs titlestring usermode um nousermode noum verbose vbs visualbell vb novisualbell novb
+ \ wildmode wim wildoptions wop
\ contained
syn region vimperatorJavascript start="\%(^\s*\%(javascript\|js\)\s\+\)\@<=" end="$" contains=@javascriptTop keepend oneline
More information about the Vimperator
mailing list