Python sublime.load_resource() Examples
The following are 30
code examples of sublime.load_resource().
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: other.py From Requester with MIT License | 6 votes |
def show_read_only_doc_view(view, content, name, syntaxes, point=0): """Helper for creating read-only scratch view. """ view.run_command('requester_replace_view_text', {'text': content, 'point': point}) view.set_read_only(True) view.set_scratch(True) view.set_name(name) # attempts to set first valid syntax for view without showing error pop-up for syntax in syntaxes: try: sublime.load_resource(syntax) except: pass else: view.set_syntax_file(syntax) return
Example #2
Source File: theme_generator.py From GitSavvy with MIT License | 6 votes |
def try_apply_theme(view, theme_path, tries=0): """ Safly apply new theme as color_scheme. """ try: sublime.load_resource(theme_path) except Exception: if tries >= 8: print( 'GitSavvy: The theme {} is not ready to load. Maybe restart to get colored ' 'highlights.'.format(theme_path) ) return delay = (pow(2, tries) - 1) * 10 sublime.set_timeout_async(lambda: try_apply_theme(view, theme_path, tries + 1), delay) return view.settings().set("color_scheme", theme_path)
Example #3
Source File: message_request_handler.py From LSP with MIT License | 6 votes |
def show_notification(view: sublime.View, source: str, message_type: int, message: str, titles: List[str], on_navigate: Callable, on_hide: Callable) -> None: stylesheet = sublime.load_resource("Packages/LSP/notification.css") contents = message_content(source, message_type, message, titles) mdpopups.show_popup( view, contents, css=stylesheet, md=False, location=-1, wrapper_class='notification', max_width=800, max_height=800, on_navigate=on_navigate, on_hide=on_hide )
Example #4
Source File: __init__.py From sublime-markdown-popups with MIT License | 6 votes |
def _get_user_css(): """Get user CSS.""" css = None user_css = _get_setting('mdpopups.user_css', DEFAULT_USER_CSS) if user_css == OLD_DEFAULT_CSS: user_css = DEFAULT_CSS try: css = clean_css(sublime.load_resource(user_css)) except Exception: pass return css if css else '' ############################## # Markdown parsing ##############################
Example #5
Source File: st_scheme_template.py From sublime-markdown-popups with MIT License | 6 votes |
def read_css(self, css): """Read the CSS file.""" try: var = copy.copy(self.variables) var.update( { 'is_phantom': self.css_type == PHANTOM, 'is_popup': self.css_type == POPUP, 'is_sheet': self.css_type == SHEET } ) if css == OLD_DEFAULT_CSS: css = DEFAULT_CSS return self.env.from_string( clean_css(sublime.load_resource(css)) ).render(var=var, plugin=self.plugin_vars) except Exception: return ''
Example #6
Source File: extract_function.py From sublime-ide-r with MIT License | 6 votes |
def detect_free_vars(self, code): dfv_path = tempfile.mkstemp(suffix=".R")[1] data = sublime.load_resource("Packages/R-IDE/ride/commands/detect_free_vars.R") with open(dfv_path, 'w') as f: f.write(data.replace("\r\n", "\n")) f.close() result = R( file=dfv_path, stdin_text=code ).strip() try: os.unlink(dfv_path) except Exception: pass return [s.strip() for s in result.split("\n")] if result else []
Example #7
Source File: docphp.py From docphp with MIT License | 6 votes |
def formatPopup(self, content, symbol, can_back=False): if not isinstance(content, str): return content = decodeEntity(content) parser = PopupHTMLParser(symbol, language, can_back) try: parser.feed(content) except FinishError: pass content = parser.output content = '<style>'+sublime.load_resource('Packages/' + package_name + '/style.css') + \ '</style><div id="outer"><div id="container">' + content + "</div></div>" content = re.sub('<strong><code>([A-Z_]+)</code></strong>', '<strong><code><a class="constant" href="constant.\\1">\\1</a></code></strong>', content) return content
Example #8
Source File: script_mixin.py From R-Box with MIT License | 6 votes |
def detect_free_vars(self, code): dfv_path = tempfile.mkstemp(suffix=".R")[1] data = sublime.load_resource("Packages/R-Box/box/detect_free_vars.R") with open(dfv_path, 'w') as f: f.write(data.replace("\r\n", "\n")) f.close() result = self.rscript( file=dfv_path, stdin_text=code ).strip() try: os.unlink(dfv_path) except Exception: pass return [s.strip() for s in result.split("\n")] if result else []
Example #9
Source File: gutter_color.py From GutterColor with MIT License | 6 votes |
def generate_scheme_fix(old_scheme, new_scheme_path): """Appends background-correction XML to a color scheme file""" from os.path import join from re import sub UUID_REGEX = '[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}' with open(join(packages_path(),current_directory(),'background_fix.xml')) as f: xml = f.read() scheme_data = load_resource(old_scheme) # only valid for ST3 API! insertion_point = scheme_data.rfind("</array>") new_scheme_data = scheme_data[:insertion_point] + xml + scheme_data[insertion_point:] def uuid_gen(args): from uuid import uuid4 return str(uuid4()) new_scheme_data = sub(UUID_REGEX, uuid_gen, new_scheme_data) with open(new_scheme_path, "wb") as f: f.write(new_scheme_data.encode("utf-8"))
Example #10
Source File: inline_documentation.py From sublimetext-cfml with MIT License | 5 votes |
def _plugin_loaded(): global DOC_TEMPLATE, COMPLETION_DOC_TEMPLATE, PAGINATION_TEMPLATE root_path = "Packages/" + utils.get_plugin_name() + "/templates" DOC_TEMPLATE = sublime.load_resource( root_path + "/inline_documentation.html" ).replace("\r", "") COMPLETION_DOC_TEMPLATE = sublime.load_resource( root_path + "/completion_doc.html" ).replace("\r", "") PAGINATION_TEMPLATE = sublime.load_resource(root_path + "/pagination.html").replace( "\r", "" )
Example #11
Source File: cfml_syntax.py From sublimetext-cfml with MIT License | 5 votes |
def load_member_functions(): member_functions = set() data = sublime.load_resource( "Packages/CFML/src/plugins_/basecompletions/json/cfml_member_functions.json" ) data = sublime.decode_value(data) for member_type in data: methods = [m.lower() for m in data[member_type].keys()] member_functions.update(methods) return list(member_functions)
Example #12
Source File: file.py From GitSavvy with MIT License | 5 votes |
def handle_sublime_syntax_files(): # type: () -> None syntax_files = sublime.find_resources("*.sublime-syntax") for syntax_file in syntax_files: try: resource = sublime.load_resource(syntax_file) except Exception: print("GitSavvy: could not load {}".format(syntax_file)) continue for extension in try_parse_for_file_extensions(resource) or []: syntax_file_map[extension].append(syntax_file)
Example #13
Source File: popups.py From EasyClangComplete with MIT License | 5 votes |
def __init__(self, max_dimensions): """Initialize basic needs. 'max_dimensions' is a tuple of (maximum_width, maximum_height) in pixels.""" self.CSS = sublime.load_resource(POPUP_CSS_FILE) self.max_width, self.max_height = max_dimensions
Example #14
Source File: test_view_config.py From EasyClangComplete with MIT License | 5 votes |
def test_flags(self): """Test that flags are properly defined for a completer.""" file_name = path.join(path.dirname(__file__), 'test_files', 'test.cpp') self.set_up_view(file_name) manager = SettingsManager() settings = manager.settings_for_view(self.view) settings.use_default_includes = False view_config = ViewConfig(self.view, settings) self.assertIsNotNone(view_config.completer) p = path.join(sublime.packages_path(), "User", "EasyClangComplete.sublime-settings") if path.exists(p): user = sublime.load_resource( "Packages/User/EasyClangComplete.sublime-settings") if "common_flags" in user: # The user modified the default common flags, just skip the # next few tests. return completer = view_config.completer self.assertTrue(len(completer.clang_flags) >= 20) # test from the start self.assertIn('-c', completer.clang_flags) self.assertIn('-fsyntax-only', completer.clang_flags) self.assertIn('-x', completer.clang_flags) self.assertIn('c++', completer.clang_flags) self.assertIn('-std=c++14', completer.clang_flags) expected = path.join(path.dirname( path.dirname(__file__)), 'local_folder') # test include folders self.assertTrue(len(view_config.include_folders) >= 7) self.assertTrue(expected in view_config.include_folders) # test include flag self.assertIn(expected, completer.clang_flags)
Example #15
Source File: test_settings.py From EasyClangComplete with MIT License | 5 votes |
def test_populate_flags(self): """Testing include population.""" # open any existing file file_name = path.join(path.dirname(__file__), 'test_files', 'test_wrong_triggers.cpp') self.set_up_view(file_name) # now test the things manager = SettingsManager() settings = manager.user_settings() valid, _ = settings.is_valid() self.assertTrue(valid) p = path.join(sublime.packages_path(), "User", "EasyClangComplete.sublime-settings") if path.exists(p): user = sublime.load_resource( "Packages/User/EasyClangComplete.sublime-settings") if "common_flags" in user: # The user modified the default common flags, just skip the # next few tests. return initial_common_flags = list(settings.common_flags) settings = manager.settings_for_view(self.view) dirs = settings.common_flags self.assertTrue(len(initial_common_flags) <= len(dirs)) reference_flag_0 = Flag.Builder().from_unparsed_string( initial_common_flags[0]).build() self.assertIn(reference_flag_0, dirs) reference_flag_1 = Flag.Builder().from_unparsed_string( initial_common_flags[1]).build() self.assertNotIn(reference_flag_1, dirs)
Example #16
Source File: scratch_buffer.py From SublimeScraps with MIT License | 5 votes |
def _syntax_name(syntax_res): syntax_file = os.path.basename(syntax_res) name, ext = os.path.splitext(syntax_file) if ext == '.sublime-syntax': contents = sublime.load_resource(syntax_res) # read the name from the YAML - not worth having a dependency on a full YAML parser for this... match = re.search(r'^name:\s+([^\r\n]+|\'[^\']+\')$', contents, re.MULTILINE) if match: name = match.group(1) return name
Example #17
Source File: cfml_syntax.py From sublimetext-cfml with MIT License | 5 votes |
def load_tag_list(): tags_to_filter = [ 'abort', 'admin', 'case', 'catch', 'component', 'continue', 'defaultcase', 'else', 'elseif', 'exit', 'finally', 'function', 'if', 'interface', 'print', 'rethrow', 'retry', 'return', 'script', 'servlet', 'servletparam', 'set', 'sleep', 'switch', 'try', 'while', ] tags = sublime.load_resource( "Packages/CFML/src/plugins_/basecompletions/json/cfml_tags.json" ) tags = sublime.decode_value(tags).keys() return [t.lower()[2:] for t in tags if t.lower()[2:] not in tags_to_filter]
Example #18
Source File: run_indent_tests.py From SublimeScraps with MIT License | 5 votes |
def run_indent_test(self, package_file): syntax = self.syntax_for_file(package_file) if syntax is None: return (0, []) input_file = sublime.load_resource(package_file) input_lines = input_file.splitlines() view = self.window.create_output_panel("indent_test", False) view.assign_syntax(syntax) view.run_command("select_all") view.run_command("left_delete") for line in input_lines: view.run_command("append", {"characters": line.lstrip() + "\n"}) view.run_command("select_all") view.run_command("reindent") output_file = view.substr(sublime.Region(0, view.size())) output_lines = output_file.splitlines() if input_file == output_file: return (len(input_lines), []) diff = ndiff(input_file.splitlines(), output_file.splitlines()) line_num = 0 errors = [] for line in diff: prefix = line[:2] line_num += 1 if prefix in (" ", "+ ") else 0 if prefix == "+ ": msg = "{}:{}:1: Indent Failure: {}".format(package_file, line_num, line[2:]) errors.append(msg) # self.window.run_command("show_panel", {"panel": "output.indent_test"}) return (len(input_lines), errors)
Example #19
Source File: run_indent_tests.py From SublimeScraps with MIT License | 5 votes |
def syntax_for_file(self, package_file): first_line = sublime.load_resource(package_file).splitlines()[0] match = re.match('^.*INDENT TEST "(.*?)"', first_line) if not match: return None return match.group(1)
Example #20
Source File: __init__.py From sublime-markdown-popups with MIT License | 5 votes |
def _get_default_css(): """Get default CSS.""" return clean_css(sublime.load_resource(DEFAULT_CSS))
Example #21
Source File: method_preview.py From sublimetext-cfml with MIT License | 5 votes |
def _plugin_loaded(): global PREVIEW_TEMPLATE, PAGINATION_TEMPLATE root_path = "Packages/" + utils.get_plugin_name() + "/templates" PREVIEW_TEMPLATE = sublime.load_resource( root_path + "/method_preview.html" ).replace("\r", "") PAGINATION_TEMPLATE = sublime.load_resource(root_path + "/pagination.html").replace( "\r", "" )
Example #22
Source File: testbox.py From sublimetext-cfml with MIT License | 5 votes |
def load_json_data(filename): json_data = sublime.load_resource( "Packages/" + utils.get_plugin_name() + "/src/plugins_/testbox/json/" + filename + ".json" ) return json.loads(json_data)
Example #23
Source File: docphp.py From docphp with MIT License | 5 votes |
def getAllLanguages(): return sublime.decode_value(sublime.load_resource('Packages/' + package_name + '/languages.json'))
Example #24
Source File: docphp.py From docphp with MIT License | 5 votes |
def decodeEntity(xml, category='iso'): global entities if not isinstance(xml, str): return xml if entities[category]: forward, reverse = entities[category] else: resourceMap = { "iso": "IsoEntities.json", "html": "HtmlEntities.json", } forward = sublime.decode_value(sublime.load_resource('Packages/' + package_name + '/' + resourceMap[category])) reverse = dict((v, k) for k, v in forward.items()) entities[category] = (forward, reverse) def parseEntity(match): entity = match.group(1) try: if entity.isdigit(): return reverse[int(entity)] else: return chr(forward[entity]) except: return match.group(0) xml = re.sub('&([a-zA-Z0-9]+);', parseEntity, xml) return xml
Example #25
Source File: help.py From GitSavvy with MIT License | 5 votes |
def run(self, edit, page, anchor, add_to_history=True): settings = self.view.settings() previous_page = settings.get("git_savvy.help.page") if not page == previous_page: settings.set("git_savvy.help.page", page) content = ( sublime.load_resource("Packages/GitSavvy/docs/" + page) .replace('\r\n', '\n') .replace('\r', '\n') ) is_read_only = self.view.is_read_only() self.view.set_read_only(False) self.view.replace(edit, sublime.Region(0, self.view.size()), content) self.view.set_read_only(is_read_only) self.collapse_links() else: content = self.view.substr(sublime.Region(0, self.view.size())) if add_to_history: history = settings.get("git_savvy.help.history") or [] history.append((page, anchor)) settings.set("git_savvy.help.history", history) pt = self.find_anchor(content, anchor) sel = self.view.sel() sel.clear() sel.add(sublime.Region(pt, pt)) self.view.show(pt)
Example #26
Source File: fw1.py From sublimetext-cfml with MIT License | 5 votes |
def load_json_data(filename): json_data = sublime.load_resource( "Packages/" + utils.get_plugin_name() + "/src/plugins_/fw1/json/" + filename + ".json" ) return json.loads(json_data)
Example #27
Source File: new_file.py From omnisharp-sublime with MIT License | 5 votes |
def get_code(self, type, namespace, filename): code = '' file_name = "%s.tmpl" % type isIOError = False tmpl_dir = 'Packages/' + self.PACKAGE_NAME + '/' + self.TMLP_DIR + '/' user_tmpl_dir = 'Packages/User/' + \ self.PACKAGE_NAME + '/' + self.TMLP_DIR + '/' self.user_tmpl_path = os.path.join(user_tmpl_dir, file_name) self.tmpl_path = os.path.join(tmpl_dir, file_name) try: code = sublime.load_resource(self.user_tmpl_path) except IOError: try: code = sublime.load_resource(self.tmpl_path) except IOError: isIOError = True if isIOError: sublime.message_dialog('[Warning] No such file: ' + self.tmpl_path + ' or ' + self.user_tmpl_path) code = code.replace('${namespace}', namespace) code = code.replace('${classname}', filename) return code
Example #28
Source File: find_results.py From BetterFindBuffer with MIT License | 5 votes |
def run(self, edit): popup_max_width = 800 popup_max_height = 800 html = sublime.load_resource("Packages/BetterFindBuffer/shortcuts.html") self.view.show_popup(html, 0, -1, popup_max_width, popup_max_height)
Example #29
Source File: color_scheme_styles.py From sublimetext-cfml with MIT License | 5 votes |
def get_user_color_scheme(color_scheme_file): try: src_str = sublime.load_resource(color_scheme_file) user_color_scheme = sublime.decode_value(src_str) if "rules" not in user_color_scheme: user_color_scheme["rules"] = [] return user_color_scheme except IOError: return {"rules": []}
Example #30
Source File: test_runner.py From sublimetext-cfml with MIT License | 5 votes |
def load(): global RESULT_TEMPLATES for n in RESULT_TEMPLATES: for t in RESULT_TEMPLATES[n]: r = ( "Packages/" + utils.get_plugin_name() + "/templates/testbox/" + n + "/" + t + ".txt" ) RESULT_TEMPLATES[n][t] = sublime.load_resource(r).replace("\r", "")