mirror of
https://github.com/nix-community/home-manager
synced 2024-12-24 10:49:48 +01:00
vim: add option programs.vim.settings
This option gathers basic Vim options into a single place. The idea is to allow many options without making the Home Manager documentation too verbose. This also deprecates the options `programs.vim.lineNumbers` and `programs.vim.tabSize`. Fixes #69.
This commit is contained in:
parent
23d3539fcb
commit
aa974c0dc3
2 changed files with 122 additions and 12 deletions
|
@ -255,6 +255,25 @@ in
|
|||
'xsession.windowManager.i3'.
|
||||
'';
|
||||
}
|
||||
|
||||
{
|
||||
time = "2017-09-30T09:44:18+00:00";
|
||||
condition = with config.programs.vim;
|
||||
enable && (tabSize != null || lineNumbers != null);
|
||||
message = ''
|
||||
The options 'programs.vim.tabSize' and 'programs.vim.lineNumbers' have
|
||||
been deprecated and will be removed in the near future.
|
||||
|
||||
The new and preferred way to configure tab size and line numbers is to
|
||||
use the more general 'programs.vim.settings' option. Specifically,
|
||||
instead of
|
||||
|
||||
- 'programs.vim.lineNumbers' use 'programs.vim.settings.number', and
|
||||
|
||||
- 'programs.vim.tabSize' use 'programs.vim.settings.tabstop' and
|
||||
'programs.vim.settings.shiftwidth'.
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
@ -7,6 +7,36 @@ let
|
|||
cfg = config.programs.vim;
|
||||
defaultPlugins = [ "sensible" ];
|
||||
|
||||
knownSettings = {
|
||||
background = types.enum [ "dark" "light" ];
|
||||
expandtab = types.bool;
|
||||
history = types.int;
|
||||
number = types.bool;
|
||||
relativenumber = types.bool;
|
||||
shiftwidth = types.int;
|
||||
tabstop = types.int;
|
||||
};
|
||||
|
||||
vimSettingsType = types.submodule {
|
||||
options =
|
||||
let
|
||||
opt = name: type: mkOption {
|
||||
type = types.nullOr type;
|
||||
default = null;
|
||||
visible = false;
|
||||
};
|
||||
in
|
||||
mapAttrs opt knownSettings;
|
||||
};
|
||||
|
||||
setExpr = name: value:
|
||||
let
|
||||
v =
|
||||
if isBool value then (if value then "" else "no") + name
|
||||
else name + "=" + toString value;
|
||||
in
|
||||
optionalString (value != null) ("set " + v);
|
||||
|
||||
in
|
||||
|
||||
{
|
||||
|
@ -17,14 +47,22 @@ in
|
|||
lineNumbers = mkOption {
|
||||
type = types.nullOr types.bool;
|
||||
default = null;
|
||||
description = "Whether to show line numbers.";
|
||||
description = ''
|
||||
Whether to show line numbers. DEPRECATED: Use
|
||||
<varname>programs.vim.settings.number</varname>.
|
||||
'';
|
||||
};
|
||||
|
||||
tabSize = mkOption {
|
||||
type = types.nullOr types.int;
|
||||
default = null;
|
||||
default = null;
|
||||
example = 4;
|
||||
description = "Set tab size and shift width to a specified number of spaces.";
|
||||
description = ''
|
||||
Set tab size and shift width to a specified number of
|
||||
spaces. DEPRECATED: Use
|
||||
<varname>programs.vim.settings.tabstop</varname> and
|
||||
<varname>programs.vim.settings.shiftwidth</varname>.
|
||||
'';
|
||||
};
|
||||
|
||||
plugins = mkOption {
|
||||
|
@ -37,6 +75,38 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
settings = mkOption {
|
||||
type = vimSettingsType;
|
||||
default = {};
|
||||
example = literalExample ''
|
||||
{
|
||||
expandtab = true;
|
||||
history = 1000;
|
||||
background = "dark";
|
||||
}
|
||||
'';
|
||||
description = ''
|
||||
At attribute set of Vim settings. The attribute names and
|
||||
corresponding values must be among the following supported
|
||||
options.
|
||||
|
||||
<informaltable frame="none"><tgroup cols="1"><tbody>
|
||||
${concatStringsSep "\n" (
|
||||
mapAttrsToList (n: v: ''
|
||||
<row>
|
||||
<entry><varname>${n}</varname></entry>
|
||||
<entry>${v.description}</entry>
|
||||
</row>
|
||||
'') knownSettings
|
||||
)}
|
||||
</tbody></tgroup></informaltable>
|
||||
|
||||
See the Vim documentation for detailed descriptions of these
|
||||
options. Note, use <varname>extraConfig</varname> to
|
||||
manually set any options not listed above.
|
||||
'';
|
||||
};
|
||||
|
||||
extraConfig = mkOption {
|
||||
type = types.lines;
|
||||
default = "";
|
||||
|
@ -57,12 +127,11 @@ in
|
|||
|
||||
config = (
|
||||
let
|
||||
optionalBoolean = name: val: optionalString (val != null) (if val then "set ${name}" else "unset ${name}");
|
||||
optionalInteger = name: val: optionalString (val != null) "set ${name}=${toString val}";
|
||||
customRC = ''
|
||||
${optionalBoolean "number" cfg.lineNumbers}
|
||||
${optionalInteger "tabstop" cfg.tabSize}
|
||||
${optionalInteger "shiftwidth" cfg.tabSize}
|
||||
${concatStringsSep "\n" (
|
||||
filter (v: v != "") (
|
||||
mapAttrsToList setExpr (
|
||||
builtins.intersectAttrs knownSettings cfg.settings)))}
|
||||
|
||||
${cfg.extraConfig}
|
||||
'';
|
||||
|
@ -76,9 +145,31 @@ in
|
|||
];
|
||||
};
|
||||
|
||||
in mkIf cfg.enable {
|
||||
programs.vim.package = vim;
|
||||
home.packages = [ cfg.package ];
|
||||
}
|
||||
in mkIf cfg.enable (mkMerge [
|
||||
{
|
||||
programs.vim.package = vim;
|
||||
home.packages = [ cfg.package ];
|
||||
}
|
||||
|
||||
(mkIf (cfg.lineNumbers != null) {
|
||||
warnings = [
|
||||
("'programs.vim.lineNumbers' is deprecated, "
|
||||
+ "use 'programs.vim.settings.number'")
|
||||
];
|
||||
|
||||
programs.vim.settings.number = cfg.lineNumbers;
|
||||
})
|
||||
|
||||
(mkIf (cfg.tabSize != null) {
|
||||
warnings = [
|
||||
("'programs.vim.tabSize' is deprecated, use "
|
||||
+ "'programs.vim.settings.tabstop' and "
|
||||
+ "'programs.vim.settings.shiftwidth'")
|
||||
];
|
||||
|
||||
programs.vim.settings.tabstop = cfg.tabSize;
|
||||
programs.vim.settings.shiftwidth = cfg.tabSize;
|
||||
})
|
||||
])
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue