-
Notifications
You must be signed in to change notification settings - Fork 50
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
Pattern for only executing a plugin for a specific filetype #1310
Comments
I would put the check inside So, something like this: def on_tab_key(
tab: tabs.FileTab, # this comes from partial()
event: tkinter.Event[textutils.MainText],
shift_pressed: bool,
) -> str:
tab.settings.debug_dump() # it's here somewhere, don't remember where
def on_new_filetab(tab: tabs.FileTab) -> None:
utils.bind_tab_key(tab.textwidget, partial(on_tab_key, tab), add=True) |
|
This is what I ended up with: if tab.settings.get("filetype_name", str) == "Markdown":
... It seems to work fine. Does this seem right/idiomatic? |
Yes, that seems right. It is the best you can do if you need to rely on the filetype. In general, I don't like checking the filetype name, because it means your code will not work with anything else than markdown, but for a first version of the plugin this is good. |
I'm not sure that it makes sense to use with anything else though. Maybe like ASCIIDoc or something? |
Yes, things like ASCIIDoc and reStructuredText. Also other custom filetypes that users might want to have and we have no idea about. Example of a custom thing: One of my older projects is |
I see, so how would you envision that working then? Add config options? |
Yes, this would ideally be configurable in |
I can't seem to figure out how this is supposed to be done for #1305
For this example:
Where would I put a line in to only have the plugin function for markdown files?
The text was updated successfully, but these errors were encountered: