Python sublime.encode_value() Examples
The following are 7
code examples of sublime.encode_value().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sublime
, or try the search function
.
Example #1
Source File: exec_command.py From sublime-import-helper with MIT License | 6 votes |
def run_command(command, data=None, callback=None): debug("run_command", [NODE_BIN, command, data]) json = sublime.encode_value({"command": command, "args": data}) err = None out = None try: (err, out) = exec([NODE_BIN, "--no-warnings", RUN_PATH], json) except Exception as e: err = traceback.format_exc() if bool(err): if callback is not None: return callback(err, None) raise err # debug('run_command: trying to decode', out) result = sublime.decode_value(out) if callback is not None: return callback(None, result) return result
Example #2
Source File: json_file.py From ProjectManager with MIT License | 6 votes |
def load(self, default=[]): self.fdir = os.path.dirname(self.fpath) if not os.path.isdir(self.fdir): os.makedirs(self.fdir) if os.path.exists(self.fpath): with open(self.fpath, mode='r', encoding=self.encoding) as f: content = f.read() try: data = sublime.decode_value(content) except Exception: sublime.message_dialog('%s is bad!' % self.fpath) raise if not data: data = default else: with open(self.fpath, mode='w', encoding=self.encoding, newline='\n') as f: data = default f.write(sublime.encode_value(data, True)) return data
Example #3
Source File: docphp.py From docphp with MIT License | 6 votes |
def getJsonOrGenerate(name, callback): filename = getI18nCachePath() + name + '.json' if os.path.exists(filename): with open(filename, 'r', encoding='utf8') as f: json = f.read(10485760) content = sublime.decode_value(json) else: content = callback() dirname = os.path.dirname(filename) if not os.path.isdir(dirname): os.makedirs(dirname) with open(filename, 'w', encoding="utf8") as f: f.write(sublime.encode_value(content)) return content
Example #4
Source File: json_file.py From UnitTesting with MIT License | 5 votes |
def save(self, data, indent=4): self.fdir = os.path.dirname(self.fpath) if not os.path.isdir(self.fdir): os.makedirs(self.fdir) f = codecs.open(self.fpath, "w+", encoding=self.encoding) f.write(sublime.encode_value(data, True)) f.close()
Example #5
Source File: json_file.py From ProjectManager with MIT License | 5 votes |
def save(self, data, indent=4): self.fdir = os.path.dirname(self.fpath) if not os.path.isdir(self.fdir): os.makedirs(self.fdir) with open(self.fpath, mode='w', encoding=self.encoding, newline='\n') as f: f.write(sublime.encode_value(data, True))
Example #6
Source File: theme_generator.py From GitSavvy with MIT License | 5 votes |
def write_new_theme(self, name): full_path = os.path.join(sublime.packages_path(), self.get_theme_path(name)) with util.file.safe_open(full_path, "wb", buffering=0) as out_f: out_f.write(sublime.encode_value(self.dict, pretty=True).encode("utf-8"))
Example #7
Source File: color_scheme_styles.py From sublimetext-cfml with MIT License | 5 votes |
def toggle(): preferences = sublime.load_settings("Preferences.sublime-settings") color_scheme = os.path.basename(preferences.get("color_scheme")) color_scheme_file = os.path.splitext(color_scheme)[0] + ".sublime-color-scheme" user_color_scheme = get_user_color_scheme("Packages/User/" + color_scheme_file) user_color_scheme_path = os.path.join( sublime.packages_path(), "User", color_scheme_file ) non_cfml_rules = [ row for row in user_color_scheme["rules"] if "scope" not in row or not row["scope"].endswith("cfml") ] has_cfml_rules = len(user_color_scheme["rules"]) > len(non_cfml_rules) if has_cfml_rules: user_color_scheme["rules"] = non_cfml_rules else: user_color_scheme["rules"].extend(get_cfml_rules()) with open(user_color_scheme_path, "w") as f: f.write(sublime.encode_value(user_color_scheme, True)) if len(user_color_scheme.keys()) == 1 and len(user_color_scheme["rules"]) == 0: print("CFML: Packages/User/{} is now empty.".format(color_scheme_file))