60 howm-mode.vim (2-31) action-lock に SyntaxPreview を追加

http://d.hatena.ne.jp/kuhukuhun/20080112/1200143567

いっしょの人が書いてた SyntaxPreview が予想以上に綺麗だったので、例のごとく howm-mode.vim の action-lock として導入してみた。導入にあわせて若干の改変を加えた。 vimrc に下記のコードを追加で動作します。

let g:sp_syntaxdir = $VIMRUNTIME . '/syntax/'
let g:sp_start_pattern = '^>|\(\w*\)|\s*$'
let g:sp_end_pattern   = '^||<\s*$'
function! HowmActionlockSyntaxPreview(str, head)
  if a:str =~ g:sp_start_pattern
    let lnum_s = line('.')
    let lnum_e = search(g:sp_end_pattern, 'nW')
  elseif a:str =~ g:sp_end_pattern
    let lnum_s = search(g:sp_start_pattern, 'bnW')
    let lnum_e = line('.')
  else
    return
  endif
  if lnum_s == 0 || lnum_e == 0 || lnum_s + 1 > lnum_e - 1 | return | endif
  let lines = getline(lnum_s + 1, lnum_e - 1)
  let filetype = get(matchlist(getline(lnum_s), g:sp_start_pattern), 1, '')
  if !filereadable(g:sp_syntaxdir . filetype . '.vim')
    echo 'syntax is not found'
  else
    silent execute 'pedit! ++enc='.&enc.' ++ff='.&ff.' SyntaxPreview'
    wincmd P
    call append(0, lines)
    execute 'setlocal bt=nofile bh=delete noswf ft='.filetype
    execute 'silent normal gg=G'
    wincmd p
  endif
endfunction
if !exists('g:howm_actionlock_list') | let g:howm_actionlock_list = [] | endif
call add(g:howm_actionlock_list, {'func': function('HowmActionlockSyntaxPreview'), 'pat': g:sp_start_pattern . '\|' . g:sp_end_pattern })

howm でメモ画面を開いて。


=
>|vim|
:echo '別に'
:echo 'アンタのことなんて'
:echo 'くふん'

<

[2008-03-07 15:36]

適当に書いて、>|vim| とか ||< とかで ENTER を叩くと、プレビューウィンドウでウマー。