Skip to content

Commit 341b956

Browse files
Matthieu Coudronteto
Matthieu Coudron
authored andcommitted
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
1 parent 63230b2 commit 341b956

File tree

3 files changed

+11
-233
lines changed

3 files changed

+11
-233
lines changed

doc/languages-frameworks/vim.section.md

+1-97
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ and additional libraries.
55

66
Loading can be deferred; see examples.
77

8-
At the moment we support three different methods for managing plugins:
8+
At the moment we support two different methods for managing plugins:
99

1010
- Vim packages (*recommended*)
11-
- VAM (=vim-addon-manager)
12-
- Pathogen
1311
- vim-plug
1412

1513
## Custom configuration {#custom-configuration}
@@ -213,100 +211,6 @@ neovim.override {
213211
}
214212
```
215213

216-
## Managing plugins with VAM {#managing-plugins-with-vam}
217-
218-
### Handling dependencies of Vim plugins {#handling-dependencies-of-vim-plugins}
219-
220-
VAM introduced .json files supporting dependencies without versioning
221-
assuming that "using latest version" is ok most of the time.
222-
223-
### Example {#example}
224-
225-
First create a vim-scripts file having one plugin name per line. Example:
226-
227-
```vim
228-
"tlib"
229-
{'name': 'vim-addon-sql'}
230-
{'filetype_regex': '\%(vim)$', 'names': ['reload', 'vim-dev-plugin']}
231-
```
232-
233-
A discrete vim-scripts file can be read by VAM as well like this:
234-
235-
```vim
236-
call vam#Scripts(expand('~/.vim-scripts'), {})
237-
```
238-
239-
Create a default.nix file:
240-
241-
```nix
242-
{ nixpkgs ? import <nixpkgs> {}, compiler ? "ghc7102" }:
243-
nixpkgs.vim_configurable.customize { name = "vim"; vimrcConfig.vam.pluginDictionaries = [ "vim-addon-vim2nix" ]; }
244-
```
245-
246-
Create a generate.vim file:
247-
248-
```vim
249-
ActivateAddons vim-addon-vim2nix
250-
let vim_scripts = "vim-scripts"
251-
call nix#ExportPluginsForNix({
252-
\ 'path_to_nixpkgs': eval('{"'.substitute(substitute(substitute($NIX_PATH, ':', ',', 'g'), '=',':', 'g'), '\([:,]\)', '"\1"',"g").'"}')["nixpkgs"],
253-
\ 'cache_file': '/tmp/vim2nix-cache',
254-
\ 'try_catch': 0,
255-
\ 'plugin_dictionaries': ["vim-addon-manager"]+map(readfile(vim_scripts), 'eval(v:val)')
256-
\ })
257-
```
258-
259-
Then run
260-
261-
```bash
262-
nix-shell -p vimUtils.vim_with_vim2nix --command "vim -c 'source generate.vim'"
263-
```
264-
265-
You should get a Vim buffer with the nix derivations (output1) and vam.pluginDictionaries (output2).
266-
You can add your Vim to your system's configuration file like this and start it by "vim-my":
267-
268-
```nix
269-
my-vim =
270-
let plugins = let inherit (vimUtils) buildVimPluginFrom2Nix; in {
271-
copy paste output1 here
272-
}; in vim_configurable.customize {
273-
name = "vim-my";
274-
275-
vimrcConfig.vam.knownPlugins = plugins; # optional
276-
vimrcConfig.vam.pluginDictionaries = [
277-
copy paste output2 here
278-
];
279-
280-
};
281-
```
282-
283-
Sample output1:
284-
285-
```nix
286-
"reload" = buildVimPluginFrom2Nix { # created by nix#NixDerivation
287-
name = "reload";
288-
src = fetchgit {
289-
url = "https://github.com/xolox/vim-reload";
290-
rev = "0a601a668727f5b675cb1ddc19f6861f3f7ab9e1";
291-
sha256 = "0vb832l9yxj919f5hfg6qj6bn9ni57gnjd3bj7zpq7d4iv2s4wdh";
292-
};
293-
dependencies = ["nim-misc"];
294-
295-
};
296-
[...]
297-
```
298-
299-
Sample output2:
300-
301-
```nix
302-
[
303-
''vim-addon-manager''
304-
''tlib''
305-
{ "name" = ''vim-addon-sql''; }
306-
{ "filetype_regex" = ''\%(vim)$$''; "names" = [ ''reload'' ''vim-dev-plugin'' ]; }
307-
]
308-
```
309-
310214
## Adding new plugins to nixpkgs {#adding-new-plugins-to-nixpkgs}
311215

312216
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`.

pkgs/applications/editors/vim/plugins/vim-utils.nix

+10-104
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,6 @@ vim-with-plugins in PATH:
3333
# To automatically load a plugin when opening a filetype, add vimrc lines like:
3434
# autocmd FileType php :packadd phpCompletion
3535
};
36-
37-
# plugins can also be managed by VAM
38-
vimrcConfig.vam.knownPlugins = pkgs.vimPlugins; # optional
39-
vimrcConfig.vam.pluginDictionaries = [
40-
# load always
41-
{ name = "youcompleteme"; }
42-
{ names = ["youcompleteme" "foo"]; }
43-
44-
# only load when opening a .php file
45-
{ name = "phpCompletion"; ft_regex = "^php\$"; }
46-
{ name = "phpCompletion"; filename_regex = "^.php\$"; }
47-
48-
# provide plugin which can be loaded manually:
49-
{ name = "phpCompletion"; tag = "lazy"; }
50-
51-
# full documentation at github.com/MarcWeber/vim-addon-manager
52-
];
53-
5436
};
5537
5638
WHAT IS A VIM PLUGIN?
@@ -278,7 +260,7 @@ let
278260

279261
plugins = findDependenciesRecursively (map (pluginToDrv knownPlugins) pathogen.pluginNames);
280262

281-
pathogenPackages.pathogen = lib.warn "'pathogen' attribute is deprecated. Use 'packages' instead in your vim configuration" {
263+
pathogenPackages.pathogen = {
282264
start = plugins;
283265
};
284266
in
@@ -313,71 +295,26 @@ let
313295
yet
314296
315297
*/
316-
vamImpl = lib.optionalString (vam != null)
317-
(let
298+
vamImpl =
299+
let
318300
knownPlugins = vam.knownPlugins or vimPlugins;
319301

320302
# plugins specified by the user
321303
specifiedPlugins = map (pluginToDrv knownPlugins) (lib.concatMap vamDictToNames vam.pluginDictionaries);
322304
# plugins with dependencies
323305
plugins = findDependenciesRecursively specifiedPlugins;
324-
325-
# Convert scalars, lists, and attrs, to VimL equivalents
326-
toVimL = x:
327-
if builtins.isString x then "'${lib.replaceStrings [ "\n" "'" ] [ "\n\\ " "''" ] x}'"
328-
else if builtins.isAttrs x && builtins ? out then toVimL x # a derivation
329-
else if builtins.isAttrs x then "{${lib.concatStringsSep ", " (lib.mapAttrsToList (n: v: "${toVimL n}: ${toVimL v}") x)}}"
330-
else if builtins.isList x then "[${lib.concatMapStringsSep ", " toVimL x}]"
331-
else if builtins.isInt x || builtins.isFloat x then builtins.toString x
332-
else if builtins.isBool x then (if x then "1" else "0")
333-
else throw "turning ${lib.generators.toPretty {} x} into a VimL thing not implemented yet";
334-
335-
in assert builtins.hasAttr "vim-addon-manager" knownPlugins;
336-
''
337-
filetype indent plugin on | syn on
338-
339-
let g:nix_plugin_locations = {}
340-
${lib.concatMapStrings (plugin: ''
341-
let g:nix_plugin_locations['${plugin.pname}'] = "${plugin.rtp}"
342-
'') plugins}
343-
let g:nix_plugin_locations['vim-addon-manager'] = "${knownPlugins.vim-addon-manager.rtp}"
344-
345-
let g:vim_addon_manager = {}
346-
347-
if exists('g:nix_plugin_locations')
348-
" nix managed config
349-
350-
" override default function making VAM aware of plugin locations:
351-
fun! NixPluginLocation(name)
352-
let path = get(g:nix_plugin_locations, a:name, "")
353-
return path == "" ? vam#DefaultPluginDirFromName(a:name) : path
354-
endfun
355-
let g:vim_addon_manager.plugin_dir_by_name = 'NixPluginLocation'
356-
" tell Vim about VAM:
357-
let &rtp.=(empty(&rtp)?"":','). g:nix_plugin_locations['vim-addon-manager']
358-
else
359-
" standalone config
360-
361-
let &rtp.=(empty(&rtp)?"":',').c.plugin_root_dir.'/vim-addon-manager'
362-
if !isdirectory(c.plugin_root_dir.'/vim-addon-manager/autoload')
363-
" checkout VAM
364-
execute '!git clone --depth=1 https://github.com/MarcWeber/vim-addon-manager '
365-
\ shellescape(c.plugin_root_dir.'/vim-addon-manager', 1)
366-
endif
367-
endif
368-
369-
" tell vam which plugins to load, and when:
370-
let l = []
371-
${lib.concatMapStrings (p: "call add(l, ${toVimL p})\n") vam.pluginDictionaries}
372-
call vam#Scripts(l, {})
373-
'');
306+
vamPackages.vam = {
307+
start = plugins;
308+
};
309+
in
310+
nativeImpl vamPackages;
374311

375312
entries = [
376313
beforePlugins
377-
vamImpl
378314
]
315+
++ lib.optional (vam != null) (lib.warn "'vam' attribute is deprecated. Use 'packages' instead in your vim configuration" vamImpl)
379316
++ lib.optional (packages != null && packages != []) (nativeImpl packages)
380-
++ lib.optional (pathogen != null) pathogenImpl
317+
++ lib.optional (pathogen != null) (lib.warn "'pathogen' attribute is deprecated. Use 'packages' instead in your vim configuration" pathogenImpl)
381318
++ lib.optional (plug != null) plugImpl
382319
++ [ customRC ];
383320

@@ -468,37 +405,6 @@ rec {
468405

469406
vimWithRC = throw "vimWithRC was removed, please use vim.customize instead";
470407

471-
pluginnames2Nix = {name, namefiles} : vim_configurable.customize {
472-
inherit name;
473-
vimrcConfig.vam.knownPlugins = vimPlugins;
474-
vimrcConfig.vam.pluginDictionaries = ["vim2nix"];
475-
vimrcConfig.customRC = ''
476-
" Yes - this is impure and will create the cache file and checkout vim-pi
477-
" into ~/.vim/vim-addons
478-
let g:vim_addon_manager.plugin_root_dir = "/tmp/vim2nix-".$USER
479-
if !isdirectory(g:vim_addon_manager.plugin_root_dir)
480-
call mkdir(g:vim_addon_manager.plugin_root_dir)
481-
else
482-
echom repeat("=", 80)
483-
echom "WARNING: reusing cache directory :".g:vim_addon_manager.plugin_root_dir
484-
echom repeat("=", 80)
485-
endif
486-
let opts = {}
487-
let opts.nix_prefetch_git = "${nix-prefetch-git}/bin/nix-prefetch-git"
488-
let opts.nix_prefetch_hg = "${nix-prefetch-hg}/bin/nix-prefetch-hg"
489-
let opts.cache_file = g:vim_addon_manager.plugin_root_dir.'/cache'
490-
let opts.plugin_dictionaries = []
491-
${lib.concatMapStrings (file: "let opts.plugin_dictionaries += map(readfile(\"${file}\"), 'eval(v:val)')\n") namefiles }
492-
493-
" uncomment for debugging failures
494-
" let opts.try_catch = 0
495-
496-
" add more files
497-
" let opts.plugin_dictionaries += map(.. other file )
498-
call nix#ExportPluginsForNix(opts)
499-
'';
500-
};
501-
502408
vimGenDocHook = callPackage ({ vim }:
503409
makeSetupHook {
504410
name = "vim-gen-doc-hook";

pkgs/test/vim/default.nix

-32
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@ in
1313

1414
### vim tests
1515
##################
16-
vim_with_vim2nix = vim_configurable.customize {
17-
name = "vim"; vimrcConfig.vam.pluginDictionaries = [ "vim2nix" ];
18-
};
19-
20-
# test cases:
21-
test_vim_with_vim_nix_using_vam = vim_configurable.customize {
22-
name = "vim-with-vim-addon-nix-using-vam";
23-
vimrcConfig.vam.pluginDictionaries = [{name = "vim-nix"; }];
24-
};
2516

2617
test_vim_with_vim_nix_using_plug = vim_configurable.customize {
2718
name = "vim-with-vim-addon-nix-using-plug";
@@ -32,27 +23,4 @@ in
3223
name = "vim-with-vim-addon-nix";
3324
vimrcConfig.packages.myVimPackage.start = with vimPlugins; [ vim-nix ];
3425
};
35-
36-
# regression test for https://github.com/NixOS/nixpkgs/issues/53112
37-
# The user may have specified their own plugins which may not be formatted
38-
# exactly as the generated ones. In particular, they may not have the `pname`
39-
# attribute.
40-
test_vim_with_custom_plugin = vim_configurable.customize {
41-
name = "vim_with_custom_plugin";
42-
vimrcConfig.vam.knownPlugins =
43-
vimPlugins // ({
44-
vim-trailing-whitespace = buildVimPluginFrom2Nix {
45-
name = "vim-trailing-whitespace";
46-
src = fetchFromGitHub {
47-
owner = "bronson";
48-
repo = "vim-trailing-whitespace";
49-
rev = "4c596548216b7c19971f8fc94e38ef1a2b55fee6";
50-
sha256 = "0f1cpnp1nxb4i5hgymjn2yn3k1jwkqmlgw1g02sq270lavp2dzs9";
51-
};
52-
# make sure string dependencies are handled
53-
dependencies = [ "vim-nix" ];
54-
};
55-
});
56-
vimrcConfig.vam.pluginDictionaries = [ { names = [ "vim-trailing-whitespace" ]; } ];
57-
};
5826
})

0 commit comments

Comments
 (0)