Skip to content

Commit

Permalink
Add CoqCommandComplete and g:coqtail#event
Browse files Browse the repository at this point in the history
  • Loading branch information
whonore committed Aug 31, 2024
1 parent a3d2830 commit 1058f77
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Unreleased ([main])

### Added
- `CoqCommandComplete` autocommand event, which is triggered whenever a command
completes.
`g:coqtail#event` contains information about the command.
(PR #368)

### Fixed
- Avoid a race condition when calling commands before Coqtail is fully initialized.
(PR #366)
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ hi def link CoqtailDiffRemovedBg DiffDelete
See the [above instructions](#syntax-highlighting-and-indentation) on how to
override these defaults.

### Autocommands

The `CoqCommandComplete` event is triggered by most of the movement/query
commands and allows user-defined actions to be executed using `autocmd User
CoqCommandComplete`.
See `:help CoqCommandComplete` for more information.

### More Options

See `:help coqtail-configuration` for a description of all the configuration options.
Expand Down
5 changes: 5 additions & 0 deletions autoload/coqtail.vim
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,11 @@ function! coqtail#defaultCB(chan, msg) abort
if a:msg.ret != v:null
call coqtail#util#err(a:msg.ret)
endif
if exists('#User#CoqCommandComplete')
let g:coqtail#event = {'cmd': a:msg.cmd}
doautocmd <nomodeline> User CoqCommandComplete
unlet g:coqtail#event
endif
endfunction

" Initialize Python interface.
Expand Down
19 changes: 19 additions & 0 deletions doc/coqtail.txt
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,25 @@ g:coqtail_treat_stderr_as_warning

Default: 0

*CoqCommandComplete* *coqtail-command-complete*
*g:coqtail#event* *coqtail-event*
CoqCommandComplete
g:coqtail#event An autocommand event that is triggered whenever an
asynchronous command is completed, and a dictionary
containing information about the command. Currently, the
only field is `cmd`, the name of the command, which is
one of: `step`, `rewind`, `to_line`, `to_top`, `query`, `refresh`,
`toggle_debug`. This allows an autocommand to filter for
specific commands. For example, to have the cursor
follow the end of the checked region: >
augroup CoqtailFollowChecked
autocmd!
autocmd! User CoqCommandComplete
\ if g:coqtail#event.cmd =~# 'step\|rewind\|to_line\|to_top'
\| CoqJumpToEnd
\| endif
augroup END
<
=======================
Backwards Compatibility *coqtail-backwards-compatibility*

Expand Down
4 changes: 2 additions & 2 deletions python/coqtail.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ def handle(self) -> None:

try:
ret = handler(**args) if handler is not None else None
msg = [self.msg_id, {"buf": self.bnum, "ret": ret}]
msg = [self.msg_id, {"buf": self.bnum, "cmd": func, "ret": ret}]
self.wfile.write(_to_jsonl(msg))
except (EOFError, ConnectionError):
break
Expand Down Expand Up @@ -1034,7 +1034,7 @@ def interrupt(self) -> None:
while not self.reqs.empty():
try:
msg_id, bnum, _, _ = self.reqs.get_nowait()
msg = [msg_id, {"buf": bnum, "ret": None}]
msg = [msg_id, {"buf": bnum, "cmd": "interrupt", "ret": None}]
self.wfile.write(_to_jsonl(msg))
except Empty:
break
Expand Down

0 comments on commit 1058f77

Please sign in to comment.