@@ -22,7 +22,7 @@ Default behavior | With hmts.nvim
2222
2323## Requirements
2424
25- - Neovim ` 0.9 ` (probably works on older versions, if anybody wants to check)
25+ - Neovim ` 0.9 `
2626- Have [ treesitter] ( https://github.com/nvim-treesitter/nvim-treesitter ) enabled
2727
2828> [ !Important]
@@ -53,8 +53,95 @@ You're done already.
5353
5454## Usage
5555
56- Just live your life. There is nothing to do, the plugin works out-of-the-box on everything it can identify in your ` nix `
57- files.
56+ ### Automatic language detection
57+
58+ The following features work out-of-the-box without any user intervention.
59+
60+ #### From filename
61+
62+ When writing a file's content directly with ` home.file ` or ` xdg.configFile ` , we can infer the language from the
63+ specified filename, if possible:
64+
65+ ``` nix
66+ # Also works with `home.file.*.text`
67+ xdg.configFile."myprogram/myScript.py".text = ''
68+ print("foo")
69+ '';
70+ ```
71+
72+ #### From arbitrary program options
73+
74+ Some programs have options asking for code in specific languages. Some of them are implemented in this plugin to
75+ automatically setup these arbitrary injections.
76+
77+ <details >
78+ <summary>Here's the full list of the currently implemented options.</summary>
79+
80+ * Bash (bash language)
81+ - ` programs.bash.bashrcExtra `
82+ - ` programs.bash.initExtra `
83+ - ` programs.bash.logoutExtra `
84+ - ` programs.bash.profileExtra `
85+ * Fish (fish language)
86+ - ` programs.fish.functions.* `
87+ - ` programs.fish.interactiveShellInit `
88+ - ` programs.fish.loginShellInit `
89+ - ` programs.fish.shellInit `
90+ * Zsh (bash language)
91+ - ` programs.bash.completionInit `
92+ - ` programs.bash.envExtra `
93+ - ` programs.bash.initExtraBeforeCompInit `
94+ - ` programs.bash.initExtraFirst `
95+ - ` programs.bash.initExtra `
96+ - ` programs.bash.loginExtra `
97+ - ` programs.bash.logoutExtra `
98+ - ` programs.bash.profileExtra `
99+ * Firefox (css language)
100+ - ` programs.firefox.profiles.*.userChrome `
101+ </details >
102+
103+ > [ !Warning]
104+ > These implementations are * not* exhaustive and may eventually be broken if the program's options change. If that
105+ > happens, please use [ explicit annotations] ( #explicit-annotations ) to set the injection.
106+
107+ > [ !Note]
108+ > Contributions to implement new programs or fix existing ones are welcome.
109+
110+ ### Explicit annotations
111+
112+ #### From a shebang expression
113+
114+ For languages that support ` # ` comments, if you provide a shebang expression, the language will be inferred whenever
115+ possible:
116+
117+ ``` nix
118+ home.activation.neovim = lib.hm.dag.entryAfter ["linkGeneration"] ''
119+ #! /bin/bash
120+ echo "Syncing neovim plugins"
121+ PATH="$PATH:${pkgs.git}/bin" $DRY_RUN_CMD ${lib.getExe my.neovim} --headless "+Lazy! restore" +qa
122+ '';
123+ ```
124+
125+ #### From a preceding comment
126+
127+ For all the cases not handled by the other features, you can specify the language yourself with a comment right before
128+ the string that should be injected:
129+
130+ ``` nix
131+ my_lua_script = /* lua */ ''
132+ require("foo")
133+ return {
134+ bar = foo.bar
135+ }
136+ '';
137+
138+ my_python_script =
139+ # python
140+ ''
141+ import foo
142+ print(foo.bar)
143+ '';
144+ ```
58145
59146## FAQ
60147
@@ -66,14 +153,13 @@ compelled to. It won't break anything.
66153## Contribute
67154
68155Very few programs are handled right now, but I welcome any addition. Just look through
69- [ the injections file] ( ./queries/nix/injections.scm ) and copy what's already there. It should be pretty straightforward
156+ [ the injections file] ( ./queries/nix/injections.scm ) and copy what's already there. It should be pretty straightforward
70157for most things. If it isn't, don't hesitate to open an issue.
71158
72159## TODO
73160
74161- [x] Better description in the readme
75- - [x ] Screenshots in the readme
162+ - [ ] Screenshots in the readme
76163- [ ] Benchmark the performance impact and see if the queries can be optimized
77164- [ ] Find a better way to handle nix nodes among string fragments in shebang scripts
78165- [ ] Check the stuff that's already done on the to-do list
79- - [ ] Add stuff to the to-do list
0 commit comments