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

Add hook functionality, update docs #23

Merged
merged 1 commit into from
Jul 27, 2021
Merged

Add hook functionality, update docs #23

merged 1 commit into from
Jul 27, 2021

Conversation

gegoune
Copy link
Contributor

@gegoune gegoune commented Jul 10, 2021

  • implement hook setting allowing users to pass in arbitrary
    function to call before reading commentstring
  • formats README file with prettier and fixes all issues reported by
    markdownlint
  • use local variable for vim.api
  • replace vim.api.nvim_command with native API
  • use <Cmd> instead of : in key mappings to avoid changing modes

Closes #6

@gegoune
Copy link
Contributor Author

gegoune commented Jul 10, 2021

@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 hook setting. Maybe something more descriptive such as pre_comment_hook?

@terrortylor
Copy link
Owner

terrortylor commented Jul 23, 2021

Sorry been awol.
Sure, take a look at the tests in the tests directory, and the Makefile for how to run.
You will need plentary (https://github.com/nvim-lua/plenary.nvim)

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 ;)
(I don't really mind they are all sensible!)

EDIT:
Actually a lot of the README style changes seem pointless, and I'm not really on board with them

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([[
Copy link
Owner

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.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still holds IMO

Copy link
Contributor Author

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.

Copy link
Owner

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

}

function M.get_comment_wrapper()
if type(M.config.hook) == 'function' then
Copy link
Owner

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.

Copy link
Contributor Author

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.

Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change these?

Copy link
Contributor Author

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.

Copy link
Owner

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
Copy link
Owner

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/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if your intention here was to have indented list, ** does not do that though.
Without my changes this block looks like:
Screenshot 2021-07-24 at 15 57 57
with them it changes to
Screenshot 2021-07-24 at 15 58 33

Copy link
Contributor Author

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. :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

top banana


## Configure
### Configure
Copy link
Owner

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,

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Owner

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
Copy link
Owner

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

Copy link
Contributor Author

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
Copy link
Owner

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

Copy link
Owner

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

Copy link
Contributor Author

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.

@mvllow
Copy link

mvllow commented Jul 23, 2021

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
@gegoune
Copy link
Contributor Author

gegoune commented Jul 25, 2021

Still missing tests, tried to give it a go but never used plenary and wrote tests, do you mind helping out a bit?

@terrortylor
Copy link
Owner

hey, regarding tests I can help for sure!
I'm super busy atm but maybe we can do a pair session?
I'll approve and merge for now (looks fine)
and then we can arrange a time to go over it together?

@gegoune
Copy link
Contributor Author

gegoune commented Jul 27, 2021

Ah, perfect, that's very nice of you, thanks!

@terrortylor terrortylor merged commit 0aa4cbf into terrortylor:main Jul 27, 2021
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.

Context dependant comment string
3 participants