Skip to content

Commit

Permalink
Merge pull request vim-skk#199 from asciian/master
Browse files Browse the repository at this point in the history
Vim 8への対応とvimprocへの依存の解消
  • Loading branch information
tyru authored Dec 31, 2017
2 parents 0f7c3b4 + f453fa6 commit 0455e8e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion autoload/eskk.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ function! eskk#_initialize() "{{{
call eskk#util#set_default('g:eskk#debug_wait_ms', 0)
call eskk#util#set_default('g:eskk#directory', '~/.eskk')

if exists('g:eskk#server') && !eskk#util#has_vimproc()
if exists('g:eskk#server') && !has('channel') && !eskk#util#has_vimproc()
call eskk#logger#warn(
\ "eskk.vim: warning: cannot use skkserv " .
\ "because vimproc is not installed."
Expand Down
51 changes: 36 additions & 15 deletions autoload/eskk/dictionary.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1248,16 +1248,23 @@ endfunction "}}}

" Initialize server.
function! s:ServerDict_init() dict "{{{
if !eskk#util#has_vimproc()
\ || !vimproc#host_exists(self.host) || self.port <= 0
return
endif
if has('channel')
let self._socket = ch_open(printf("%s:%s", self.host, self.port), {'mode': 'nl', 'timeout': self.timeout})
if ch_status(self._socket) == "fail"
call eskk#logger#warn('server initialization failed.')
endif
else
if !eskk#util#has_vimproc()
\ || !vimproc#host_exists(self.host) || self.port <= 0
return
endif

try
let self._socket = vimproc#socket_open(self.host, self.port)
catch
call eskk#logger#warn('server initialization failed.')
endtry
try
let self._socket = vimproc#socket_open(self.host, self.port)
catch
call eskk#logger#warn('server initialization failed.')
endtry
endif
endfunction "}}}

function! s:ServerDict_request(command, key) dict "{{{
Expand All @@ -1270,21 +1277,35 @@ function! s:ServerDict_request(command, key) dict "{{{
if self.encoding != ''
let key = iconv(key, &encoding, self.encoding)
endif
call self._socket.write(printf("%s%s%s\n",
\ a:command, key, (key[strlen(key)-1] != ' ' ? ' ' : '')))
let result = self._socket.read_line(-1, self.timeout)
if has('channel')
let result = ch_evalraw(self._socket, printf("%s%s%s\n",
\ a:command, key, (key[strlen(key)-1] != ' ' ? ' ' : '')))
else
call self._socket.write(printf("%s%s%s\n",
\ a:command, key, (key[strlen(key)-1] != ' ' ? ' ' : '')))
let result = self._socket.read_line(-1, self.timeout)
endif
if self.encoding != ''
let result = iconv(result, self.encoding, &encoding)
endif

if result == ''
" Reset.
call self._socket.write("0\n")
call self._socket.close()
if has('channel')
call ch_evalraw(self._socket, "0\n")
call ch_close(self._socket)
else
call self._socket.write("0\n")
call self._socket.close()
endif
call self.init()
endif
catch
call self._socket.close()
if has('channel')
call ch_close(self._socket)
else
call self._socket.close()
endif
return ''
endtry

Expand Down
2 changes: 1 addition & 1 deletion doc/eskk.jax
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ g:eskk#large_dictionary *g:eskk#large_dictionary*
g:eskk#server *g:eskk#server*
(デフォルト値: 下を参照)
Skkserv のサーバ情報
Note: この機能を使用するためには、|vimproc| が必要。
Note: この機能を使用するためには、|channel||vimproc| が必要。

この変数の定義は:
辞書型なら:
Expand Down
2 changes: 1 addition & 1 deletion doc/eskk.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ g:eskk#large_dictionary *g:eskk#large_dictionary*
g:eskk#server *g:eskk#server*
(Default: See below)
Skkserv information.
Note: |vimproc| is required.
Note: |channel| or |vimproc| is required.

This variable value is:
Dictionary:
Expand Down

0 comments on commit 0455e8e

Please sign in to comment.