Skip to content

Commit

Permalink
improve dictionary.vim: use abort for :function
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Apr 12, 2015
1 parent 1ac779a commit fe0580c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
46 changes: 23 additions & 23 deletions autoload/dictionary.vim
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
" Filename: autoload/dictionary.vim " Filename: autoload/dictionary.vim
" Author: itchyny " Author: itchyny
" License: MIT License " License: MIT License
" Last Change: 2014/12/07 20:21:59. " Last Change: 2015/03/29 01:38:09.
" ============================================================================= " =============================================================================


let s:save_cpo = &cpo let s:save_cpo = &cpo
Expand All @@ -26,7 +26,7 @@ try
catch catch
endtry endtry


function! dictionary#new(args) function! dictionary#new(args) abort
if s:check_mac() | return | endif if s:check_mac() | return | endif
if s:check_exe() | call s:check_vimproc() | return | endif if s:check_exe() | call s:check_vimproc() | return | endif
if s:check_vimproc() | return | endif if s:check_vimproc() | return | endif
Expand All @@ -44,7 +44,7 @@ function! dictionary#new(args)
\ filetype=dictionary \ filetype=dictionary
endfunction endfunction


function! s:search_buffer() function! s:search_buffer() abort
let bufs = filter(tabpagebuflist(), "getbufvar(v:val, '&ft') ==# 'dictionary'") let bufs = filter(tabpagebuflist(), "getbufvar(v:val, '&ft') ==# 'dictionary'")
if len(bufs) if len(bufs)
return { 'command': bufwinnr(bufs[0]) . 'wincmd w' } return { 'command': bufwinnr(bufs[0]) . 'wincmd w' }
Expand All @@ -53,7 +53,7 @@ function! s:search_buffer()
endif endif
endfunction endfunction


function! s:parse(args) function! s:parse(args) abort
let args = split(a:args, '\s\+') let args = split(a:args, '\s\+')
let isnewbuffer = bufname('%') != '' || &l:filetype != '' || &modified let isnewbuffer = bufname('%') != '' || &l:filetype != '' || &modified
\ || winheight(0) > 9 * &lines / 10 \ || winheight(0) > 9 * &lines / 10
Expand Down Expand Up @@ -106,7 +106,7 @@ let s:noconflict = [
\ [ '-newtab', '-below' ], \ [ '-newtab', '-below' ],
\ ] \ ]


function! dictionary#complete(arglead, cmdline, cursorpos) function! dictionary#complete(arglead, cmdline, cursorpos) abort
try try
let options = copy(s:options) let options = copy(s:options)
if a:arglead != '' if a:arglead != ''
Expand Down Expand Up @@ -152,7 +152,7 @@ function! dictionary#complete(arglead, cmdline, cursorpos)
endtry endtry
endfunction endfunction


function! s:buffername(name) function! s:buffername(name) abort
let buflist = [] let buflist = []
for i in range(tabpagenr('$')) for i in range(tabpagenr('$'))
call extend(buflist, tabpagebuflist(i + 1)) call extend(buflist, tabpagebuflist(i + 1))
Expand All @@ -165,7 +165,7 @@ function! s:buffername(name)
return '[' . a:name . (len(bufs) && index ? ' ' . index : '') . ']' return '[' . a:name . (len(bufs) && index ? ' ' . index : '') . ']'
endfunction endfunction


function! s:au() function! s:au() abort
augroup Dictionary augroup Dictionary
autocmd CursorMovedI <buffer> call s:update() autocmd CursorMovedI <buffer> call s:update()
autocmd CursorHoldI <buffer> call s:check() autocmd CursorHoldI <buffer> call s:check()
Expand All @@ -174,16 +174,16 @@ function! s:au()
augroup END augroup END
endfunction endfunction


function! s:initdict() function! s:initdict() abort
let b:dictionary = { 'input': '', 'history': [], let b:dictionary = { 'input': '', 'history': [],
\ 'jump_history': [], 'jump_history_index': 0 } \ 'jump_history': [], 'jump_history_index': 0 }
endfunction endfunction


function! DictionaryComplete(findstart, base) function! DictionaryComplete(findstart, base) abort
return a:findstart ? -1 : [] return a:findstart ? -1 : []
endfunction endfunction


function! s:update() function! s:update() abort
setlocal completefunc=DictionaryComplete omnifunc= setlocal completefunc=DictionaryComplete omnifunc=
let word = getline(1) let word = getline(1)
if exists('b:dictionary.proc') if exists('b:dictionary.proc')
Expand All @@ -206,11 +206,11 @@ function! s:update()
call s:updatetime() call s:updatetime()
endfunction endfunction


