-
-
Notifications
You must be signed in to change notification settings - Fork 274
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
plugins/navbuddy: init + tests #600
Conversation
plugins/utils/navbuddy.nix
Outdated
''; | ||
|
||
# TODO: how to set mappings, like in nvim-cmp ? | ||
mapping = {}; |
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.
How do I set the typing for key maps ?
For example we have:
mappings = {
["<esc>"] = actions.close(), -- Close and cursor to original location
["q"] = actions.close(),
["j"] = actions.next_sibling(), -- down
}
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.
You would map the keys to some actions (i.e. strings: close
; next_sibling
) and then you create the mappings from that yourself.
See
nixvim/plugins/utils/spider.nix
Lines 54 to 65 in 32a64af
mappings = | |
mapAttrs' | |
(motion: key: { | |
name = key; | |
value = { | |
action = "function() require('spider').motion('${motion}') end"; | |
lua = true; | |
inherit (cfg.keymaps) silent; | |
desc = "Spider-${motion}"; | |
}; | |
}) | |
cfg.keymaps.motions; |
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
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.
Ok, I actually took the time to look at the plugin.
Actually, mappings
is a plugin option itself.
We should not create the mappings using the nixvim maps
option.
We should only provide the given mappings in the setupOptions
attrs.
As for the option declaration, I would go for:
mappings =
helpers.defaultNullOpts.mkNullable
(with types;
attrsOf
(either
str
helpers.rawTypes
)
)
''
{
"<esc>" = "close";
q = "close";
...
}
''
''
<Description>
Mention that it can take either a `rawType` (for user liberty) or an action name.
''
Then, in the implementation,
setupOptions = with cfg; {
...
mappings = ifNonNull' mappings
(mapAttrs
(key: action:
if isString action
then helpers.mkRaw "actions.${action}()"
else action
)
mappings
...
} // cfg.extraOptions;
And, in extraConfigLua
, add local actions = require("nvim-navbuddy.actions")
before the call to setup()
.
Of course, you can get rid of the keymapsSilent
option.
Sorry for you needing to do that, im still trying to get my head around nix 😓. |
No worry !
Don't forget this :) |
4ac0a49
to
63e5d5e
Compare
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
plugins/utils/navbuddy.nix
Outdated
enabled = helpers.defaultNullOpts.mkBool true; | ||
icons = { | ||
leaf = helpers.defaultNullOpts.mkStr " " '' | ||
The icon to use for leaf nodes. | ||
''; | ||
|
||
leaf_selected = helpers.defaultNullOpts.mkStr " → " '' | ||
The icon to use for selected leaf node. | ||
''; | ||
branch = helpers.defaultNullOpts.mkStr " " '' | ||
The icon to use for branch nodes. | ||
''; | ||
}; |
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.
enabled = helpers.defaultNullOpts.mkBool true; | |
icons = { | |
leaf = helpers.defaultNullOpts.mkStr " " '' | |
The icon to use for leaf nodes. | |
''; | |
leaf_selected = helpers.defaultNullOpts.mkStr " → " '' | |
The icon to use for selected leaf node. | |
''; | |
branch = helpers.defaultNullOpts.mkStr " " '' | |
The icon to use for branch nodes. | |
''; | |
}; | |
enabled = helpers.defaultNullOpts.mkBool true "Enable node markers."; | |
icons = { | |
leaf = helpers.defaultNullOpts.mkStr " " '' | |
The icon to use for leaf nodes. | |
''; | |
leaf_selected = helpers.defaultNullOpts.mkStr " → " '' | |
The icon to use for selected leaf node. | |
''; | |
branch = helpers.defaultNullOpts.mkStr " " '' | |
The icon to use for branch nodes. | |
''; | |
}; |
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.
Also, leaf_selected
-> leafSelected
. We use camelCase for all of our options.
Don't forget to write leaf_selected = leafSelected
in the config
section below.
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.
ahh yes ofc course will add this change then update in setup options
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.
And don't forget to change it in the test.
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
plugins/utils/navbuddy.nix
Outdated
border = helpers.defaultNullOpts.mkBorder "rounded" "double" "solid" "none" '' | ||
"rounded", "double", "solid", "none" or an array with eight chars building up the border in a clockwise fashion | ||
starting with the top-left corner. eg: { "╔", "═" ,"╗", "║", "╝", "═", "╚", "║" }. | ||
''; |
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.
mkBorder
is wrongly called here and elsewhere as well.
It expects the default
value for the option, the name
of what the borders are for and an optional desc
ription for this option (you can simply provide ""
if you don't want to provide it).
Function declaration:
Line 140 in 05b7773
mkBorder = default: name: desc: |
Examples of how it is properly used: https://github.com/search?q=repo%3Anix-community%2Fnixvim%20mkBorder&type=code
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.
hahah yeh I just saw this error running the nix flake check locally.
Ahh I see I though it was like an enum, not sure why! Fixing now.
plugins/utils/navbuddy.nix
Outdated
node_markers = nodeMarkers; | ||
icons = with icons; { | ||
leaf_selected = leafSelected; | ||
inherit leaf branch; | ||
}; | ||
|
||
use_default_mapping = useDefaultMapping; |
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.
Be careful, there are two icons
options. The one with leafSelected
is inside nodeMarkers
.
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
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.
A few last formatting changes.
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
Co-authored-by: Gaétan Lepage <33058747+GaetanLepage@users.noreply.github.com>
Thanks for all the help with this pR. I hope the next few I will be able to do mostly on my own!!! (ROI) |
Thank you for your contribution ! It is really welcomed. |
PR to add support for the [nvim-navbuddy](https://github.com/SmiteshP/nvim-navbuddy plugin