Skip to content

Commit 795b24d

Browse files
committed
Raise custom event - fixes #37, #19
1 parent 156f393 commit 795b24d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

README.adoc

+17
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ Plug 'raghur/vim-ghost', {'do': ':GhostInstall'}
1616
. 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.
1717
. When done, just delete the buffer with `:bd!` - you'll be disconnected
1818

19+
== Configuring filetype
20+
Whenever a buffer is connected, a `User` event `vim-ghost#connected` is raised. Here's a quick sample of
21+
setting filetype to `markdown` if the textarea was on github or reddit
22+
23+
```
24+
function! s:SetupGhostBuffer()
25+
if match(expand("%:a"), '\v/ghost-(github|reddit)\.com-')
26+
set ft=markdown
27+
endif
28+
endfunction
29+
30+
augroup vim-ghost
31+
au!
32+
au User vim-ghost#connected call s:SetupGhostBuffer()
33+
augroup END
34+
```
35+
1936
== Requirements
2037

2138
* Recent neovim/vim

rplugin/python3/ghost.py

+2
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ def _handle_on_message(self, req, websocket):
236236
buffer_handler_map[websocket] = [bufnr, temp_file_handle]
237237
self.nvim.command(delete_cmd)
238238
logger.debug("Set up aucmd: %s", delete_cmd)
239+
self.nvim.command("doauto User vim-ghost#connected")
240+
logger.debug("Raised custom au event")
239241
self._raise_window()
240242
change_cmd = ("au TextChanged,TextChangedI <buffer> call"
241243
" GhostNotify('text_changed', %d)" % bufnr)

0 commit comments

Comments
 (0)