Re: Re: autocmd がわからない

Vimperator の設定が複雑すぎて弱音を吐いていたら ( http://d.hatena.ne.jp/janus_wel/20080718#1216497573 ) id:teramakohttp://d.hatena.ne.jp/teramako/20080731/p1 でそっと教えてくれたよ。ありがとう。そして反応が遅すぎてごめん。…ほ、ほら、空の軌跡 3rd とか飲み会とかいろいろ忙しかったんだよ ( えー。無視してたわけじゃないんだからねッ !?

というのとはまた別にいつのまにかこんな記事が書かれたみたいなので参考にするといいかもしれない -> http://anond.hatelabo.jp/20080803202321

とりあえず書いてくれていたコード試したみたけどニコ動用の map と普段の map の切り替えができなかったよ… ? というのに加えて count 指定つきの map も使いたいので以下のように変更ッ。他にも :nnppushallvideos をランキングやマイリストで使いたかったので URL チェックをいじってあったり 'r' は :reload っていうのが俺的に抜けなかったので :nnprem'o've で 'o' に map するようにしていたり ( 'e' は :eijiro に割り当ててあるんだよッ !! 大体 't' で済むので 'o' をつぶした形 ) とけっこういじってる感じ。あと正直データをオブジェクトで持つのは冗長かもしれないけど気にすんなー。 URL も追加してどっかの SITEINFO 風にするっていう方向で書いてたけどタブ切り替えのたびに発生するコストを考えて思いとどまった跡だー。

javascript <<EOM
liberator.plugins.nicomap = function() {
/*
        template
        {
            command:        '',
            action:         function() {},
            description:    '',
            extra:          {},
        },
*/
    // stuff functions
    function registMaps(maps) {
        for (let i=0 ; i<maps.length ; ++i) {
            liberator.mappings.addUserMap(
                [liberator.modes.NORMAL],
                [maps[i].command],
                maps[i].description,
                maps[i].action,
                maps[i].extra
            );
        }
        return true;
    }
    function removeMaps(maps) {
        for (let i=0 ; i<maps.length ; ++i) {
            liberator.mappings.remove(liberator.modes.NORMAL, maps[i].command);
        }
        return true;
    }

    // URL applied maps
    const specialURL = '^http://www\.nicovideo\.jp/(watch|ranking|mylist)';

    // map definitions
    const defMaps = [
        {
            command:        'a',
            action:         function() { liberator.execute('normal :sbm<Space>'); },
            description:    'ready social bookmark command',
            extra:          { rhs: ':sbm<Space>', },
        },
        {
            command:        'v',
            action:         function() { liberator.execute('viewSBMComments -t hd'); },
            description:    'display social bookmark comments',
            extra:          { rhs: ':viewSBMComments -t hd<CR>', },
        },
    ];
    const nicoMaps = [
        {
            command:        'a',
            action:         function() { liberator.execute('nnppushallvideos'); },
            description:    'push all video in current tab to NicoNicoPlaylist',
            extra:          { rhs: ':nnppushallvideos<CR>', },
        },
        {
            command:        'l',
            action:         function() { liberator.execute('nnpgetlist'); },
            description:    'display NicoNicoPlaylist',
            extra:          { rhs: ':nnpgetlist<CR>', },
        },
        {
            command:        'i',
            action:         function() { liberator.execute('nicoinfo') },
            description:    'display "nicontroller.js" information',
            extra:          { rhs: ':nicoinfo<CR>', },
        },
        {
            command:        'p',
            action:         function() { liberator.execute('nicopause'); },
            description:    'toggle pause / play current tab\'s video',
            extra:          { rhs: ':nicopause<CR>', },
        },
        {
            command:        'm',
            action:         function() { liberator.execute('nicomute'); },
            description:    'toggle mute current tab\'s video',
            extra:          { rhs: ':nicomute<CR>', },
        },
        {
            command:        'v',
            action:         function() { liberator.execute('nicommentvisible'); },
            description:    'toggle comment visible current tab\'s video',
            extra:          { rhs: ':nicommentvisible<CR>', },
        },
        {
            command:        'z',
            action:         function() { liberator.execute('nicosize'); },
            description:    'toggle normal / fit-window size current tab\'s video',
            extra:          { rhs: ':nicosize<CR>', },
        },
        {
            command:        's',
            action:         function() { liberator.execute('nicoseek'); },
            description:    'seek to start current tab\'s video',
            extra:          { rhs: ':nicoseek<CR>', },
        },
        {
            // [N]n
            // N 番目の動画を再生する。
            // 指定なしの場合次の動画が再生される。
            command:        'n',
            action:         function(count) {
                if(count === -1) count = 1;
                liberator.execute(':nnpplaynext ' + count);
            },
            description:    'play next item in NicoNicoPlaylist',
            extra:          { flags:  liberator.Mappings.flags.COUNT },
        },
        {
            // [N]o
            // 上から N 個の動画を削除する。
            // 指定なしの場合一番上の動画が削除される。
            command:        'o',
            action:         function(count) {
                if(count === -1) count = 1;
                for(let i=0 ; i<count ; ++i) liberator.execute(':nnpremove');
                liberator.execute(':nnpgetlist');
            },
            description:    'remove item in NicoNicoPlaylist',
            extra:          { flags:  liberator.Mappings.flags.COUNT },
        },
        {
            // [N]-
            // N 秒前にシークする。
            // 指定なしの場合 10 秒前。
            command:        '-',
            action:         function(count) {
                if(count === -1) count = 10;
                liberator.execute(':nicoseek! ' + '-' + count);
            },
            description:    'seek by count backward',
            extra:          { flags:  liberator.Mappings.flags.COUNT },
        },
        {
            // [N]+
            // N 秒後にシークする。
            // 指定なしの場合 10 秒後。
            command:        '+',
            action:         function(count) {
                if(count === -1) count = 10;
                liberator.execute(':nicoseek! ' + count);
            },
            description:    'seek by count forward',
            extra:          { flags:  liberator.Mappings.flags.COUNT },
        },
    ];

    // main
    if(buffer.URL.match(specialURL)) {
        removeMaps(defMaps);
        registMaps(nicoMaps);
    }
    else {
        removeMaps(nicoMaps);
        registMaps(defMaps);
    }
};

liberator.autocommands.add('LocationChange', '.*', 'js liberator.plugins.nicomap()');
EOM

とりあえずこれで特定ページに対して何かやる方法を得たわけだけど長いな、コレ…。 vimperatorrc に書く内容じゃないよ。 URL 部分を map 定義に含めてしまって他のサイト向けにもいい感じに拡張したほうが使いでがあるかもしれないねぇ。タブ切り替えごとの関数実行もそんなに負担にならなそうならって条件はつくと思うけど今の段階で no delay なのでいけるかもしれない。けど今はやる気ないので放置。