diff --git a/flake.lock b/flake.lock index af915a56..b9f6d4b6 100644 --- a/flake.lock +++ b/flake.lock @@ -7,11 +7,11 @@ ] }, "locked": { - "lastModified": 1706981411, - "narHash": "sha256-cLbLPTL1CDmETVh4p0nQtvoF+FSEjsnJTFpTxhXywhQ=", + "lastModified": 1710888565, + "narHash": "sha256-s9Hi4RHhc6yut4EcYD50sZWRDKsugBJHSbON8KFwoTw=", "owner": "nix-community", "repo": "home-manager", - "rev": "652fda4ca6dafeb090943422c34ae9145787af37", + "rev": "f33900124c23c4eca5831b9b5eb32ea5894375ce", "type": "github" }, "original": { @@ -23,11 +23,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1708294118, - "narHash": "sha256-evZzmLW7qoHXf76VCepvun1esZDxHfVRFUJtumD7L2M=", + "lastModified": 1710951922, + "narHash": "sha256-FOOBJ3DQenLpTNdxMHR2CpGZmYuctb92gF0lpiirZ30=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "e0da498ad77ac8909a980f07eff060862417ccf7", + "rev": "f091af045dff8347d66d186a62d42aceff159456", "type": "github" }, "original": { diff --git a/modules/apps/default.nix b/modules/apps/default.nix new file mode 100644 index 00000000..bea99deb --- /dev/null +++ b/modules/apps/default.nix @@ -0,0 +1,7 @@ +{ ... }: + +{ + imports = [ + ./kate.nix + ]; +} diff --git a/modules/apps/kate.nix b/modules/apps/kate.nix new file mode 100644 index 00000000..9c2314d1 --- /dev/null +++ b/modules/apps/kate.nix @@ -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; + }; + }; +} diff --git a/modules/default.nix b/modules/default.nix index bdd4393c..c872ce76 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -11,6 +11,7 @@ ./kwin.nix ./startup.nix ./panels.nix + ./apps ]; options.programs.plasma.enable = lib.mkEnableOption '' diff --git a/modules/files.nix b/modules/files.nix index 335cc808..80567717 100644 --- a/modules/files.nix +++ b/modules/files.nix @@ -56,6 +56,7 @@ let "dolphinrc" "ffmpegthumbsrc" "kactivitymanagerdrc" + "katerc" "kcminputrc" "kded5rc" "kdeglobals"