Skip to content

Commit 5250f8e

Browse files
authored
Merge pull request #480 from NotAShelf/more-option-stuff
neovim: gradually deprecate shorthand `vim.*` aliases to `vim.options` and `vim.globals`
2 parents ea05653 + 6f12930 commit 5250f8e

File tree

9 files changed

+178
-130
lines changed

9 files changed

+178
-130
lines changed

docs/release-notes/rl-0.7.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ configuration formats.
2828

2929
### `vim.maps` rewrite {#sec-vim-maps-rewrite}
3030

31-
Instead of specifying map modes using submodules (eg.: `vim.maps.normal`), a new
32-
`vim.keymaps` submodule with support for a `mode` option has been introduced. It
33-
can be either a string, or a list of strings, where a string represents the
34-
short-name of the map mode(s), that the mapping should be set for. See
35-
`:help map-modes` for more information.
31+
Instead of specifying map modes using submodules (e.g.: `vim.maps.normal`), a
32+
new `vim.keymaps` submodule with support for a `mode` option has been
33+
introduced. It can be either a string, or a list of strings, where a string
34+
represents the short-name of the map mode(s), that the mapping should be set
35+
for. See `:help map-modes` for more information.
3636

3737
For example:
3838

docs/release-notes/rl-0.8.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
- Implement [](#opt-vim.git.gitsigns.setupOpts) for user-specified setup table
1717
in gitsigns configuration.
1818

19+
- [](#opt-vim.options.mouse) no longer compares values to an enum of available
20+
mouse modes. This means you can provide any string without the module system
21+
warning you that it is invalid. Do keep in mind that this value is no longer
22+
checked, so you will be responsible for ensuring its validity.
23+
24+
- Deprecated `vim.enableEditorconfig` in favor of
25+
[](#opt-vim.globals.editorconfig).
26+
1927
[amadaluzia](https://github.com/amadaluzia):
2028

2129
[haskell-tools.nvim]: https://github.com/MrcJkb/haskell-tools.nvim

lib/languages.nix

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
inherit (lib.nvim.attrsets) mapListToAttrs;
77
in {
88
# Converts a boolean to a yes/no string. This is used in lots of
9-
# configuration formats.
9+
# configuration formats, and is not covered by `toLuaObject`
10+
toVimBool = bool:
11+
if bool
12+
then "yes"
13+
else "no";
14+
1015
diagnosticsToLua = {
1116
lang,
1217
config,
@@ -30,8 +35,8 @@ in {
3035

3136
mkEnable = desc:
3237
mkOption {
33-
description = "Turn on ${desc} for enabled languages by default";
34-
type = bool;
3538
default = false;
39+
type = bool;
40+
description = "Turn on ${desc} for enabled languages by default";
3641
};
3742
}

modules/extra/deprecations.nix

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
splitRight = "splitright";
1515
autoIndent = "autoindent";
1616
wordWrap = "wrap";
17+
showSignColumn = "signcolumn";
1718
};
1819
in {
1920
imports = concatLists [
@@ -35,23 +36,28 @@ in {
3536
vim.autopairs.enable has been removed in favor of per-plugin modules.
3637
You can enable nvim-autopairs with vim.autopairs.nvim-autopairs.enable instead.
3738
'')
39+
3840
(mkRemovedOptionModule ["vim" "autopairs" "type"] ''
3941
vim.autopairs.type has been removed in favor of per-plugin modules.
4042
You can enable nvim-autopairs with vim.autopairs.nvim-autopairs.enable instead.
4143
'')
44+
4245
(mkRemovedOptionModule ["vim" "autocomplete" "enable"] ''
4346
vim.autocomplete.enable has been removed in favor of per-plugin modules.
4447
You can enable nvim-cmp with vim.autocomplete.nvim-cmp.enable instead.
4548
'')
49+
4650
(mkRemovedOptionModule ["vim" "autocomplete" "type"] ''
4751
vim.autocomplete.type has been removed in favor of per-plugin modules.
4852
You can enable nvim-cmp with vim.autocomplete.nvim-cmp.enable instead.
4953
'')
54+
5055
(mkRemovedOptionModule ["vim" "autocomplete" "sources"] ''
5156
vim.autocomplete.sources has been removed in favor of per-plugin modules.
5257
You can add nvim-cmp sources with vim.autocomplete.nvim-cmp.sources
5358
instead.
5459
'')
60+
5561
(mkRemovedOptionModule ["vim" "snippets" "vsnip" "enable"] ''
5662
vim.snippets.vsnip.enable has been removed in favor of the more modern luasnip.
5763
'')
@@ -84,9 +90,12 @@ in {
8490
`tabstop` and `shiftwidth` manually in `vim.options` or per-filetype in a
8591
`ftplugin` directory added to your runtime path.
8692
'')
93+
94+
# 2024-12-02
95+
(mkRenamedOptionModule ["vim" "enableEditorconfig"] ["vim" "globals" "editorconfig"])
8796
]
8897

89-
# 2024-12-1
98+
# 2024-12-01
9099
# Migrated via batchRenameOptions. Further batch renames must be below this line.
91100
renamedVimOpts
92101
];

modules/neovim/init/basic.nix

Lines changed: 49 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
}: let
66
inherit (lib.options) mkOption mkEnableOption literalMD;
77
inherit (lib.strings) optionalString;
8+
inherit (lib.attrsets) optionalAttrs;
89
inherit (lib.types) enum bool str int either;
910
inherit (lib.generators) mkLuaInline;
1011
inherit (lib.nvim.dag) entryAfter;
@@ -58,24 +59,12 @@ in {
5859
description = "Prevent swapfile and backupfile from being created";
5960
};
6061

61-
showSignColumn = mkOption {
62-
type = bool;
63-
default = true;
64-
description = "Show the sign column";
65-
};
66-
6762
bell = mkOption {
6863
type = enum ["none" "visual" "on"];
6964
default = "none";
7065
description = "Set how bells are handled. Options: on, visual or none";
7166
};
7267

73-
enableEditorconfig = mkOption {
74-
type = bool;
75-
default = true;
76-
description = "Follow editorconfig rules in current directory";
77-
};
78-
7968
searchCase = mkOption {
8069
type = enum ["ignore" "smart" "sensitive"];
8170
default = "sensitive";
@@ -106,63 +95,55 @@ in {
10695
# Set options that were previously interpolated in 'luaConfigRC.basic' as vim.options (vim.o)
10796
# and 'vim.globals' (vim.g). Future options, if possible, should be added here instead of the
10897
# luaConfigRC section below.
109-
options = pushDownDefault {
110-
encoding = "utf-8";
111-
hidden = true;
112-
expandtab = true;
113-
};
114-
115-
globals = pushDownDefault {
116-
editorconfig = cfg.enableEditorconfig;
117-
};
118-
119-
# Options that are more difficult to set through 'vim.options'. Fear not, though
120-
# as the Lua DAG is still as powerful as it could be.
98+
options = pushDownDefault (lib.mergeAttrsList [
99+
{
100+
# Options that are always set, with a lower priority
101+
encoding = "utf-8";
102+
hidden = true;
103+
expandtab = true;
104+
105+
# Junkfile Behaviour
106+
swapfile = !cfg.preventJunkFiles;
107+
backup = !cfg.preventJunkFiles;
108+
writebackup = !cfg.preventJunkFiles;
109+
}
110+
111+
(optionalAttrs cfg.undoFile.enable {
112+
undofile = true;
113+
undodir = cfg.undoFile.path;
114+
})
115+
116+
(optionalAttrs (cfg.bell == "none") {
117+
errorbells = false;
118+
visualbell = false;
119+
})
120+
121+
(optionalAttrs (cfg.bell == "on") {
122+
visualbell = false;
123+
})
124+
125+
(optionalAttrs (cfg.bell == "visual") {
126+
visualbell = false;
127+
})
128+
129+
(optionalAttrs (cfg.lineNumberMode == "relative") {
130+
relativenumber = true;
131+
})
132+
133+
(optionalAttrs (cfg.lineNumberMode == "number") {
134+
number = true;
135+
})
136+
137+
(optionalAttrs (cfg.lineNumberMode == "relNumber") {
138+
number = true;
139+
relativenumber = true;
140+
})
141+
]);
142+
143+
# Options that are more difficult to set through 'vim.options'. Namely, appending values
144+
# to pre-set Neovim options. Fear not, though as the Lua DAG is still as powerful as it
145+
# could be.
121146
luaConfigRC.basic = entryAfter ["globalsScript"] ''
122-
-- Settings that are set for everything
123-
vim.opt.shortmess:append("c")
124-
125-
${optionalString cfg.undoFile.enable ''
126-
vim.o.undofile = true
127-
vim.o.undodir = ${toLuaObject cfg.undoFile.path}
128-
''}
129-
130-
${optionalString cfg.showSignColumn ''
131-
vim.o.signcolumn = "yes"
132-
''}
133-
134-
${optionalString cfg.preventJunkFiles ''
135-
vim.o.swapfile = false
136-
vim.o.backup = false
137-
vim.o.writebackup = false
138-
''}
139-
140-
${optionalString (cfg.bell == "none") ''
141-
vim.o.errorbells = false
142-
vim.o.visualbell = false
143-
''}
144-
145-
${optionalString (cfg.bell == "on") ''
146-
vim.o.visualbell = false
147-
''}
148-
149-
${optionalString (cfg.bell == "visual") ''
150-
vim.o.errorbells = false
151-
''}
152-
153-
${optionalString (cfg.lineNumberMode == "relative") ''
154-
vim.o.relativenumber = true
155-
''}
156-
157-
${optionalString (cfg.lineNumberMode == "number") ''
158-
vim.o.number = true
159-
''}
160-
161-
${optionalString (cfg.lineNumberMode == "relNumber") ''
162-
vim.o.number = true
163-
vim.o.relativenumber = true
164-
''}
165-
166147
${optionalString cfg.useSystemClipboard ''
167148
vim.opt.clipboard:append("unnamedplus")
168149
''}

modules/neovim/init/spellcheck.nix

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ in {
124124
nvim --headless --clean \
125125
--cmd "mkspell $out/spell/$name.add.spl $spellfile" -Es -n
126126
done
127-
128127
'';
129128
in
130129
mkIf (cfg.extraSpellWords != {}) [
@@ -133,10 +132,12 @@ in {
133132
compileJoinedSpellfiles.outPath
134133
];
135134

136-
luaConfigRC.spellcheck = entryAfter ["basic"] ''
137-
vim.opt.spell = true
138-
vim.opt.spelllang = ${listToLuaTable cfg.languages}
135+
options = {
136+
spell = true;
137+
spelllang = cfg.languages;
138+
};
139139

140+
luaConfigRC.spellcheck = entryAfter ["basic"] ''
140141
-- Disable spellchecking for certain filetypes
141142
-- as configured by `vim.spellcheck.ignoredFiletypes`
142143
vim.api.nvim_create_augroup("nvf_autocmds", {clear = false})

modules/plugins/utility/gestures/gesture-nvim/config.nix

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,47 @@
1515
mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions;
1616
in {
1717
config = mkIf cfg.enable {
18-
vim.startPlugins = ["gesture-nvim"];
19-
20-
vim.maps.normal = mkMerge [
21-
(mkSetLuaBinding mappings.draw "require('gesture').draw")
22-
(mkSetLuaBinding mappings.finish "require('gesture').finish")
23-
(mkIf (mappings.draw.value == "<RightDrag>") {
24-
"<RightMouse>" = {action = "<Nop>";};
25-
})
26-
];
27-
28-
vim.pluginRC.gesture-nvim = entryAnywhere ''
29-
vim.opt.mouse = "a"
30-
31-
local gesture = require("gesture")
32-
gesture.register({
33-
name = "scroll to bottom",
34-
inputs = { gesture.up(), gesture.down() },
35-
action = "normal! G",
36-
})
37-
gesture.register({
38-
name = "next tab",
39-
inputs = { gesture.right() },
40-
action = "tabnext",
41-
})
42-
gesture.register({
43-
name = "previous tab",
44-
inputs = { gesture.left() },
45-
action = function(ctx) -- also can use callable
46-
vim.cmd.tabprevious()
47-
end,
48-
})
49-
gesture.register({
50-
name = "go back",
51-
inputs = { gesture.right(), gesture.left() },
52-
-- map to `<C-o>` keycode
53-
action = [[lua vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<C-o>", true, false, true), "n", true)]],
54-
})
55-
'';
18+
vim = {
19+
startPlugins = ["gesture-nvim"];
20+
21+
maps.normal = mkMerge [
22+
(mkSetLuaBinding mappings.draw "require('gesture').draw")
23+
(mkSetLuaBinding mappings.finish "require('gesture').finish")
24+
(mkIf (mappings.draw.value == "<RightDrag>") {
25+
"<RightMouse>" = {action = "<Nop>";};
26+
})
27+
];
28+
29+
options.mouse = "a";
30+
pluginRC.gesture-nvim = entryAnywhere ''
31+
local gesture = require("gesture")
32+
gesture.register({
33+
name = "scroll to bottom",
34+
inputs = { gesture.up(), gesture.down() },
35+
action = "normal! G",
36+
})
37+
38+
gesture.register({
39+
name = "next tab",
40+
inputs = { gesture.right() },
41+
action = "tabnext",
42+
})
43+
44+
gesture.register({
45+
name = "previous tab",
46+
inputs = { gesture.left() },
47+
action = function(ctx) -- also can use callable
48+
vim.cmd.tabprevious()
49+
end,
50+
})
51+
52+
gesture.register({
53+
name = "go back",
54+
inputs = { gesture.right(), gesture.left() },
55+
-- map to `<C-o>` keycode
56+
action = [[lua vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<C-o>", true, false, true), "n", true)]],
57+
})
58+
'';
59+
};
5660
};
5761
}

modules/plugins/utility/gestures/gesture-nvim/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
_: {
1+
{
22
imports = [
33
./gesture-nvim.nix
44
./config.nix

0 commit comments

Comments
 (0)