Comments (5)
I think I can tackle this next week.
The only hurdle I can think of right now is we would want event
to be null
or string
or list of string
just like autoCmd.*.event
, and in the list of string
case we would want the keymap to be registered in both groupings of event
and I'm not sure how to implement that.
The basic string
case I'm pretty sure I can get going though!
from nixvim.
I think I can tackle this next week.
👀 If you run into issues or loose interest, I'm also tempted to work on this
in the
list of string
case we would want the keymap to be registered in both groupings ofevent
and I'm not sure how to implement that.
I hadn't thought about lists of events, that makes sense...
Would something like this work?
Draft one
eventKeys = let
# The mapping function converts a keymap
# with a _list of events_ into a _list
# of keymaps_, each with a _single_ event.
mapper = keymap:
if isList keymap.event
then map (event: keymap // {inherit event;}) keymap.event
else [keymap];
# Filter for keymaps with events
# this could be made more efficient by
# making the mapper handle null events
matched = filter (k: k ? "event" && k.event != null) cfg.keymaps;
# Map using mapper, then flatten the result
# this is a flat list of keymaps,
# each with a str-type event
flattened = concatMap mapper matched;
# Group by event
grouped = groupBy (k: k.event) flattened;
in grouped;
# keymaps without event
globalKeys = filter (k: !(k ? "event") || k.event == null) cfg.keymaps;
EDIT: A better approach might use foldAttrs
instead of groupBy
, since we probably want to also filter out the event
attribute:
eventKeymaps = let
inherit (builtins) concatMap isList isString map removeAttrs;
inherit (lib) foldAttrs;
# map a keymap into a list of pairs.
# only include keymaps that are associated with an event
# flatten keymaps associated with multiple events
# i.e. [{event=keymap}]
toPairs = attrs@{ event ? null, ... }: let
# TODO could convert to lua table at this point...
keymap = removeAttrs attrs ["event"];
in
if event == null then []
else if isString event then [{ ${event} = keymap; }]
else map (e: { ${e} = keymap; }) event;
# a list of pairs
# i.e. [{event=keymap}]
pairs = concatMap toPairs cfg.keymaps;
# group pairs into a single set
# i.e. {event=[keymap]}
grouped = foldAttrs (val: acc: acc ++ [val]) [] pairs;
in grouped
I threw this together on my phone so forgive any mistakes, it's mostly to demonstrate the concept.
from nixvim.
I think the general solution of adding event
to keymaps that I proposed above is probably not the right approach... Similar to #1214; it adds too much magic, on top of how neovim does things.
For LSPs we could instead make use of the existing onAttach
option (__lspOnAttach
func).
For a general solution, perhaps auto commands could support recieving a NixVim config in a similar way to the files
option? Maybe this should have its own issue...
from nixvim.
I've got some working code for this already which I was going to tidy up today, but I hear what you're saying.
What do the maintainers think @pta2002 , @traxys, @GaetanLepage?
from nixvim.
I think it would depend on how much it is applicable to different kind of plugins. If you have something maybe you can try to open a PR, but I won't guarantee that we would integrate this in nixvim.
from nixvim.
Related Issues (20)
- [BUG] 'undodir' option does not recognize '~' and '$HOME' HOT 2
- Add somesass_ls LSP server
- [BUG] Alias eslint is still in node-packages.nix HOT 3
- [BUG] "Alias eslint is still in node-packages.nix" when installing nixvim as a home-manager module HOT 4
- [BUG] Rustacean no longer works - rustanalyizer can't find dynamically linked cargo HOT 3
- Paths referenced by plugins.luasnip.from{Lua,Snipmate,Vscode}.*.paths are removed by `nix store gc` HOT 2
- [LSP REQUEST] basedpyright HOT 1
- plugins/todo-comments: assertions read `cfg.keymaps.todoTelescope.key`, which may be an undefined option HOT 10
- [PLUGIN REQUEST] markdown-oxide
- [PLUGIN REQUEST] hex.nvim
- [BUG] treesitter-just-grammar doesn't highlight anything HOT 2
- [BUG] Lualine options don't behave as like actual lualine configuration HOT 7
- none-ls: source packages missing HOT 6
- [BUG] Hardtime: 'enabled' option no longer works HOT 5
- [PLUGIN REQUEST] llm.nvim
- transitionType: allow passing extra warning text
- Re-imagined standalone mode (`nixvimConfig`)
- docs: use consistent admonitions syntax in options and user-guides HOT 4
- [BUG] <BUG> `plugins.treesitter.folding = true;` causes extremely slow startup
- [BUG] gitblame causing startup errors HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nixvim.