Python sublime.expand_variables() Examples
The following are 20
code examples of sublime.expand_variables().
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: ShellExec.py From sublime-3-shell-exec with MIT License | 9 votes |
def command_variables(args, view, command, format=True): if format and args.get("format"): command = args["format"].replace('${input}', command) for region in view.sel(): (row,col) = view.rowcol(view.sel()[0].begin()) command = command.replace('${row}', str(row+1)) command = command.replace('${region}', view.substr(region)) break # packages, platform, file, file_path, file_name, file_base_name, # file_extension, folder, project, project_path, project_name, # project_base_name, project_extension. command = sublime.expand_variables(command, sublime.active_window().extract_variables()) return command
Example #2
Source File: exec.py From sublime-ide-r with MIT License | 9 votes |
def run(self, cmd="", env={}, working_dir="", subdir="", **kwargs): try: cmd = "{package}::{function}({args})".format(**kwargs) except KeyError: pass _kwargs = {} _kwargs["cmd"] = [ride_settings.r_binary(), "--quiet", "-e", cmd] if not working_dir: working_dir = find_working_dir(window=self.window) if working_dir and subdir: working_dir = os.path.join(working_dir, subdir) _kwargs["working_dir"] = working_dir _kwargs = sublime.expand_variables(_kwargs, self.window.extract_variables()) _env = ride_settings.ride_env() _env.update(env) _kwargs["env"] = _env if "file_regex" in kwargs: _kwargs["file_regex"] = kwargs["file_regex"] if ride_settings.get("terminus_exec", False): self.window.run_command("terminus_exec", _kwargs) else: self.window.run_command("exec", _kwargs)
Example #3
Source File: configuration.py From sublime_debugger with MIT License | 8 votes |
def _expand_variables_and_platform(json: dict, variables: Optional[dict]) -> dict: json = json.copy() platform = None #type: Optional[dict] if core.platform.osx: platform = json.get('osx') elif core.platform.linux: platform = json.get('linux') elif core.platform.windows: platform = json.get('windows') if platform: for key, value in platform.items(): json[key] = value if variables is not None: return sublime.expand_variables(json, variables) return json
Example #4
Source File: PyYapf.py From PyYapf with Apache License 2.0 | 6 votes |
def find_yapf(self): """Find the yapf executable.""" # default to what is in the settings file cmd = self.get_setting("yapf_command") cmd = os.path.expanduser(cmd) cmd = sublime.expand_variables( cmd, sublime.active_window().extract_variables() ) save_settings = not cmd for maybe_cmd in ['yapf', 'yapf3', 'yapf.exe', 'yapf3.exe']: if not cmd: cmd = which(maybe_cmd) if cmd: self.debug('Found yapf: %s', cmd) break if cmd and save_settings: settings = sublime.load_settings(PLUGIN_SETTINGS_FILE) settings.set("yapf_command", cmd) sublime.save_settings(PLUGIN_SETTINGS_FILE) return cmd
Example #5
Source File: clients.py From LSP with MIT License | 6 votes |
def get_window_env(window: sublime.Window, config: ClientConfig) -> Tuple[List[str], Dict[str, str]]: # Create a dictionary of Sublime Text variables variables = window.extract_variables() # Expand language server command line environment variables expanded_args = list( sublime.expand_variables(os.path.expanduser(arg), variables) for arg in config.binary_args ) # Override OS environment variables env = os.environ.copy() for var, value in config.env.items(): # Expand both ST and OS environment variables env[var] = os.path.expandvars(sublime.expand_variables(value, variables)) return expanded_args, env
Example #6
Source File: file.py From EasyClangComplete with MIT License | 6 votes |
def expand_all(input_path, wildcard_values={}, current_folder='', expand_globbing=True): """Expand everything in this path. This returns a list of canonical paths. """ expanded_path = path.expandvars(input_path) expanded_path = sublime.expand_variables( expanded_path, wildcard_values) expanded_path = File.canonical_path(expanded_path, current_folder) if not expanded_path: return [] if expand_globbing: from glob import glob all_paths = glob(expanded_path) else: all_paths = [expanded_path] if len(all_paths) > 0 and all_paths[0] != input_path: log.debug("Populated '%s' to '%s'", input_path, all_paths) return all_paths elif expanded_path != input_path: log.debug("Populated '%s' to '%s'", input_path, expanded_path) return [expanded_path]
Example #7
Source File: custom_build_variables.py From SublimeScraps with MIT License | 6 votes |
def createExecDict(self, sourceDict): global custom_var_list # Get the project specific settings project_data = self.window.project_data () project_settings = (project_data or {}).get ("settings", {}) # Get the view specific settings view_settings = self.window.active_view ().settings () # Variables to expand; start with defaults, then add ours. variables = self.window.extract_variables () for custom_var in custom_var_list: variables[custom_var] = view_settings.get (custom_var, project_settings.get (custom_var, "")) # Create arguments to return by expanding variables in the # arguments given. args = sublime.expand_variables (sourceDict, variables) # Rename the command parameter to what exec expects. args["cmd"] = args.pop ("command", []) return args
Example #8
Source File: menu_exec.py From SublimeScraps with MIT License | 6 votes |
def run(self, show_panel=None, **kwargs): variables = self.window.extract_variables() for key in ("cmd", "shell_cmd", "working_dir"): if key in kwargs: kwargs[key] = sublime.expand_variables(kwargs[key], variables) settings = sublime.load_settings("Preferences.sublime-settings") pref_var = settings.get("show_panel_on_build") show_panel = pref_var if show_panel is None else show_panel if show_panel != pref_var: settings.set("show_panel_on_build", show_panel) super().run(**kwargs) if show_panel != pref_var: settings.set("show_panel_on_build", pref_var)
Example #9
Source File: sthelper.py From SublimeJsPrettier with MIT License | 5 votes |
def expand_var(window, var_to_expand): if not is_str_none_or_empty(var_to_expand): expanded = os.path.expanduser(var_to_expand) expanded = os.path.expandvars(expanded) if IS_ST3 and window: window_variables = window.extract_variables() expanded = sublime.expand_variables(expanded, window_variables) return expanded return var_to_expand
Example #10
Source File: method_preview.py From sublimetext-cfml with MIT License | 5 votes |
def build_pagination(current_index, total_pages): pagination_variables = { "current_page": str(current_index + 1), "total_pages": str(total_pages), } previous_index = current_index - 1 if current_index > 0 else total_pages - 1 pagination_variables["prev"] = "page_" + str(previous_index) next_index = current_index + 1 if current_index < total_pages - 1 else 0 pagination_variables["next"] = "page_" + str(next_index) return sublime.expand_variables(PAGINATION_TEMPLATE, pagination_variables)
Example #11
Source File: inline_documentation.py From sublimetext-cfml with MIT License | 5 votes |
def build_doc_html(inline_doc, doc_type): template = DOC_TEMPLATE if doc_type != "completion_doc" else COMPLETION_DOC_TEMPLATE html = sublime.expand_variables(template, inline_doc) if doc_type == "completion_doc": html = html.replace('<div class="body"></div>', "") return html
Example #12
Source File: inline_documentation.py From sublimetext-cfml with MIT License | 5 votes |
def build_pagination(current_index, total_pages): pagination_variables = { "current_page": str(current_index + 1), "total_pages": str(total_pages), } previous_index = current_index - 1 if current_index > 0 else total_pages - 1 pagination_variables["prev"] = "page_" + str(previous_index) next_index = current_index + 1 if current_index < total_pages - 1 else 0 pagination_variables["next"] = "page_" + str(next_index) return sublime.expand_variables(PAGINATION_TEMPLATE, pagination_variables)
Example #13
Source File: test_runner.py From sublimetext-cfml with MIT License | 5 votes |
def render_result(result_data, test_bundle, reporter): # lowercase all the keys since we can't guarantee the casing coming from CFML # also convert floats to ints, since CFML might serialize ints to floats result_data = preprocess(result_data) padToLen = 7 if reporter == "compacttext" else 0 result_string = sublime.expand_variables( RESULT_TEMPLATES[reporter]["results"], filter_stats_dict(result_data, padToLen) ) for bundle in result_data["bundlestats"]: if len(test_bundle) and bundle["path"] != test_bundle: continue result_string += sublime.expand_variables( RESULT_TEMPLATES[reporter]["bundle"], filter_stats_dict(bundle) ) if isinstance(bundle["globalexception"], dict): result_string += ( sublime.expand_variables( RESULT_TEMPLATES[reporter]["global_exception"], filter_exception_dict(bundle["globalexception"]), ) + "\n" ) for suite in bundle["suitestats"]: result_string += gen_suite_report(bundle, suite, reporter) result_string += "\n" + RESULT_TEMPLATES[reporter]["legend"] return result_string
Example #14
Source File: getter.py From SendCode with MIT License | 5 votes |
def resolve(self, code): view = self.view window = view.window() extracted_variables = window.extract_variables() variable_getter = { "line": self.get_line, "selection": self.get_selection, "current_folder": self.get_current_folder } for v, getter in variable_getter.items(): value = getter() if value is not None: extracted_variables[v] = value def convert(m): quote = m.group("quote") var = m.group("quoted_var") if quote else m.group("var") if var == "$code_above": var = self.get_code_above() else: var = sublime.expand_variables(var, extracted_variables) if quote == "'": return "'" + escape_squote(var) + "'" elif quote == '"': return '"' + escape_dquote(var) + '"' else: return var code = PATTERN.sub(convert, code) return code
Example #15
Source File: open_file_env.py From SublimeScraps with MIT License | 5 votes |
def run(self, **kwargs): # Create a set of variables based on the current process environment # and the standard Sublime variables variables = dict(os.environ) variables.update(self.window.extract_variables()) # Expand all variables and execute the base command with them kwargs = sublime.expand_variables(kwargs, variables) self.window.run_command("open_file", kwargs)
Example #16
Source File: utils.py From sublime-ide-r with MIT License | 5 votes |
def expand_variables(cmd, extracted_variables): def convert(m): quote = m.group("quote") if quote: var = sublime.expand_variables(m.group("quoted_var"), extracted_variables) if quote == "'": return "'" + escape_squote(var) + "'" else: return '"' + escape_dquote(var) + '"' else: return sublime.expand_variables(m.group("var"), extracted_variables) cmd = PATTERN.sub(convert, cmd) return cmd
Example #17
Source File: TerminalView.py From TerminalView with MIT License | 5 votes |
def run(self, cmd="/bin/bash -l", title="Terminal", cwd=None, syntax=None, keep_open=False): """ Open a new terminal view Args: cmd (str, optional): Shell to execute. Defaults to 'bash -l. title (str, optional): Terminal view title. Defaults to 'Terminal'. cwd (str, optional): The working dir to start out with. Defaults to either the currently open file, the currently open folder, $HOME, or "/", in that order of precedence. You may pass arbitrary snippet-like variables. syntax (str, optional): Syntax file to use in the view. keep_open (bool, optional): Keep view open after cmd exits. """ if sublime.platform() not in ("linux", "osx"): sublime.error_message("TerminalView: Unsupported OS") return st_vars = self.window.extract_variables() if not cwd: cwd = "${file_path:${folder}}" cwd = sublime.expand_variables(cwd, st_vars) if not cwd: cwd = os.environ.get("HOME", None) if not cwd: # Last resort cwd = "/" args = {"cmd": cmd, "title": title, "cwd": cwd, "syntax": syntax, "keep_open": keep_open} self.window.new_file().run_command("terminal_view_activate", args=args)
Example #18
Source File: cfdocs.py From sublimetext-cfml with MIT License | 4 votes |
def build_function_completion_doc(function_call_params, data): cfdoc = {"side_color": SIDE_COLOR, "html": {}} cfdoc["html"]["header"] = build_cfdoc_header(data, include_params=False) cfdoc["html"]["body"] = "" description_params = [] if len(data["params"]) > 0: for index, param in enumerate(data["params"]): if function_call_params.named_params: active_name = ( function_call_params.params[function_call_params.current_index][0] or "" ) is_active = active_name.lower() == param["name"].lower() else: is_active = index == function_call_params.current_index if is_active: param_variables = { "name": param["name"], "description": param["description"].replace("\n", "<br>"), "values": "", } if "type" in param and len(param["type"]): param_variables["name"] += ": " + param["type"] if "values" in param and len(param["values"]): param_variables["values"] = "<em>values:</em> " + ", ".join( [str(value) for value in param["values"]] ) if ( len(param_variables["description"]) > 0 or len(param_variables["values"]) > 0 ): cfdoc["html"]["body"] = sublime.expand_variables( "<p>${description}</p><p>${values}</p>", param_variables ) description_params.append( '<span class="active">' + param["name"] + "</span>" ) elif param["required"]: description_params.append( '<span class="required">' + param["name"] + "</span>" ) else: description_params.append( '<span class="optional">' + param["name"] + "</span>" ) cfdoc["html"]["arguments"] = "(" + ", ".join(description_params) + ")" return cfdoc
Example #19
Source File: sublimefunctions.py From FileManager with MIT License | 4 votes |
def transform_aliases(window, string): """Transform aliases using the settings and the default variables It's recursive, so you can use aliases *in* your aliases' values """ vars = window.extract_variables() vars.update(get_settings().get("aliases")) def has_unescaped_dollar(string): start = 0 while True: index = string.find("$", start) if index < 0: return False elif string[index - 1] == "\\": start = index + 1 else: return True string = string.replace("$$", "\\$") inifinite_loop_counter = 0 while has_unescaped_dollar(string): inifinite_loop_counter += 1 if inifinite_loop_counter > 100: sublime.error_message( "Infinite loop: you better check your " "aliases, they're calling each other " "over and over again." ) if get_settings().get("open_help_on_alias_infinite_loop", True) is True: sublime.run_command( "open_url", { "url": "https://github.com/math2001/ " "FileManager/wiki/Aliases " "#watch-out-for-infinite-loops" }, ) return string string = sublime.expand_variables(string, vars) return string
Example #20
Source File: SublimePhpCsFixer.py From SublimePhpCsFixer with MIT License | 4 votes |
def format_file(tmp_file, settings): php_path = settings.get('php_path') path = settings.get('path') if not path: path = locate_php_cs_fixer() if not path: raise ExecutableNotFoundException("Couldn't find php-cs-fixer") if not is_executable_file(path): raise ExecutableNotFoundException("Couldn't execute file: {0}".format(path)) configs = settings.get('config') rules = settings.get('rules') cmd = [php_path] if php_path else [] cmd += [path, "fix", "--using-cache=off", tmp_file] if configs: if not type(configs) is list: configs = [configs] variables = get_active_window_variables() for config in configs: config_path = sublime.expand_variables(config, variables) if is_readable_file(config_path): cmd.append('--config=' + config_path) log_to_console("Using config: " + config_path) break; if rules: if isinstance(rules, list): rules = rules.join(",") if isinstance(rules, str): cmd.append("--rules=" + rules) log_to_console("Using rules: " + rules) p = create_process_for_platform(cmd) output, err = p.communicate() if p.returncode != 0: log_to_console("There was an error formatting the view") log_to_console("Command: {0}".format(cmd)) log_to_console("Error output: {0}".format(err))