kakoune: escape showWhitespace separators

We were passing the separators for the `show-whitespaces` highlighter
verbatim. This was problematic in case one wanted to use, spaces,
quotes or `%` as separators since the resulting kakoune configuration
would be invalid.

According to kakoune's docs, the separator has to be one character
long, so we can use a simple rule for escaping them. It is possible
that people has been working this around by passing, e.g. `"' '"` as
separator in order to get a space (i.e., escaped explicitly by the
user), so we just let longer strings be used verbatim.

PR #1357
This commit is contained in:
Daniel Gorin 2020-06-24 18:30:16 +01:00 committed by Robert Helgesson
parent 861690ff29
commit d1f4d1514d
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
4 changed files with 47 additions and 8 deletions

View file

@ -506,12 +506,22 @@ let
];
showWhitespaceOptions = with cfg.config.showWhitespace;
concatStrings [
(optionalString (tab != null) " -tab ${tab}")
(optionalString (tabStop != null) " -tabpad ${tabStop}")
(optionalString (space != null) " -spc ${space}")
(optionalString (nonBreakingSpace != null) " -nbsp ${nonBreakingSpace}")
(optionalString (lineFeed != null) " -lf ${lineFeed}")
let
quoteSep = sep:
if sep == "'" then
''"'"''
else if lib.strings.stringLength sep == 1 then
"'${sep}'"
else
sep; # backwards compat, in case sep == "' '", etc.
in concatStrings [
(optionalString (tab != null) " -tab ${quoteSep tab}")
(optionalString (tabStop != null) " -tabpad ${quoteSep tabStop}")
(optionalString (space != null) " -spc ${quoteSep space}")
(optionalString (nonBreakingSpace != null)
" -nbsp ${quoteSep nonBreakingSpace}")
(optionalString (lineFeed != null) " -lf ${quoteSep lineFeed}")
];
uiOptions = with cfg.config.ui;

View file

@ -1 +1,5 @@
{ kakoune-whitespace-highlighter = ./whitespace-highlighter.nix; }
{
kakoune-whitespace-highlighter = ./whitespace-highlighter.nix;
kakoune-whitespace-highlighter-corner-cases =
./whitespace-highlighter-corner-cases.nix;
}

View file

@ -0,0 +1,25 @@
{ config, lib, pkgs, ... }:
with lib;
{
config = {
programs.kakoune = {
enable = true;
config.showWhitespace = {
enable = true;
lineFeed = ''"'';
space = " ";
nonBreakingSpace = "' '"; # backwards compat
tab = "'";
# tabStop = <default>
};
};
nmt.script = ''
assertFileExists home-files/.config/kak/kakrc
assertFileContains home-files/.config/kak/kakrc \
"add-highlighter global/ show-whitespaces -tab \"'\" -spc ' ' -nbsp ' ' -lf '\"'"
'';
};
}

View file

@ -19,7 +19,7 @@ with lib;
nmt.script = ''
assertFileExists home-files/.config/kak/kakrc
assertFileContains home-files/.config/kak/kakrc \
"add-highlighter global/ show-whitespaces -tab 4 -tabpad 5 -spc 2 -nbsp 3 -lf 1"
"add-highlighter global/ show-whitespaces -tab '4' -tabpad '5' -spc '2' -nbsp '3' -lf '1'"
'';
};
}