// PLUGIN_INFO//{{{
var PLUGIN_INFO =
    {NAME}
    character hint mode.
    hogelog
    0.1
    2.0pre 2008/12/12
    2.0a1
    
    
;
//}}}
(function () {
    const DEFAULT_HINTCHARS = "HJKLASDFGYUIOPQWERTNMZXCVB";
    const hintContext = hints.addMode;
    let inputCase = function(str) str.toUpperCase();
    let inputRegex = /[A-Z]/;
    let showCase = function(str) str.toUpperCase();
    options.add(["hintchars", "hchar"], //{{{
        "Hint characters",
        "string", DEFAULT_HINTCHARS); //}}}
    options.add(["charhintinput", "chinput"], //{{{
        "Character Hint Input",
        "string", "uppercase",
        {
            setter: function (value)
            {
                switch (value)
                {
                    default:
                    case "uppercase":
                        inputCase = function(str) str.toUpperCase();
                        inputRegex = /[A-Z]/;
                        break;
                    case "lowercase":
                        inputCase = function(str) str.toLowerCase();
                        inputRegex = /[a-z]/;
                        break;
                }
            },
            completer: function () [
                ["uppercase", "Input charhint UpperCase"],
                ["lowercase", "Input charhint LowerCase"],
            ],
        }); //}}}
    options.add(["charhintshow", "chshow"], //{{{
        "Character Hint Show",
        "string", "uppercase",
        {
            setter: function (value)
            {
                switch (value)
                {
                    default:
                    case "uppercase":
                        showCase = function(str) str.toUpperCase();
                        break;
                    case "lowercase":
                        showCase = function(str) str.toLowerCase();
                        break;
                }
            },
            completer: function () [
                ["uppercase", "show charhint UpperCase"],
                ["lowercase", "show charhint LowerCase"],
            ],
        }); //}}}
        
    function chars2num(chars) //{{{
    {
        let num = 0;
        let hintchars = inputCase(options.hintchars);
        let base = hintchars.length;
        for(let i=0,l=chars.length;i0);
        return chars;
    } //}}}
    function showCharHints() //{{{
    {
        function showHints(win)
        {
            for(let elem in buffer.evaluateXPath("//*[@liberator:highlight and @number]", win.document))
            {
                let num = elem.getAttribute("number");
                let hintchar = num2chars(parseInt(num, 10));
                elem.setAttribute("hintchar", showCase(hintchar));
                if(isValidHint(hintchar))
                    validHints.push(elem);
            }
            Array.forEach(win.frames, showHints);
        }
        validHints = [];
        showHints(window.content);
    } //}}}
    function isValidHint(hint) //{{{
    {
        return inputCase(hint).indexOf(hintInput) == 0;
    } //}}}
    var hintInput = "";
    var validHints = [];
    var charhints = plugins.charhints = {
        show: function (minor, filter, win) //{{{
        {
            charhints.original.show(minor, filter, win);
            hintInput = "";
            showCharHints();
        }, //}}}
        onInput: function (event) //{{{
        {
            let eventkey = events.toString(event);
            if(/^\d$/.test(eventkey)) {
                commandline.command += eventkey;
            }
            let hintString = commandline.command;
            commandline.command = hintString.replace(inputRegex, "");
            charhints.original.onInput(event);
            showCharHints();
            for(let i=0,l=hintString.length;i0) {
                let numstr = String(chars2num(hintInput));
                // no setTimeout, don't run nice
                setTimeout(function () {
                    for(let i=0,l=numstr.length;i