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 all 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
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
];
}
101 changes: 101 additions & 0 deletions modules/apps/kate.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{ config, lib, ... }:



let
cfg = config.programs.kate;
# compute kate's magic TabHandlingMode
# 0 is not tab & not undoByShiftTab
# 1 is tab & undoByShiftTab
# 2 is not tab & undoByShiftTab
tabHandlingMode = indentSettings:
if (!indentSettings.undoByShiftTab && !indentSettings.tabFromEverywhere) then 0 else
(
if (indentSettings.undoByShiftTab && indentSettings.tabFromEverywhere) then 1 else
2
);
in
{
options.programs.kate = {
enable = lib.mkEnableOption ''
Enable configuration management for 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 = cfg.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 = cfg.editor.indent.undoByShiftTab || (!cfg.editor.indent.tabFromEverywhere);
message = "Kate does not support both 'undoByShiftTab' to be disabled and 'tabFromEverywhere' to be enabled at the same time.";
}
];

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

"KTextEditor Renderer" = {
"Show Indentation Lines" = cfg.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 @@ -56,6 +56,7 @@ let
"dolphinrc"
"ffmpegthumbsrc"
"kactivitymanagerdrc"
"katerc"
"kcminputrc"
"kded5rc"
"kdeglobals"
Expand Down
Loading