Nothing Special   »   [go: up one dir, main page]

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

Deactivate doge if no placeholders left #51

Merged
merged 7 commits into from
Oct 11, 2019
Merged

Deactivate doge if no placeholders left #51

merged 7 commits into from
Oct 11, 2019

Conversation

mg979
Copy link
Contributor
@mg979 mg979 commented Oct 6, 2019

Check on InsertLeave if there are placeholders left, if not, deactivate
doge.

Prelude

Thank you for helping out DoGe!

By contributing to DoGe you agree to the following statements (Replace [ ] with [x] with those you agree with):

Why this PR?

Before this PR, after the last placeholder was consumed, the first Tab keypress would still use doge mapping, which is undesiderable. It checks on InsertLeave, so that if the placeholder is reached, but not consumed, doge remains active.

mg979 and others added 4 commits October 6, 2019 21:56
Check on InsertLeave if there are placeholders left, if not, deactivate
doge.
If text is deleted in normal mode, this should be checked too.
@kkoomen
Copy link
Owner
kkoomen commented Oct 10, 2019

I added proper documentation to the function, adjusted the function name to be more global and I did use the helpers function doge#helpers#count() to simplify the code. I moved your function code to the TextChangedI callback function and there it will properly update the new todo_count variable in b:doge_interactive. Your function will then only check if the amount of TODO items is 0 and will deactivate when the statement evaluates.

Any suggestions / recommendations or possible drawbacks towards my implementation I haven't thought about?

@mg979
Copy link
Contributor Author
mg979 commented Oct 10, 2019

Unfortunately this way TextChanged doesn't work, because if placeholders are deleted in normal mode that counter won't be updated (because it's updated when jumping). I tried a similar approach in my very first PR (checking the count) and I didn't like it. If you want it to work with TextChanged I don't think there are alternatives to search for the pattern in the autocommand, but it's not that there are performance issues or anything, so I don't see the problem.

@kkoomen
Copy link
Owner
kkoomen commented Oct 10, 2019

Agree, I haven't thought about that, but wasn't for of this while I implemented it. I changed the implementation by moving the update part in the TextChangedI function to your function. This works perfectly as I see for now. Agree?

@mg979
Copy link
Contributor Author
mg979 commented Oct 10, 2019

You sure it's working now? tabbing in insert mode seems broken to me.

@kkoomen
Copy link
Owner
kkoomen commented Oct 10, 2019

I do have the same. Didn't test insert-mode last time. This has to do with the doge#helpers#count function. It seems to be the let l:cnt = execute(l:range . 's/' . a:word . '//gn') line and I have no idea why. If I remove this and just return 4 then it doesn't occur that the count returns 0.

EDIT: This is only at the InsertLeave auto-command. Removing autocmd insertleave * call doge#comment#deactivate_when_done() immediately resolves the problem.

@mg979
Copy link
Contributor Author
mg979 commented Oct 10, 2019

I think you should learn a thing or two from this guy. Then maybe you can tell me what was wrong with the function I wrote :).

@kkoomen
Copy link
Owner
kkoomen commented Oct 11, 2019

I reverted back to your previous commit. The reason I prefer my version is because your code is redundant while there is a helper function that should work, but the helper function is not being called at the auto-commandInsertLeave so I'll just leave it at your version and I will do more research about this behavior this weekend. For now your version is fine.

@kkoomen kkoomen merged commit e820516 into kkoomen:master Oct 11, 2019
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