1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-10-26 13:40:10 +03:00

Suggest data-files be prefixed, too.

Screwtapello 2020-10-02 22:57:30 +10:00
parent d88c3da829
commit 3be9a4b165

@ -2,7 +2,7 @@ A Kakoune plugin is just a file with the `.kak` extension, living in the `%val{c
## Naming things
All commands created by plugins must live together, all options created by plugins must live together, all user-modes created by plugins must live together, etc. It's a good practice to prefix everything you declare or define with your plugin's name, to reduce the chance of collision with other plugins.
All commands created by plugins must live together, all options created by plugins must live together, all user-modes created by plugins must live together, etc. Some people even copy all the files used by different plugins directly into their autoload folder, side-by-side. It's a good practice to prefix everything with your plugin's name, to reduce the chance of collision with other plugins.
## Do not create default mappings or hooks
@ -20,13 +20,13 @@ Luckily, Kakoune provides a solution, in the form of the `%val{source}` expansio
|
+- my-plugin.kak (our plugin script)
|
+- data.csv (the data our plugin requires)
+- my-plugin-data.csv (the data our plugin requires)
At the top of `my-plugin.kak`, declare an option to store the path to the plugin directory. We use the `-hidden` flag because end-users don't need to see or modify this option, it's purely internal:
declare-option -hidden str my_plugin_path %sh{ dirname "$kak_source" }
Now `%opt{my_plugin_path}` contains the absolute path of the plugin directory, probably something like `/home/somebody/.config/kak/autoload/kakoune-my-plugin` (but the whole point is that it can vary). When a shell block in your plugin needs to refer to the data file, it can say `$kak_opt_my_plugin_path/data.csv`.
Now `%opt{my_plugin_path}` contains the absolute path of the plugin directory, probably something like `/home/somebody/.config/kak/autoload/kakoune-my-plugin` (but the whole point is that it can vary). When a shell block in your plugin needs to refer to the data file, it can say `$kak_opt_my_plugin_path/my-plugin-data.csv`.
## Create highlighters in the `shared/` namespace