Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Public API #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Public API #34

wants to merge 2 commits into from

Conversation

noahfrederick
Copy link
Contributor

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

- accio#accio() now accepts a Vim list or a string, making it easier to
  use programmatically:

      call accio#accio("foo")
      call accio#accio(["foo", "bar"])

- The appropriate job handler is selected automatically (no more
  accio#accio_vim()).
- Adds -bar parameter to :Accio definition.
- Fall back to using arguments in b:accio or b:current_compiler
- Focus tasks globally via :Accio! {task}
- Forget the focused tasks via :Accio! with no arguments
@pgdouyon
Copy link
Owner

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.

@pgdouyon
Copy link
Owner

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.

@noahfrederick
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants