Skip to content

Instantly share code, notes, and snippets.

@FichteFoll
Last active August 29, 2015 14:16
Show Gist options
  • Save FichteFoll/a1ec2e3225b96c5489e6 to your computer and use it in GitHub Desktop.
Save FichteFoll/a1ec2e3225b96c5489e6 to your computer and use it in GitHub Desktop.
Bootstraps the sublime.log_* functions to automatically toggle when called with no parameter (or `None`)
import sublime
from functools import partial
function_names = ('input', 'commands', 'result_regex', 'indexing')
# Cleanup
if hasattr(sublime, 'logging_unbootstrap'):
sublime.logging_unbootstrap()
# Assure this exists
if not hasattr(sublime, 'logging_cache'):
setattr(sublime, 'logging_cache', {})
# Collect original functions
original_functions = {name: getattr(sublime, "log_" + name)
for name in function_names}
# Override functions with our new function
def toogle_logging(name, value=None):
if value is None:
value = not sublime.logging_cache.get(name, False)
if value in (True, False):
sublime.logging_cache[name] = value
original_functions[name](value)
for name in function_names:
setattr(sublime, "log_" + name, partial(toogle_logging, name))
# Register cleanup
def unbootstrap():
for name, func in original_functions.items():
setattr(sublime, "log_" + name, func)
delattr(sublime, 'logging_unbootstrap')
setattr(sublime, 'logging_unbootstrap', unbootstrap)
# Done
print("Note: sublime.log* methods have been overridden and now toggle when "
"called without a parameter")
def plugin_unloaded():
unbootstrap()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment