From 7bb0611e2e27b3e5b7db7c93a3635fab5f7d3306 Mon Sep 17 00:00:00 2001 From: Nick Novitski Date: Wed, 22 Feb 2017 13:06:34 +1300 Subject: vim_configurable: Add packPath option to vimrcConfig (#22776) * vim_configurable: Add packages option to vimrcConfig Version 8 of vim adds the concept of "vim packages": directories which contain one or more vim plugins, in either "start" or "opt" subdirectories. Those in "start" are to be loaded automatically, while those in "opt" can be loaded manually. Vim detects any packages located in one of its "packpaths". The packages option takes a set of sets describing one or more vim packages, and adds the derivation containing these packages to the packpath. * fix documentation. --- pkgs/misc/vim-plugins/vim-utils.nix | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/pkgs/misc/vim-plugins/vim-utils.nix b/pkgs/misc/vim-plugins/vim-utils.nix index d714b290a905..4b754f15c0fa 100644 --- a/pkgs/misc/vim-plugins/vim-utils.nix +++ b/pkgs/misc/vim-plugins/vim-utils.nix @@ -17,6 +17,17 @@ vim-with-plugins in PATH: set hidden ''; + # store your plugins in Vim packages + vimrcConfig.packages.myVimPackage = with pkgs.vimPlugins; { + # loaded on launch + start = [ youcompleteme fugitive ]; + # manually loadable by calling `:packadd $plugin-name` + opt = [ phpCompletion elm-vim ]; + # 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 @@ -154,6 +165,7 @@ let in lib.uniqList { inputList = recurseNames [] names; }; vimrcFile = { + packages ? null, vam ? null, pathogen ? null, customRC ? "" @@ -253,6 +265,31 @@ let call vam#Scripts(l, {}) ''); + nativeImpl = lib.optionalString (packages != null) + (let + link = (packageName: dir: pluginPath: "ln -sf ${pluginPath}/share/vim-plugins/* $out/pack/${packageName}/${dir}"); + packageLinks = (packageName: {start ? [], opt ? []}: + ["mkdir -p $out/pack/${packageName}/start"] + ++ (builtins.map (link packageName "start") start) + ++ ["mkdir -p $out/pack/${packageName}/opt"] + ++ (builtins.map (link packageName "opt") opt) + ); + packDir = (packages: + stdenv.mkDerivation rec { + name = "vim-pack-dir"; + src = ./.; + installPhase = lib.concatStringsSep + "\n" + (lib.flatten (lib.mapAttrsToList packageLinks packages)); + } + ); + in + '' + set packpath-=~/.vim/after + set packpath+=${packDir packages} + set packpath+=~/.vim/after + ''); + # somebody else could provide these implementations vundleImpl = ""; @@ -267,6 +304,7 @@ let ${pathogenImpl} ${vundleImpl} ${neobundleImpl} + ${nativeImpl} filetype indent plugin on | syn on @@ -385,4 +423,9 @@ rec { vimrcConfig.pathogen.pluginNames = [ "vim-addon-nix" ]; }; + test_vim_with_vim_addon_nix = vim_configurable.customize { + name = "vim-with-vim-addon-nix"; + vimrcConfig.packages.myVimPackage.start = with vimPlugins; [ vim-addon-nix ]; + }; + } -- cgit v1.2.3