Skip to content

Commit

Permalink
Added send_to_simai.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikoto2000 committed Nov 12, 2024
1 parent 9dc0e94 commit 3a3a6d9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
28 changes: 28 additions & 0 deletions autoload/send_to_simai.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
vim9script

if get(g:, "devcontainer_vim", v:false)
export def Send(host: string, port: number)
var buffer_content = join(getbufline('%', 1, '$'), "\n")
call send_to_simai#SendWithText(buffer_content, host, port)
enddef

export def SendWithText(text: string, host: string, port: number)
var channelToSimai = ch_open($"{host}:{port}", {"mode": "raw"})
call ch_sendraw(channelToSimai, text, {})
call ch_close(channelToSimai)
enddef

export def StartPreview()
augroup devcontainer_md
autocmd!
autocmd BufWritePost *.md execute ':call send_to_simai#Send("host.docker.internal", 7878)'
augroup END
enddef

export def StopPreview()
augroup devcontainer_md
autocmd!
augroup END
enddef
endif

5 changes: 5 additions & 0 deletions vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ augroup devcontainer_json
autocmd BufEnter *devcontainer.json setlocal ft=json5
autocmd BufEnter *devcontainer.vim.json setlocal ft=json5
augroup END

if get(g:, "devcontainer_vim", v:false)
command! StartMdPreview :call send_to_simai#StartPreview()
command! StopMdPreview :call send_to_simai#StopPreview()
endif
""" }}}

""" {{{ highlight white spaces
Expand Down

0 comments on commit 3a3a6d9

Please sign in to comment.