function! s:void() function! s:void() abort
silent call feedkeys(mode() ==# 'i' ? "\<C-g>\<ESC>" : "g\<ESC>", 'n') silent call feedkeys(mode() ==# 'i' ? "\<C-g>\<ESC>" : "g\<ESC>", 'n')
endfunction endfunction


function! s:check() function! s:check() abort
try try
if !exists('b:dictionary.proc') || b:dictionary.proc.stdout.eof if !exists('b:dictionary.proc') || b:dictionary.proc.stdout.eof
return return
Expand Down Expand Up @@ -243,14 +243,14 @@ function! s:check()
endtry endtry
endfunction endfunction


function! s:updatetime() function! s:updatetime() abort
if !exists('s:updatetime') if !exists('s:updatetime')
let s:updatetime = &updatetime let s:updatetime = &updatetime
endif endif
set updatetime=50 set updatetime=50
endfunction endfunction


function! s:restore() function! s:restore() abort
try try
if exists('s:updatetime') if exists('s:updatetime')
let &updatetime = s:updatetime let &updatetime = s:updatetime
Expand All @@ -260,7 +260,7 @@ function! s:restore()
endtry endtry
endfunction endfunction


function! s:map() function! s:map() abort
if &l:filetype ==# 'dictionary' if &l:filetype ==# 'dictionary'
return return
endif endif
Expand All @@ -281,7 +281,7 @@ function! s:map()
let &cpo = save_cpo let &cpo = save_cpo
endfunction endfunction


function! s:with(word) function! s:with(word) abort
call setline(1, a:word) call setline(1, a:word)
call cursor(1, 1) call cursor(1, 1)
startinsert! startinsert!
Expand All @@ -291,7 +291,7 @@ function! s:with(word)
endif endif
endfunction endfunction


function! s:jump() function! s:jump() abort
try try
let prev_word = substitute(getline(1), ' $', '', '') let prev_word = substitute(getline(1), ' $', '', '')
call insert(b:dictionary.jump_history, prev_word, b:dictionary.jump_history_index) call insert(b:dictionary.jump_history, prev_word, b:dictionary.jump_history_index)
Expand All @@ -303,7 +303,7 @@ function! s:jump()
endtry endtry
endfunction endfunction


function! s:back() function! s:back() abort
try try
if len(b:dictionary.jump_history) && b:dictionary.jump_history_index if len(b:dictionary.jump_history) && b:dictionary.jump_history_index
let b:dictionary.jump_history_index -= max([v:count, 1]) let b:dictionary.jump_history_index -= max([v:count, 1])
Expand All @@ -317,7 +317,7 @@ function! s:back()
endtry endtry
endfunction endfunction


function! s:cursorword() function! s:cursorword() abort
try try
let curpos = getpos('.') let curpos = getpos('.')
let c = curpos[2] let c = curpos[2]
Expand All @@ -341,21 +341,21 @@ function! s:cursorword()
endtry endtry
endfunction endfunction


function! s:error(msg) function! s:error(msg) abort
echohl ErrorMsg echohl ErrorMsg
echomsg 'dictionary.vim: '.a:msg echomsg 'dictionary.vim: '.a:msg
echohl None echohl None
endfunction endfunction


function! s:check_mac() function! s:check_mac() abort
if !(has('mac') || has('macunix') || has('guimacvim') || system('uname') =~? '^darwin') if !(has('mac') || has('macunix') || has('guimacvim') || system('uname') =~? '^darwin')
call s:error('Mac is required.') call s:error('Mac is required.')
return 1 return 1
endif endif
return 0 return 0
endfunction endfunction


function! s:check_exe() function! s:check_exe() abort
if !executable(s:exe) if !executable(s:exe)
call s:error('The dictionary executable is not created.') call s:error('The dictionary executable is not created.')
try try
Expand All @@ -372,7 +372,7 @@ function! s:check_exe()
return 0 return 0
endfunction endfunction


function! s:check_vimproc() function! s:check_vimproc() abort
try try
call vimproc#version() call vimproc#version()
catch catch
Expand Down
4 changes: 2 additions & 2 deletions syntax/dictionary.vim
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
" Filename: syntax/dictionary.vim " Filename: syntax/dictionary.vim
" Author: itchyny " Author: itchyny
" License: MIT License " License: MIT License
" Last Change: 2014/12/09 08:16:41. " Last Change: 2015/03/29 07:23:38.
" ============================================================================= " =============================================================================


scriptencoding utf-8 scriptencoding utf-8
Expand Down Expand Up @@ -53,7 +53,7 @@ syntax match DictionaryGrammer '^\(动\|介\|量\|数\|连\)$'
syntax match DictionaryName '^\S\+\s*\n^\(\(pro\)\?noun\|adjective\|det\|verb\|adverb\|abbreviation\|preposition\|suffix\|prefix\|conjunction\|symb\)\>' syntax match DictionaryName '^\S\+\s*\n^\(\(pro\)\?noun\|adjective\|det\|verb\|adverb\|abbreviation\|preposition\|suffix\|prefix\|conjunction\|symb\)\>'
\ contains=DictionaryGrammer \ contains=DictionaryGrammer
syntax match DictionaryName '^\(-\a\|\|~́\|~̀\|\).*\|^\a\+\s/\S\+/.*$' syntax match DictionaryName '^\(-\a\|\|~́\|~̀\|\).*\|^\a\+\s/\S\+/.*$'
\ contains=DictionaryGrammer,DictionaryPronounceNoHead,DictionarySemicolon,DictionaryComment \ contains=DictionaryGrammer,DictionaryPronounceNoHead,DictionarySemicolon,DictionaryComment
syntax match DictionaryComment '^\(DERIVATIVES\|ORIGIN\|PHRASES\)\|⦅.\{-}⦆\|〖.\{-}〗\|〘.\{-}〙' syntax match DictionaryComment '^\(DERIVATIVES\|ORIGIN\|PHRASES\)\|⦅.\{-}⦆\|〖.\{-}〗\|〘.\{-}〙'
syntax match DictionarySemicolon ';' syntax match DictionarySemicolon ';'


Expand Down

0 comments on commit fe0580c

Please sign in to comment.