mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-25 23:02:35 +03:00
Reorder Neovim launch init sequence
Colorscheme change notification still not working
This commit is contained in:
parent
3a0b8a6ebf
commit
ca8c7fedb6
@ -93,101 +93,97 @@ extension NvimView {
|
||||
// We wait here, since the user of NvimView cannot subscribe
|
||||
// on the Completable. We could demand that the user call launchNeoVim()
|
||||
// by themselves, but...
|
||||
var c: Int32 = 0 // FIXME
|
||||
try?
|
||||
self.api.run(at: sockPath, inPipe: inPipe, outPipe: outPipe, errorPipe: errorPipe)
|
||||
.andThen(self.api.getApiInfo(errWhenBlocked: false).map { value in
|
||||
guard let info = value.arrayValue,
|
||||
info.count == 2,
|
||||
let channel = info[0].int32Value,
|
||||
let dict = info[1].dictionaryValue,
|
||||
let version = dict["version"]?.dictionaryValue,
|
||||
let major = version["major"]?.intValue,
|
||||
let minor = version["minor"]?.intValue
|
||||
else {
|
||||
throw RxNeovimApi.Error.exception(message: "Could not convert values to api info.")
|
||||
}
|
||||
|
||||
guard (major >= kMinAlphaVersion && minor >= kMinMinorVersion) || major >=
|
||||
kMinMajorVersion
|
||||
else {
|
||||
self.eventsSubject.onNext(.ipcBecameInvalid(
|
||||
"Incompatible neovim version \(major).\(minor)"
|
||||
))
|
||||
throw RxNeovimApi.Error
|
||||
.exception(message: "Incompatible neovim version.")
|
||||
}
|
||||
|
||||
c = channel
|
||||
|
||||
return channel
|
||||
}.asCompletable())
|
||||
try? self.api.run(at: sockPath, inPipe: inPipe, outPipe: outPipe, errorPipe: errorPipe)
|
||||
.andThen(
|
||||
self.api.command(command: "let g:gui_vimr = 1", expectsReturnValue: false)
|
||||
self.api.getApiInfo(errWhenBlocked: false)
|
||||
.map { value in
|
||||
guard let info = value.arrayValue,
|
||||
info.count == 2,
|
||||
let channel = info[0].int32Value,
|
||||
let dict = info[1].dictionaryValue,
|
||||
let version = dict["version"]?.dictionaryValue,
|
||||
let major = version["major"]?.intValue,
|
||||
let minor = version["minor"]?.intValue
|
||||
else {
|
||||
throw RxNeovimApi.Error.exception(message: "Could not convert values to api info.")
|
||||
}
|
||||
|
||||
guard (major >= kMinAlphaVersion && minor >= kMinMinorVersion) || major >=
|
||||
kMinMajorVersion
|
||||
else {
|
||||
self.eventsSubject.onNext(.ipcBecameInvalid(
|
||||
"Incompatible neovim version \(major).\(minor)"
|
||||
))
|
||||
throw RxNeovimApi.Error.exception(message: "Incompatible neovim version.")
|
||||
}
|
||||
|
||||
return channel
|
||||
}
|
||||
.map { (channel: Int32) in
|
||||
self.api.exec2(src: """
|
||||
":augroup vimr
|
||||
":augroup!
|
||||
:autocmd VimEnter * call rpcnotify(\(channel), 'autocommand', 'vimenter')
|
||||
:autocmd BufWinEnter * call rpcnotify(\(
|
||||
channel
|
||||
), 'autocommand', 'bufwinenter', str2nr(expand('<abuf>')))
|
||||
:autocmd BufWinEnter * call rpcnotify(\(
|
||||
channel
|
||||
), 'autocommand', 'bufwinleave', str2nr(expand('<abuf>')))
|
||||
:autocmd TabEnter * call rpcnotify(\(
|
||||
channel
|
||||
), 'autocommand', 'tabenter', str2nr(expand('<abuf>')))
|
||||
:autocmd BufWritePost * call rpcnotify(\(
|
||||
channel
|
||||
), 'autocommand', 'bufwritepost', str2nr(expand('<abuf>')))
|
||||
:autocmd BufEnter * call rpcnotify(\(
|
||||
channel
|
||||
), 'autocommand', 'bufenter', str2nr(expand('<abuf>')))
|
||||
:autocmd DirChanged * call rpcnotify(\(
|
||||
channel
|
||||
), 'autocommand', 'dirchanged', expand('<afile>'))
|
||||
:autocmd ColorScheme * call rpcnotify(\(channel), 'autocommand', 'colorscheme', \
|
||||
get(nvim_get_hl(0, {'id': hlID('Normal')}), 'fg', -1), \
|
||||
get(nvim_get_hl(0, {'id': hlID('Normal')}), 'bg', -1), \
|
||||
get(nvim_get_hl(0, {'id': hlID('Visual')}), 'fg', -1), \
|
||||
get(nvim_get_hl(0, {'id': hlID('Visual')}), 'bg', -1), \
|
||||
get(nvim_get_hl(0, {'id': hlID('Directory')}), 'fg', -1))
|
||||
:autocmd ExitPre * call rpcnotify(\(channel), 'autocommand', 'exitpre')
|
||||
:autocmd BufModifiedSet * call rpcnotify(\(
|
||||
channel
|
||||
), 'autocommand', 'bufmodifiedset', \
|
||||
str2nr(expand('<abuf>')), getbufinfo(str2nr(expand('<abuf>')))[0].changed)
|
||||
":augroup END
|
||||
""", opts: [:], errWhenBlocked: false)
|
||||
}
|
||||
.asCompletable()
|
||||
)
|
||||
.andThen(self.api.uiAttach(width: size.width, height: size.height, options: [
|
||||
"ext_linegrid": true,
|
||||
"ext_multigrid": false,
|
||||
"ext_tabline": MessagePackValue(self.usesCustomTabBar),
|
||||
"rgb": true,
|
||||
]))
|
||||
.andThen(self.api.command(command: "let g:gui_vimr = 1", expectsReturnValue: false))
|
||||
.andThen(
|
||||
self.api.exec2(src: """
|
||||
":augroup vimr
|
||||
":augroup!
|
||||
:autocmd VimEnter * call rpcnotify(\(c), 'autocommand', 'vimenter')
|
||||
:autocmd BufWinEnter * call rpcnotify(\(
|
||||
c
|
||||
), 'autocommand', 'bufwinenter', str2nr(expand('<abuf>')))
|
||||
:autocmd BufWinEnter * call rpcnotify(\(
|
||||
c
|
||||
), 'autocommand', 'bufwinleave', str2nr(expand('<abuf>')))
|
||||
:autocmd TabEnter * call rpcnotify(\(
|
||||
c
|
||||
), 'autocommand', 'tabenter', str2nr(expand('<abuf>')))
|
||||
:autocmd BufWritePost * call rpcnotify(\(
|
||||
c
|
||||
), 'autocommand', 'bufwritepost', str2nr(expand('<abuf>')))
|
||||
:autocmd BufEnter * call rpcnotify(\(
|
||||
c
|
||||
), 'autocommand', 'bufenter', str2nr(expand('<abuf>')))
|
||||
:autocmd DirChanged * call rpcnotify(\(
|
||||
c
|
||||
), 'autocommand', 'dirchanged', expand('<afile>'))
|
||||
:autocmd ColorScheme * call rpcnotify(\(c), 'autocommand', 'colorscheme', \
|
||||
get(nvim_get_hl(0, {'id': hlID('Normal')}), 'fg', -1), \
|
||||
get(nvim_get_hl(0, {'id': hlID('Normal')}), 'bg', -1), \
|
||||
get(nvim_get_hl(0, {'id': hlID('Visual')}), 'fg', -1), \
|
||||
get(nvim_get_hl(0, {'id': hlID('Visual')}), 'bg', -1), \
|
||||
get(nvim_get_hl(0, {'id': hlID('Directory')}), 'fg', -1))
|
||||
:autocmd ExitPre * call rpcnotify(\(c), 'autocommand', 'exitpre')
|
||||
:autocmd BufModifiedSet * call rpcnotify(\(
|
||||
c
|
||||
), 'autocommand', 'bufmodifiedset', \
|
||||
str2nr(expand('<abuf>')), getbufinfo(str2nr(expand('<abuf>')))[0].changed)
|
||||
":augroup END
|
||||
""", opts: [:], errWhenBlocked: false).asCompletable()
|
||||
self.api.uiAttach(width: size.width, height: size.height, options: [
|
||||
"ext_linegrid": true,
|
||||
"ext_multigrid": false,
|
||||
"ext_tabline": MessagePackValue(self.usesCustomTabBar),
|
||||
"rgb": true,
|
||||
])
|
||||
)
|
||||
.andThen(
|
||||
self.sourceFileUrls.reduce(Completable.empty()) { prev, url in
|
||||
prev
|
||||
.andThen(
|
||||
self.api.exec2(src: "source \(url.shellEscapedPath)", opts: ["output": true])
|
||||
.map {
|
||||
retval in
|
||||
guard let output_value = retval["output"] ?? retval["output"],
|
||||
let output = output_value.stringValue
|
||||
else {
|
||||
throw RxNeovimApi.Error
|
||||
.exception(message: "Could not convert values to output.")
|
||||
}
|
||||
return output
|
||||
self.sourceFileUrls.reduce(.empty()) { prev, url in
|
||||
prev.andThen(
|
||||
self.api.exec2(src: "source \(url.shellEscapedPath)", opts: ["output": true])
|
||||
.map { retval in
|
||||
guard let output = retval["output"]?.stringValue else {
|
||||
throw RxNeovimApi.Error
|
||||
.exception(message: "Could not convert values to output.")
|
||||
}
|
||||
.asCompletable()
|
||||
)
|
||||
return output
|
||||
}
|
||||
.asCompletable()
|
||||
)
|
||||
}
|
||||
)
|
||||
.andThen(self.api.subscribe(event: NvimView.rpcEventName)).wait()
|
||||
.andThen(self.api.subscribe(event: NvimView.rpcEventName))
|
||||
.wait()
|
||||
}
|
||||
|
||||
private func randomEmoji() -> String {
|
||||
|
Loading…
Reference in New Issue
Block a user