vim-accio
vim-accio copied to clipboard
Public API
I've been sitting on these changes for a couple weeks. They aim to make programmatic usage of Accio easier. My motivation is wanting to call :Accio
in a BufWritePost
autocommand. It's a little cumbersome to pass a list of tasks to the command in a variable, so it makes more sense to call the function in that case. Furthermore, the user must decide between accio#accio()
and accio#accio_vim()
if s/he wishes to do so. The first change eliminates accio#accio_vim()
in favor of one function that chooses the appropriate handler itself. It is also no longer responsible for parsing the argument to :Accio
.
My first approach to defining which tasks to run per file type was to set buffer-local autocommands. This proved to be a slight hassle, so I instead settled on something like:
augroup init_accio
autocmd!
autocmd BufWritePost * if exists("b:accio") | call accio#accio(b:accio) | endif
augroup END
That way, I need only set a buffer var per file type. (I'm not sure whether or not this will explode if a buffer other than the current buffer is written, e.g., :wall
. Haven't tried it.)
This still leaves a problem of wanting to call :Accio
interactively with the current tasks without having to specify them, so I opted to explore #5. I discarded the possibility of supporting b:dispatch
early on. Although it sounded like a good idea to me at first, there are a couple problems in that it can contain things that aren't compilers as well as potentially containing Vim script commands. For example, if you set it via projectionist.vim, you can wind up with something like ProjectDo Dispatch mycompiler
. So my second change is supporting b:accio
as a fallback when no arguments are provided to :Accio
.
My third change is introducing the concept of "focusing" a task. Given that you may want to run a task several times without specifying the tasks each time and without disturbing b:accio
, I added something like :FocusDispatch
but a bit simpler:
Accio! foo " Run 'foo' and remember it for next time
Accio " Subsequent invocations without arguments run 'foo'
Accio! " Forget the task
Accio " Subsequent invocations fall back to b:accio (or fail if not set)
Note that a task is focused globally rather than per buffer, which seems more intuitive (less to keep track of mentally) and distinguishes it from the b:accio
use case. (This may step on your plans for #7.) These last couple of changes make :Accio<CR>
a rather attractive normal-mode mapping.
I'm not married to these changes in their current form, but they've been useful. What do you think? Totally open to refining any and all of these ideas or even discarding them.
—N
Just took a passing glance over the changes but I like the idea a lot. I'll probably have a few more questions when I dive a bit deeper, but I'm slammed at work right now. Should be able to take a closer look at it this weekend and get back to you.
Finally found the time to go through this PR. I think my only real concern is the lack of visibility into what commands execute when you run :Accio
. You have to remember whether or not you ever focused the task, whether you made Accio forget the focused task, and what that focused task was. Which seems like a lot to keep in mind.
Dispatch seems to handle this problem by having a separate command for focusing/forgetting and also by having a command to show the currently focused task.
I'm not sure if a separate command is necessary in this case, it might be enough to simply echo the tasks being used when the no-arg version of :Accio
is invoked. We can probably wait until later to see if adding a separate command to echo the tasks is necessary, so that you can check the tasks before running :Accio
.
I agree that's a valid concern. :Accio
could take a special argument that means "echo the task(s) that would be run."
:Accio?
No tasks
['foo', 'bar'] - buffer-local setting
['baz'] - focused
Maybe :Accio?
is too clever.