-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add hook functionality, update docs #23
Conversation
@terrortylor This PR is missing tests. I have never written one before and am not sure how to do that. Some guidance would be really appreciated. Wasn't sure what to call |
Sorry been awol. Suggestion for a test would be to create a clouse function and set that in the hook that modified a variable local to the test (maybe a counter), comment out some code, toggle it and check that that the variable is modified as expected. You've some very opinionated readme changes there too ;) EDIT: |
lua/nvim_comment.lua
Outdated
vim.api.nvim_call_function("execute", {vim_func}) | ||
vim.api.nvim_command("command! -range CommentToggle lua require('nvim_comment').comment_toggle(<line1>, <line2>)") | ||
vim.g.loaded_text_objects_plugin = 1 | ||
api.nvim_exec([[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't 0.5 safe... FYI why it's done in this backwards way..
Whilst neovim 0.5 is now released it's not available on all distro's so changing this may be a breaking change for some users, best not to put this change in just yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still holds IMO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted. Although not sure how important pre 0.5 compatibility is. You can just require 0.5 as a minimum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one of the things I wanted was support for <0.5 as selfishly I can use this one some work servers ;P
lua/nvim_comment.lua
Outdated
} | ||
|
||
function M.get_comment_wrapper() | ||
if type(M.config.hook) == 'function' then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd actually suggest moving this to line 97 before get_comment_wrapper is set
whilst for this use case it's probably to be used to override commentstring value, it could be for somehitng else like changing the comment highlight value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, did not consider other use cases. Have moved to as instructed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
```lua | ||
require('nvim_comment').setup({ | ||
hook = function() | ||
if vim.api.nvim_buf_get_option(0, "filetype") == "vue" then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
* `CommentToggle` comment/uncomment current line | ||
* `67,69CommentToggle` comment/uncomment a range | ||
* `'<,'>CommentToggle` comment/uncomment a visual selection | ||
- `CommentToggle` comment/uncomment current line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why change these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All README changes were dictated by linter. I think in above snippet *
is redundant. It's either *
or -
list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah I don't use a markdown linter, shame on me.
README.md
Outdated
** `gc4j` comment/uncomment 4 lines below the current line | ||
- `gcc` comment/uncomment current line, this does not take a count, if you want | ||
a count use the `gc{count}{motion}` | ||
- `gc{motion}` comment/uncomment selection defined by a motion: \*\*As lines are |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again why change these list types/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, just noticed that I have omitted one **
there. Will hold off fixing it for now until you give me green light. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
top banana
|
||
## Configure | ||
### Configure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
happy with current heading level,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was reported by linter as skipping heading levels.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only unwanted side effect here is that GitHub generates link in TOC, that might not be something you want as it gets populated. Perhaps a list then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a bad point actually, alright fair enough
README.md
Outdated
} | ||
``` | ||
|
||
**Ignore Empty Lines** | ||
#### Ignore Empty Lines |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again happy with these as just bold
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was reported by linter as something along the line: emphasis used in place of header. I agree with linter as emphasis such as bold text probably fit more within the sentence to emphasise it's part.
|
||
```lua | ||
-- Assumes this is being run in the context of the filetype... | ||
vim.api.nvim_buf_set_option(0, "commentstring", "# %s") | ||
``` | ||
|
||
# Installation | ||
## Installation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
happy with current heading level
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ignore this then based on your TOC comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made it a list, not sure if it's good enough now. Perhaps doesn't even need to be a list. Detail though.
Really looking forward to this getting merged, can we just remove any unnecessary doc changes? That should be it's own PR anyways imo. |
- implement `hook` setting allowing users to pass in arbitrary function to call before reading `commentstring` - format README file with prettier and fix all issues reported by markdownlint - use local variable for `vim.api` - use `<Cmd>` instead of `:` in key mappings to avoid changing modes
Still missing tests, tried to give it a go but never used plenary and wrote tests, do you mind helping out a bit? |
hey, regarding tests I can help for sure! |
Ah, perfect, that's very nice of you, thanks! |
hook
setting allowing users to pass in arbitraryfunction to call before reading
commentstring
markdownlint
vim.api
vim.api.nvim_command
with native API<Cmd>
instead of:
in key mappings to avoid changing modesCloses #6