-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
the preSave Action isn't triggered when the file is saved during quit dialog #3550
Comments
Because it was the |
I see. |
Is there a reason behind the |
I assume it was easier to implement in that way, since an additional callback is used. I assume there are more scenarios/use cases in which It's possible...
...but doesn't look that nice so far, since it may end in this...
....since the |
The save command does not trigger the preSave/onSave Action either. reading your comment i suppose this is intentional too. |
Micro clearly defines what is an "action". It is something that is bound to a key, i.e. triggered when this key is pressed. There are over 100 actions, they all are listed in Which doesn't mean that a callback that is triggered whenever micro saves a file for whatever reason, not just when pressing Ctrl-S, wouldn't be useful. But it would probably need to be named differently, e.g. |
Thanks for the explanation, that clarifies it a lot. I disagree on the "clearly defines" part though – the documentation in plugins.md says:
The save in the quit dialog is clearly triggered by the user by answering the prompt. It's not clear in the documentation that an action can only be triggered directly through a keybinding that they have explicitly set or that is part of the documented defaultkeys. One could reasonably assume (as I did) that in the prompt pressing "y" is bound to From a plugin perspective this system is a bit silly – plugins tend to care about what actions are happening in the editor and not so much about what triggered the action. This means that in practice using Adding |
I said "clearly defines", not "clearly documents".
We can trivially fix it, right? --- a/runtime/help/plugins.md
+++ b/runtime/help/plugins.md
@@ -67,8 +67,8 @@ that micro defines:
* `onSetActive(bufpane)`: runs when changing the currently active bufpane.
-* `onAction(bufpane)`: runs when `Action` is triggered by the user, where
- `Action` is a bindable action (see `> help keybindings`). A bufpane
+* `onAction(bufpane)`: runs when `Action` is triggered by the user, when
+ pressing a key bound to this action (see `> help keybindings`). A bufpane
is passed as input and the function should return a boolean defining
whether the view should be relocated after this action is performed.
If we take the existing description literally, it wouldn't make much sense, since it would mean that
Doesn't seem like a reasonable assumption to me. A key being "bound" to something means that the user can check what it is bound to with the
Yep, basically this system is a quick smart hack: since we need to define a bunch of "actions" to let the users configure their keybindings anyway, why not also, as a bonus, allow the user to hook custom Lua logic on all those same actions. IOW, perhaps the primary target audience of these "action callbacks" is not plugin writers but normal users who just hack on their IOW, if such "action callbacks" are not very useful or reliable for use by plugins, it just means that plugin authors should rather ignore their existence and instead aim at using, let's call it, "event callbacks", that are triggered by some well-defined events irregardless of keybindings. Micro has a few such callbacks (
The documentation doesn't even mention |
BTW also thanks for bringing my attention to this:
What the heck is that? Micro doesn't implement anything like that. It uses the return value of |
Ok, that's the other way around. We leave the "action callbacks" ( And I definitely agree to rework the documentation. |
Description of the problem or steps to reproduce
the preSave Action isn't triggered when the file is saved during quit dialog (answering the question with "yes").
Specifications
Version: 2.0.14-dev.73
Commit hash: 8724709
Compiled on March 17, 2024
I suppose further information about used terminal isn't necessary in this case.
The text was updated successfully, but these errors were encountered: