sublimetext3 - SublimeText 3 - dynamically enable/disable invisible white space option -
is there dynamic way enable , disable invisible white space display apart persistent setting, via:
"draw_white_space": "all",
the way control state of display white space via changing setting reference in question, draw_white_space
:
// set "none" turn off drawing white space, "selection" draw // white space within selection, , "all" draw white space "draw_white_space": "selection",
for many such settings boolean value, can bind key toggle_setting
command, telling setting want toggle between. however, case of draw_white_space
option, takes string argument of either "all"
, "selection"
or "none"
, standard toggle command won't work.
the following simple plugin implements toggle_white_space
command performs operation you. use it, select tools > developer > new plugin...
menu, replace stub code see plugin code here, , save .py
file in location sublime default (your user
package):
import sublime import sublime_plugin class togglewhitespacecommand(sublime_plugin.textcommand): def run(self, edit, options=["none", "selection", "all"]): try: current = self.view.settings().get("draw_white_space", "selection") index = options.index(current) except: index = 0 index = (index + 1) % len(options) self.view.settings().set("draw_white_space", options[index])
the defined command takes optional argument named options
allows specify values want toggle between, default being of possible options.
you can bind key directly command toggle state of setting between of possible values of setting, or use following if want swap between being on , being off, example:
{ "keys": ["super+s"], "command": "toggle_white_space", "args": { "options": ["all", "none"] } },
note although changing setting, it's applying setting directly focused view, persistent view in question , long view open. doesn't alter setting other files open or new files might open in future; default such files still have setting set in user preferences.
Comments
Post a Comment