diff --git a/CHANGELOG.md b/CHANGELOG.md index cbcffda3..801ba74e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/README.md b/README.md index 7b3ac80f..5b172e8e 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/autoload/coqtail.vim b/autoload/coqtail.vim index 4a66873e..fb7553b8 100644 --- a/autoload/coqtail.vim +++ b/autoload/coqtail.vim @@ -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 User CoqCommandComplete + unlet g:coqtail#event + endif endfunction " Initialize Python interface. diff --git a/doc/coqtail.txt b/doc/coqtail.txt index 935360f4..278a5199 100644 --- a/doc/coqtail.txt +++ b/doc/coqtail.txt @@ -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* diff --git a/python/coqtail.py b/python/coqtail.py index a188719f..46135fcb 100644 --- a/python/coqtail.py +++ b/python/coqtail.py @@ -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 @@ -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