Merge pull request #91792 from jcpetruzza/kakoune-plugins
kakoune: rework plugin support
This commit is contained in:
commit
ce3a2e6e49
5 changed files with 38 additions and 72 deletions
|
@ -6,9 +6,7 @@
|
|||
<para>
|
||||
Kakoune can be built to autoload plugins:
|
||||
<programlisting>(kakoune.override {
|
||||
configure = {
|
||||
plugins = with pkgs.kakounePlugins; [ parinfer-rust ];
|
||||
};
|
||||
plugins = with pkgs.kakounePlugins; [ parinfer-rust ];
|
||||
})</programlisting>
|
||||
</para>
|
||||
</section>
|
||||
|
|
|
@ -30,6 +30,15 @@ stdenv.mkDerivation rec {
|
|||
$out/bin/kak -ui json -E "kill 0"
|
||||
'';
|
||||
|
||||
postInstall = ''
|
||||
# make share/kak/autoload a directory, so we can use symlinkJoin with plugins
|
||||
cd "$out/share/kak"
|
||||
autoload_target=$(readlink autoload)
|
||||
rm autoload
|
||||
mkdir autoload
|
||||
ln -s --relative "$autoload_target" autoload
|
||||
'';
|
||||
|
||||
meta = {
|
||||
homepage = "http://kakoune.org/";
|
||||
description = "A vim inspired text editor";
|
||||
|
|
|
@ -1,44 +1,31 @@
|
|||
{ stdenv, bash }:
|
||||
with stdenv.lib;
|
||||
|
||||
kakoune:
|
||||
{ symlinkJoin, makeWrapper, kakoune, plugins ? [], configure ? {} }:
|
||||
|
||||
let
|
||||
getPlugins = { plugins ? [] }: plugins;
|
||||
# "plugins" is the preferred way, but some configurations may be
|
||||
# using "configure.plugins", so accept both
|
||||
requestedPlugins = plugins ++ (configure.plugins or []);
|
||||
|
||||
wrapper = { configure ? {} }:
|
||||
stdenv.mkDerivation rec {
|
||||
pname = "kakoune";
|
||||
version = getVersion kakoune;
|
||||
in
|
||||
symlinkJoin {
|
||||
name = "kakoune-${kakoune.version}";
|
||||
|
||||
src = ./.;
|
||||
buildCommand = ''
|
||||
mkdir -p $out/share/kak
|
||||
for plugin in ${strings.escapeShellArgs (getPlugins configure)}; do
|
||||
if [[ -d $plugin/share/kak/autoload ]]; then
|
||||
find "$plugin/share/kak/autoload" -type f -name '*.kak'| while read rcfile; do
|
||||
printf 'source "%s"\n' "$rcfile"
|
||||
done
|
||||
fi
|
||||
done >>$out/share/kak/plugins.kak
|
||||
buildInputs = [ makeWrapper ];
|
||||
|
||||
mkdir -p $out/bin
|
||||
substitute ${src}/wrapper.sh $out/bin/kak \
|
||||
--subst-var-by bash "${bash}" \
|
||||
--subst-var-by kakoune "${kakoune}" \
|
||||
--subst-var-by out "$out"
|
||||
chmod +x $out/bin/kak
|
||||
paths = [ kakoune ] ++ requestedPlugins;
|
||||
|
||||
postBuild = ''
|
||||
# location of kak binary is used to find ../share/kak/autoload,
|
||||
# unless explicitly overriden with KAKOUNE_RUNTIME
|
||||
rm "$out/bin/kak"
|
||||
makeWrapper "${kakoune}/bin/kak" "$out/bin/kak" --set KAKOUNE_RUNTIME "$out/share/kak"
|
||||
|
||||
# currently kakoune ignores doc files if they are symlinks, so workaround by
|
||||
# copying doc files over, so they become regular files...
|
||||
mkdir "$out/DELETE_ME"
|
||||
mv "$out/share/kak/doc" "$out/DELETE_ME"
|
||||
cp -r --dereference "$out/DELETE_ME/doc" "$out/share/kak"
|
||||
rm -Rf "$out/DELETE_ME"
|
||||
'';
|
||||
|
||||
preferLocalBuild = true;
|
||||
buildInputs = [ bash kakoune ];
|
||||
passthru = { unwrapped = kakoune; };
|
||||
|
||||
meta = kakoune.meta // {
|
||||
# prefer wrapper over the package
|
||||
priority = (kakoune.meta.priority or 0) - 1;
|
||||
hydraPlatforms = [];
|
||||
};
|
||||
};
|
||||
in
|
||||
makeOverridable wrapper
|
||||
meta = kakoune.meta // { priority = (kakoune.meta.priority or 0) - 1; };
|
||||
}
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
#!@bash@/bin/bash
|
||||
|
||||
# We use the -E option to load plugins. This only makes sense when we are
|
||||
# starting a new session, so we detect that. Also, Kakoune can only handle
|
||||
# one -E option, so we prepend loading plugins to an existing one.
|
||||
args=( "$@" )
|
||||
loadPlugins=true
|
||||
EValueOffset=-1
|
||||
pluginScript='@out@/share/kak/plugins.kak'
|
||||
|
||||
for (( i = 0; i < ${#args[@]}; i++ )); do
|
||||
case "${args[i]}" in
|
||||
-n|-c|-l|-p|-clear|-version) loadPlugins=false;;
|
||||
-E) EValueOffset=$(( i + 1 ));;
|
||||
--) break;;
|
||||
esac
|
||||
case "${args[i]}" in
|
||||
-E|-c|-e|-s|-p|-f|-i|-ui|-debug) i=$(( i + 1 ));;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ $loadPlugins = true ]]; then
|
||||
if (( EValueOffset >= 0 )); then
|
||||
args[EValueOffset]="source '$pluginScript'"$'\n'"${args[EValueOffset]}"
|
||||
else
|
||||
args=( "-E" "source '$pluginScript'" "${args[@]}" )
|
||||
fi
|
||||
fi
|
||||
|
||||
exec @kakoune@/bin/kak "${args[@]}"
|
|
@ -4907,10 +4907,12 @@ in
|
|||
|
||||
kalibrate-hackrf = callPackage ../applications/radio/kalibrate-hackrf { };
|
||||
|
||||
wrapKakoune = callPackage ../applications/editors/kakoune/wrapper.nix { };
|
||||
wrapKakoune = kakoune: attrs: callPackage ../applications/editors/kakoune/wrapper.nix (attrs // { inherit kakoune; });
|
||||
kakounePlugins = callPackage ../applications/editors/kakoune/plugins { };
|
||||
kakoune-unwrapped = callPackage ../applications/editors/kakoune { };
|
||||
kakoune = wrapKakoune kakoune-unwrapped { };
|
||||
kakoune = wrapKakoune kakoune-unwrapped {
|
||||
plugins = [ ]; # override with the list of desired plugins
|
||||
};
|
||||
|
||||
kak-lsp = callPackage ../tools/misc/kak-lsp { };
|
||||
|
||||
|
|
Loading…
Reference in a new issue