vimperatorでもifがしたい!

Vimperator Advent Calendar 2012 9日目担当 caisui です。


ローカルパッチで 作成していた if コマンドを pluginに移植してみました。
改変部位が io.source のため 一工夫入れないと使えませんがご了承願います。


https://gist.github.com/4239753#file_cmd_if.js


特徴として

  • 評価するのは、javascript
  • heredoc サポート(最後の行を評価結果として判定)
  • elseif に 変数を引き継ぎする
  • 無いよりまし程度だけど、commandlineでも 動作
  • vim の if と違い 実行しないブロックのコマンドもパースする(heredocの関係で同等にすることは断念しました)


細かい仕様は、
https://gist.github.com/4239753#file_test.vimp
から読みとってください!


以下は、rc晒しです。参考になる部位があれば何よりです。
(ざっくりですがコメントも入れました)

" vim: set ft=vim:

" 以下2行を アンコメントで noplugin 相当でFirefox を 起動
"js liberator.commandLineOptions.noPlugins=true
":finish

" io.source を 上書き
so ~/vimperator/gist/4239753/cmd-if.js

" if が 有効な io.source で 実行
exstr <<RC

" runtimepath 初期化
set runtimepath=~/vimperator/github,~/vimperator/common


" profile name 固有 設定 plugin を 読み込む
execute "so ~/vimperator/" + liberator.profileName + ".vimp"
execute "set runtimepath+=~/vimperator/" + liberator.profileName

" migemo が 有効なら hint の 絞り込みを変更
if window.migemo
    set hintmatching=custom
endif

set hc=hjklasdfgyuiopqwertnmzxcvb
set nohlsearch

set nofocuscontent
set noautocomplete

nnoremap <silent> g# :b#<cr>

" 某plugin map 割り当て
nnoremap <silent> <S-b> :pi tab<CR>
nnoremap <silent> <c-s-j> :pi console<CR>
nnoremap <silent> <c-j> :pi download<CR>
nnoremap <silent> ,b :pi hatenta-bookmark<cr>
nnoremap <silent> ,s :pi noscript<cr>
nnoremap <silent> ,a :pi tab-history<CR>

cnoremap <silent> <C-f> :pi command-mru<cr>

nnoremap / :grep2<space>


" カレンダー表示
command cal :js liberator.echo(<datepicker type="grid" xmlns={XUL}/>)
" MOW で 右クリック有効化
js document.getElementById("liberator-multiline-output").setAttribute("contextmenu", "contentAreaContextMenu")

" 某プラグイン 諸設定
let use_hintchars_ex=2
let use_hints_ext_hinttags=1
let use_hints_ext_extendedhinttags=1
let use_hints_ext_caret="c"
let use_hints_ext_visual="v"
let typescript_path="~/vimperator/lib/typescript/"

" nomenu(menu非表示)状態から menuを出すと1行ずれるので overlay 化
style -name=menu chrome://browser/content/browser.xul <<CSS
#toolbar-menubar[autohide="true"] {
    background-color:transparent!important;
    position:fixed;
    z-index:999999;
    left:1ex;
    top:1ex;
}
#toolbar-menubar[autohide="true"] #main-menubar {
    background-color:rgba(0,0,0,.7)!important;
    padding: 1ex!important;
    border-radius:4px;
}
#toolbar-menubar[autohide="true"] #main-menubar>menu {
    color: white!important;
    border-radius: 2px;
    transition: .5s background;
}
#toolbar-menubar[autohide="true"] #main-menubar>menu[_moz-menuactive="true"] {
    -moz-appearance:none!important;
    background-color: rgba(255,255,255,.5)!important;
}
CSS

noremap <silent> <C-h> :tabh back<CR>
noremap <silent> <C-l> :tabh forward<CR>

" tree style tab 用 設定
if window.TreeStyleTabService
    style   -name=floatbox  chrome://browser/content/browser.xul .liberator-floatbox{z-index: 9999;}
    let mapleader=":tst<space>"

    nmap <silent> ,t <Leader>open<Space>
    nmap <silent> ,T <Leader>

    nmap <silent> zj <Leader>next<cr>
    nmap <silent> zk <Leader>prev<cr>

    nmap <silent> zh <Leader> goto parent<cr>
    nmap <silent> zl <Leader> goto cfirst<cr>
    nmap <silent> zL <Leader> goto clast<cr>
    nmap <silent> zH <Leader> goto root<cr>

    nmap <silent> zK <Leader>move -r<cr>
    nmap <silent> zJ <Leader>move<cr>

    nmap <silent> d  <Leader> bdelete<cr>
    nmap <silent> zd <Leader> delete!<cr>

    nmap <silent> >> <Leader> shift<cr>
    nmap <silent> << <Leader> unshift<cr>

    nmap <silent> gzz <Leader>scroll --pos=center<cr>
    nmap <silent> gzt <Leader>scroll --pos=top<cr>
    nmap <silent> gzb <Leader>scroll --pos=bottom<cr>

    nmap <silent> zn <Leader>goto pnext<cr>
    nmap <silent> zp <Leader>goto pprev<cr>
    nmap <silent> zN <Leader>goto rnext<cr>
    nmap <silent> zP <Leader>goto rprev<cr>

    nmap <silent> gp <Leader>paste<cr>
    unlet mapleader
endif

"ここでplugin 読み込み
loadplugins
" 以下plugin 依存諸設定

if plugins.hintsExt
    hi -append HintExt font-family: Consolas;
    hi HintExt::before opacity: .6;
endif

hi StatusLineSecure -append font-weight: bold;

coffee <<CODE
userContext.__defineGetter__ "doc", () -> content.document
userContext.__defineGetter__ "win", () -> content.window

s = ",t"
map = mappings.get modes.NORMAL, s
if map
    [modes.CARET, modes.VISUAL].forEach (m)->
        mappings.remove m, s
        mappings._user[m].push map
        map.modes.push m

if plugins.hintsExt
    hints.addSimpleMap "<C-l>", () -> this.relocation()
CODE
RC