More efficient kakoune editing integration
This commit is contained in:
parent
d5989c525c
commit
d625bb2c15
|
@ -19,10 +19,11 @@ let
|
|||
};
|
||||
in
|
||||
{
|
||||
imports = [ ../modules/programs/my-kakoune ];
|
||||
|
||||
imports = [ ../modules/programs/my-kakoune ./kaktex.nix ];
|
||||
|
||||
# Enable the kakoune package.
|
||||
programs.my-kakoune.enable = true;
|
||||
programs.my-kakoune.enable-fish-session = true;
|
||||
programs.kak-lsp.enable = true;
|
||||
|
||||
programs.my-kakoune.package = kakounePkg;
|
||||
|
|
28
home/kakoune/kaktex
Executable file
28
home/kakoune/kaktex
Executable file
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env fish
|
||||
|
||||
function usage
|
||||
echo "Usage: "
|
||||
echo " kaktex set [client] [session]"
|
||||
echo " kaktex jump [file] [line]"
|
||||
exit 1
|
||||
end
|
||||
|
||||
if test (count $argv) -ne 3
|
||||
usage
|
||||
end
|
||||
|
||||
switch $argv[1]
|
||||
case "set"
|
||||
set -U _kaktex_client $argv[2]
|
||||
set -U _kaktex_session $argv[3]
|
||||
case "jump"
|
||||
echo "
|
||||
evaluate-commands -client $_kaktex_client %{
|
||||
evaluate-commands -try-client $_kaktex_client %{
|
||||
edit -- $argv[2] $argv[3]
|
||||
}
|
||||
}
|
||||
" | kak -p $_kaktex_session
|
||||
case '*'
|
||||
usage
|
||||
end
|
22
home/kakoune/kaktex.nix
Normal file
22
home/kakoune/kaktex.nix
Normal file
|
@ -0,0 +1,22 @@
|
|||
{ config, pkgs, lib, ... }:
|
||||
|
||||
let
|
||||
kaktexScript = ./kaktex;
|
||||
in
|
||||
{
|
||||
# Create kak-tex executable
|
||||
home.file.kaktex = {
|
||||
source = kaktexScript;
|
||||
executable = true;
|
||||
target = ".bin/kaktex";
|
||||
};
|
||||
|
||||
# Source kaktex whenever we have a tex file
|
||||
programs.my-kakoune.rc = ''
|
||||
hook global WinSetOption filetype=(tex|latex) %{
|
||||
eval %sh{
|
||||
${kaktexScript} set $kak_client $kak_session
|
||||
}
|
||||
}
|
||||
'';
|
||||
}
|
|
@ -18,7 +18,7 @@ let
|
|||
};
|
||||
in
|
||||
{
|
||||
imports = [ ./kak-lsp.nix ];
|
||||
imports = [ ./kak-lsp.nix ./fish-session.nix ];
|
||||
|
||||
options.programs.my-kakoune = {
|
||||
enable = mkEnableOption "My version of the kakoune configuration";
|
||||
|
|
57
home/modules/programs/my-kakoune/fish-session.nix
Normal file
57
home/modules/programs/my-kakoune/fish-session.nix
Normal file
|
@ -0,0 +1,57 @@
|
|||
{ config, pkgs, lib, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
cfg = config.programs.my-kakoune;
|
||||
in
|
||||
{
|
||||
options.programs.my-kakoune.enable-fish-session = mkEnableOption "Enable fish integration script";
|
||||
config = mkIf cfg.enable-fish-session {
|
||||
programs.fish.functions = {
|
||||
kak-session = ''
|
||||
if set -q kak_session
|
||||
echo "Another kakoune session ($kak_session) is currently running. Do `kill-kak-session` to stop it." >&2
|
||||
return 1
|
||||
end
|
||||
|
||||
if test (count $argv) -ge 1
|
||||
set -gx kak_session $argv[1]
|
||||
else
|
||||
set -gx kak_session "kak-"(random)
|
||||
end
|
||||
|
||||
# Start a new kakoune session
|
||||
kak -s $kak_session -d &
|
||||
echo "New kakoune session started (pid = $last_pid, session name = $kak_session)."
|
||||
|
||||
# Rebind $VISUAL, $EDITOR and e command
|
||||
set -gx VISUAL "kak -s $kak_session"
|
||||
set -gx EDITOR "kak -s $kak_session"
|
||||
alias e="kak -c $kak_session"
|
||||
'';
|
||||
|
||||
kill-kak-session = ''
|
||||
if not set -q kak_session
|
||||
echo "No kakoune session found on this terminal instance." >&2
|
||||
return 1
|
||||
end
|
||||
|
||||
echo kill | kak -p $kak_session
|
||||
set -eg kak_session
|
||||
|
||||
# Rebind $VISUAL, $EDITOR and e command
|
||||
set -gx VISUAL "kak"
|
||||
set -gx EDITOR "kak"
|
||||
alias e="kak"
|
||||
'';
|
||||
|
||||
_tide_item_kakoune = ''
|
||||
if set -q kak_session
|
||||
set -U tide_kakoune_color FFA500
|
||||
set -U tide_kakoune_bg_color normal
|
||||
_tide_print_item kakoune " " "e[$kak_session]"
|
||||
end
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue