Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 41 additions & 15 deletions colorcoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ def on_load(self,view):
view.settings().set('colorcode',False)
return

if view.size() > set.get('max_size',10000) and not view.settings().get('forcecolorcode',False):
if view.size() > set.get('max_size',colorshemeemodifier.get_max_size()) and not view.settings().get('forcecolorcode',False):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sublime API states:

get(name, default) Returns the named setting, or default if it's not defined.

what you are doing here is essentially

 set.get('max_size',set.get('max_size'))

which is redundant
please revert this and following changes of same manner

sublime.status_message("File is too big, disabling colorcoding as it might hurt perfromance")
view.settings().set('colorcode',False)
return

vcc = view.settings().get('color_scheme')
if vcc and "Widget" in vcc:
if vcc and "Widget" in vcc:
view.settings().set('colorcode',False)
return

Expand Down Expand Up @@ -126,15 +126,15 @@ def run(self):
for i in map(hex,range(256)):
view.erase_regions('cc'+i)
else:
if view.size() > sublime.load_settings("colorcoder.sublime-settings").get('max_size',10000):
if view.size() > sublime.load_settings("colorcoder.sublime-settings").get('max_size',colorshemeemodifier.get_max_size()):
view.settings().set('forcecolorcode',True)
view.run_command("colorcoder")

def is_checked(self):
return sublime.active_window().active_view().settings().get('colorcode',False)

def description(self):
if sublime.active_window().active_view().size() > sublime.load_settings("colorcoder.sublime-settings").get('max_size',10000):
if sublime.active_window().active_view().size() > sublime.load_settings("colorcoder.sublime-settings").get('max_size',colorshemeemodifier.get_max_size()):
return "Colorcoding may hurt performance, File is large"
else:
return "Colorcode this view"
Expand All @@ -152,6 +152,36 @@ def panel_callback(self, text):
sublime.save_settings("colorcoder.sublime-settings")
colorshemeemodifier.modify_color_scheme(l,s,True)

@staticmethod
def get_max_size():
return sublime.load_settings("colorcoder.sublime-settings").get('max_size')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as noted above this is not needed


@staticmethod
def get_save_dir():
colorcoder_settings = sublime.load_settings("colorcoder.sublime-settings")
save_dir = colorcoder_settings.get('colorcoder_schemas_dir')
if save_dir:
if save_dir[0] != '/':
save_dir = '/' + save_dir
if save_dir[-1] != '/':
save_dir = save_dir + '/'
else:
save_dir = ''

colorcoder_settings.set('colorcoder_schemas_dir', save_dir)
sublime.save_settings("colorcoder.sublime-settings")

pp = sublime.packages_path()
save_dir = pp + save_dir
if not os.path.exists(save_dir):
os.makedirs(save_dir)
firstrunfile = save_dir + '/firstrun'
if not os.path.exists(firstrunfile):
colorshemeemodifier.maybefixscheme()
open(firstrunfile, 'a').close()

return save_dir

@staticmethod
def maybefixscheme():
set = sublime.load_settings("colorcoder.sublime-settings")
Expand Down Expand Up @@ -204,9 +234,9 @@ def modify_color_scheme(l,s,read_original = False):
)
))

newname = "/Colorcoder/%s (Colorcoded).tmTheme" % re.search("/([^/]+).tmTheme$", name).group(1)
newname = "/%s (Colorcoded).tmTheme" % re.search("/([^/]+).tmTheme$", name).group(1)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the way you populate newname will lead to problems in L#238, as color_scheme setting expects to have an sublime.load_resource compatible path eg Packages/Colorcoder/Obsidian (Colorcoded).tmTheme

i guess it would be simpler just to do

newname = "/%s/%s (Colorcoded).tmTheme" % (set.get('colorcoder_schemas_dir').strip("/\\"), re.search("/([^/]+).tmTheme$", name).group(1))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it. It has a relative and full path now. Phew! You were completely right. I was missing something huge!


plistlib.writePlist(cs,"%s%s" % (sublime.packages_path(),newname))
plistlib.writePlist(cs,"%s%s" % (colorshemeemodifier.get_save_dir(),newname))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is needed so colorcoder modifies the currently used theme when being installed

revert this change please

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. So if I add colorshemeemodifier.get_save_dir() under it, that should be sufficient correct?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it needs to create the /Colorcoder directory, if not existent, and run the maybefixscheme function if firstrun file does not exist

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole addition should be fixed now if you wanna give it another shot.


sublime.load_settings("Preferences.sublime-settings").set("original_color_scheme", name)
sublime.load_settings("Preferences.sublime-settings").set("color_scheme","Packages%s" % newname)
Expand All @@ -227,16 +257,12 @@ def run(self):

def plugin_loaded():
sublime.load_settings("Preferences.sublime-settings").add_on_change('color_scheme',colorshemeemodifier.maybefixscheme)
sublime.load_settings("colorcoder.sublime-settings").add_on_change('scopes',colorcoder.update_scopes)
colorcoder_settings = sublime.load_settings("colorcoder.sublime-settings")
colorcoder_settings.add_on_change('scopes',colorcoder.update_scopes)
colorcoder_settings.add_on_change('colorcoder_schemas_dir',colorshemeemodifier.get_save_dir)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesnt make sense to call get_save_dir as it is side-effects free, and rereads the settings anyway each time executed

this line is useless and should be removed

colorcoder_settings.add_on_change('max_size',colorshemeemodifier.get_max_size)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as line above, also ,as noted above, get_max_size is not needed at all


colorcoder.update_scopes()
pp = sublime.packages_path()
if not os.path.exists(pp+"/Colorcoder"):
os.makedirs(pp+"/Colorcoder")

firstrunfile = pp+"/Colorcoder/firstrun"
if not os.path.exists(firstrunfile):
colorshemeemodifier.maybefixscheme()
open(firstrunfile, 'a').close()

for wnd in sublime.windows():
for view in wnd.views():
Expand Down
2 changes: 2 additions & 0 deletions colorcoder.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"meta.function-call",
"variable.other"],
"auto_apply_on_scheme_change": true,
"colorcoder_schemas_dir": "/Colorcoder",
"lightness":0.5,
"max_size": 10000,
"saturation":0.5
}