↓(日付をクリック。)
:if exists('loaded_undobranch_viewer')
:finish
:endif
:let loaded_undobranch_viewer = 1
:command! -nargs=0 UndoBranchViewer :call s:UndoBranchViewer()
:function! s:UndoBranchViewer()
:let g:undolistHandlers = [
\ {'key': 16, 'agent': s:SNR().'AgentUndoPreview', 'key_name': '<c-p>', 'help': 'Undo preview'},
\ {'pick_last_item': 0},
\ ]
:let s:undolists = tlib#cmd#OutputAsList('undolist')
:call tlib#input#List('s', 'UndoBranch', s:undolists, g:undolistHandlers)
:endfunction
:function! s:AgentUndoPreview(world, selected)
:return a:world
:endfunction
:function! s:SNR()
:return matchstr(expand('<sfile>'), '<SNR>\d\+_\zeSNR$')
:endfunction
finish
==============================================================
スクリプトのコメントとか、
履歴とか記述。
「finish」と書いて、そこでスクリプトの読み込みを停止、<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.apple.cvspserver</string>
<key>UserName</key>
<string>username</string>
<key>Program</key>
<string>/usr/bin/cvs</string>
<key>ProgramArguments</key>
<array>
<string>cvs</string>
<string>-f</string>
<string>--allow-root=/Volumes/DATA/cvs</string>
<string>pserver</string>
</array>
<key>Sockets</key>
<dict>
<key>Listeners</key>
<dict>
<key>SockPassive</key>
<true/>
<key>SockServiceName</key>
<string>cvspserver</string>
<key>SockType</key>
<string>SOCK_STREAM</string>
</dict>
</dict>
<key>inetdCompatibility</key>
<dict>
<key>Wait</key>
<false/>
</dict>
</dict>
</plist>
cp cvspserver.plist /Library/LaunchDaemons
launchctl load /Library/LaunchDaemons/cvspserver.plist
cvs -d :pserver:loginname@serverhost login cvs -d :pserver:loginname@serverhost checkout module
ウィンドウを分割して、片方のウィンドウに何かのリストを表示、選択されたら何かの処理を行うという、
ファイルエクスプローラーとかでよくあるUIを、簡単に構築できてしまうvimスクリプト tlibの使い方を突き止めた。
(vimスクリプト組む人以外には、役に立たない情報ですが)
で、下が最小のサンプル。
:UndoBranchViewerで起動して、<C-p>で選択した行のメッセージを表示する。
動かすには、もちろん、tlibが必要。
tlib#input#List()に表示する文字列のリストと、
どのキーが押されたら、どのファンクションを呼び出すかのマッピングを渡す。
keyがリストの選択に使うキーで、agentがファンクション。
スクリプトの中で使っている tlib#cmd#OutputAsList()は、
コマンドの結果で文字列のリストを作るコマンドです。
" スクリプトが何度も読まれるのを防止するためのおまじない
:if exists('loaded_undobranch_viewer')
:finish
:endif
:let loaded_undobranch_viewer = 1
" コマンドの定義
" :UndoBranchViewerってすると、s:UndoBranchViewer()が呼び出される。
:command! -nargs=0 UndoBranchViewer :call s:UndoBranchViewer()
:function! s:UndoBranchViewer()
:let g:undolistHandlers = [
\ {'key': 16, 'agent': s:SNR().'AgentUndoPreview', 'key_name': '<c-p>', 'help': 'Undo preview'},
\ {'key': 21, 'agent': s:SNR().'AgentUndoAndClose', 'key_name': '<c-u>', 'help': 'Undo and close'},
\ {'pick_last_item': 0},
\ ]
:let s:undolists = tlib#cmd#OutputAsList('undolist')
:call tlib#input#List('s', 'UndoBranch', s:undolists, g:undolistHandlers)
:endfunction
" リストから<c-p>で選択されたときに呼び出される。
:function! s:AgentUndoPreview(world, selected)
:let l:entry = a:selected[0]
" 選択された文字を表示。
:echo l:entry
" 文字を表示できるように、ちょっと待ってもらう。
:5sleep
:return a:world
:endfunction
" リストから<c-u>で選択されたときに呼び出される。
" 説明は省略
:function! s:AgentUndoAndClose(world, selected)
:return a:world
:endfunction
" tlibのリストでどれが選択されたかを特定するための文字を返す
:function! s:SNR()
:return matchstr(expand('<sfile>'), '<SNR>\d\+_\zeSNR$')
:endfunction