rumly111 / simpleifdef

Sublime Text 3 plugin to highlight #ifdef-#else-#endif

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Only check in C/C++/ObjC/ObjC++ files

rwols opened this issue · comments

This package runs its code in on_selection_modified for every file. This is wasteful and can even slow down unrelated files. Please make sure to do the checks only in files that match the selector

source.c | source.c++ | source.objc | source.objc++

This package runs its code in on_selection_modified for every file. This is wasteful and can even slow down unrelated files. Please make sure to do the checks only in files that match the selector

source.c | source.c++ | source.objc | source.objc++

Oh man, I haven't touched this extension for a long time.
TBH I don't know how to restrict it only to c/c++/objc files. And I lack the motivation to search the ST documentation.
But the guy who is in charge of ST package manager repository helped me correct a lot of errors in the early stages of development. He seemed nice and smart, maybe he can help you. I'll be glad to accept a PR, or just modify the plugin if you find the answer.

Just add something like this in on_selection_modified:

if not view.match_selector("source.c | source.c++ | source.objc | source.objc++"):
    return

Just add something like this in on_selection_modified:

if not view.match_selector("source.c | source.c++ | source.objc | source.objc++"):
    return

That would correspond to python philosophy "explicit is better than implicit". But on_selection_modified would still be called every time on every type of file, and I have doubts that checking the file type on every modification would work faster than the existing code.
It would be nice if there was a way to deactivate the plugin for non-related files. Maybe there is some sort of meta file for each plugin that can do it? Or do it in the class constructor (init) ? If there is no other way, I will consider adding those lines

There exists a method on_selection_modified_async , which could probably make it run smoother

Using on_selection_modified_async may help a little, but it would still take a long time to compute its thing, only now in an alternative worker thread. So I would still suggest to check for the selector as well.

I found this ST forum post https://forum.sublimetext.com/t/plugin-for-only-a-specific-file-type/51729 .
It seems on_selection_modified will be run with every file type, which makes me wonder if I should maybe be checking the file type, after all. Maybe add it to _rescan() function. I will ponder over it a bit more.

Probably fixed in 0.3.3 ;-)