Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

23
Before LISPs Just Part of the Past ~ #1 vim as a Lisp front end~

description

Introduce how to use vim as a lisp front end. In short, slimv is cool. The contents is writte in Japanese.

Transcript of Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

Page 1: Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

Before LISPs

Just Part of the Past

~ #1 vim as a Lisp front end~

Page 2: Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

あるvimmerの嘆き

VIM

Page 3: Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

あるvimmerの嘆き

C-M-x が うらやましい…

VIM

Page 4: Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

VIM

vimmerの嘆き

VIM

Page 5: Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

vim as a Lisp front end

• Send whole buffer to interpreter • slime.vim - screen –X stuff • slimv - a swank client for vim • limp - another Lisp IDE for vim

Page 6: Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

Send whole buffer

function! LispEval() execute “w” execute “r !sbcl –noinform < %” endfunction

au Filetype lisp nmap <C-j> :call LispEval()<CR>

Page 7: Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

Send whole buffer

function! LispEval() execute “w” execute “r !sbcl –noinform < %” endfunction

au Filetype lisp nmap <C-j> :call LispEval()<CR>

編集中のファイルをsbclに入力して結果を現在のバッファに書き戻す

normal modeのC-jを上記関数に

マップ

Page 8: Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

Send whole buffer • C-jで編集中のファイルをsbclに送って結果を書き戻す

• 確認したらuで消す • 編集 -> C-j -> u -> 編集 -> … というサイクル • 利点

– 仕組みが圧倒的にわかりやすい – 対話環境を備えた言語なら大体使える

• 欠点 – とにかく効率が悪い。

Page 9: Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

Schemeでも

function! GoshEval () execute "w“ execute "r !gosh -i < %“ endfunction au Filetype scheme nmap <C-j> :call GoshEval<CR>

Page 10: Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

Haskellでも

function! HaskellEval() execute "w“ execute "r !ghci < %” endfunction au Filetype haskell nmap <C-j> :call HaskellEval<CR>

Page 11: Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

OCamlでも

function! OCamlEval() execute "w“ execute "r !ocaml < %“ endfunction au Filetype ocaml nmap <C-j> :call OCamlEval()<CR>

Page 12: Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

マイナー言語でも

function! JoCamlEval() execute "w“ execute "r !jocaml < %“ endfunction au Filetype ocaml nmap <C-j> :call JoCamlEval()<CR>

Page 13: Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

screen –X stuff • screen –Xでscreenにscreen commandを送信できる – sessionは-Sで指定

• 省略した場合は現在のsession – windowは-pで指定 (番号 or 名前)

• 省略した場合は現在のwindow

• stuff commandで文字列を入力できる • screen –S lisp-session –p 0 –X stuff “’a^m” • なお、screenの文字列エスケープは大変複雑です。

Page 14: Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

slime.vim • screen –X stuffを利用してフォームをscreenに起動してあるREPLに送るvim script

• 利点 – 内容を全部把握できる

• 空行を除くと全体で20行しかない上に、動機から仕組みまで解説した作者のブログ記事がある。

– http://technotales.wordpress.com/2007/10/03/like-slime-for-vim/ – 対話環境を備えた言語なら大体使える

• 欠点 – 事前にscreenをsession名付で起動したり、REPLを起動しておいたりするのがやや面倒

– 補完やインデントまでサポートするように改良するのは大変。slime.vimという名前は盛りすぎ。

Page 15: Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

slime.vim インストールと使い方

• slime.vimを~/.vim/plugin/に配置 • Lispソースを開いて評価したいフォーム上でC-c C-c –起動して1回目ならREPLの起動している

session名とwindowを聞かれる • トップレベルフォームでは都合が悪い場合は範囲選択してC-c C-c

• 送信先のsession/windowを変えたい場合はC-c v

Page 16: Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

slimv

• vim用のSWANKクライアント

SWANK server

VIM

slimv TCP

Page 17: Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

環境とインストール

環境 – python enabledなvim (7.0以上) – python 2.4以上

インストール –展開して中身を.vim内にコピー

Page 18: Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

入手先やドキュメント

• リポジトリ – https://bitbucket.org/kovisoft/slimv

• リリース (Vim online) – http://www.vim.org/scripts/script.php?script

_id=2531 • チュートリアル

– http://kovisoft.bitbucket.org/tutorial.html • ドキュメント

– ~/.vim/doc/slimv.txt

Page 19: Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

キーバンド系列の設定

<Leader>に1キー続ける2stroke系列と2キー続ける3stroke系列がある

–例) SWANKに接続 2stroke : <Leader>c 3stroke : <Leader>rc

– let g:slimv_keybindings = 1 または 2 • 1で2stroke (default), 2で3stroke

– cross referenceはどちらの系列でも3stroke

Page 20: Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

その他の重要な設定項目 <Leader>

– デフォルトはカンマ(,)だが、後方ジャンプと衝突する – let g:slimv_leader = ‘\’

処理系

– let g:slimv_impl = ‘sbcl’ – デフォルトはCLISP

paredit mode

– let g:paredit_mode = 0 でoffにできる – デフォルトはon

REPLに引数を渡す – let g:slimv_lisp = '"sbcl --core $HOME/.sbcl/main.core --no-userinit"'

Page 21: Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

よく使うキーバインド • <Leader>c : SWANK serverに接続 • <Leader>d : トップレベルフォームを評価 • <Leader>r : 選択範囲を評価 • <Leader>e : 式を評価 • <Leader>1 : MACROEXPAND-1 • <Leader>v : 対話的評価

– SLDB中では現在のフレーム内で評価 • <Leader>a : Abort • <Leader>s : DESCRIBE • <Leader>y : 評価の中断

Page 22: Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

その他

• screen上だとSWANKもscreen上で起動するのでおすすめ

• Common Lispだけでなく、MIT schemeやClojureでも使える

• <Leader>d – <Leader>dはたまにうまく動作しない

• 例) トップレベルで‘a – 選択して<Leader>rがいつでも正しく動作する – (変な)リーダマクロを書いているときにはまることが多い

Page 23: Before LIPSs Just Before the Past #1 ~vim as a Lisp front end~

limp

• slimeを実装目指したもう1つのvim script • REPLを見ながら作業できない • REPL画面との切り替えがF12

– HHKユーザには辛いキー • Vim onlineで配布しているが0.3.4のまま

2008年6月から更新されていない。 –作者のwebサイトは503。