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

Feature update profiles #20

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

Conversation

intuited
Copy link
Contributor

This adds the ability to switch between "update modes" on a per-buffer basis. Update profiles determine which hooks (autocommands, key mappings) will trigger calls to JSLint(), JSLintClear(), etc. I just added one other to the default "thorough" update mode. There's more info in new comments and in the commit message.

My main motivation for doing this was to avoid issues with quickfix not working. I determined that removing the BufEnter autocommand prevented this issue from occurring, but I couldn't figure out how to remove that without totally changing the way the plugin works. I ended up setting up a second update profile that only updates on BufWrite events.

Issue specifics

  • About (maybe exactly) half of the times that JSLint() got run — either via an autocommand or by running JSLintUpdate directly — I would have problems using the quickfix list.
  • Subsequently going to a quickfix entry via :cc, or by pressing <Enter> on the entry in the qf window, or by any other means, I would end up at the wrong line number. It seemed to be using the wrong quickfix entry: I would end up at a line that was referenced by one of the other quickfix entries.
  • If I disabled JSLint (using :JSLintToggle), the stabilized quickfix list would continue to exhibit this behaviour.
  • This issue was readily reproducible. The line I would end up at seemed to alternate between two different options. I think that one of the options was always the correct line number.
  • With the stabilized quickfix list in a weird state, I noticed that the return value of getqflist() was as expected, and that it matched up with b:jslint_qf or whatever it's called.
  • Going to the last entry in the quickfix list seemed to resolve the issue (again, this is with jslint.vim disabled via :JSLintToggle). It would happen again if I re-enabled jslint.vim.
  • Removing the au BufEnter ... line in the source code and then restarting vim would result in this issue not occurring. My guess is that using the quickfix list triggers a BufEnter event and that this results in recursive weirdness somewhere in vim's internals. It does seem like it's probably a vim issue.

I'm running vim 7.2 with patches 1-330, the current ubuntu 10.10 vim-gnome package. I didn't actually bother to check the patches list to see if there's a resolved issue along these lines, mostly because I'm not about to get my vim from a PPA or build from source just to resolve this.

Anyway, if there is some option or something that fixes this, it would be cool to find out about that. It seems like some people might want to have update profiles anyway, in case they are editing massive JS scripts and linting with rhino or something. I personally find that checking on write is enough for me — I save paranoidiacally after each edit of my code anyway.

style

I'm using dictionary functions and probably some other vaguely recent vim features, hope that's okay. I didn't start using vim until version 7.something so I'm not very clear on what features were added when, nor on what's an acceptable compatibility target.

There might be some other stylistic issues. I tried not to clash too hard with what you've got going on in there, but my usual coding style is pretty different from the addon's existing code. It seems a bit inconsistent anyway, so it seemed like a bit more variety wouldn't hurt too much. For example, I prefixed the name of a buffer-scope variable with jslint_ even though this is not being done for most/all of the variables in the addon. I think probably it should be, since there could be conflict with other addons.

Created the `thorough` and `onwrite` profiles.

These profiles govern the hooks -- autocommands and mappings --
that jslint.vim will respond to with update events.

It is possible to switch a buffer's update profile
with the new `:JSLintUpdateMode` command.

The `thorough` profile, enabled by default,
sets up buffers as they have been set up.

It may be useful to people with slow machines, large JS scripts,
and/or slow JS interpreters
to have the lint checked less often, so I added the `onwrite` profile.

Use of the `onwrite` profile alleviates issues I was having
where the quickfix entries would not work properly:

About half of the time, quickfix entry selection
-- via `:cc`, pressing <Enter> on a qf entry, etc. --
would go to the wrong line.

The cursor would end up
on the line of another entry in the quickfix list.

Disabling the BufEnter autocommand fixes this.
Moved out of `s:update` existence check block.
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.

None yet

1 participant