def run(self, edit): for r in self.view.sel(): if r.a == r.b: p = get_unicode_prefix(self.view, r.a) if p: rep = symbol_by_name(p[0]) if rep: self.view.replace(edit, p[1], rep) continue (pre, list_chars) = get_list_prefix(p[0]) if pre is not None: rep = ''.join( [symbol_by_name(pre + ch) for ch in list_chars]) self.view.replace(edit, p[1], rep) continue if is_script(p[0]): (script_char, chars) = get_script(p[0]) rep = ''.join( [symbol_by_name(script_char + ch) for ch in chars]) self.view.replace(edit, p[1], rep) continue rep = symbol_by_code(p[0]) if rep: self.view.replace(edit, p[1], rep) continue
def can_convert(view): """ Determines if there are any regions, where symbol can be converted Used not to call command when it will not convert anything, because such call modified edit, which lead to call of on_modified recursively Some times (is it sublime bug?) on_modified called twice on every change, which makes hard to detect whether this on_modified was called as result of previous call of command """ for r in view.sel(): if r.a == r.b: p = get_unicode_prefix(view, r.a) if p: rep = symbol_by_name(p[0]) if rep: return True (pre, list_chars) = get_list_prefix(p[0]) if get_settings().get('convert_list', True) and pre is not None: if all([symbol_by_name(pre + ch) for ch in list_chars]): return True if get_settings().get('convert_sub_super', True) and is_script( p[0]): (script_char, chars) = get_script(p[0]) if all([symbol_by_name(script_char + ch) for ch in chars]): return True if get_settings().get('convert_codes', True): rep = symbol_by_code(p[0]) if rep: return True return False
def can_convert(view): """ Determines if there are any regions, where symbol can be converted Used not to call command when it will not convert anything, because such call modified edit, which lead to call of on_modified recursively Some times (is it sublime bug?) on_modified called twice on every change, which makes hard to detect whether this on_modified was called as result of previous call of command """ for r in view.sel(): if r.a == r.b: p = get_unicode_prefix(view, r.a) if p: rep = symbol_by_name(p[0]) if rep: return True (pre, list_chars) = get_list_prefix(p[0]) if get_settings().get('convert_list', True) and pre is not None: if all([symbol_by_name(pre + ch) for ch in list_chars]): return True if get_settings().get('convert_sub_super', True) and is_script(p[0]): (script_char, chars) = get_script(p[0]) if all([symbol_by_name(script_char + ch) for ch in chars]): return True if get_settings().get('convert_codes', True): rep = symbol_by_code(p[0]) if rep: return True return False
def run(self, edit): for r in self.view.sel(): if r.a == r.b: p = get_unicode_prefix(self.view, r.a) if p: rep = symbol_by_name(p[0]) if rep: self.view.replace(edit, p[1], rep) continue (pre, list_chars) = get_list_prefix(p[0]) if pre is not None: rep = ''.join([symbol_by_name(pre + ch) for ch in list_chars]) self.view.replace(edit, p[1], rep) continue if is_script(p[0]): (script_char, chars) = get_script(p[0]) rep = ''.join([symbol_by_name(script_char + ch) for ch in chars]) self.view.replace(edit, p[1], rep) continue rep = symbol_by_code(p[0]) if rep: self.view.replace(edit, p[1], rep) continue
def run(self, edit): for r in self.view.sel(): upref = get_unicode_prefix(self.view, self.view.word(r).b) sym = symbol_by_name(upref[0]) if upref else None symc = symbol_by_code(upref[0]) if upref else None if upref and (sym or symc): self.view.replace(edit, upref[1], sym or symc) elif r.b - r.a <= 1: u = sublime.Region(r.b - 1, r.b) usym = self.view.substr(u) names = names_by_symbol(usym) if not names: self.view.replace(edit, u, u'\\' + code_by_symbol(usym)) else: self.view.replace(edit, u, u'\\' + names[0])