3
0
Fork 0
forked from mirrors/nixpkgs

vimUtils: remove vam support

having this many (complex) options not only is hard to maintain but I cant see the benefit of these options now that vim supports packages
This commit is contained in:
Matthieu Coudron 2022-06-25 19:35:48 +02:00 committed by Matthieu Coudron
parent 63230b2fce
commit 341b9564bb
3 changed files with 11 additions and 233 deletions

View file

@ -5,11 +5,9 @@ and additional libraries.
Loading can be deferred; see examples.
At the moment we support three different methods for managing plugins:
At the moment we support two different methods for managing plugins:
- Vim packages (*recommended*)
- VAM (=vim-addon-manager)
- Pathogen
- vim-plug
## Custom configuration {#custom-configuration}
@ -213,100 +211,6 @@ neovim.override {
}
```
## Managing plugins with VAM {#managing-plugins-with-vam}
### Handling dependencies of Vim plugins {#handling-dependencies-of-vim-plugins}
VAM introduced .json files supporting dependencies without versioning
assuming that "using latest version" is ok most of the time.
### Example {#example}
First create a vim-scripts file having one plugin name per line. Example:
```vim
"tlib"
{'name': 'vim-addon-sql'}
{'filetype_regex': '\%(vim)$', 'names': ['reload', 'vim-dev-plugin']}
```
A discrete vim-scripts file can be read by VAM as well like this:
```vim
call vam#Scripts(expand('~/.vim-scripts'), {})
```
Create a default.nix file:
```nix
{ nixpkgs ? import <nixpkgs> {}, compiler ? "ghc7102" }:
nixpkgs.vim_configurable.customize { name = "vim"; vimrcConfig.vam.pluginDictionaries = [ "vim-addon-vim2nix" ]; }
```
Create a generate.vim file:
```vim
ActivateAddons vim-addon-vim2nix
let vim_scripts = "vim-scripts"
call nix#ExportPluginsForNix({
\ 'path_to_nixpkgs': eval('{"'.substitute(substitute(substitute($NIX_PATH, ':', ',', 'g'), '=',':', 'g'), '\([:,]\)', '"\1"',"g").'"}')["nixpkgs"],
\ 'cache_file': '/tmp/vim2nix-cache',
\ 'try_catch': 0,
\ 'plugin_dictionaries': ["vim-addon-manager"]+map(readfile(vim_scripts), 'eval(v:val)')
\ })
```
Then run
```bash
nix-shell -p vimUtils.vim_with_vim2nix --command "vim -c 'source generate.vim'"
```
You should get a Vim buffer with the nix derivations (output1) and vam.pluginDictionaries (output2).
You can add your Vim to your system's configuration file like this and start it by "vim-my":
```nix
my-vim =
let plugins = let inherit (vimUtils) buildVimPluginFrom2Nix; in {
copy paste output1 here
}; in vim_configurable.customize {
name = "vim-my";
vimrcConfig.vam.knownPlugins = plugins; # optional
vimrcConfig.vam.pluginDictionaries = [
copy paste output2 here
];
};
```
Sample output1:
```nix
"reload" = buildVimPluginFrom2Nix { # created by nix#NixDerivation
name = "reload";
src = fetchgit {
url = "https://github.com/xolox/vim-reload";
rev = "0a601a668727f5b675cb1ddc19f6861f3f7ab9e1";
sha256 = "0vb832l9yxj919f5hfg6qj6bn9ni57gnjd3bj7zpq7d4iv2s4wdh";
};
dependencies = ["nim-misc"];
};
[...]
```
Sample output2:
```nix
[
''vim-addon-manager''
''tlib''
{ "name" = ''vim-addon-sql''; }
{ "filetype_regex" = ''\%(vim)$$''; "names" = [ ''reload'' ''vim-dev-plugin'' ]; }
]
```
## Adding new plugins to nixpkgs {#adding-new-plugins-to-nixpkgs}
Nix expressions for Vim plugins are stored in [pkgs/applications/editors/vim/plugins](https://github.com/NixOS/nixpkgs/tree/master/pkgs/applications/editors/vim/plugins). For the vast majority of plugins, Nix expressions are automatically generated by running [`./update.py`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/vim/plugins/update.py). This creates a [generated.nix](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/vim/plugins/generated.nix) file based on the plugins listed in [vim-plugin-names](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/vim/plugins/vim-plugin-names). Plugins are listed in alphabetical order in `vim-plugin-names` using the format `[github username]/[repository]@[gitref]`. For example https://github.com/scrooloose/nerdtree becomes `scrooloose/nerdtree`.

View file

@ -33,24 +33,6 @@ vim-with-plugins in PATH:
# To automatically load a plugin when opening a filetype, add vimrc lines like:
# autocmd FileType php :packadd phpCompletion
};
# plugins can also be managed by VAM
vimrcConfig.vam.knownPlugins = pkgs.vimPlugins; # optional
vimrcConfig.vam.pluginDictionaries = [
# load always
{ name = "youcompleteme"; }
{ names = ["youcompleteme" "foo"]; }
# only load when opening a .php file
{ name = "phpCompletion"; ft_regex = "^php\$"; }
{ name = "phpCompletion"; filename_regex = "^.php\$"; }
# provide plugin which can be loaded manually:
{ name = "phpCompletion"; tag = "lazy"; }
# full documentation at github.com/MarcWeber/vim-addon-manager
];
};
WHAT IS A VIM PLUGIN?
@ -278,7 +260,7 @@ let
plugins = findDependenciesRecursively (map (pluginToDrv knownPlugins) pathogen.pluginNames);
pathogenPackages.pathogen = lib.warn "'pathogen' attribute is deprecated. Use 'packages' instead in your vim configuration" {
pathogenPackages.pathogen = {
start = plugins;
};
in
@ -313,71 +295,26 @@ let
yet
*/
vamImpl = lib.optionalString (vam != null)
(let
vamImpl =
let
knownPlugins = vam.knownPlugins or vimPlugins;
# plugins specified by the user
specifiedPlugins = map (pluginToDrv knownPlugins) (lib.concatMap vamDictToNames vam.pluginDictionaries);
# plugins with dependencies
plugins = findDependenciesRecursively specifiedPlugins;
# Convert scalars, lists, and attrs, to VimL equivalents
toVimL = x:
if builtins.isString x then "'${lib.replaceStrings [ "\n" "'" ] [ "\n\\ " "''" ] x}'"
else if builtins.isAttrs x && builtins ? out then toVimL x # a derivation
else if builtins.isAttrs x then "{${lib.concatStringsSep ", " (lib.mapAttrsToList (n: v: "${toVimL n}: ${toVimL v}") x)}}"
else if builtins.isList x then "[${lib.concatMapStringsSep ", " toVimL x}]"
else if builtins.isInt x || builtins.isFloat x then builtins.toString x
else if builtins.isBool x then (if x then "1" else "0")
else throw "turning ${lib.generators.toPretty {} x} into a VimL thing not implemented yet";
in assert builtins.hasAttr "vim-addon-manager" knownPlugins;
''
filetype indent plugin on | syn on
let g:nix_plugin_locations = {}
${lib.concatMapStrings (plugin: ''
let g:nix_plugin_locations['${plugin.pname}'] = "${plugin.rtp}"
'') plugins}
let g:nix_plugin_locations['vim-addon-manager'] = "${knownPlugins.vim-addon-manager.rtp}"
let g:vim_addon_manager = {}
if exists('g:nix_plugin_locations')
" nix managed config
" override default function making VAM aware of plugin locations:
fun! NixPluginLocation(name)
let path = get(g:nix_plugin_locations, a:name, "")
return path == "" ? vam#DefaultPluginDirFromName(a:name) : path
endfun
let g:vim_addon_manager.plugin_dir_by_name = 'NixPluginLocation'
" tell Vim about VAM:
let &rtp.=(empty(&rtp)?"":','). g:nix_plugin_locations['vim-addon-manager']
else
" standalone config
let &rtp.=(empty(&rtp)?"":',').c.plugin_root_dir.'/vim-addon-manager'
if !isdirectory(c.plugin_root_dir.'/vim-addon-manager/autoload')
" checkout VAM
execute '!git clone --depth=1 https://github.com/MarcWeber/vim-addon-manager '
\ shellescape(c.plugin_root_dir.'/vim-addon-manager', 1)
endif
endif
" tell vam which plugins to load, and when:
let l = []
${lib.concatMapStrings (p: "call add(l, ${toVimL p})\n") vam.pluginDictionaries}
call vam#Scripts(l, {})
'');
vamPackages.vam = {
start = plugins;
};
in
nativeImpl vamPackages;
entries = [
beforePlugins
vamImpl
]
++ lib.optional (vam != null) (lib.warn "'vam' attribute is deprecated. Use 'packages' instead in your vim configuration" vamImpl)
++ lib.optional (packages != null && packages != []) (nativeImpl packages)
++ lib.optional (pathogen != null) pathogenImpl
++ lib.optional (pathogen != null) (lib.warn "'pathogen' attribute is deprecated. Use 'packages' instead in your vim configuration" pathogenImpl)
++ lib.optional (plug != null) plugImpl
++ [ customRC ];
@ -468,37 +405,6 @@ rec {
vimWithRC = throw "vimWithRC was removed, please use vim.customize instead";
pluginnames2Nix = {name, namefiles} : vim_configurable.customize {
inherit name;
vimrcConfig.vam.knownPlugins = vimPlugins;
vimrcConfig.vam.pluginDictionaries = ["vim2nix"];
vimrcConfig.customRC = ''
" Yes - this is impure and will create the cache file and checkout vim-pi
" into ~/.vim/vim-addons
let g:vim_addon_manager.plugin_root_dir = "/tmp/vim2nix-".$USER
if !isdirectory(g:vim_addon_manager.plugin_root_dir)
call mkdir(g:vim_addon_manager.plugin_root_dir)
else
echom repeat("=", 80)
echom "WARNING: reusing cache directory :".g:vim_addon_manager.plugin_root_dir
echom repeat("=", 80)
endif
let opts = {}
let opts.nix_prefetch_git = "${nix-prefetch-git}/bin/nix-prefetch-git"
let opts.nix_prefetch_hg = "${nix-prefetch-hg}/bin/nix-prefetch-hg"
let opts.cache_file = g:vim_addon_manager.plugin_root_dir.'/cache'
let opts.plugin_dictionaries = []
${lib.concatMapStrings (file: "let opts.plugin_dictionaries += map(readfile(\"${file}\"), 'eval(v:val)')\n") namefiles }
" uncomment for debugging failures
" let opts.try_catch = 0
" add more files
" let opts.plugin_dictionaries += map(.. other file )
call nix#ExportPluginsForNix(opts)
'';
};
vimGenDocHook = callPackage ({ vim }:
makeSetupHook {
name = "vim-gen-doc-hook";

View file

@ -13,15 +13,6 @@ in
### vim tests
##################
vim_with_vim2nix = vim_configurable.customize {
name = "vim"; vimrcConfig.vam.pluginDictionaries = [ "vim2nix" ];
};
# test cases:
test_vim_with_vim_nix_using_vam = vim_configurable.customize {
name = "vim-with-vim-addon-nix-using-vam";
vimrcConfig.vam.pluginDictionaries = [{name = "vim-nix"; }];
};
test_vim_with_vim_nix_using_plug = vim_configurable.customize {
name = "vim-with-vim-addon-nix-using-plug";
@ -32,27 +23,4 @@ in
name = "vim-with-vim-addon-nix";
vimrcConfig.packages.myVimPackage.start = with vimPlugins; [ vim-nix ];
};
# regression test for https://github.com/NixOS/nixpkgs/issues/53112
# The user may have specified their own plugins which may not be formatted
# exactly as the generated ones. In particular, they may not have the `pname`
# attribute.
test_vim_with_custom_plugin = vim_configurable.customize {
name = "vim_with_custom_plugin";
vimrcConfig.vam.knownPlugins =
vimPlugins // ({
vim-trailing-whitespace = buildVimPluginFrom2Nix {
name = "vim-trailing-whitespace";
src = fetchFromGitHub {
owner = "bronson";
repo = "vim-trailing-whitespace";
rev = "4c596548216b7c19971f8fc94e38ef1a2b55fee6";
sha256 = "0f1cpnp1nxb4i5hgymjn2yn3k1jwkqmlgw1g02sq270lavp2dzs9";
};
# make sure string dependencies are handled
dependencies = [ "vim-nix" ];
};
});
vimrcConfig.vam.pluginDictionaries = [ { names = [ "vim-trailing-whitespace" ]; } ];
};
})