Skip to content

Commit

Permalink
Raise custom event - fixes #37, #19
Browse files Browse the repository at this point in the history
  • Loading branch information
raghur committed May 20, 2020
1 parent 156f393 commit 795b24d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@ Plug 'raghur/vim-ghost', {'do': ':GhostInstall'}
. On any textarea, click the ghost icon - switch to neovim and edit!. Content is sync'ed real time. Works both ways - edits in the browser window are pushed to neovim as well.
. When done, just delete the buffer with `:bd!` - you'll be disconnected

== Configuring filetype
Whenever a buffer is connected, a `User` event `vim-ghost#connected` is raised. Here's a quick sample of
setting filetype to `markdown` if the textarea was on github or reddit

```
function! s:SetupGhostBuffer()
if match(expand("%:a"), '\v/ghost-(github|reddit)\.com-')
set ft=markdown
endif
endfunction

augroup vim-ghost
au!
au User vim-ghost#connected call s:SetupGhostBuffer()
augroup END
```

== Requirements

* Recent neovim/vim
Expand Down
2 changes: 2 additions & 0 deletions rplugin/python3/ghost.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ def _handle_on_message(self, req, websocket):
buffer_handler_map[websocket] = [bufnr, temp_file_handle]
self.nvim.command(delete_cmd)
logger.debug("Set up aucmd: %s", delete_cmd)
self.nvim.command("doauto User vim-ghost#connected")
logger.debug("Raised custom au event")
self._raise_window()
change_cmd = ("au TextChanged,TextChangedI <buffer> call"
" GhostNotify('text_changed', %d)" % bufnr)
Expand Down

0 comments on commit 795b24d

Please sign in to comment.