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 colortheme configuration to kate #95

Merged
merged 11 commits into from
Mar 29, 2024

Conversation

Asqiir
Copy link
Contributor

@Asqiir Asqiir commented Mar 25, 2024

This is the second contribution to #87.

This contribution adds support for kate's colorthemes. A user can either pick one of the system themes by name, or a file for a custom theme.

The custom file will never override any existing file, nor will it introduce name collisions.

Known limitations

When picking a theme by name there is no check whether such a theme exists. The existing themes live in the ksyntaxhighlighting framework in data/themes.
But these existing themes do not live in any of ${XDG_DATA_DIRS}. They are included as a linked library. I don't know if there is any non-ugly way to access these (option 1: via an overlay. option 2: going through multiple layers of built-inputs).

As an artefact of that process (when I tried to find the themes) there is an option home.kate.package that allows the user to pick a package to be installed. By default, this is pkgs.kate. That changes the default behaviour of programs.kate.enable: When enabling this option, a package will be installed. I believe this is a more natural behaviour for the enable option.

Copy link
Collaborator

@magnouvean magnouvean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comments for some initial possible tweaks

modules/apps/check-theme-name-free.sh Outdated Show resolved Hide resolved
${./check-theme-name-free.sh} ${cfg.editor.theme.name} ${pkgs.jq}/bin/jq
'');

# In case of using a system theme, there should be a check that there exists such a theme
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there something missing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tldr: No, this is a note that there should be a check – if I just knew how to. (See "known limitations" above.) I improved the comment.

long form: I would like to check that a user can only select valid themes – that are those already packaged in the installed kate package. I could not figure out a viable way, which makes this an error-prone string entry.

# In case of using a custom theme, check that there is no name collision
home.activation.checkKateTheme = lib.mkIf (cfg.enable && cfg.editor.theme.src != null) (lib.hm.dag.entryBefore [ "writeBoundary" ]
''
${./check-theme-name-free.sh} ${cfg.editor.theme.name} ${pkgs.jq}/bin/jq
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I would suggest creating a nix-derivation here which runs the script. That way you don't have to send in the jquery path as a command-line argument, and in general is a better practice. See here for how we did with the config-writing script

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed to to a derivation in the same style. Imo it looks a bit bloated:

    checkThemeNameScript = pkgs.writeShellApplication {
      name = "checkThemeName";
      runtimeInputs = with pkgs; [ jq ];
      text = builtins.readFile ./check-theme-name-free.sh;
    };

    checkThemeName = name:
    ''
      ${checkThemeNameScript}/bin/checkThemeName ${name}
    '';

    script = pkgs.writeScript "kate-check" (checkThemeName cfg.editor.theme.name);

Maybe it would be nicer to do this with just 1-2 definitions? My attempt would be:

    checkThemeNameScript = pkgs.writeShellApplication {
      name = "checkThemeName";
      runtimeInputs = with pkgs; [ jq ];
      text = builtins.readFile ./check-theme-name-free.sh;
    };

    script = pkgs.writeScript "kate-check" "${checkThemeNameScript}/bin/checkThemeName ${name}";

What do you think?

modules/apps/kate.nix Outdated Show resolved Hide resolved
modules/apps/kate.nix Outdated Show resolved Hide resolved
modules/apps/kate.nix Outdated Show resolved Hide resolved
@Asqiir
Copy link
Contributor Author

Asqiir commented Mar 29, 2024

@magnouvean do my changes look alright to you?

@magnouvean
Copy link
Collaborator

I will check this out later today (when I get home). There has been a change in the configuration syntax lately after #94, so will probably need some tweaks, but they should be fairly straight forward :). Your solutions to the comments look good though :)

@Asqiir
Copy link
Contributor Author

Asqiir commented Mar 29, 2024

@magnouvean You are right it needs some tweaks. I would have preferred to rebase this branch myself & do a new commit at the same time, so there wouldn't have been this broken state now ;)

@magnouvean
Copy link
Collaborator

magnouvean commented Mar 29, 2024

Ah sorry about that. Some prefer different things. I can revert it :)

Copy link
Collaborator

@magnouvean magnouvean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good if you could make sure to have ran nixpkgs-fmt on these files. Other than that if you can get these functional with the latest syntax I think this looks great!

modules/apps/default.nix Outdated Show resolved Hide resolved
modules/apps/kate/default.nix Show resolved Hide resolved
modules/apps/kate/default.nix Outdated Show resolved Hide resolved
@Asqiir
Copy link
Contributor Author

Asqiir commented Mar 29, 2024

I did the changes you proposed.
The kate config now sets all values but makes none immutable. (Should it? What do we want the default behaviour to be?)

@magnouvean
Copy link
Collaborator

No, immutability isn't needed granted the module works just fine without them. I see there were some problems with the merging leading to changes in files and hotkeys which shouldn't be there (but this is very easy to fix, I'll do it soon). Are you happy enough with this that we can merge then?

@Asqiir
Copy link
Contributor Author

Asqiir commented Mar 29, 2024

@magnouvean yes I'm happy with the current state :)
thx for the fast workflow!

@magnouvean
Copy link
Collaborator

Great, I'll merge right away then! Thanks for the contribution, prs like this helps plasma-manager grow and makes the plasma experience in nix better!

@magnouvean magnouvean merged commit fb4a1cd into nix-community:trunk Mar 29, 2024
1 check passed
@Asqiir Asqiir deleted the colortheme branch March 30, 2024 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants