How would I go about setting F8 key to toggle between "draw_white_space" : "all" and "draw_white_space" : "selection"
I tried several things and gaze at default ones to figure out pattern but now I rather ask and wait...
import sublime
import sublime_plugin
class ToggleWhiteSpaceCommand(sublime_plugin.ApplicationCommand):
def run(self):
settings = sublime.load_settings("Preferences.sublime-settings")
white_space = "selection" if settings.get("draw_white_space", "selection") != "selection" else "all"
settings.set("draw_white_space", white_space)
sublime.save_settings("Preferences.sublime-settings") {
"keys": ["f8"],
"command": "toggle_white_space"
}facelessuser wrote:
- Code: Select all
import sublime
import sublime_plugin
class ToggleWhiteSpaceCommand(sublime_plugin.ApplicationCommand):
def run(self):
settings = sublime.load_settings("Preferences.sublime-settings")
white_space = "selection" if settings.get("draw_white_space", "selection") != "selection" else "all"
settings.set("draw_white_space", white_space)
sublime.save_settings("Preferences.sublime-settings")
There you go.
probiner wrote:facelessuser wrote:
- Code: Select all
import sublime
import sublime_plugin
class ToggleWhiteSpaceCommand(sublime_plugin.ApplicationCommand):
def run(self):
settings = sublime.load_settings("Preferences.sublime-settings")
white_space = "selection" if settings.get("draw_white_space", "selection") != "selection" else "all"
settings.set("draw_white_space", white_space)
sublime.save_settings("Preferences.sublime-settings")
There you go.
Sorry for the newbiness. But how do I apply this? Tried to paste it on the console but a "IndentationError: unexpected indent" shows up.
Cheers
#!/usr/bin/python -O
# -*- coding: iso-8859-15 -*-
import sublime, sublime_plugin
class LnToggleDisplayCommand(sublime_plugin.TextCommand):
def run(self, edit, **kwargs):
action = kwargs['action'].upper()
view = self.view
my_id = self.view.id()
# --------------------------------------------------------------
# - To see what settings are available, and a description of each,
# - take a look at Packages/Default/Preferences.sublime-settings.
# --------------------------------------------------------------
settings = view.settings()
if action == 'WHITE_SPACE':
propertyName, propertyValue1, propertyValue2 = "draw_white_space", "all", "selection"
elif action == 'GUTTER':
propertyName, propertyValue1, propertyValue2 = "gutter", False, True
elif action == 'LINE_NO':
propertyName, propertyValue1, propertyValue2 = "line_numbers", False, True
# propertyName = "line_numbers"
elif action == 'INDENT_GUIDE':
propertyName, propertyValue1, propertyValue2 = "draw_indent_guides", False, True
else:
propertyValue = None
if propertyName:
propertyValue = propertyValue1 if settings.get(propertyName, propertyValue1) != propertyValue1 else propertyValue2
settings.set(propertyName, propertyValue)
{ "keys": ["alt+d", "alt+b"], "command": "ln_toggle_display", "args": {"action": "WHITE_SPACE"}},
{ "keys": ["alt+d", "alt+l"], "command": "ln_toggle_display", "args": {"action": "LINE_NO"}},
{ "keys": ["alt+d", "alt+i"], "command": "ln_toggle_display", "args": {"action": "INDENT_GUIDE"}},
{ "keys": ["alt+d", "alt+g"], "command": "ln_toggle_display", "args": {"action": "GUTTER"}},
{ "keys": ["f6"], "command": "toggle_setting", "args": {"setting": "spell_check"} },Users browsing this forum: No registered users and 7 guests