From 4f8b523579c4afe8d419e453a42bc0a7a706ea9a Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Fri, 17 May 2024 13:25:36 +0300 Subject: [PATCH] lib/types: add extCommasEnum... that convert enum or list of enum to commas --- lib/types.nix | 10 +++++--- modules/vim/options.nix | 54 ++++++++++++++++++++--------------------- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/lib/types.nix b/lib/types.nix index 2af9dbc..63309d5 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -1,12 +1,16 @@ { lib, nix2lua }: let - extCommas = with lib.types; + extendCommasTypeWith = t: + with lib.types; coercedTo - (either (listOf str) commas) + (either (listOf t) t) (x: lib.concatStringsSep "," (lib.toList x)) commas; + extCommas = extendCommasTypeWith lib.types.str; + extCommasEnum = variants: extendCommasTypeWith (lib.types.enum variants); + modeEnum = lib.types.enum [ "" "n" "!" "i" "c" "v" "x" "s" "o" "t" "l" ]; mode = with lib.types; either modeEnum (uniq (listOf modeEnum)); @@ -151,6 +155,6 @@ let }); in { - inherit extCommas; + inherit extCommas extCommasEnum; inherit mode keymap; } diff --git a/modules/vim/options.nix b/modules/vim/options.nix index 8d43087..018071e 100644 --- a/modules/vim/options.nix +++ b/modules/vim/options.nix @@ -24,7 +24,7 @@ let sharedGlobalOrWindow = with lib.types; { fillchars = { - type = listOf (enum [ + type = extCommasEnum [ "stl" "stlnc" "wbr" @@ -43,7 +43,7 @@ let "msgsep" "eob" "lastline" - ]); + ]; vimDefault = [ ]; description = '' Characters to fill the statuslines, vertical separators and special lines in the window. @@ -100,7 +100,7 @@ let }; virtualedit = { - type = listOf (enum [ "block" "insert" "all" "onemore" "none" "NONE" ]); + type = extCommasEnum [ "block" "insert" "all" "onemore" "none" "NONE" ]; vimDefault = [ ]; description = '' Virtual editing means that the cursor can be positioned where there is @@ -144,7 +144,7 @@ let }; backupcopy = { - type = listOf (enum [ "yes" "no" "auto" "breaksymlink" "breakhardlink" ]); + type = extCommasEnum [ "yes" "no" "auto" "breaksymlink" "breakhardlink" ]; vimDefault = [ "auto" ]; description = '' When writing a file and a backup is made, this option tells how it's @@ -457,7 +457,7 @@ let }; backspace = { - type = listOf (enum [ "indent" "eol" "start" "nostop" ]); + type = extCommasEnum [ "indent" "eol" "start" "nostop" ]; vimDefault = [ "indent" "eol" "start" ]; description = '' Influences the working of , , CTRL-W and CTRL-U in Insert @@ -521,7 +521,7 @@ let }; belloff = { - type = listOf (enum [ + type = extCommasEnum [ "all" "backspace" "cursor" @@ -539,7 +539,7 @@ let "shell" "spell" "willmode" - ]); + ]; vimDefault = [ "all" ]; description = '' Specifies for which events the bell will not be rung. It is a comma- @@ -596,7 +596,7 @@ let }; casemap = { - type = listOf (enum [ "internal" "keepascii" ]); + type = extCommasEnum [ "internal" "keepascii" ]; vimDefault = [ "internal" "keepascii" ]; description = '' Specifies details about changing the case of letters. It may contain @@ -654,14 +654,14 @@ let }; completeopt = { - type = listOf (enum [ + type = extCommasEnum [ "menu" "menuone" "longest" "preview" "noinsert" "noselect" - ]); + ]; vimDefault = [ "menu" "preview" ]; description = '' A comma-separated list of options for Insert mode completion |ins-completion|. @@ -695,7 +695,7 @@ let }; debug = { - type = listOf (enum [ "msg" "throw" "beep" ]); + type = extCommasEnum [ "msg" "throw" "beep" ]; vimDefault = [ ]; description = '' These values can be used: @@ -756,7 +756,7 @@ let }; display = { - type = listOf (enum [ "lastline" "truncate" "uhex" "msgsep" ]); + type = extCommasEnum [ "lastline" "truncate" "uhex" "msgsep" ]; vimDefault = [ "lastline" ]; description = '' Change the way text is displayed. @@ -850,7 +850,7 @@ let }; fileformats = { - type = listOf (enum [ "dos" "unix" "mac" ]); + type = extCommasEnum [ "dos" "unix" "mac" ]; vimDefault = '' Windows default: ["dos" "unix"], Unix default: ["unix" "dos"] @@ -896,7 +896,7 @@ let }; foldopen = { - type = listOf (enum [ + type = extCommasEnum [ "all" "block" "hor" @@ -908,7 +908,7 @@ let "search" "tag" "undo" - ]); + ]; vimDefault = [ "block" "hor" @@ -1640,7 +1640,7 @@ let }; redrawdebug = { - type = listOf (enum [ "compositor" "line" "flush" "nothrottle" "invalid" "nodelta" ]); + type = extCommasEnum [ "compositor" "line" "flush" "nothrottle" "invalid" "nodelta" ]; vimDefault = [ ]; description = '' Flags to change the way redrawing works, for debugging purposes. @@ -1748,7 +1748,7 @@ let }; scrollopt = { - type = listOf (enum [ "ver" "hor" "jump" ]); + type = extCommasEnum [ "ver" "hor" "jump" ]; vimDefault = [ "ver" "jump" ]; description = '' This is a comma-separated list of words that specifies how @@ -1769,7 +1769,7 @@ let }; sessionoptions = { - type = listOf (enum [ + type = extCommasEnum [ "blank" "buffers" "curdir" @@ -1785,7 +1785,7 @@ let "terminal" "winpos" "winsize" - ]); + ]; vimDefault = [ "blank" "buffers" @@ -2214,7 +2214,7 @@ let }; switchbuf = { - type = listOf (enum [ "useopen" "usetab" "split" "vsplit" "newtab" "uselast" ]); + type = extCommasEnum [ "useopen" "usetab" "split" "vsplit" "newtab" "uselast" ]; vimDefault = [ "uselast" ]; description = '' This option controls the behavior when switching between buffers. @@ -2311,7 +2311,7 @@ let }; termpastefilter = { - type = listOf (enum [ "BS" "HT" "FF" "ESC" "DEL" "C0" "C1" ]); + type = extCommasEnum [ "BS" "HT" "FF" "ESC" "DEL" "C0" "C1" ]; vimDefault = [ "BS" "HT" "ESC" "DEL" ]; description = '' list of options for specifying control characters @@ -2530,7 +2530,7 @@ let }; viewoptions = { - type = listOf (enum [ "cursor" "curdir" "folds" "options" "localoptions" "slash" "unix" ]); + type = extCommasEnum [ "cursor" "curdir" "folds" "options" "localoptions" "slash" "unix" ]; vimDefault = [ "folds" "cursor" "curdir" ]; description = '' Changes the effect of the |:mkview| command. @@ -2557,7 +2557,7 @@ let }; whichwrap = { - type = listOf (enum [ "b" "s" "h" "l" "<" ">" "~" "[" "]" ]); + type = extCommasEnum [ "b" "s" "h" "l" "<" ">" "~" "[" "]" ]; vimDefault = [ "b" "s" ]; description = '' Allow specified keys that move the cursor left/right to move to the @@ -2672,7 +2672,7 @@ let }; wildoptions = { - type = listOf (enum [ "fuzzy" "pum" "tagfile" ]); + type = extCommasEnum [ "fuzzy" "pum" "tagfile" ]; vimDefault = [ "pum" "tagfile" ]; description = '' A list of words that change how |cmdline-completion| is done. @@ -2953,7 +2953,7 @@ let }; cursorlineopt = { - type = listOf (enum [ "line" "screenline" "number" "both" ]); + type = extCommasEnum [ "line" "screenline" "number" "both" ]; vimDefault = [ "number" "line" ]; description = '' list of settings for how 'cursorline' is displayed. @@ -3889,7 +3889,7 @@ let }; nrformats = { - type = listOf (enum [ "alpha" "octal" "hex" "bin" "unsigned" ]); + type = extCommasEnum [ "alpha" "octal" "hex" "bin" "unsigned" ]; vimDefault = [ "bin" "hex" ]; description = '' This defines what bases Vim will consider for numbers when using the @@ -4052,7 +4052,7 @@ let }; spelloptions = { - type = listOf (enum [ "camel" "noplainbuffer" ]); + type = extCommasEnum [ "camel" "noplainbuffer" ]; vimDefault = [ ]; description = '' list of options for spell checking: