本文整理汇总了Python中sublime.expand_variables方法的典型用法代码示例。如果您正苦于以下问题:Python sublime.expand_variables方法的具体用法?Python sublime.expand_variables怎么用?Python sublime.expand_variables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sublime
的用法示例。
在下文中一共展示了sublime.expand_variables方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: command_variables
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import expand_variables [as 别名]
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
示例2: _expand_variables_and_platform
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import expand_variables [as 别名]
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
示例3: run
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import expand_variables [as 别名]
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)
示例4: find_yapf
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import expand_variables [as 别名]
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
示例5: get_window_env
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import expand_variables [as 别名]
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
示例6: expand_all
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import expand_variables [as 别名]
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]
示例7: createExecDict
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import expand_variables [as 别名]
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
示例8: run
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import expand_variables [as 别名]
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)
示例9: run
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import expand_variables [as 别名]
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)
示例10: expand_var
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import expand_variables [as 别名]
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
示例11: expand_variables
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import expand_variables [as 别名]
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
示例12: run
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import expand_variables [as 别名]
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)
示例13: resolve
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import expand_variables [as 别名]
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
示例14: render_result
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import expand_variables [as 别名]
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
示例15: build_pagination
# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import expand_variables [as 别名]
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)