Skip to content

Commit

Permalink
add indentation options to kate
Browse files Browse the repository at this point in the history
  • Loading branch information
blitter committed Mar 19, 2024
1 parent 26acf8f commit 11adaa9
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
7 changes: 7 additions & 0 deletions modules/apps/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ ... }:

{
imports = [
./kate.nix
];
}
89 changes: 89 additions & 0 deletions modules/apps/kate.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{ config, lib, ... }:

let
# compute kate's magic TabHandlingMode
boolToInt = b: if b then 1 else 0;
t = boolToInt config.programs.kate.editor.indent.tabFromEverywhere;
s = boolToInt config.programs.kate.editor.indent.undoByShiftTab;
tabHandlingMode = t + 2 * s - 1;
in
{
options.programs.kate.editor = {
tabWidth = lib.mkOption {
description = "The width of a single tab (\\t) sign (in number of spaces).";
default = 4;
type = lib.types.int;
};

indent.showLines = lib.mkOption {
description = "Whether to show the vertical lines that mark each indentation level.";
default = true;
type = lib.types.bool;
};

indent.width = lib.mkOption {
description = "The width of each indent level (in number of spaces).";
default = config.programs.kate.editor.tabWidth;
type = lib.types.int;
};

indent.autodetect = lib.mkOption {
description = "Whether kate should try to detect indentation for each given file and not impose default indentation settings.";
default = true;
type = lib.types.bool;
};

indent.keepExtraSpaces = lib.mkOption {
description = "Whether additional spaces that do not match the indent should be kept when adding/removing indentation level. If these are kept (option to true) then indenting 1 space further (with a default of 4 spaces) will be set to 5 spaces.";
default = false;
type = lib.types.bool;
};

indent.replaceWithSpaces = lib.mkOption {
description = "Whether all indentation should be automatically converted to spaces.";
default = false;
type = lib.types.bool;
};

indent.backspaceDecreaseIndent = lib.mkOption {
description = "Whether the backspace key in the indentation should decrease indentation by a full level always.";
default = true;
type = lib.types.bool;
};

indent.tabFromEverywhere = lib.mkOption {
description = "Whether the tabulator key increases intendation independent from the current cursor position.";
default = false;
type = lib.types.bool;
};

indent.undoByShiftTab = lib.mkOption {
description = "Whether to unindent the current line by one level with the shortcut Shift+Tab";
default = true;
type = lib.types.bool;
};
};

config.assertions = [
{
assertion = tabHandlingMode >= -1;
message = "Either 'undeByShiftTab' or 'tabFromEverywhere' needs to be enabled!";
# kate does not seem to support disabling both.
}
];

config.programs.plasma.configFile."katerc" = {
"KTextEditor Document" = {
"Auto Detect Indent" = config.programs.kate.editor.indent.autodetect;
"Indentation Width" = config.programs.kate.editor.indent.width;
"Tab Handling" = tabHandlingMode;
"Tab Width" = config.programs.kate.editor.tabWidth;
"Keep Extra Spaces" = config.programs.kate.editor.indent.keepExtraSpaces;
"ReplaceTabsDyn" = config.programs.kate.editor.indent.replaceWithSpaces;
};

"KTextEditor Renderer" = {
"Show Indentation Lines" = config.programs.kate.editor.indent.showLines;
};
};
}
1 change: 1 addition & 0 deletions modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
./kwin.nix
./startup.nix
./panels.nix
./apps
];

options.programs.plasma.enable = lib.mkEnableOption ''
Expand Down

0 comments on commit 11adaa9

Please sign in to comment.