Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add indentation options to kate #88

Merged
merged 8 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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).";
magnouvean marked this conversation as resolved.
Show resolved Hide resolved
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.
Asqiir marked this conversation as resolved.
Show resolved Hide resolved
}
];

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
1 change: 1 addition & 0 deletions modules/files.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ let
"dolphinrc"
"ffmpegthumbsrc"
"kactivitymanagerdrc"
"katerc"
"kcminputrc"
"kded5rc"
"kdeglobals"
Expand Down