Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,25 @@ Replace `4001` with the port number you have set in the browser extension

## Custom settings according to website

When you trigger GhostText, nvim-ghost triggers an `User` autocommand. You can
listen for that autocommand and run your own commands (e.g. setting filetype)

**NOTE:** All the autocommands should be in the `nvim_ghost_user_autocommands`
augroup

When you trigger GhostText, nvim-ghost triggers an `User` autocommand. You
can either use `nvim_create_autocmd()` to listen for the `GhostTextAttach`
pattern and retrieve the URL from the `data.url` callback parameter (Lua), or
create an autocommand in the `nvim_ghost_user_autocommands` augroup and
pattern match against the URL directly to set the filetype.
Some examples -

```lua
vim.api.nvim_create_autocmd({ 'User' }, {
group = vim.api.nvim_create_augroup('NvimGhostText', { clear = true }),
pattern = {"GhostTextAttach"},
callback = function(ev)
if ev.data.url == "github.com" then
vim.o.filetype = "markdown"
end
end,
})
```

```vim
" Autocommand for a single website (i.e. stackoverflow.com)
au nvim_ghost_user_autocommands User www.stackoverflow.com setfiletype markdown
Expand Down
6 changes: 6 additions & 0 deletions binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,12 @@ def _neovim_handler(self, *args):

def _trigger_autocmds(self, url: str):
self.neovim_handle.command(f"doau nvim_ghost_user_autocommands User {url}")
self.neovim_handle.api.exec_autocmds("User", {
"pattern": "GhostTextAttach",
"data": {
"url": url
}
})

def _do_close(self):
log(
Expand Down