Wrap filetype detection hooks in module to allow order of evaluation specification with ModuleLoaded hook#5365
Wrap filetype detection hooks in module to allow order of evaluation specification with ModuleLoaded hook#5365pylasnier wants to merge 7 commits intomawww:masterfrom
Conversation
I dedicate any and all copyright interest in this software to the public domain. I make this dedication for the benefit of the public at large and to the detriment of my heirs and successors. I intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.
|
I haven't had time to look at this in detail but In general I'd either fix the stdlib rc file, or use a different filetype If your plugin disables it, that might break other use cases and plugins.
So the issue is that for your case, "*.sml" files should not have the Of course the user should always be in control; |
I would rather keep the HOL4-specific stuff separate because it is not commonly used compared to SML, and I would rather not surprise a kak user who happened to decide to call their file
With this version of config, the HOL4 plugin doesn't disable SML detection, but merely takes precedence over it by setting the regex hook after. It should not break other use-cases, so long as the user does not name their file As far as I can tell, this proposal of wrapping with a module should not impact default behaviour in any way. It simply sets a checkpoint which plugin or user code can wait for to allow their code to run after, which should be a helpful feature. This is the best solution I could come up with that uses existing syntax.
This is exactly what my example does, it just uses the module wrapping and The point is that it is difficult to be careful about hook ordering. Many of these issues arise from the fact that stdlib is autoloaded after people's custom hooks and overrides them. I expect an idiomatic solution would be the allow the user to specify an order of execution, in spirit of the lazy, module-based evaluation that does not require file-level changes. |
|
I have added similar I really think a solution like this would be a useful addition to the rcs. Even if it's not this particular solution and its something else, I think it would be a step in the right direction to have some sort of feature which allows plugins to resolve conflicts with the stdlib without requiring the user to modify their default autoload. Perhaps some change to hooks. |
rc/filetype/apl.kak
Outdated
| @@ -1,3 +1,4 @@ | |||
| provide-module detect-apl %@ | |||
There was a problem hiding this comment.
I wonder if we should change module names. With this PR, we have.
provide-module detect-apl %{
hook global WinSetOption filetype=apl %{
require-module apl
}
...
}
provide-module apl %{
add-highlighter shared/apl regions
...
}It's possible that we want to include the "filetype" path component,
to prevent future clashes.
We could do this in a backwards-compatible way
by also providing an empty module with the old name.
provide-module filetype-apl-detection %{
hook global WinSetOption filetype=apl %{
require-module filetype-apl
}
...
}
provide-module filetype-apl %{
provide-module apl %{} # historical
add-highlighter shared/apl regions
...
}Not yet sure if this is worth it, but it seems like now is a good time to think about this.
There's no existing discussion in #2782.
I wonder what are the odds that our modules (like jump, make, tmux, screen) will ever collide with filetype modules of the same name..
There was a problem hiding this comment.
I would be happy to use different names for the detection modules if you'd like. I would probably need to check but I'm not entirely sure if your suggested filetype module name change, though, wouldn't be breaking? The apl module would be kept hidden until filetype-apl is required?
Perhaps we could open an issue on the topic, I would personally consider it a separate change.
|
|
||
| require-module detect-exherbo | ||
|
|
||
| provide-module exheres %{ |
There was a problem hiding this comment.
huh, so this is an odd module where the filename (and thus the "detect-exherbo" hook)
don't match the actual filetype modules (exheres, paludis etc.).
I guess if we really qualify module names, this would imply
module names like filetype-exherbo-exheres and filetype-exherbo-paludis.
Moving all into a single module would probably work too, but I guess it's nice to allow multiple modules per file.
There was a problem hiding this comment.
Oops, it indeed seems like I missed some hooks scattered around in files, I think I have cleaned everything up now.
I have opted to go with one detection module per file,
- for consistency; some files (for example git.kak) have I think too many filetypes to want to split apart, so if those stay grouped then others should stay grouped
- I believe users are unlikely to need these modules below the granularity of a file, since they exist only to specify an order of execution. They would simply want to state 'run the hooks from this file first', and I expect further specificity of hook ordering is redundant.
- IMO slightly easier discovery, it's just the name of the kak file
|
|
||
| } | ||
|
|
||
| require-module detect-sml |
There was a problem hiding this comment.
Thanks for this, this seems like the ideal solution to define custom
filetype detection hooks after the ones defined by the stdlib,
which is usually the right thing to do (as opposed to completely removing the stdlib one).
I agree that hook groups wouldn't help here.
Your last comment on Discourse was also helpful.
I guess this means that all scripts in "rc/filetype/*.kak" put all executable code into the "detect-$filetype" and "$filetype" modules?
Two possible future directions:
- for people who want to completely override a "$filetype" module, we
can addprovide-module -overrideas suggested in [REQUEST] A better way to prevent standard library plugins from loading #4375 (comment) - for people who want to (also) override the filetype detection hooks,
that is, either of these:hook global BufCreate .*\.(sml|fun|sig)hook global WinSetOption filetype=smlhook -group sml-highlight global WinSetOption filetype=sml
we could- either add hook groups to the first two, so they can use the familiar
remove-hooksandset-option global disabled_hooks - or
- move the "require-module detect-$foo" hooks into a "hook -once global KakBegin .*".
- then they can use
provide-module -override detect-sml %{}
There was a problem hiding this comment.
I guess this means that all scripts in "rc/filetype/*.kak" put all executable code into the "detect-$filetype" and "$filetype" modules?
Almost everything, there are some hidden commands (like indentation commands) which I thought were probably redundant to wrap up. All hooks are in modules now.
|
Hi, coming late to this discussion, I am still unclear on how this is supposed to work, as far as I understand the only difference this introduces is that we will get a
in other words, AFAIU, the only difference between: and In the user kakrc, is that the former will only add the hook if we have sourced sml.kak while the latter will always add that hook. Is my understanding correct ? Is that what you are trying to achieve with this change ? |
|
The issue is that, as is commonly the case, |
|
Hum, do you mean then that this hook is inside another autoload file ? Because if it is in the user kakrc it should run after. The existing workaround for this is to use the |
|
Oh I see, that could work to solve my issue. I hadn't come across that workaround before. This change could still offer solutions that the Thank you for the workaround regardless! |
I propose wrapping filetype detection config code in a dedicated module, for now I've named
detect-<filetype>, which gets immediately required after defining it, so as to preserve the normal autoload behaviour for the filetype rcs.What this change does is enable people to manage conflicts between their own plugin or kakrc code, without having to modify or delete default rcs from their autoload, by forcing their code to run after the filetype detection codes using the
ModuleLoadedhook. This specifies an order of execution, and is consistent regardless of the order of loading of files, as per the behaviour described in #4841.For example, the SML filetype detection regex may be partially overridden by making a new
BufCreatehook, which runs after the default SML detection:The changes I have included for now only address the issues from this discussion, but I propose similar changes may be added to all filetype rcs, or possibly any eagerly-evaluated autoload code which might be helpful to specify order of evaluation for.
This change could help solve the following issues: