40 howm-mode.vim (2-18) TODO処理。スマートに。

ActionLock についてちょっと調べようと思って見ていたら「もっとスマートに」があったので、自分なりにスマートにしてみた。

まずは before 。

function! s:ActionLockCheckOff(str, head)
  let mark = substitute(a:str, '{\(.*\)}', '\1', '')
  " TODO:もっとスマートに…
  if mark == ' '
    let newmark = '*'
  elseif mark == '*'
    let newmark = '-'
  elseif mark == '-'
    let newmark = ' '
  else
    let newmark = ''
  endif

  if newmark != ''
    call cursor(line('.'), a:head)
    silent! exe "normal! c".strlen(a:str)."l{".newmark."}\<ESC>"
    call cursor(line('.'), a:head)
  endif
endfunction

そんでもって after 。actionlock_pat4 というのが ActionLock 定義用の定数として使われていたので、それを利用。

function! s:ActionLockCheckOff(str, head)
  let marklist = substitute(s:actionlock_pat4, '{\[\(.*\)\]}', '\1', '')
  let mark = substitute(a:str, '{\(.*\)}', '\1', '')
  let idx = stridx(marklist, mark)
  if idx != -1
    let newmark = marklist[((idx+1)%strlen(marklist))]
    call cursor(line('.'), a:head)
    silent! exe "normal! c".strlen(a:str)."l{".newmark."}\<ESC>"
    call cursor(line('.'), a:head)
  endif
endfunction

スマートかなあ。