├── .python-version ├── tests ├── lwp.png ├── score.png ├── call-cc.png ├── lwp.ss ├── score.json └── call-cc.ss ├── .gitattributes ├── messages ├── 4.3.1.txt ├── 4.3.2.txt ├── 4.2.0.txt ├── 4.3.0.txt ├── 4.1.0.txt └── install.txt ├── images ├── example.png ├── material-json.png ├── material-lighter.png └── material-scheme.png ├── dependencies.json ├── plugin ├── consts.py ├── logger.py ├── __init__.py ├── color_scheme.py ├── executor.py ├── commands.py └── manager.py ├── boot.py ├── pyproject.toml ├── Default.sublime-commands ├── LICENSE ├── keymap ├── Default (Linux).sublime-keymap ├── Default (OSX).sublime-keymap └── Default (Windows).sublime-keymap ├── Main.sublime-menu ├── RainbowBrackets.sublime-settings ├── typings ├── _sublime_types.pyi ├── sublime_plugin.pyi └── sublime.pyi └── README.md /.python-version: -------------------------------------------------------------------------------- 1 | 3.8 2 | -------------------------------------------------------------------------------- /tests/lwp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/absop/RainbowBrackets/HEAD/tests/lwp.png -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /messages/4.3.1.txt: -------------------------------------------------------------------------------- 1 | => 4.3.1 2 | 3 | # Features and Fixes 4 | 5 | - Updated docs 6 | -------------------------------------------------------------------------------- /tests/score.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/absop/RainbowBrackets/HEAD/tests/score.png -------------------------------------------------------------------------------- /images/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/absop/RainbowBrackets/HEAD/images/example.png -------------------------------------------------------------------------------- /tests/call-cc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/absop/RainbowBrackets/HEAD/tests/call-cc.png -------------------------------------------------------------------------------- /images/material-json.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/absop/RainbowBrackets/HEAD/images/material-json.png -------------------------------------------------------------------------------- /images/material-lighter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/absop/RainbowBrackets/HEAD/images/material-lighter.png -------------------------------------------------------------------------------- /images/material-scheme.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/absop/RainbowBrackets/HEAD/images/material-scheme.png -------------------------------------------------------------------------------- /dependencies.json: -------------------------------------------------------------------------------- 1 | { 2 | "*": { 3 | ">=4096": [ 4 | "typing_extensions" 5 | ] 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /messages/4.3.2.txt: -------------------------------------------------------------------------------- 1 | => 4.3.2 2 | 3 | # Features and Fixes 4 | 5 | - Fixed a plugin loading problem caused by the `typing_extensions` module 6 | -------------------------------------------------------------------------------- /messages/4.2.0.txt: -------------------------------------------------------------------------------- 1 | RainbowBrackets 2 | --------------- 3 | 4 | ## Changelog 5 | 6 | 1. Fixed an issue where bracket colors did not update with switching color schemes. 7 | -------------------------------------------------------------------------------- /messages/4.3.0.txt: -------------------------------------------------------------------------------- 1 | => 4.3.0 2 | 3 | # Features and Fixes 4 | 5 | - Supported outward-spreading bracket transformations 6 | - Fixed `ignored_scopes` for Bash 7 | - Various small improvements 8 | -------------------------------------------------------------------------------- /plugin/consts.py: -------------------------------------------------------------------------------- 1 | PACKAGE_NAME = __package__.partition(".")[0] 2 | PACKAGE_URL = "https://github.com/absop/RainbowBrackets" 3 | PACKAGE_VERSION = "5.0.0" 4 | 5 | DEFAULT_CS = "Packages/Color Scheme - Default/Monokai.sublime-color-scheme" 6 | PREFS_FILE = "Preferences.sublime-settings" 7 | SETTINGS_FILE = "RainbowBrackets.sublime-settings" 8 | -------------------------------------------------------------------------------- /messages/4.1.0.txt: -------------------------------------------------------------------------------- 1 | RainbowBrackets 2 | --------------- 3 | 4 | ## Changelog 5 | 6 | 1. More reasonable and user-friendly settings 7 | 8 | Please update your custom settings file, by running the command `pref:rb sts`(Preferences: RainbowBrackets Settings) from the Command Palette and modifying the content in the right view by referring to the content in the left view. 9 | -------------------------------------------------------------------------------- /messages/install.txt: -------------------------------------------------------------------------------- 1 | RainbowBrackets 2 | --------------- 3 | `RainbowBrackets` is a brackets highlighting plugin which color brackets at different level with different colors. 4 | 5 | 6 | ## Read usage 7 | Preferences>Package Settings>RainbowBrackets>README 8 | 9 | ## Custom settings 10 | Preferences>Package Settings>RainbowBrackets>Settings 11 | ctrl+shift+p, PRBSetting... 12 | -------------------------------------------------------------------------------- /boot.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | 4 | def reload_plugin() -> None: 5 | import sys 6 | 7 | # remove all previously loaded plugin modules 8 | prefix = f"{__package__}." 9 | plugin_modules = tuple( 10 | filter(lambda m: m.startswith(prefix) and m != __name__, sys.modules) 11 | ) 12 | for module_name in plugin_modules: 13 | del sys.modules[module_name] 14 | 15 | 16 | reload_plugin() 17 | 18 | from .plugin import * # noqa: F401, F403 19 | -------------------------------------------------------------------------------- /tests/lwp.ss: -------------------------------------------------------------------------------- 1 | (define lwp-list '()) 2 | 3 | (define lwp 4 | (lambda (thunk) 5 | (set! lwp-list (append lwp-list (list thunk))))) 6 | 7 | (define start 8 | (lambda () 9 | (let ([p (car lwp-list)]) 10 | (set! lwp-list (cdr lwp-list)) 11 | (p)))) 12 | 13 | (define pause 14 | (lambda () 15 | (call/cc 16 | (lambda (k) 17 | ; (lwp (lambda () (k #f))) 18 | (lwp k) 19 | (start))))) 20 | 21 | (lwp (lambda () (let f () (display "h") (pause) (f)))) 22 | (lwp (lambda () (let f () (display "e") (pause) (f)))) 23 | (lwp (lambda () (let f () (display "y") (pause) (f)))) 24 | (lwp (lambda () (let f () (display "!") (pause) (f)))) 25 | (lwp (lambda () (let f () (newline) (pause) (f)))) 26 | 27 | (start) 28 | -------------------------------------------------------------------------------- /plugin/logger.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | from .consts import PACKAGE_NAME 4 | 5 | 6 | class Logger(): 7 | debug = False 8 | employer = PACKAGE_NAME 9 | 10 | @classmethod 11 | def print(cls, *args, **kwargs): 12 | if cls.debug: 13 | print(f"{cls.employer}:", *args, **kwargs) 14 | 15 | @classmethod 16 | def pprint(cls, obj): 17 | class setEncoder(json.JSONEncoder): 18 | def default(self, obj): 19 | if isinstance(obj, set): 20 | return sorted(obj) 21 | return json.JSONEncoder.default(self, obj) 22 | 23 | if cls.debug: 24 | print(f"{cls.employer}:", json.dumps(obj, 25 | cls=setEncoder, indent=4, 26 | sort_keys=True, ensure_ascii=False)) 27 | 28 | -------------------------------------------------------------------------------- /tests/score.json: -------------------------------------------------------------------------------- 1 | { 2 | "students": [ 3 | { 4 | "name": "Tom", 5 | "age": 12, 6 | "grade": 6, 7 | "scores": { 8 | "English": 96, 9 | "Math": 92, 10 | "Physics": 93 11 | } 12 | }, 13 | { 14 | "name": "John", 15 | "age": 15, 16 | "grade": 8, 17 | "scores": { 18 | "English": 97, 19 | "Math": 89, 20 | "Physics": 83 21 | } 22 | }, 23 | { 24 | "name": "Julia", 25 | "age": 9, 26 | "grade": 4, 27 | "scores": { 28 | "English": 97, 29 | "Math": 99 30 | } 31 | } 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.pyright] 2 | include = ['./'] 3 | exclude = [ 4 | '**/__pycache__/', 5 | '**/node_modules/', 6 | # git-related 7 | '**/.git/', 8 | '**/br-*/', 9 | '**/branch-*/', 10 | ] 11 | ignore = ['**/.venv', '**/libs'] 12 | stubPath = 'typings' 13 | pythonVersion = '3.8' 14 | 15 | [tool.ruff] 16 | preview = true 17 | line-length = 120 18 | target-version = 'py38' 19 | exclude = [ 20 | "*/libs/*", 21 | ".git", 22 | ".mypy_cache", 23 | ".venv", 24 | ".venv-*", 25 | "branch-*", 26 | "stubs", 27 | "tests/files", 28 | "typings", 29 | "vendor", 30 | "venv", 31 | "venv-*", 32 | ] 33 | 34 | [tool.ruff.lint] 35 | select = [ 36 | "E", 37 | "F", 38 | "W", 39 | "I", 40 | "UP", 41 | "FURB", 42 | # "SIM", 43 | ] 44 | ignore = ["E203"] 45 | 46 | [tool.ruff.lint.per-file-ignores] 47 | "boot.py" = ["E402"] 48 | -------------------------------------------------------------------------------- /plugin/__init__.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import sublime 4 | 5 | from .manager import RainbowBracketsViewManager 6 | from .commands import RbToggleDebugCommand 7 | from .commands import RbClearColorSchemesCommand 8 | from .commands import RbColorCommand 9 | from .commands import RbSweepCommand 10 | from .commands import RbSetupCommand 11 | from .commands import RbCloseCommand 12 | from .commands import RbEditBracketsCommand 13 | 14 | 15 | __all__ = ( 16 | # ST: core 17 | 'plugin_loaded', 18 | 'plugin_unloaded', 19 | # ST: listeners 20 | 'RainbowBracketsViewManager', 21 | # ST: commands 22 | 'RbToggleDebugCommand', 23 | 'RbClearColorSchemesCommand', 24 | 'RbEditBracketsCommand', 25 | 'RbColorCommand', 26 | 'RbSweepCommand', 27 | 'RbSetupCommand', 28 | 'RbCloseCommand', 29 | ) 30 | 31 | 32 | def plugin_loaded(): 33 | sublime.set_timeout_async(RainbowBracketsViewManager.init) 34 | 35 | 36 | def plugin_unloaded(): 37 | RainbowBracketsViewManager.exit() 38 | -------------------------------------------------------------------------------- /Default.sublime-commands: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "caption": "Preferences: RainbowBrackets Settings", 4 | "command": "edit_settings", 5 | "args": { 6 | "base_file": "${packages}/RainbowBrackets/RainbowBrackets.sublime-settings", 7 | "default": "/*\n\tRainbowBrackets user settings in here override the default\n*/\n{\n\t$0\n}\n" 8 | } 9 | }, 10 | { 11 | "caption": "RainbowBrackets: Color", 12 | "command": "rb_color", 13 | }, 14 | { 15 | "caption": "RainbowBrackets: Sweep", 16 | "command": "rb_sweep", 17 | }, 18 | { 19 | "caption": "RainbowBrackets: Setup", 20 | "command": "rb_setup", 21 | }, 22 | { 23 | "caption": "RainbowBrackets: Close", 24 | "command": "rb_close", 25 | }, 26 | { 27 | "caption": "RainbowBrackets: Clear Color Schemes", 28 | "command": "rb_clear_color_schemes", 29 | }, 30 | { 31 | "caption": "RainbowBrackets: Toggle Debug", 32 | "command": "rb_toggle_debug", 33 | } 34 | ] 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 - 2022 absop 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /tests/call-cc.ss: -------------------------------------------------------------------------------- 1 | (printf "~a\n" 2 | (apply + (call/cc 3 | (lambda (continuation) 4 | (continuation '(1 2 3 4 5 6 7)))))) 5 | 6 | ; Emmm continuation <=> 善后 7 | ;=> equal to 8 | (printf "~a\n" 9 | ((lambda (continuation) 10 | (continuation '(1 2 3 4 5 6 7))) 11 | (lambda (ls) (apply + ls)))) 12 | 13 | (printf "~a\n" 14 | (call/cc 15 | (lambda (continuation) 16 | (set! p continuation)))) 17 | 18 | (printf "~a\n" 19 | (call/cc 20 | (lambda (continuation) 21 | (set! p continuation) 22 | p))) 23 | 24 | (printf "~a\n" 25 | (call/cc 26 | (lambda (continuation) 27 | (set! p continuation) 28 | "This is a string"))) 29 | 30 | (printf "~a\n" 31 | (call/cc 32 | (lambda (continuation) 33 | (set! p continuation) 34 | printf))) 35 | (p p) ;=> # 36 | 37 | (printf "~a\n" 38 | (call/cc 39 | (lambda (continuation) 40 | (set! p (lambda (x) (continuation x))) 41 | p))) 42 | ;=> # 43 | ;=> equal to (set! p (lambda (x) (printf "~a\n" x))) 44 | 45 | (p 1) ;=> 1 46 | (p p) ;=> # 47 | -------------------------------------------------------------------------------- /keymap/Default (Linux).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "keys": ["ctrl+alt+9"], 4 | "command": "rb_edit_brackets", 5 | "args": { "operation": "transform", "to": "(" } 6 | }, 7 | { 8 | "keys": ["ctrl+alt+0"], 9 | "command": "rb_edit_brackets", 10 | "args": { "operation": "transform", "to": "(" } 11 | }, 12 | { 13 | "keys": ["ctrl+alt+["], 14 | "command": "rb_edit_brackets", 15 | "args": { "operation": "transform", "to": "[" } 16 | }, 17 | { 18 | "keys": ["ctrl+alt+]"], 19 | "command": "rb_edit_brackets", 20 | "args": { "operation": "transform", "to": "[" } 21 | }, 22 | { 23 | "keys": ["ctrl+alt+shift+["], 24 | "command": "rb_edit_brackets", 25 | "args": { "operation": "transform", "to": "{" } 26 | }, 27 | { 28 | "keys": ["ctrl+alt+shift+]"], 29 | "command": "rb_edit_brackets", 30 | "args": { "operation": "transform", "to": "{" } 31 | }, 32 | { 33 | "keys": ["ctrl+alt+r"], 34 | "command": "rb_edit_brackets", 35 | "args": { "operation": "remove", "select_content": false } 36 | }, 37 | { 38 | "keys": ["ctrl+alt+."], 39 | "command": "rb_edit_brackets", 40 | "args": { "operation": "remove", "select_content": true } 41 | }, 42 | { 43 | "keys": ["ctrl+alt+,"], 44 | "command": "rb_edit_brackets", 45 | "args": { "operation": "select" }, 46 | }, 47 | { 48 | "keys": ["ctrl+alt+shift+,"], 49 | "command": "rb_edit_brackets", 50 | "args": { "operation": "select", "to": "cond|define|lambda|let" }, 51 | } 52 | ] 53 | -------------------------------------------------------------------------------- /keymap/Default (OSX).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "keys": ["ctrl+alt+9"], 4 | "command": "rb_edit_brackets", 5 | "args": { "operation": "transform", "to": "(" } 6 | }, 7 | { 8 | "keys": ["ctrl+alt+0"], 9 | "command": "rb_edit_brackets", 10 | "args": { "operation": "transform", "to": "(" } 11 | }, 12 | { 13 | "keys": ["ctrl+alt+["], 14 | "command": "rb_edit_brackets", 15 | "args": { "operation": "transform", "to": "[" } 16 | }, 17 | { 18 | "keys": ["ctrl+alt+]"], 19 | "command": "rb_edit_brackets", 20 | "args": { "operation": "transform", "to": "[" } 21 | }, 22 | { 23 | "keys": ["ctrl+alt+shift+["], 24 | "command": "rb_edit_brackets", 25 | "args": { "operation": "transform", "to": "{" } 26 | }, 27 | { 28 | "keys": ["ctrl+alt+shift+]"], 29 | "command": "rb_edit_brackets", 30 | "args": { "operation": "transform", "to": "{" } 31 | }, 32 | { 33 | "keys": ["ctrl+alt+r"], 34 | "command": "rb_edit_brackets", 35 | "args": { "operation": "remove", "select_content": false } 36 | }, 37 | { 38 | "keys": ["ctrl+alt+."], 39 | "command": "rb_edit_brackets", 40 | "args": { "operation": "remove", "select_content": true } 41 | }, 42 | { 43 | "keys": ["ctrl+alt+,"], 44 | "command": "rb_edit_brackets", 45 | "args": { "operation": "select" }, 46 | }, 47 | { 48 | "keys": ["ctrl+alt+shift+,"], 49 | "command": "rb_edit_brackets", 50 | "args": { "operation": "select", "to": "cond|define|lambda|let" }, 51 | } 52 | ] 53 | -------------------------------------------------------------------------------- /keymap/Default (Windows).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "keys": ["ctrl+alt+9"], 4 | "command": "rb_edit_brackets", 5 | "args": { "operation": "transform", "to": "(" } 6 | }, 7 | { 8 | "keys": ["ctrl+alt+0"], 9 | "command": "rb_edit_brackets", 10 | "args": { "operation": "transform", "to": "(" } 11 | }, 12 | { 13 | "keys": ["ctrl+alt+["], 14 | "command": "rb_edit_brackets", 15 | "args": { "operation": "transform", "to": "[" } 16 | }, 17 | { 18 | "keys": ["ctrl+alt+]"], 19 | "command": "rb_edit_brackets", 20 | "args": { "operation": "transform", "to": "[" } 21 | }, 22 | { 23 | "keys": ["ctrl+alt+shift+["], 24 | "command": "rb_edit_brackets", 25 | "args": { "operation": "transform", "to": "{" } 26 | }, 27 | { 28 | "keys": ["ctrl+alt+shift+]"], 29 | "command": "rb_edit_brackets", 30 | "args": { "operation": "transform", "to": "{" } 31 | }, 32 | { 33 | "keys": ["ctrl+alt+r"], 34 | "command": "rb_edit_brackets", 35 | "args": { "operation": "remove", "select_content": false } 36 | }, 37 | { 38 | "keys": ["ctrl+alt+."], 39 | "command": "rb_edit_brackets", 40 | "args": { "operation": "remove", "select_content": true } 41 | }, 42 | { 43 | "keys": ["ctrl+alt+,"], 44 | "command": "rb_edit_brackets", 45 | "args": { "operation": "select" }, 46 | }, 47 | { 48 | "keys": ["ctrl+alt+shift+,"], 49 | "command": "rb_edit_brackets", 50 | "args": { "operation": "select", "to": "cond|define|lambda|let" }, 51 | } 52 | ] 53 | -------------------------------------------------------------------------------- /Main.sublime-menu: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "preferences", 4 | "children": [ 5 | { 6 | "caption": "Package Settings", 7 | "id": "package-settings", 8 | "mnemonic": "P", 9 | "children": [ 10 | { 11 | "caption": "RainbowBrackets", 12 | "mnemonic": "R", 13 | "children": [ 14 | { 15 | "caption": "README", 16 | "command": "open_file", 17 | "args": { 18 | "file": "${packages}/RainbowBrackets/README.md" 19 | } 20 | }, 21 | { 22 | "caption": "-" 23 | }, 24 | { 25 | "caption": "Settings", 26 | "command": "edit_settings", 27 | "args": { 28 | "base_file": "${packages}/RainbowBrackets/RainbowBrackets.sublime-settings", 29 | "default": "// RainbowBrackets Preferences – User\n// ====================================================\n\n{\n\t$0\n}\n" 30 | } 31 | }, 32 | { 33 | "caption": "Key Bindings", 34 | "command": "edit_settings", 35 | "mnemonic": "K", 36 | "args": {"base_file": "${packages}/RainbowBrackets/keymap/Default ($platform).sublime-keymap", "default": "[\n\t$0\n]\n"} 37 | } 38 | ] 39 | } 40 | ] 41 | } 42 | ] 43 | } 44 | ] 45 | -------------------------------------------------------------------------------- /RainbowBrackets.sublime-settings: -------------------------------------------------------------------------------- 1 | { 2 | "debug": false, 3 | 4 | "default_config": { 5 | "bracket_pairs": { 6 | "(": ")", 7 | "[": "]", 8 | "{": "}" 9 | }, 10 | 11 | "coloring": false, 12 | 13 | "enabled": true, 14 | 15 | "ignored_scopes": [ 16 | "comment", 17 | "string", 18 | "constant" 19 | ], 20 | 21 | "color.error": "#FF0000", 22 | 23 | "color.cycle": [ 24 | "#FF0000", // level0 25 | "#FF6A00", // level1 26 | "#FFD800", // level2 27 | "#00FF00", // level3 28 | "#0094FF", // level4 29 | "#0041FF", // level5 30 | "#7D00E5" // level6 31 | ], 32 | }, 33 | 34 | "syntax_specific": { 35 | "Bash": { 36 | "coloring": false, 37 | 38 | "ignored_scopes": ["keyword"] 39 | }, 40 | 41 | "JSON": { 42 | "coloring": true, 43 | 44 | "bracket_pairs": { 45 | "{": "}", 46 | "[": "]", 47 | }, 48 | 49 | "extensions": [ 50 | ".json", 51 | ".sublime-settings", 52 | ".sublime-menu", 53 | ".sublime-build", 54 | ".sublime-keymap", 55 | ".sublime-commands", 56 | ".sublime-theme", 57 | ".sublime-color-scheme" 58 | ], 59 | 60 | "ignored_scopes": [ 61 | "comment", "string" 62 | ] 63 | }, 64 | 65 | "Regular Expression": { 66 | "extensions": [ 67 | ".sublime-syntax" 68 | ], 69 | 70 | "ignored_scopes": [ 71 | "string", 72 | "comment", 73 | "constant", 74 | "meta.literal", 75 | "meta.set", 76 | ] 77 | }, 78 | 79 | "Scheme": { 80 | "coloring": true, 81 | 82 | "bracket_pairs": { 83 | "(": ")", 84 | "[": "]", 85 | }, 86 | 87 | "extensions": [ 88 | ".scm", 89 | ".ss" 90 | ], 91 | 92 | "ignored_scopes": [ 93 | "comment", "string", "constant" 94 | ] 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /typings/_sublime_types.pyi: -------------------------------------------------------------------------------- 1 | # This file is maintained on https://github.com/jfcherng-sublime/ST-API-stubs 2 | 3 | from __future__ import annotations 4 | 5 | from typing import Any, Callable, Dict, Iterable, List, Protocol, Sequence, Tuple, TypedDict, TypeVar 6 | 7 | import sublime 8 | 9 | # ----- # 10 | # types # 11 | # ----- # 12 | 13 | T = TypeVar("T") 14 | 15 | AnyCallable = Callable[..., Any] 16 | Callback0 = Callable[[], Any] 17 | Callback1 = Callable[[T], Any] 18 | 19 | T_AnyCallable = TypeVar("T_AnyCallable", bound=AnyCallable) 20 | T_ExpandableVar = TypeVar( 21 | "T_ExpandableVar", 22 | bound=None | bool | int | float | str | Dict[Any, Any] | List[Any] | Tuple[Any, ...], 23 | ) 24 | 25 | Point = int 26 | Dip = float 27 | Str = str # alias in case we have a variable named as "str" 28 | 29 | Completion = str | Sequence[str] | Tuple[str, str] | sublime.CompletionItem 30 | CompletionKind = Tuple[int, str, str] 31 | CompletionNormalized = Tuple[ 32 | str, # trigger 33 | str, # annotation 34 | str, # details 35 | str, # completion 36 | str, # kind_name 37 | int, # icon letter (Unicode code point, decimal form) 38 | int, # completion_format 39 | int, # flags 40 | int, # kind 41 | ] 42 | 43 | Location = Tuple[str, str, Tuple[int, int]] 44 | Vector = Tuple[Dip, Dip] 45 | 46 | 47 | class Layout(TypedDict): 48 | cols: List[float] 49 | rows: List[float] 50 | cells: List[List[int]] 51 | 52 | 53 | class EventDict(TypedDict): 54 | x: float 55 | y: float 56 | modifier_keys: EventModifierKeysDict 57 | 58 | 59 | class EventModifierKeysDict(TypedDict, total=False): 60 | primary: bool 61 | ctrl: bool 62 | alt: bool 63 | altgr: bool 64 | shift: bool 65 | super: bool 66 | 67 | 68 | class ExtractVariablesDict(TypedDict): 69 | file: str 70 | file_base_name: str 71 | file_extension: str 72 | file_name: str 73 | file_path: str 74 | folder: str 75 | packages: str 76 | platform: str 77 | project: str 78 | project_base_name: str 79 | project_extension: str 80 | project_name: str 81 | project_path: str 82 | 83 | 84 | class ScopeStyleDict(TypedDict, total=False): 85 | foreground: str 86 | background: str 87 | bold: bool 88 | italic: bool 89 | glow: bool 90 | underline: bool 91 | stippled_underline: bool 92 | squiggly_underline: bool 93 | source_line: int 94 | source_column: int 95 | source_file: str 96 | 97 | 98 | class CommandArgsDict(TypedDict): 99 | command: str 100 | args: None | Dict[str, Any] 101 | 102 | 103 | class HasKeysMethod(Protocol): 104 | def keys(self) -> Iterable[str]: 105 | ... 106 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RainbowBrackets 2 | 3 | [![License][license-image]](/LICENSE) 4 | [![Downloads][packagecontrol-image]][packagecontrol-link] 5 | 6 | 7 | ## Introduction 8 | 9 | RainbowBrackets uses the brackets and colors that you give in the settings file, searches and highlights brackets in file views. Brackets at different levels will be dyed with different colors according to the settings. Colors are gave in a list, and will be used repeatedly. 10 | 11 | parentheses, braces, brackets are treated as brackets. brackets are configured in setting file, it means you can use `OO` as a opening bracket and `CC` as a close bracket. some characters will cause many match error, can't serve as brackets, such as `<>`. 12 | 13 | 14 | ## Example 15 | ``` 16 | { [ 【 OO OO 《《》OOxCC》 CC CC 】 ] } 17 | ``` 18 | ![](images/example.png) 19 | 20 | 21 | ## Installation 22 | 23 | Clone or download this repository to your **Packages directory** of Sublime Text. Note that the directory name should be the name of this repository. 24 | 25 | If you have installed Package Control, press down ctrl+shift+p to get into the command palette, then, input the command `pcip (Package Control: Install Package)` and Enter to run it. Wait some time… After package infomations have been loaded remotely, input the name of this plugin `RainbowBrackets`, and press down Enter to install it. 26 | 27 | 28 | ## Usage 29 | 30 | ### Settings 31 | 32 | Settings template 33 | 34 | ```json 35 | { 36 | "debug": false, 37 | 38 | "default_config": { 39 | "bracket_pairs": { 40 | "(": ")", 41 | "[": "]", 42 | "{": "}" 43 | }, 44 | 45 | "coloring": false, 46 | 47 | "enabled": true, 48 | 49 | "ignored_scopes": [ 50 | "comment", 51 | "string", 52 | "constant" 53 | ], 54 | 55 | "color.error": "#FF0000", 56 | 57 | "color.cycle": [ 58 | "#FF0000", // level0 59 | "#FF6A00", // level1 60 | "#FFD800", // level2 61 | "#00FF00", // level3 62 | "#0094FF", // level4 63 | "#0041FF", // level5 64 | "#7D00E5" // level6 65 | ], 66 | 67 | }, 68 | 69 | "syntax_specific": { 70 | "Scheme": { 71 | "coloring": true, 72 | 73 | "extensions": [".scm", ".ss"], 74 | 75 | "ignored_scopes": [ 76 | "comment", "string", "constant", "symbol" 77 | ] 78 | }, 79 | 80 | "JSON": { 81 | "coloring": true, 82 | 83 | "bracket_pairs": { 84 | "{": "}", 85 | "[": "]" 86 | }, 87 | 88 | "extensions": [ 89 | ".json", 90 | ".sublime-build", 91 | ".sublime-color-scheme", 92 | ".sublime-commands", 93 | ".sublime-keymap", 94 | ".sublime-menu", 95 | ".sublime-settings", 96 | ".sublime-theme", 97 | ], 98 | 99 | "ignored_scopes": [ 100 | "comment", "string" 101 | ] 102 | } 103 | } 104 | } 105 | ``` 106 | 107 | - `ignored_scopes`: to ignore brackets in some scopes(such as comment, string). 108 | 109 | ### Commands 110 | - Preferences: RainbowBrackets Settings 111 | - RainbowBrackets: Toggle Debug 112 | - RainbowBrackets: Color/Sweep 113 | - RainbowBrackets: Close/Setup 114 | - RainbowBrackets: Clear Color Schemes 115 | 116 | ### Key bindings 117 | RainbowBrackets support fast opreating brackets, including `select`, `remove` and `transform`. 118 | 119 | | Keys | Description | 120 | | :-------------------------- | :----------------------------------------------------------- | 121 | | ctrl+alt+9 | Replace the brackets around the cursors with `()` | 122 | | ctrl+alt+0 | Replace the brackets around the cursors with `()` | 123 | | ctrl+alt+[ | Replace the brackets around the cursors with `[]` | 124 | | ctrl+alt+] | Replace the brackets around the cursors with `[]` | 125 | | ctrl+alt+shift+[ | Replace the brackets around the cursors with `{}` | 126 | | ctrl+alt+shift+] | Replace the brackets around the cursors with `{}` | 127 | | ctrl+alt+r | Remove the brackets around the cursors | 128 | | ctrl+alt+. | Remove the brackets around the cursors and select the text within the brackets | 129 | | ctrl+alt+, | Select the brackets around the cursors and the text within the brackets | 130 | 131 | 132 | ## Screenshots 133 | 134 | - Material color scheme, JSON file. 135 | ![](images/material-json.png) 136 | - Material color scheme, Scheme language 137 | ![](images/material-scheme.png) 138 | - Material lighter color scheme, Scheme language 139 | ![](images/material-lighter.png) 140 | 141 | 142 | [license-image]: https://img.shields.io/badge/license-MIT-blue.svg 143 | [packagecontrol-image]: https://img.shields.io/packagecontrol/dt/RainbowBrackets.svg 144 | [packagecontrol-link]: https://packagecontrol.io/packages/RainbowBrackets 145 | -------------------------------------------------------------------------------- /plugin/color_scheme.py: -------------------------------------------------------------------------------- 1 | import json 2 | import weakref 3 | 4 | from functools import lru_cache 5 | from typing import Dict, List, Optional, Tuple 6 | from pathlib import PurePath, Path 7 | 8 | import sublime 9 | 10 | from .logger import Logger 11 | from .consts import DEFAULT_CS 12 | from .consts import PACKAGE_NAME 13 | from .consts import PACKAGE_URL 14 | 15 | 16 | builtin_color_names = [ 17 | 'redish', 18 | 'orangish', 19 | 'yellowish', 20 | 'greenish', 21 | 'cyanish', 22 | 'bluish', 23 | 'purplish', 24 | 'pinkish' 25 | ] 26 | 27 | 28 | def _nearest_color(color: str): 29 | """ 30 | Assume the input color is well-formed 31 | """ 32 | c = int(color[1:], 16) 33 | r, g, b = (c >> 16) & 0xff, (c >> 8) & 0xff, c & 0xff 34 | r = r + (1 if r < 255 else -1) 35 | return f'#{r:02x}{g:02x}{b:02x}' 36 | 37 | 38 | # scope color pairs 39 | PlainRules = List[Tuple[str, str]] 40 | 41 | 42 | class ColorSchemeManager: 43 | plain_rules: Dict[str, PlainRules] = {} 44 | 45 | view_current_cs: Dict[sublime.View, Optional[str]] = {} 46 | 47 | def __new__(cls, *args, **kwargs): 48 | if hasattr(cls, 'objref'): 49 | if obj := cls.objref(): 50 | return obj 51 | self = object.__new__(cls) 52 | cls.objref = weakref.ref(self) 53 | return self 54 | 55 | def set_colors(self, scope_color_pairs: PlainRules): 56 | index = str(scope_color_pairs) 57 | self.last_written_cs = None 58 | self.plain_rules[index] = scope_color_pairs 59 | self.current_rules_index = index 60 | 61 | for view in self.view_current_cs: 62 | self.rewrite_view_cs(view) 63 | 64 | def attach_view(self, view: sublime.View): 65 | self.view_current_cs[view] = None 66 | def on_change(): 67 | view_new_cs = settings.get('color_scheme', DEFAULT_CS) 68 | if view_new_cs != self.view_current_cs[view]: 69 | self.view_current_cs[view] = view_new_cs 70 | if view_new_cs != self.last_written_cs: 71 | self.rewrite_view_cs(view) 72 | settings = view.settings() 73 | settings.add_on_change('rb.color_scheme_mgr', on_change) 74 | 75 | def detach_view(self, view: sublime.View): 76 | view.settings().clear_on_change('rb.color_scheme_mgr') 77 | self.view_current_cs.pop(view, None) 78 | 79 | def rewrite_view_cs(self, view: sublime.View): 80 | cs = self.view_current_cs[view] 81 | if cs is None: 82 | return 83 | 84 | def update_cs(): 85 | # The color scheme to preview has been updated since 86 | # the timeout was created 87 | if cs != self.view_current_cs[view]: 88 | return 89 | if cs == self.last_written_cs: 90 | return 91 | self.write_view_cs(view, cs) 92 | self.last_written_cs = cs 93 | 94 | sublime.set_timeout(update_cs, 250) 95 | 96 | def write_view_cs(self, view: sublime.View, color_scheme: str) -> None: 97 | """ 98 | We assume that there are no two CS with the same name 99 | and different extensions. Even if they do, they are not 100 | used at the same time. 101 | """ 102 | style = view.style() 103 | cs_text = self.generate_cs_text( 104 | tuple(style[k] for k in builtin_color_names), 105 | style['background'], 106 | self.current_rules_index 107 | ) 108 | cs_path = PurePath(color_scheme) 109 | cache_path = self.cache_path() 110 | cache_path.mkdir(parents=True, exist_ok=True) 111 | cache_path.joinpath( 112 | cs_path.with_suffix('.sublime-color-scheme').name 113 | ).write_text(cs_text) 114 | Logger.print(f'Write color scheme {cs_path.stem}') 115 | 116 | def cache_path(self): 117 | try: 118 | return self._cache_path 119 | except: 120 | self._cache_path = Path( 121 | sublime.packages_path(), 'User', 'Color Schemes', PACKAGE_NAME) 122 | return self._cache_path 123 | 124 | @lru_cache 125 | def generate_cs_text(self, 126 | colors: Tuple[str], bg: str, rules_index: str) -> str: 127 | """ 128 | Generate the color scheme text from the given colors, 129 | background color and rules index, use lru_cache to 130 | cache the results. 131 | """ 132 | rules = [] 133 | variables = {} 134 | nearest_bg = _nearest_color(bg) 135 | color_map = dict(zip(builtin_color_names, colors)) 136 | for scope, color in self.plain_rules[rules_index]: 137 | if scope.endswith('error._rb'): 138 | background = bg 139 | else: 140 | background = nearest_bg 141 | if color in color_map: 142 | variables[f'region-{color}'] = color_map[color] 143 | foreground = f'var(region-{color})' 144 | else: 145 | foreground = color 146 | rules.append({ 147 | "scope": scope, 148 | "foreground": foreground, 149 | "background": background 150 | }) 151 | 152 | return json.dumps( 153 | { 154 | "author": PACKAGE_URL, 155 | "variables": variables, 156 | "rules": rules 157 | } 158 | ) 159 | 160 | def get_all_inuse_color_schemes(self): 161 | color_scheme_set = set() 162 | for window in sublime.windows(): 163 | for view in window.views(include_transient=True): 164 | color_scheme = view.settings().get('color_scheme') 165 | color_scheme_set.add(PurePath(color_scheme).stem) 166 | return color_scheme_set 167 | 168 | def clear_color_schemes(self): 169 | cache_path = self.cache_path() 170 | inuse_color_schemes = self.get_all_inuse_color_schemes() 171 | for file in cache_path.iterdir(): 172 | if file.stem not in inuse_color_schemes: 173 | try: 174 | file.unlink() 175 | Logger.print('Removed', file.name) 176 | except: 177 | pass 178 | 179 | 180 | cs_mgr = ColorSchemeManager() 181 | -------------------------------------------------------------------------------- /plugin/executor.py: -------------------------------------------------------------------------------- 1 | import re 2 | import os 3 | import time 4 | import sublime 5 | 6 | from typing import Callable, Dict, List, Optional, TypedDict 7 | from typing_extensions import Self 8 | 9 | from .logger import Logger 10 | 11 | 12 | class BracketTree: 13 | __slots__ = ['opening', 'closing', 'contain'] 14 | 15 | def __init__( 16 | self, 17 | opening: sublime.Region, 18 | closing: sublime.Region, 19 | contain: List[Self] 20 | ): 21 | self.opening = opening 22 | self.closing = closing 23 | self.contain = contain 24 | 25 | 26 | class RainbowBracketsExecutor(): 27 | def __init__(self, view: sublime.View, syntax: Optional[str], config): 28 | self.err_key = config['err_key'] # type: str 29 | self.err_scope = config['err_scope'] # type: str 30 | self.coloring = config['coloring'] # type: bool 31 | self.keys = config['keys'] # type: List[str] 32 | self.scopes = config['scopes'] # type: List[str] 33 | self.selector = config['selector'] # type: str 34 | self.brackets = config['bracket_pairs'] # type: Dict[str, str] 35 | self.pattern = config['pattern'] # type: str 36 | self.color_number = len(self.keys) 37 | self.err_bracket_regions: List[sublime.Region] = [] 38 | self.bracket_regions_lists: List[List[sublime.Region]] = [] 39 | self.bracket_regions_trees: List[BracketTree] = [] 40 | self.regexp = re.compile(self.pattern) 41 | self.syntax = syntax 42 | self.config = config 43 | self.view = view 44 | 45 | def __del__(self): 46 | self.clear_bracket_regions() 47 | Logger.print(f'Exited from {self.view_file_name()}') 48 | 49 | def view_file_name(self): 50 | return os.path.basename(self.view.file_name() or 'untitled') 51 | 52 | def load(self): 53 | start = time.time() 54 | self.check_bracket_regions() 55 | end = time.time() 56 | if Logger.debug: 57 | Logger.print( 58 | '\n\t'.join([ 59 | f'Loaded on {self.view_file_name()}', 60 | f'pattern: {self.pattern}', 61 | f'selector: {self.selector}', 62 | f'syntax: {self.syntax}', 63 | f'coloring: {self.coloring}', 64 | f'cost time: {end - start:>.2f}' 65 | ]) 66 | ) 67 | 68 | # TODO: Update the bracket trees dynamically rather 69 | # than reconstruct them from beginning every time. 70 | def check_bracket_regions(self): 71 | if self.coloring: 72 | self.construct_bracket_trees_and_lists() 73 | self.clear_bracket_regions() 74 | if self.bracket_regions_lists: 75 | for level, regions in enumerate(self.bracket_regions_lists): 76 | self.view.add_regions( 77 | self.keys[level], 78 | regions, 79 | scope=self.scopes[level], 80 | flags=sublime.DRAW_NO_OUTLINE|sublime.PERSISTENT 81 | ) 82 | if self.err_bracket_regions: 83 | self.view.add_regions( 84 | self.err_key, 85 | self.err_bracket_regions, 86 | scope=self.err_scope, 87 | flags=sublime.DRAW_EMPTY|sublime.PERSISTENT 88 | ) 89 | else: 90 | self.construct_bracket_trees() 91 | 92 | def clear_bracket_regions(self): 93 | self.view.erase_regions(self.err_key) 94 | for key in self.keys: 95 | self.view.erase_regions(key) 96 | 97 | def construct_bracket_trees(self): 98 | self.bracket_regions_trees = [] 99 | 100 | opening_stack = [] 101 | tree_node_stack = [BracketTree(None, None, self.bracket_regions_trees)] 102 | 103 | def handle_bracket_region( 104 | bracket, region, 105 | Node=BracketTree, 106 | brackets=self.brackets, 107 | opening_stack=opening_stack, 108 | opening_stack_append=opening_stack.append, 109 | opening_stack_pop=opening_stack.pop, 110 | tree_node_stack=tree_node_stack, 111 | tree_node_stack_append=tree_node_stack.append, 112 | tree_node_stack_pop=tree_node_stack.pop 113 | ): 114 | if bracket in brackets: 115 | tree_node_stack_append(Node(region, None, [])) 116 | opening_stack_append(bracket) 117 | 118 | elif opening_stack and bracket == brackets[opening_stack[-1]]: 119 | opening_stack_pop() 120 | node = tree_node_stack_pop() 121 | node.closing = region 122 | tree_node_stack[-1].contain.append(node) 123 | 124 | self._iterate_brackets(handle_bracket_region) 125 | 126 | def construct_bracket_trees_and_lists(self): 127 | self.err_bracket_regions = [] 128 | self.bracket_regions_lists = [] 129 | self.bracket_regions_trees = [] 130 | 131 | opening_stack = [] 132 | tree_node_stack = [BracketTree(None, None, self.bracket_regions_trees)] 133 | regions_by_layer = [list() for _ in range(self.color_number)] 134 | 135 | def handle_bracket_region( 136 | bracket, region, 137 | Node=BracketTree, 138 | brackets=self.brackets, 139 | num_layers=self.color_number, 140 | opening_stack=opening_stack, 141 | opening_stack_append=opening_stack.append, 142 | opening_stack_pop=opening_stack.pop, 143 | tree_node_stack=tree_node_stack, 144 | tree_node_stack_append=tree_node_stack.append, 145 | tree_node_stack_pop=tree_node_stack.pop, 146 | appends=[rs.append for rs in regions_by_layer] 147 | ): 148 | if bracket in brackets: 149 | tree_node_stack_append(Node(region, None, [])) 150 | opening_stack_append(bracket) 151 | 152 | elif opening_stack and bracket == brackets[opening_stack[-1]]: 153 | opening_stack_pop() 154 | node = tree_node_stack_pop() 155 | node.closing = region 156 | tree_node_stack[-1].contain.append(node) 157 | layer = len(opening_stack) % num_layers 158 | appends[layer](node.opening) 159 | appends[layer](node.closing) 160 | else: 161 | self.err_bracket_regions.append(region) 162 | 163 | self._iterate_brackets(handle_bracket_region) 164 | self.bracket_regions_lists = [ls for ls in regions_by_layer if ls] 165 | 166 | def _iterate_brackets( 167 | self, 168 | handle: Callable[[str, sublime.Region], None], 169 | Region=sublime.Region 170 | ): 171 | full_text = self.view.substr(Region(0, self.view.size())) 172 | matches = self.regexp.finditer(full_text) 173 | ignore = self.view.match_selector 174 | ignored_scope_selector = self.selector 175 | if ignored_scope_selector: 176 | for m in matches: 177 | if ignore(m.span()[0], ignored_scope_selector): 178 | continue 179 | handle(m.group(), Region(*m.span())) 180 | else: 181 | for m in matches: 182 | handle(m.group(), Region(*m.span())) 183 | -------------------------------------------------------------------------------- /plugin/commands.py: -------------------------------------------------------------------------------- 1 | import re 2 | import time 3 | import sublime 4 | import sublime_plugin 5 | 6 | from typing import Iterable, List, Optional, Pattern, Tuple 7 | 8 | from .consts import SETTINGS_FILE 9 | from .logger import Logger 10 | from .manager import RainbowBracketsViewManager as _manager 11 | from .executor import BracketTree 12 | from .color_scheme import cs_mgr 13 | 14 | 15 | class RbToggleDebugCommand(sublime_plugin.ApplicationCommand): 16 | def run(self): 17 | Logger.debug = not Logger.debug 18 | sublime.load_settings(SETTINGS_FILE).set('debug', Logger.debug) 19 | sublime.save_settings(SETTINGS_FILE) 20 | 21 | 22 | class RbClearColorSchemesCommand(sublime_plugin.ApplicationCommand): 23 | def run(self): 24 | cs_mgr.clear_color_schemes() 25 | 26 | 27 | class RbViewCommand(sublime_plugin.TextCommand): 28 | def get_executor(self): 29 | return _manager.get_view_executor(self.view) 30 | 31 | def is_coloring(self): 32 | executor = self.get_executor() 33 | return bool(executor and executor.coloring) 34 | 35 | 36 | class RbColorCommand(RbViewCommand): 37 | def run(self, edit): 38 | _manager.color_view(self.view) 39 | 40 | def is_enabled(self): 41 | return not self.is_coloring() 42 | 43 | 44 | class RbSweepCommand(RbViewCommand): 45 | def run(self, edit): 46 | _manager.sweep_view(self.view) 47 | 48 | def is_enabled(self): 49 | return self.is_coloring() 50 | 51 | 52 | class RbSetupCommand(RbViewCommand): 53 | def run(self, edit): 54 | _manager.setup_view_executor(self.view) 55 | 56 | def is_enabled(self): 57 | return self.get_executor() is None 58 | 59 | 60 | class RbCloseCommand(RbViewCommand): 61 | def run(self, edit): 62 | _manager.close_view_executor(self.view) 63 | self.view.settings().set('rb_enable', False) 64 | 65 | def is_enabled(self): 66 | return self.get_executor() is not None 67 | 68 | 69 | class RbEditBracketsCommand(sublime_plugin.TextCommand): 70 | def __init__(self, view): 71 | self.view = view 72 | self.timestamp = 0 73 | self.operators = { 74 | 'select': self.select, 75 | 'remove': self.remove, 76 | 'transform': self.transform, 77 | } 78 | 79 | def run(self, edit, operation='', **args): 80 | trees = _manager.get_view_bracket_trees(self.view) 81 | if trees: 82 | self.operators[operation](edit, trees, **args) 83 | 84 | def remove(self, edit, bracket_trees, select_content): 85 | pairs = [p for p in self._find_cursor_brackets(bracket_trees)] 86 | regions = [r for p in pairs for r in p] 87 | regions.sort() 88 | for r in reversed(regions): 89 | self.view.erase(edit, r) 90 | if select_content: 91 | selections = [] 92 | _Region = sublime.Region 93 | for p in pairs: 94 | begin = p[0].a - regions.index(p[0]) 95 | end = p[1].a - regions.index(p[1]) 96 | selections.append(_Region(begin, end)) 97 | self.view.sel().add_all(selections) 98 | 99 | def select(self, edit, bracket_trees, to=''): 100 | regex = to and re.compile(to + r'\b') or None 101 | for p in self._find_cursor_brackets(bracket_trees, regex=regex): 102 | region = self._cover(p) 103 | self.view.sel().add(region) 104 | 105 | def transform(self, edit, bracket_trees, to): 106 | left = to 107 | brackets = _manager.get_view_bracket_pairs(self.view) 108 | if not brackets or brackets.get(left) is None: 109 | return 110 | timestamp = time.time() 111 | look_farther = False 112 | if timestamp - self.timestamp < 1 and left == self.last_tobe: 113 | # Look further away when the keyboard is repeatedly pressed 114 | look_farther = True 115 | self.timestamp = timestamp 116 | self.last_tobe = left 117 | right = brackets[left] 118 | 119 | points = self.view.sel() 120 | while True: 121 | replacements = [] 122 | outer_points = [] 123 | found = False 124 | for p in self._find_cursor_brackets(bracket_trees, cursors=points): 125 | outer_points.append(p[0]) 126 | if self.view.substr(p[0]) == left: 127 | continue 128 | replacements.append((p[0], left)) 129 | replacements.append((p[1], right)) 130 | found = True 131 | if not look_farther or found: 132 | break 133 | if not outer_points or outer_points == points: 134 | break 135 | points = outer_points 136 | 137 | replacements.sort(key=lambda i:i[0], reverse=True) 138 | for region, content in replacements: 139 | self.view.replace(edit, region, content) 140 | 141 | def _cover(self, bracket_pair, _Region=sublime.Region): 142 | return _Region(bracket_pair[0].a, bracket_pair[1].b) 143 | 144 | def _find_cursor_brackets( 145 | self, 146 | trees: List[BracketTree], 147 | cursors: Optional[Iterable[sublime.Region]] = None, 148 | regex: Optional[Pattern[str]] = None 149 | ): 150 | last_bracket = None 151 | if cursors is None: 152 | cursors = self.view.sel() 153 | for region in cursors: 154 | bracket = self._find_nearest(trees, region, regex) 155 | if bracket is None or bracket == last_bracket: 156 | continue 157 | else: 158 | last_bracket = bracket 159 | yield bracket 160 | 161 | def _find_nearest( 162 | self, 163 | trees: List[BracketTree], 164 | region: sublime.Region, 165 | regex: Optional[Pattern[str]], 166 | _Region=sublime.Region 167 | ): 168 | pairs = self._binary_path_search(trees, region.begin(), region.end()) 169 | bracket = None 170 | if pairs and regex is not None: 171 | for p in reversed(pairs): 172 | point = p[0].end() 173 | text = self.view.substr(_Region(point, point + 31)) 174 | if regex.match(text) is not None: 175 | bracket = p 176 | break 177 | else: 178 | bracket = pairs[0] 179 | elif pairs: 180 | bracket = pairs[-1] 181 | 182 | if bracket is None and region.empty(): 183 | for tree in trees: 184 | if (tree.opening.a == region.a or 185 | tree.closing.b == region.a): 186 | bracket = (tree.opening, tree.closing) 187 | break 188 | return bracket 189 | 190 | def _binary_path_search( 191 | self, 192 | trees: List[BracketTree], 193 | r_begin: int, 194 | r_end: int 195 | ): 196 | bracket_path: List[Tuple[sublime.Region, sublime.Region]] = [] 197 | while True: 198 | found_closer = False 199 | lo, hi = 0, len(trees) - 1 200 | while lo <= hi: 201 | mi = (lo + hi) >> 1 202 | tr = trees[mi] 203 | oa = tr.opening.a 204 | cb = tr.closing.b 205 | if cb < r_begin: 206 | lo = mi + 1 207 | elif oa > r_end: 208 | hi = mi - 1 209 | else: 210 | if (oa < r_begin and r_end < cb or 211 | r_begin == r_end and (r_end == oa or r_begin == cb)): 212 | found_closer = True 213 | trees = tr.contain 214 | p = (tr.opening, tr.closing) 215 | bracket_path.append(p) 216 | break 217 | if not found_closer: 218 | break 219 | return bracket_path 220 | -------------------------------------------------------------------------------- /plugin/manager.py: -------------------------------------------------------------------------------- 1 | import re 2 | import os 3 | import sublime 4 | import sublime_plugin 5 | 6 | from collections import ChainMap 7 | from typing import Any, Dict, Mapping, Optional, Tuple 8 | 9 | from .color_scheme import cs_mgr 10 | from .consts import PACKAGE_NAME 11 | from .consts import SETTINGS_FILE 12 | from .logger import Logger 13 | from .executor import RainbowBracketsExecutor 14 | 15 | 16 | def show_error_message(msg: str): 17 | sublime.error_message(f'{PACKAGE_NAME}: {msg}') 18 | 19 | 20 | def compile_config( 21 | config: Dict[str, Any], 22 | syntax: Optional[str], 23 | is_default: bool, 24 | scope_color_map: Dict[str, str] 25 | ): 26 | color_cycle = config.get('color.cycle', []) 27 | color_error = config.get('color.error') 28 | if color_cycle: 29 | scopes = config['scopes'] = [] 30 | keys = config['keys'] = [] 31 | for i, color in enumerate(color_cycle): 32 | if is_default: 33 | key = f'_rb_l{i}' 34 | scope = f'l{i}._rb' 35 | else: 36 | key = f'_rb_l{i}_{syntax}' 37 | scope = f'{syntax}.l{i}._rb' 38 | keys.append(key) 39 | scopes.append(scope) 40 | scope_color_map[scope] = color 41 | config['keys'] = keys 42 | config['scopes'] = scopes 43 | if color_error is not None: 44 | if is_default: 45 | key = f'_rb_error' 46 | scope = f'error._rb' 47 | else: 48 | key = f'_rb_error_{syntax}' 49 | scope = f'{syntax}.error._rb' 50 | config['err_key'] = key 51 | config['err_scope'] = scope 52 | scope_color_map[scope] = color_error 53 | if 'bracket_pairs' in config: 54 | pairs = config['bracket_pairs'] 55 | brackets = sorted(list(pairs.keys()) + list(pairs.values())) 56 | config['pattern'] = '|'.join(re.escape(b) for b in brackets) 57 | if 'ignored_scopes' in config: 58 | config['selector'] = '|'.join(config['ignored_scopes']) 59 | 60 | 61 | class RainbowBracketsViewManager(sublime_plugin.EventListener): 62 | default_config = {} 63 | configs_by_stx = {} 64 | syntaxes_by_ext: Dict[str, str] = {} 65 | view_executors: Dict[int, RainbowBracketsExecutor] = {} 66 | is_ready = False 67 | 68 | @classmethod 69 | def init(cls): 70 | cls.settings = sublime.load_settings(SETTINGS_FILE) 71 | cls.settings.add_on_change(PACKAGE_NAME, cls.reload) 72 | cls.load_config() 73 | cls.check_load_active_view() 74 | 75 | @classmethod 76 | def exit(cls): 77 | cls.settings.clear_on_change(PACKAGE_NAME) 78 | 79 | @classmethod 80 | def reload(cls): 81 | cls.load_config() 82 | cls.check_load_active_view() 83 | cls.reload_view_executors() 84 | 85 | @classmethod 86 | def load_config(cls): 87 | cls.is_ready = False 88 | 89 | default_config = cls.settings.get('default_config', {}) 90 | configs_by_stx = cls.settings.get('syntax_specific', {}) 91 | syntaxes_by_ext = {} 92 | scope_color_map = {} 93 | 94 | default_config.setdefault('coloring', False) 95 | default_config.setdefault('enabled', True) 96 | 97 | compile_config(default_config, None, True, scope_color_map) 98 | for syntax, config in configs_by_stx.items(): 99 | compile_config(config, syntax, False, scope_color_map) 100 | 101 | for syntax, config in configs_by_stx.items(): 102 | for ext in config.get('extensions', []): 103 | syntaxes_by_ext[ext] = syntax 104 | 105 | Logger.debug = cls.settings.get('debug', False) 106 | Logger.pprint(configs_by_stx) 107 | 108 | cs_mgr.set_colors(list(scope_color_map.items())) 109 | 110 | cls.syntaxes_by_ext = syntaxes_by_ext 111 | cls.configs_by_stx = configs_by_stx 112 | cls.default_config = default_config 113 | cls.is_ready = True 114 | 115 | @classmethod 116 | def reload_view_executors(cls): 117 | disabled_views = [] 118 | for view_id in cls.view_executors: 119 | executor = cls.view_executors[view_id] 120 | view = executor.view 121 | syntax, config = cls.get_syntax_config(view) 122 | if not config['enabled']: 123 | disabled_views.append(view) 124 | continue 125 | if (syntax == executor.syntax and 126 | config == executor.config): 127 | continue 128 | Logger.print(f'Reloading {executor.view_file_name()}') 129 | executor.clear_bracket_regions() 130 | executor.__init__(view, syntax, config) 131 | executor.load() 132 | for view in disabled_views: 133 | cls.close_view_executor(view) 134 | 135 | @classmethod 136 | def check_view_add_executor(cls, view: sublime.View, force=False): 137 | if not cls.is_ready: 138 | if force: 139 | show_error_message('error in loading settings') 140 | return 141 | 142 | if view.view_id in cls.view_executors: 143 | return cls.view_executors[view.view_id] 144 | 145 | if view.settings().get('rb_enable', True): 146 | syntax, config = cls.get_syntax_config(view) 147 | if config['enabled'] or force: 148 | if config['bracket_pairs']: 149 | executor = RainbowBracketsExecutor(view, syntax, config) 150 | cs_mgr.attach_view(view) 151 | cls.view_executors[view.view_id] = executor 152 | return executor 153 | elif force: 154 | show_error_message('empty brackets list') 155 | return None 156 | 157 | @classmethod 158 | def get_syntax_config( 159 | cls, view: sublime.View 160 | ) -> Tuple[Optional[str], Mapping[str, Any]]: 161 | config = None 162 | syntax = view.syntax() 163 | if syntax: 164 | syntax = syntax.name 165 | if syntax in cls.configs_by_stx: 166 | config = cls.configs_by_stx[syntax] 167 | else: 168 | filename = view.file_name() 169 | if filename: 170 | ext = os.path.splitext(filename)[1] 171 | stx = cls.syntaxes_by_ext.get(ext, None) 172 | if stx in cls.configs_by_stx: 173 | config = cls.configs_by_stx[stx] 174 | syntax = stx 175 | if config is not None: 176 | return syntax, ChainMap(config, cls.default_config) 177 | else: 178 | return syntax, cls.default_config 179 | 180 | @classmethod 181 | def force_add_executor(cls, view: sublime.View): 182 | view.settings().set('rb_enable', True) 183 | return cls.check_view_add_executor(view, force=True) 184 | 185 | @classmethod 186 | def get_view_executor(cls, view: sublime.View): 187 | return cls.view_executors.get(view.view_id, None) 188 | 189 | @classmethod 190 | def check_load_active_view(cls): 191 | active_view = sublime.active_window().active_view() 192 | if active_view: 193 | cls.check_view_load_executor(active_view) 194 | 195 | @classmethod 196 | def check_view_load_executor(cls, view: sublime.View): 197 | executor = view.size() and cls.check_view_add_executor(view) 198 | if executor and not executor.bracket_regions_trees: 199 | executor.load() 200 | 201 | @classmethod 202 | def setup_view_executor(cls, view: sublime.View): 203 | executor = cls.force_add_executor(view) 204 | executor and executor.load() # type: ignore 205 | 206 | @classmethod 207 | def close_view_executor(cls, view: sublime.View): 208 | executor = cls.view_executors.pop(view.view_id, None) 209 | if executor and executor.coloring: 210 | executor.clear_bracket_regions() 211 | 212 | @classmethod 213 | def color_view(cls, view: sublime.View): 214 | executor = cls.get_view_executor(view) 215 | if executor and not executor.coloring: 216 | executor.coloring = True 217 | executor.check_bracket_regions() 218 | elif not executor: 219 | executor = cls.force_add_executor(view) 220 | if executor: 221 | executor.coloring = True 222 | executor.load() 223 | 224 | @classmethod 225 | def sweep_view(cls, view: sublime.View): 226 | executor = cls.get_view_executor(view) 227 | if executor and executor.coloring: 228 | executor.coloring = False 229 | executor.clear_bracket_regions() 230 | 231 | @classmethod 232 | def get_view_bracket_pairs(cls, view: sublime.View): 233 | executor = cls.get_view_executor(view) 234 | return executor and executor.brackets 235 | 236 | @classmethod 237 | def get_view_bracket_trees(cls, view: sublime.View): 238 | executor = cls.get_view_executor(view) 239 | if not executor: 240 | cls.setup_view_executor(view) 241 | executor = cls.get_view_executor(view) 242 | return executor and executor.bracket_regions_trees 243 | 244 | def on_load(self, view: sublime.View): 245 | self.check_view_load_executor(view) 246 | 247 | def on_post_save(self, view: sublime.View): 248 | self.check_view_load_executor(view) 249 | 250 | def on_activated(self, view: sublime.View): 251 | self.check_view_load_executor(view) 252 | 253 | def on_modified(self, view: sublime.View): 254 | executor = self.view_executors.get(view.view_id, None) 255 | executor and executor.check_bracket_regions() # type: ignore 256 | 257 | def on_close(self, view: sublime.View): 258 | self.view_executors.pop(view.view_id, None) 259 | cs_mgr.detach_view(view) 260 | -------------------------------------------------------------------------------- /typings/sublime_plugin.pyi: -------------------------------------------------------------------------------- 1 | # This file is maintained on https://github.com/jfcherng-sublime/ST-API-stubs 2 | # ST version: 4136 3 | 4 | from __future__ import annotations 5 | 6 | import importlib.abc 7 | import io 8 | import os 9 | import threading 10 | from importlib.machinery import ModuleSpec 11 | from types import ModuleType 12 | from typing import ( 13 | Any, 14 | Callable, 15 | Dict, 16 | Generator, 17 | Generic, 18 | Iterable, 19 | Iterator, 20 | List, 21 | Sequence, 22 | Set, 23 | Tuple, 24 | Type, 25 | TypeVar, 26 | overload, 27 | ) 28 | 29 | import sublime 30 | from _sublime_types import AnyCallable, Completion, CompletionNormalized, EventDict, Point, T_AnyCallable 31 | 32 | # ----- # 33 | # types # 34 | # ----- # 35 | 36 | InputType = None | str | int | float | Dict[str, Any] | List[Any] | Tuple[Any, ...] 37 | T_InputType = TypeVar("T_InputType", bound=InputType) 38 | 39 | # -------- # 40 | # ST codes # 41 | # -------- # 42 | 43 | api_ready: bool = False 44 | 45 | deferred_plugin_loadeds: List[Callable[[], None]] = [] 46 | 47 | application_command_classes: List[Type] = [] 48 | window_command_classes: List[Type] = [] 49 | text_command_classes: List[Type] = [] 50 | 51 | view_event_listener_classes: List[Type] = [] 52 | view_event_listeners: Dict[int, List[ViewEventListener]] = {} 53 | 54 | all_command_classes: List[List[Type]] = [application_command_classes, window_command_classes, text_command_classes] 55 | 56 | all_callbacks: Dict[str, List[object]] = { 57 | "on_init": [], 58 | "on_new": [], 59 | "on_clone": [], 60 | "on_load": [], 61 | "on_revert": [], 62 | "on_reload": [], 63 | "on_pre_close": [], 64 | "on_close": [], 65 | "on_pre_save": [], 66 | "on_post_save": [], 67 | "on_pre_move": [], 68 | "on_post_move": [], 69 | "on_modified": [], 70 | "on_selection_modified": [], 71 | "on_activated": [], 72 | "on_deactivated": [], 73 | "on_query_context": [], 74 | "on_query_completions": [], 75 | "on_hover": [], 76 | "on_text_command": [], 77 | "on_window_command": [], 78 | "on_post_text_command": [], 79 | "on_post_window_command": [], 80 | "on_modified_async": [], 81 | "on_selection_modified_async": [], 82 | "on_pre_save_async": [], 83 | "on_post_save_async": [], 84 | "on_post_move_async": [], 85 | "on_activated_async": [], 86 | "on_deactivated_async": [], 87 | "on_new_async": [], 88 | "on_load_async": [], 89 | "on_revert_async": [], 90 | "on_reload_async": [], 91 | "on_clone_async": [], 92 | "on_new_buffer": [], 93 | "on_new_buffer_async": [], 94 | "on_close_buffer": [], 95 | "on_close_buffer_async": [], 96 | "on_new_project": [], 97 | "on_new_project_async": [], 98 | "on_load_project": [], 99 | "on_load_project_async": [], 100 | "on_pre_save_project": [], 101 | "on_post_save_project": [], 102 | "on_post_save_project_async": [], 103 | "on_pre_close_project": [], 104 | "on_new_window": [], 105 | "on_new_window_async": [], 106 | "on_pre_close_window": [], 107 | "on_exit": [], 108 | } 109 | 110 | pending_on_activated_async_lock: threading.Lock = threading.Lock() 111 | 112 | pending_on_activated_async_callbacks: Dict[str, List[Type]] = {"EventListener": [], "ViewEventListener": []} 113 | 114 | view_event_listener_excluded_callbacks: Set[str] = { 115 | "on_clone", 116 | "on_clone_async", 117 | "on_exit", 118 | "on_init", 119 | "on_load_project", 120 | "on_load_project_async", 121 | "on_new", 122 | "on_new_async", 123 | "on_new_buffer", 124 | "on_new_buffer_async", 125 | "on_associate_buffer", 126 | "on_associate_buffer_async", 127 | "on_close_buffer", 128 | "on_close_buffer_async", 129 | "on_new_project", 130 | "on_new_project_async", 131 | "on_new_window", 132 | "on_new_window_async", 133 | "on_post_save_project", 134 | "on_post_save_project_async", 135 | "on_post_window_command", 136 | "on_pre_close_project", 137 | "on_pre_close_window", 138 | "on_pre_save_project", 139 | "on_window_command", 140 | } 141 | 142 | text_change_listener_classes: List[Type] = [] 143 | text_change_listener_callbacks: Set[str] = { 144 | "on_text_changed", 145 | "on_text_changed_async", 146 | "on_revert", 147 | "on_revert_async", 148 | "on_reload", 149 | "on_reload_async", 150 | } 151 | text_change_listeners: Dict[int, List[TextChangeListener]] = {} 152 | 153 | profile: Dict[str, Dict[str, Any]] = {} 154 | 155 | 156 | def add_profiling(event_handler: T_AnyCallable) -> T_AnyCallable: 157 | """ 158 | Decorator to measure blocking event handler methods. Also prevents 159 | exceptions from interrupting other events handlers. 160 | 161 | :param event_handler: 162 | The event handler method - must be an unbound method 163 | 164 | :return: 165 | The decorated method 166 | """ 167 | ... 168 | 169 | 170 | def trap_exceptions(event_handler: T_AnyCallable) -> T_AnyCallable: 171 | """ 172 | Decorator to prevent exceptions from interrupting other events handlers. 173 | 174 | :param event_handler: 175 | The event handler method - must be an unbound method 176 | 177 | :return: 178 | The decorated method 179 | """ 180 | ... 181 | 182 | 183 | def decorate_handler(cls: Type, method_name: str) -> None: 184 | """ 185 | Decorates an event handler method with exception trapping, and in the case 186 | of blocking calls, profiling. 187 | 188 | :param cls: 189 | The class object to decorate 190 | 191 | :param method_name: 192 | A unicode string of the name of the method to decorate 193 | """ 194 | ... 195 | 196 | 197 | def unload_module(module: ModuleType) -> None: 198 | ... 199 | 200 | 201 | def unload_plugin(modulename: str) -> None: 202 | ... 203 | 204 | 205 | def reload_plugin(modulename: str) -> None: 206 | ... 207 | 208 | 209 | def load_module(m: ModuleType) -> None: 210 | ... 211 | 212 | 213 | def synthesize_on_activated_async() -> None: 214 | ... 215 | 216 | 217 | def _instantiation_error(cls: Type, e: Exception) -> None: 218 | ... 219 | 220 | 221 | def notify_application_commands() -> None: 222 | ... 223 | 224 | 225 | def create_application_commands() -> List[Tuple[ApplicationCommand, str]]: 226 | ... 227 | 228 | 229 | def create_window_commands(window_id: int) -> List[Tuple[WindowCommand, str]]: 230 | ... 231 | 232 | 233 | def create_text_commands(view_id: int) -> List[Tuple[TextCommand, str]]: 234 | ... 235 | 236 | 237 | def on_api_ready() -> None: 238 | ... 239 | 240 | 241 | def is_view_event_listener_applicable(cls: Type[ViewEventListener], view: sublime.View) -> bool: 242 | ... 243 | 244 | 245 | def create_view_event_listeners(classes: Iterable[Type[ViewEventListener]], view: sublime.View) -> None: 246 | ... 247 | 248 | 249 | def check_view_event_listeners(view: sublime.View) -> None: 250 | ... 251 | 252 | 253 | def attach_view(view: sublime.View) -> None: 254 | ... 255 | 256 | 257 | check_all_view_event_listeners_scheduled: bool = False 258 | 259 | 260 | def check_all_view_event_listeners() -> None: 261 | ... 262 | 263 | 264 | def detach_view(view: sublime.View) -> None: 265 | ... 266 | 267 | 268 | def find_view_event_listener(view: sublime.View, cls: Type) -> None | ViewEventListener: 269 | """Find the view event listener object, whose class is `cls`, for the `view`.""" 270 | ... 271 | 272 | 273 | def attach_buffer(buf: sublime.Buffer) -> None: 274 | ... 275 | 276 | 277 | def check_text_change_listeners(buf: sublime.Buffer) -> None: 278 | ... 279 | 280 | 281 | def detach_buffer(buf: sublime.Buffer) -> None: 282 | ... 283 | 284 | 285 | def plugin_module_for_obj(obj: object) -> str: 286 | ... 287 | 288 | 289 | def el_callbacks(name: str, listener_only: bool = False) -> Generator[Type | str, None, None]: 290 | ... 291 | 292 | 293 | def vel_callbacks(v: sublime.View, name: str, listener_only: bool = False) -> Generator[Type | str, None, None]: 294 | ... 295 | 296 | 297 | def run_view_callbacks( 298 | name: str, 299 | view_id: int, 300 | *args: Any, 301 | el_only: bool = False, 302 | ) -> None: 303 | ... 304 | 305 | 306 | def run_window_callbacks(name: str, window_id: int, *args: Any) -> None: 307 | ... 308 | 309 | 310 | def on_init(module: str) -> None: 311 | """ 312 | Trigger the on_init() methods on EventListener and ViewEventListener 313 | objects. This is method that allows event listeners to run something 314 | once per view, even if the view is done loading before the listener 315 | starts listening. 316 | 317 | :param module: 318 | A unicode string of the name of a plugin module to filter listeners by 319 | """ 320 | ... 321 | 322 | 323 | def on_new(view_id: int) -> None: 324 | ... 325 | 326 | 327 | def on_new_async(view_id: int) -> None: 328 | ... 329 | 330 | 331 | def on_new_buffer(buffer_id: int) -> None: 332 | ... 333 | 334 | 335 | def on_new_buffer_async(buffer_id: int) -> None: 336 | ... 337 | 338 | 339 | def on_associate_buffer(buffer_id: int) -> None: 340 | ... 341 | 342 | 343 | def on_associate_buffer_async(buffer_id: int) -> None: 344 | ... 345 | 346 | 347 | def on_close_buffer(buffer_id: int) -> None: 348 | ... 349 | 350 | 351 | def on_close_buffer_async(buffer_id: int) -> None: 352 | ... 353 | 354 | 355 | def on_clone(view_id: int) -> None: 356 | ... 357 | 358 | 359 | def on_clone_async(view_id: int) -> None: 360 | ... 361 | 362 | 363 | class Summary: 364 | max: float 365 | sum: float 366 | count: int 367 | 368 | def __init__(self) -> None: 369 | ... 370 | 371 | def record(self, x: float) -> None: 372 | ... 373 | 374 | 375 | def get_profiling_data() -> List[Tuple[str, str, int, float, float]]: 376 | ... 377 | 378 | 379 | def on_load(view_id: int) -> None: 380 | ... 381 | 382 | 383 | def on_load_async(view_id: int) -> None: 384 | ... 385 | 386 | 387 | def on_revert(view_id: int) -> None: 388 | ... 389 | 390 | 391 | def on_revert_async(view_id: int) -> None: 392 | ... 393 | 394 | 395 | def on_reload(view_id: int) -> None: 396 | ... 397 | 398 | 399 | def on_reload_async(view_id: int) -> None: 400 | ... 401 | 402 | 403 | def on_pre_close(view_id: int) -> None: 404 | ... 405 | 406 | 407 | def on_close(view_id: int) -> None: 408 | ... 409 | 410 | 411 | def on_pre_save(view_id: int) -> None: 412 | ... 413 | 414 | 415 | def on_pre_save_async(view_id: int) -> None: 416 | ... 417 | 418 | 419 | def on_post_save(view_id: int) -> None: 420 | ... 421 | 422 | 423 | def on_post_save_async(view_id: int) -> None: 424 | ... 425 | 426 | 427 | def on_pre_move(view_id: int) -> None: 428 | ... 429 | 430 | 431 | def on_post_move(view_id: int) -> None: 432 | ... 433 | 434 | 435 | def on_post_move_async(view_id: int) -> None: 436 | ... 437 | 438 | 439 | def on_modified(view_id: int) -> None: 440 | ... 441 | 442 | 443 | def on_modified_async(view_id: int) -> None: 444 | ... 445 | 446 | 447 | def on_selection_modified(view_id: int) -> None: 448 | ... 449 | 450 | 451 | def on_selection_modified_async(view_id: int) -> None: 452 | ... 453 | 454 | 455 | def on_activated(view_id: int) -> None: 456 | ... 457 | 458 | 459 | def on_activated_async(view_id: int) -> None: 460 | ... 461 | 462 | 463 | def on_deactivated(view_id: int) -> None: 464 | ... 465 | 466 | 467 | def on_deactivated_async(view_id: int) -> None: 468 | ... 469 | 470 | 471 | def on_query_context( 472 | view_id: int, 473 | key: str, 474 | operator: str, 475 | operand: Any, 476 | match_all: bool, 477 | ) -> None | bool: 478 | ... 479 | 480 | 481 | def normalise_completion(c: sublime.CompletionItem | str | Sequence[str]) -> CompletionNormalized: 482 | ... 483 | 484 | 485 | class MultiCompletionList: 486 | remaining_calls: int 487 | view_id: int 488 | req_id: int 489 | completions: List[CompletionNormalized] 490 | flags: int 491 | 492 | def __init__(self, num_completion_lists: int, view_id: int, req_id: int) -> None: 493 | ... 494 | 495 | def completions_ready( 496 | self, 497 | completions: Iterable[sublime.CompletionItem | str | Sequence[str]], 498 | flags: int, 499 | ) -> None: 500 | ... 501 | 502 | 503 | def on_query_completions( 504 | view_id: int, 505 | req_id: int, 506 | prefix: str, 507 | locations: Sequence[Point], 508 | ) -> None | List[Completion] | Tuple[List[Completion], int]: 509 | ... 510 | 511 | 512 | def on_hover(view_id: int, point: Point, hover_zone: int) -> None: 513 | ... 514 | 515 | 516 | def on_text_command( 517 | view_id: int, 518 | name: str, 519 | args: None | Dict[str, Any], 520 | ) -> None | Tuple[str, None | Dict[str, Any]]: 521 | ... 522 | 523 | 524 | def on_window_command( 525 | window_id: int, 526 | name: str, 527 | args: None | Dict[str, Any], 528 | ) -> None | Tuple[str, None | Dict[str, Any]]: 529 | ... 530 | 531 | 532 | def on_post_text_command(view_id: int, name: str, args: None | Dict[str, Any]) -> None: 533 | ... 534 | 535 | 536 | def on_post_window_command(window_id: int, name: str, args: None | Dict[str, Any]) -> None: 537 | ... 538 | 539 | 540 | def on_new_project(window_id: int) -> None: 541 | ... 542 | 543 | 544 | def on_new_project_async(window_id: int) -> None: 545 | ... 546 | 547 | 548 | def on_load_project(window_id: int) -> None: 549 | ... 550 | 551 | 552 | def on_load_project_async(window_id: int) -> None: 553 | ... 554 | 555 | 556 | def on_pre_save_project(window_id: int) -> None: 557 | ... 558 | 559 | 560 | def on_post_save_project(window_id: int) -> None: 561 | ... 562 | 563 | 564 | def on_post_save_project_async(window_id: int) -> None: 565 | ... 566 | 567 | 568 | def on_pre_close_project(window_id: int) -> None: 569 | ... 570 | 571 | 572 | def on_new_window(window_id: int) -> None: 573 | ... 574 | 575 | 576 | def on_new_window_async(window_id: int) -> None: 577 | ... 578 | 579 | 580 | def on_pre_close_window(window_id: int) -> None: 581 | ... 582 | 583 | 584 | def on_exit(log_path: str) -> None: 585 | ... 586 | 587 | 588 | class CommandInputHandler(Generic[T_InputType]): 589 | def name(self) -> str: 590 | """ 591 | The command argument name this input handler is editing. 592 | Defaults to `foo_bar` for an input handler named `FooBarInputHandler`. 593 | """ 594 | ... 595 | 596 | def next_input(self, args: Dict[str, Any]) -> None | CommandInputHandler[InputType]: 597 | """ 598 | Returns the next input after the user has completed this one. 599 | May return None to indicate no more input is required, 600 | or `sublime_plugin.BackInputHandler()` to indicate that 601 | the input handler should be poped off the stack instead. 602 | """ 603 | ... 604 | 605 | def placeholder(self) -> str: 606 | """ 607 | Placeholder text is shown in the text entry box before the user has entered anything. 608 | Empty by default. 609 | """ 610 | ... 611 | 612 | def initial_text(self) -> str: 613 | """Initial text shown in the text entry box. Empty by default.""" 614 | ... 615 | 616 | def initial_selection( 617 | self, 618 | ) -> List[Tuple[List[str | Tuple[str, T_InputType] | sublime.ListInputItem[T_InputType]], int]]: 619 | """A list of 2-element tuplues, defining the initially selected parts of the initial text.""" 620 | ... 621 | 622 | def preview(self, arg: T_InputType) -> str | sublime.Html: 623 | """ 624 | Called whenever the user changes the text in the entry box. 625 | The returned value (either plain text or HTML) will be shown in the preview area of the Command Palette. 626 | """ 627 | ... 628 | 629 | def validate(self, arg: T_InputType) -> bool: 630 | """ 631 | Called whenever the user presses enter in the text entry box. 632 | Return False to disallow the current value. 633 | """ 634 | ... 635 | 636 | def cancel(self) -> None: 637 | """Called when the input handler is canceled, either by the user pressing backspace or escape.""" 638 | ... 639 | 640 | @overload 641 | def confirm(self, arg: T_InputType) -> None: 642 | """Called when the input is accepted, after the user has pressed enter and the text has been validated.""" 643 | ... 644 | 645 | @overload 646 | def confirm(self, arg: T_InputType, event: EventDict) -> None: 647 | """Called when the input is accepted, after the user has pressed enter and the text has been validated.""" 648 | ... 649 | 650 | def create_input_handler_(self, args: Dict[str, Any]) -> None | CommandInputHandler[T_InputType]: 651 | ... 652 | 653 | def preview_(self, v: str) -> Tuple[str, int]: 654 | ... 655 | 656 | def validate_(self, v: str) -> bool: 657 | ... 658 | 659 | def cancel_(self) -> None: 660 | ... 661 | 662 | def confirm_(self, v: str) -> None: 663 | ... 664 | 665 | def want_event(self) -> bool: 666 | ... 667 | 668 | 669 | class BackInputHandler(CommandInputHandler[None]): 670 | def name(self) -> str: 671 | """The command argument name this input handler is editing. Defaults to `_Back`.""" 672 | ... 673 | 674 | 675 | class TextInputHandler(CommandInputHandler[str]): 676 | """ 677 | TextInputHandlers can be used to accept textual input in the Command Palette. 678 | Return a subclass of this from the `input()` method of a command. 679 | """ 680 | 681 | def description(self, text: str) -> str: 682 | """ 683 | The text to show in the Command Palette when this input handler is not at the top of the input handler stack. 684 | Defaults to the text the user entered. 685 | """ 686 | ... 687 | 688 | def setup_(self, args: Dict[Any, Any]) -> Tuple[List[Any], Dict[str, str]]: 689 | ... 690 | 691 | def description_(self, v: str, text: str) -> str: 692 | ... 693 | 694 | 695 | class ListInputHandler(CommandInputHandler[T_InputType], Generic[T_InputType]): 696 | """ 697 | ListInputHandlers can be used to accept a choice input from a list items in the Command Palette. 698 | Return a subclass of this from the input() method of a command. 699 | """ 700 | 701 | def list_items( 702 | self, 703 | ) -> ( 704 | List[str | Tuple[str, T_InputType] | sublime.ListInputItem[T_InputType]] 705 | | Tuple[List[str | Tuple[str, T_InputType] | sublime.ListInputItem[T_InputType]], int] 706 | ): 707 | """ 708 | The items to show in the list. If returning a list of `(str, value)` tuples, 709 | then the str will be shown to the user, while the value will be used as the command argument. 710 | 711 | Optionally return a tuple of `(list_items, selected_item_index)` to indicate an initial selection. 712 | """ 713 | ... 714 | 715 | def description(self, v: str, text: str) -> str: 716 | """ 717 | The text to show in the Command Palette when this input handler is not at the top of the input handler stack. 718 | Defaults to the text of the list item the user selected. 719 | """ 720 | ... 721 | 722 | def setup_(self, args: Dict[Any, Any]) -> Tuple[List[Tuple[Any, ...]], Dict[str, str]]: 723 | ... 724 | 725 | def description_(self, v: str, text: str) -> str: 726 | ... 727 | 728 | 729 | class Command: 730 | def name(self) -> str: 731 | """ 732 | The command argument name this input handler is editing. 733 | Defaults to `foo_bar` for an input handler named `FooBarInputHandler`. 734 | """ 735 | ... 736 | 737 | def is_enabled_(self, args: Dict[str, Any]) -> bool: 738 | ... 739 | 740 | def is_enabled(self) -> bool: 741 | """ 742 | Returns True if the command is able to be run at this time. 743 | The default implementation simply always returns True. 744 | """ 745 | ... 746 | 747 | def is_visible_(self, args: Dict[str, Any]) -> bool: 748 | ... 749 | 750 | def is_visible(self) -> bool: 751 | """ 752 | Returns True if the command should be shown in the menu at this time. 753 | The default implementation always returns True. 754 | """ 755 | ... 756 | 757 | def is_checked_(self, args: Dict[str, Any]) -> bool: 758 | ... 759 | 760 | def is_checked(self) -> bool: 761 | """ 762 | Returns True if a checkbox should be shown next to the menu item. 763 | The `.sublime-menu` file must have the "checkbox key set to true for this to be used. 764 | """ 765 | ... 766 | 767 | def description_(self, args: Dict[str, Any]) -> str: 768 | ... 769 | 770 | def description(self) -> str: 771 | """ 772 | Returns a description of the command with the given arguments. 773 | Used in the menus, and for Undo / Redo descriptions. 774 | Return None to get the default description. 775 | """ 776 | ... 777 | 778 | def filter_args(self, args: Dict[str, Any]) -> Dict[str, Any]: 779 | """Returns the args after without the "event" entry""" 780 | ... 781 | 782 | def want_event(self) -> bool: 783 | """ 784 | Return True to receive an event argument when the command is triggered by a mouse action. 785 | The event information allows commands to determine which portion of the view was clicked on. 786 | The default implementation returns False. 787 | """ 788 | ... 789 | 790 | def input(self, args: Dict[str, Any]) -> None | CommandInputHandler[InputType]: 791 | """ 792 | If this returns something other than `None`, 793 | the user will be prompted for an input before the command is run in the Command Palette. 794 | """ 795 | ... 796 | 797 | def input_description(self) -> str: 798 | """ 799 | Allows a custom name to be show to the left of the cursor in the input box, 800 | instead of the default one generated from the command name. 801 | """ 802 | ... 803 | 804 | def create_input_handler_(self, args: Dict[str, Any]) -> None | CommandInputHandler[InputType]: 805 | ... 806 | 807 | 808 | class ApplicationCommand(Command): 809 | """ApplicationCommands are instantiated once per application.""" 810 | 811 | def run_(self, edit_token: int, args: Dict[str, Any]) -> None: 812 | ... 813 | 814 | run: AnyCallable 815 | 816 | 817 | class WindowCommand(Command): 818 | """WindowCommands are instantiated once per window. The Window object may be retrieved via `self.window`""" 819 | 820 | window: sublime.Window 821 | 822 | def __init__(self, window: sublime.Window) -> None: 823 | ... 824 | 825 | def run_(self, edit_token: int, args: Dict[str, Any]) -> None: 826 | ... 827 | 828 | run: AnyCallable 829 | 830 | 831 | class TextCommand(Command): 832 | """TextCommands are instantiated once per view. The View object may be retrieved via `self.view`""" 833 | 834 | view: sublime.View 835 | 836 | def __init__(self, view: sublime.View) -> None: 837 | ... 838 | 839 | def run_(self, edit_token: int, args: Dict[str, Any]) -> None: 840 | ... 841 | 842 | run: AnyCallable 843 | 844 | 845 | class EventListener: 846 | pass 847 | 848 | 849 | class ViewEventListener: 850 | """ 851 | A class that provides similar event handling to EventListener, but bound to a specific view. 852 | Provides class method-based filtering to control what views objects are created for. 853 | 854 | The view is passed as a single parameter to the constructor. 855 | The default implementation makes the view available via `self.view`. 856 | """ 857 | 858 | view: sublime.View 859 | 860 | @classmethod 861 | def is_applicable(cls, settings: sublime.Settings) -> bool: 862 | """ 863 | Receives a Settings object and should return a bool 864 | indicating if this class applies to a view with those settings. 865 | """ 866 | ... 867 | 868 | @classmethod 869 | def applies_to_primary_view_only(cls) -> bool: 870 | """ 871 | Returns a bool indicating if this class applies only to the primary view for a file. 872 | A view is considered primary if it is the only, or first, view into a file. 873 | """ 874 | ... 875 | 876 | def __init__(self, view: sublime.View) -> None: 877 | ... 878 | 879 | 880 | class TextChangeListener: 881 | """ 882 | Base implementation of a text change listener. 883 | 884 | An instance may be added to a view using `sublime.View.add_text_listener`. 885 | 886 | Has the following callbacks: 887 | 888 | on_text_changed(changes): 889 | Called when text is changed in a buffer. 890 | 891 | :param changes: 892 | A list of TextChange 893 | 894 | on_text_changed_async(changes): 895 | Async version of on_text_changed_async. 896 | 897 | on_revert(): 898 | Called when the buffer is reverted. 899 | 900 | A revert does not trigger text changes. If the contents of the buffer 901 | are required here use View.substr() 902 | 903 | on_revert_async(): 904 | Async version of on_revert_async. 905 | 906 | on_reload(): 907 | Called when the buffer is reloaded. 908 | 909 | A reload does not trigger text changes. If the contents of the buffer 910 | are required here use View.substr() 911 | 912 | on_reload_async(): 913 | Async version of on_reload_async. 914 | """ 915 | 916 | __key: None | int 917 | buffer: None | sublime.Buffer 918 | 919 | @classmethod 920 | def is_applicable(cls, buffer: sublime.Buffer) -> bool: 921 | """ 922 | Receives a Buffer object and should return a bool 923 | indicating if this class applies to a view with the Buffer. 924 | """ 925 | ... 926 | 927 | def __init__(self) -> None: 928 | ... 929 | 930 | def detach(self) -> None: 931 | """ 932 | Remove this listener from the buffer. 933 | 934 | Async callbacks may still be called after this, as they are queued separately. 935 | """ 936 | ... 937 | 938 | def attach(self, buffer: sublime.Buffer) -> None: 939 | """Attach this listener to a buffer.""" 940 | ... 941 | 942 | def is_attached(self) -> bool: 943 | """ 944 | Check whether the listener is receiving events from a buffer. 945 | May not be called from __init__. 946 | """ 947 | ... 948 | 949 | 950 | class MultizipImporter(importlib.abc.MetaPathFinder): 951 | loaders: List[importlib.abc.Loader] 952 | 953 | def __init__(self) -> None: 954 | ... 955 | 956 | def _make_spec(self, loader: importlib.abc.Loader, fullname: str) -> ModuleSpec: 957 | """ 958 | :param loader: 959 | The importlib.abc.Loader to create the ModuleSpec from 960 | 961 | :param fullname: 962 | A unicode string of the module name 963 | 964 | :return: 965 | An instance of importlib.machinery.ModuleSpec() 966 | """ 967 | ... 968 | 969 | def find_spec( 970 | self, 971 | fullname: str, 972 | path: None | Sequence[bytes | str], 973 | target: None | Any = None, 974 | ) -> None | ModuleSpec: 975 | """ 976 | :param fullname: 977 | A unicode string of the module name 978 | 979 | :param path: 980 | None or a list with a single unicode string of the __path__ of 981 | the parent module if importing a submodule 982 | 983 | :param target: 984 | Unused - extra info that importlib may provide? 985 | 986 | :return: 987 | An importlib.machinery.ModuleSpec() object 988 | """ 989 | ... 990 | 991 | 992 | class ZipResourceReader(importlib.abc.ResourceReader): 993 | """ 994 | Implements the resource reader interface introduced in Python 3.7 995 | """ 996 | 997 | loader: ZipLoader 998 | fullname: str 999 | 1000 | def __init__(self, loader: ZipLoader, fullname: str) -> None: 1001 | """ 1002 | :param loader: 1003 | The source ZipLoader() object 1004 | 1005 | :param fullname: 1006 | A unicode string of the module name to load resources for 1007 | """ 1008 | ... 1009 | 1010 | def open_resource(self, resource: bytes | str | os.PathLike[Any]) -> io.BytesIO: 1011 | """ 1012 | :param resource: 1013 | A unicode string of a resource name - should not contain a path 1014 | separator 1015 | 1016 | :raises: 1017 | FileNotFoundError - when the resource doesn't exist 1018 | 1019 | :return: 1020 | An io.BytesIO() object 1021 | """ 1022 | ... 1023 | 1024 | def resource_path(self, resource: bytes | str | os.PathLike[Any]) -> str: 1025 | """ 1026 | :param resource: 1027 | A unicode string of a resource name - should not contain a path 1028 | separator 1029 | 1030 | :raises: 1031 | FileNotFoundError - always, since there is no normal filesystem access 1032 | """ 1033 | ... 1034 | 1035 | def is_resource(self, name: str) -> bool: 1036 | """ 1037 | :param name: 1038 | A unicode string of a file name to check if it is a resource 1039 | 1040 | :return: 1041 | A boolean indicating if the file is a resource 1042 | """ 1043 | ... 1044 | 1045 | def contents(self) -> Iterator[str]: 1046 | """ 1047 | :return: 1048 | A list of the resources for this module 1049 | """ 1050 | ... 1051 | 1052 | 1053 | class ZipLoader(importlib.abc.InspectLoader): 1054 | """ 1055 | A custom Python loader that handles loading .py and .pyc files from 1056 | .sublime-package zip files, and supports overrides where a loose file in 1057 | the Packages/ folder of the data dir may be loaded instead of a file in 1058 | the .sublime-package file. 1059 | """ 1060 | 1061 | zippath: str 1062 | name: str 1063 | 1064 | contents: Dict[str, str] 1065 | filenames: Dict[str, str] 1066 | packages: Set[str] 1067 | resources: Dict[str, Dict[str, str]] 1068 | refreshed: float 1069 | 1070 | def __init__(self, zippath: str) -> None: 1071 | """ 1072 | :param zippath: 1073 | A unicode string of the full filesystem path to the zip file 1074 | """ 1075 | ... 1076 | 1077 | def _get_name_key(self, fullname: str) -> Tuple[None, None] | Tuple[str, str]: 1078 | """ 1079 | Converts a module name into a pair of package name and key. The 1080 | key is used to access the various data structures in this object. 1081 | 1082 | :param fullname: 1083 | A unicode string of a module name 1084 | 1085 | :return: 1086 | If the fullname is not a module in this package, (None, None), 1087 | otherwise a 2-element tuple of unicode strings. The first element 1088 | being the package name, and the second being a sub-module, e.g. 1089 | ("Default", "indentation"). 1090 | """ 1091 | ... 1092 | 1093 | def has(self, fullname: str) -> bool: 1094 | """ 1095 | Checks if the module is handled by this loader 1096 | 1097 | :param fullname: 1098 | A unicode string of the module to check 1099 | 1100 | :return: 1101 | A boolean if the module is handled by this loader 1102 | """ 1103 | ... 1104 | 1105 | def get_resource_reader(self, fullname: str) -> None | importlib.abc.ResourceReader: 1106 | """ 1107 | :param fullname: 1108 | A unicode string of the module name to get the resource reader for 1109 | 1110 | :return: 1111 | None if the module is not a package, otherwise an object that 1112 | implements the importlib.abc.ResourceReader() interface 1113 | """ 1114 | ... 1115 | 1116 | def get_filename(self, fullname: str) -> str: 1117 | """ 1118 | :param fullname: 1119 | A unicode string of the module name 1120 | 1121 | :raises: 1122 | ImportError - when the module has no file path 1123 | 1124 | :return: 1125 | A unicode string of the file path to the module 1126 | """ 1127 | ... 1128 | 1129 | def get_code(self, fullname: str) -> Any: 1130 | """ 1131 | :param fullname: 1132 | A unicode string of the module to get the code for 1133 | 1134 | :raises: 1135 | ModuleNotFoundError - when the module is not part of this zip file 1136 | ImportError - when there is an error loading the code 1137 | 1138 | :return: 1139 | A code object for the module 1140 | """ 1141 | ... 1142 | 1143 | def get_source(self, fullname: str) -> None | str: 1144 | """ 1145 | :param fullname: 1146 | A unicode string of the module to get the source for 1147 | 1148 | :raises: 1149 | ModuleNotFoundError - when the module is not part of this zip file 1150 | ImportError - when there is an error loading the source file 1151 | 1152 | :return: 1153 | A unicode string of the source code, or None if there is no source 1154 | for the module (i.e. a .pyc file) 1155 | """ 1156 | ... 1157 | 1158 | def _load_source(self, fullname: str, path: str) -> str: 1159 | """ 1160 | Loads the source code to the module 1161 | 1162 | :param fullname: 1163 | A unicode string of the module name 1164 | 1165 | :param path: 1166 | A filesystem path to the module - may be a path into s 1167 | .sublime-package file 1168 | 1169 | :return: 1170 | A unicode string 1171 | """ 1172 | ... 1173 | 1174 | def is_package(self, fullname: str) -> bool: 1175 | """ 1176 | :param fullname: 1177 | A unicode string of the module to see if it is a package 1178 | 1179 | :return: 1180 | A boolean if the module is a package 1181 | """ 1182 | ... 1183 | 1184 | def _spec_info(self, fullname: str) -> Tuple[None, None] | Tuple[str, bool]: 1185 | """ 1186 | :param fullname: 1187 | A unicode string of the module that an 1188 | importlib.machinery.ModuleSpec() object is going to be created for 1189 | 1190 | :return: 1191 | A 2-element tuple of: 1192 | - (None, None) if the loader does not know about the module 1193 | - (unicode string, bool) of the origin and is_package params to 1194 | pass to importlib.machinery.ModuleSpec() 1195 | """ 1196 | ... 1197 | 1198 | def _scan_zip(self) -> None: 1199 | """ 1200 | Rebuild the internal cached info about the contents of the zip 1201 | """ 1202 | ... 1203 | 1204 | 1205 | override_path: None | str = None 1206 | multi_importer: MultizipImporter = MultizipImporter() 1207 | 1208 | 1209 | def update_compressed_packages(pkgs: Iterable[str]) -> None: 1210 | ... 1211 | 1212 | 1213 | def set_override_path(path: str) -> None: 1214 | ... 1215 | -------------------------------------------------------------------------------- /typings/sublime.pyi: -------------------------------------------------------------------------------- 1 | # This file is maintained on https://github.com/jfcherng-sublime/ST-API-stubs 2 | # ST version: 4136 3 | 4 | from __future__ import annotations 5 | 6 | from typing import ( 7 | Any, 8 | Callable, 9 | Dict, 10 | Generic, 11 | Iterable, 12 | Iterator, 13 | List, 14 | Literal, 15 | Mapping, 16 | Reversible, 17 | Sequence, 18 | Tuple, 19 | TypeVar, 20 | ) 21 | 22 | from _sublime_types import ( 23 | Callback0, 24 | Callback1, 25 | CommandArgsDict, 26 | Completion, 27 | CompletionKind, 28 | Dip, 29 | HasKeysMethod, 30 | Layout, 31 | Location, 32 | Point, 33 | Str, 34 | T_ExpandableVar, 35 | Vector, 36 | ) 37 | 38 | # ----- # 39 | # types # 40 | # ----- # 41 | 42 | T = TypeVar("T") 43 | 44 | # -------- # 45 | # ST codes # 46 | # -------- # 47 | 48 | HOVER_TEXT: int = 1 49 | HOVER_GUTTER: int = 2 50 | HOVER_MARGIN: int = 3 51 | 52 | ENCODED_POSITION: int = 1 53 | TRANSIENT: int = 4 54 | FORCE_GROUP: int = 8 55 | # Only valid with ADD_TO_SELECTION or REPLACE_MRU 56 | SEMI_TRANSIENT: int = 16 57 | ADD_TO_SELECTION: int = 32 58 | REPLACE_MRU: int = 64 59 | # Only valid with ADD_TO_SELECTION 60 | CLEAR_TO_RIGHT: int = 128 61 | IGNORECASE: int = 2 62 | LITERAL: int = 1 63 | MONOSPACE_FONT: int = 1 64 | KEEP_OPEN_ON_FOCUS_LOST: int = 2 65 | WANT_EVENT: int = 4 66 | 67 | HTML: int = 1 68 | COOPERATE_WITH_AUTO_COMPLETE: int = 2 69 | HIDE_ON_MOUSE_MOVE: int = 4 70 | HIDE_ON_MOUSE_MOVE_AWAY: int = 8 71 | KEEP_ON_SELECTION_MODIFIED: int = 16 72 | HIDE_ON_CHARACTER_EVENT: int = 32 73 | 74 | DRAW_EMPTY: int = 1 75 | HIDE_ON_MINIMAP: int = 2 76 | DRAW_EMPTY_AS_OVERWRITE: int = 4 77 | PERSISTENT: int = 16 78 | # Deprecated, use `DRAW_NO_FILL` instead 79 | DRAW_OUTLINED: int = 32 80 | DRAW_NO_FILL: int = 32 81 | DRAW_NO_OUTLINE: int = 256 82 | DRAW_SOLID_UNDERLINE: int = 512 83 | DRAW_STIPPLED_UNDERLINE: int = 1024 84 | DRAW_SQUIGGLY_UNDERLINE: int = 2048 85 | NO_UNDO: int = 8192 86 | HIDDEN: int = 128 87 | 88 | OP_EQUAL: int = 0 89 | OP_NOT_EQUAL: int = 1 90 | OP_REGEX_MATCH: int = 2 91 | OP_NOT_REGEX_MATCH: int = 3 92 | OP_REGEX_CONTAINS: int = 4 93 | OP_NOT_REGEX_CONTAINS: int = 5 94 | CLASS_WORD_START: int = 1 95 | CLASS_WORD_END: int = 2 96 | CLASS_PUNCTUATION_START: int = 4 97 | CLASS_PUNCTUATION_END: int = 8 98 | CLASS_SUB_WORD_START: int = 16 99 | CLASS_SUB_WORD_END: int = 32 100 | CLASS_LINE_START: int = 64 101 | CLASS_LINE_END: int = 128 102 | CLASS_EMPTY_LINE: int = 256 103 | 104 | INHIBIT_WORD_COMPLETIONS: int = 8 105 | INHIBIT_EXPLICIT_COMPLETIONS: int = 16 106 | DYNAMIC_COMPLETIONS: int = 32 107 | INHIBIT_REORDER: int = 128 108 | 109 | DIALOG_CANCEL: int = 0 110 | DIALOG_YES: int = 1 111 | DIALOG_NO: int = 2 112 | 113 | UI_ELEMENT_SIDE_BAR: int = 1 114 | UI_ELEMENT_MINIMAP: int = 2 115 | UI_ELEMENT_TABS: int = 4 116 | UI_ELEMENT_STATUS_BAR: int = 8 117 | UI_ELEMENT_MENU: int = 16 118 | UI_ELEMENT_OPEN_FILES: int = 32 119 | 120 | LAYOUT_INLINE: int = 0 121 | LAYOUT_BELOW: int = 1 122 | LAYOUT_BLOCK: int = 2 123 | 124 | KIND_ID_AMBIGUOUS: int = 0 125 | KIND_ID_KEYWORD: int = 1 126 | KIND_ID_TYPE: int = 2 127 | KIND_ID_FUNCTION: int = 3 128 | KIND_ID_NAMESPACE: int = 4 129 | KIND_ID_NAVIGATION: int = 5 130 | KIND_ID_MARKUP: int = 6 131 | KIND_ID_VARIABLE: int = 7 132 | KIND_ID_SNIPPET: int = 8 133 | 134 | # These should only be used for QuickPanelItem 135 | # and ListInputItem, not for CompletionItem 136 | KIND_ID_COLOR_REDISH: int = 9 137 | KIND_ID_COLOR_ORANGISH: int = 10 138 | KIND_ID_COLOR_YELLOWISH: int = 11 139 | KIND_ID_COLOR_GREENISH: int = 12 140 | KIND_ID_COLOR_CYANISH: int = 13 141 | KIND_ID_COLOR_BLUISH: int = 14 142 | KIND_ID_COLOR_PURPLISH: int = 15 143 | KIND_ID_COLOR_PINKISH: int = 16 144 | KIND_ID_COLOR_DARK: int = 17 145 | KIND_ID_COLOR_LIGHT: int = 18 146 | 147 | KIND_AMBIGUOUS: CompletionKind = (KIND_ID_AMBIGUOUS, "", "") 148 | KIND_KEYWORD: CompletionKind = (KIND_ID_KEYWORD, "", "") 149 | KIND_TYPE: CompletionKind = (KIND_ID_TYPE, "", "") 150 | KIND_FUNCTION: CompletionKind = (KIND_ID_FUNCTION, "", "") 151 | KIND_NAMESPACE: CompletionKind = (KIND_ID_NAMESPACE, "", "") 152 | KIND_NAVIGATION: CompletionKind = (KIND_ID_NAVIGATION, "", "") 153 | KIND_MARKUP: CompletionKind = (KIND_ID_MARKUP, "", "") 154 | KIND_VARIABLE: CompletionKind = (KIND_ID_VARIABLE, "", "") 155 | KIND_SNIPPET: CompletionKind = (KIND_ID_SNIPPET, "s", "Snippet") 156 | 157 | SYMBOL_SOURCE_ANY: int = 0 158 | SYMBOL_SOURCE_INDEX: int = 1 159 | SYMBOL_SOURCE_OPEN_FILES: int = 2 160 | 161 | SYMBOL_TYPE_ANY: int = 0 162 | SYMBOL_TYPE_DEFINITION: int = 1 163 | SYMBOL_TYPE_REFERENCE: int = 2 164 | 165 | COMPLETION_FORMAT_TEXT: int = 0 166 | COMPLETION_FORMAT_SNIPPET: int = 1 167 | COMPLETION_FORMAT_COMMAND: int = 2 168 | 169 | COMPLETION_FLAG_KEEP_PREFIX: int = 1 170 | 171 | 172 | def version() -> str: 173 | """Returns the version number.""" 174 | ... 175 | 176 | 177 | def platform() -> Literal["osx", "linux", "windows"]: 178 | """Returns the platform, which may be `"osx"`, `"linux"` or `"windows"`.""" 179 | ... 180 | 181 | 182 | def arch() -> Literal["x32", "x64", "arm64"]: 183 | """Returns the CPU architecture, which may be `"x32"`, `"x64"` or `"arm64"`.""" 184 | ... 185 | 186 | 187 | def channel() -> Literal["stable", "dev"]: 188 | """Returns the release channel, which may be `"stable"` or `"dev"`.""" 189 | ... 190 | 191 | 192 | def executable_path() -> str: 193 | """Returns the path to the "sublime_text" executable.""" 194 | ... 195 | 196 | 197 | def executable_hash() -> Tuple[str, str, str]: 198 | """ 199 | Returns `(version_number, platform_arch, executable_hash)` such as 200 | 201 | ```python 202 | ('4079', 'windows_x64', '906388de50d5233b5648200ce9d1452a') 203 | ``` 204 | """ 205 | ... 206 | 207 | 208 | def packages_path() -> str: 209 | """Returns the path where all the user's loose packages are located.""" 210 | ... 211 | 212 | 213 | def installed_packages_path() -> str: 214 | """Returns the path where all the user's `.sublime-package` files are located.""" 215 | ... 216 | 217 | 218 | def cache_path() -> str: 219 | """Returns the path where Sublime Text stores cache files.""" 220 | ... 221 | 222 | 223 | def status_message(msg: str) -> None: 224 | """Shows a message in the status bar.""" 225 | ... 226 | 227 | 228 | def error_message(msg: str) -> None: 229 | """Displays an error dialog to the user.""" 230 | ... 231 | 232 | 233 | def message_dialog(msg: str) -> None: 234 | """Displays a message dialog to the user.""" 235 | ... 236 | 237 | 238 | def ok_cancel_dialog(msg: str, ok_title: str = "", title: str = "") -> bool: 239 | """ 240 | Show a popup dialog with an "ok" and "cancel" button. 241 | 242 | - `msg`: The message to show in the dialog. 243 | - `ok_title`: Optional replacement string for the "ok" button. 244 | - `title`: Optional title for the dialog. Note Linux and macOS do not have 245 | a title in their dialog. 246 | 247 | Returns `True` if the user presses the `ok` button, `False` otherwise. 248 | """ 249 | ... 250 | 251 | 252 | def yes_no_cancel_dialog(msg: str, yes_title: str = "", no_title: str = "", title: str = "") -> int: 253 | """ 254 | Displays a `yes` `no` `cancel` question dialog to the user 255 | If `yes_title` and/or `no_title` are provided, they will be used as the 256 | text on the corresponding buttons on some platforms. 257 | 258 | - `msg`: The message to show in the dialog. 259 | - `yes_title`: Optional replacement string for the "yes" button. 260 | - `no_title`: Optional replacement string for the "no" button. 261 | - `title`: Optional title for the dialog. Note Linux and macOS do not have 262 | a title in their dialog. 263 | 264 | Returns `DIALOG_YES`, `DIALOG_NO` or `DIALOG_CANCEL`. 265 | """ 266 | ... 267 | 268 | 269 | def open_dialog( 270 | callback: Callable[[None | str | Sequence[str]], None], 271 | file_types: Sequence[Tuple[str, Sequence[str]]] = [], 272 | directory: None | str = None, 273 | multi_select: bool = False, 274 | allow_folders: bool = False, 275 | ) -> None: 276 | """ 277 | Presents the user with a file dialog for the purpose of opening a file, 278 | and passes the resulting file path to callback. 279 | 280 | @version ST(>=4075) 281 | 282 | --- 283 | 284 | - `callback`: Called with selected path or `None` once open dialog is closed. 285 | - `file_types`: A list of allowed file types, consisting of a description and a list of allowed extensions. 286 | - `directory`: The directory the dialog should start in. Will use the virtual working directory if not provided. 287 | - `multi_select`: Whether to allow selecting multiple files. 288 | Function will call `callback` with a list if this is `True`. 289 | - `allow_folders`: Whether to also allow selecting folders. Only works on macOS. 290 | If you only want to select folders use `select_folder_dialog`. 291 | """ 292 | ... 293 | 294 | 295 | def save_dialog( 296 | callback: Callable[[None | str], None], 297 | file_types: Sequence[Tuple[str, Sequence[str]]] = [], 298 | directory: None | str = None, 299 | name: None | str = None, 300 | extension: None | str = None, 301 | ) -> None: 302 | """ 303 | Presents the user with file dialog for the purpose of saving a file, 304 | and passes the result to callback. 305 | 306 | @version ST(>=4075) 307 | 308 | --- 309 | 310 | - `callback`: Called with selected path or `None` once open dialog is closed. 311 | - `file_types`: A list of allowed file types, consisting of a description and a list of allowed extensions. 312 | - `directory`: The directory the dialog should start in. Will use the virtual working directory if not provided. 313 | - `name`: The default name of the file in the save dialog. 314 | - `extension`: The default extension used in the save dialog. 315 | """ 316 | ... 317 | 318 | 319 | def select_folder_dialog( 320 | callback: Callable[[None | str | Sequence[str]], None], 321 | directory: None | str = None, 322 | multi_select: bool = False, 323 | ) -> None: 324 | """ 325 | Presents the user with a file dialog for the purpose of selecting a folder, 326 | and passes the result to callback. 327 | 328 | @version ST(>=4075) 329 | 330 | --- 331 | 332 | - `callback`: Called with selected path or `None` once open dialog is closed. 333 | - `directory`: The directory the dialog should start in. Will use the virtual working directory if not provided. 334 | - `multi_select`: Whether to allow selecting multiple folders. 335 | Function will call `callback` with a list if this is `True`. 336 | """ 337 | ... 338 | 339 | 340 | def run_command(cmd: str, args: None | Dict[str, Any] = None) -> None: 341 | """Runs the named `ApplicationCommand` with the (optional) given `args`.""" 342 | ... 343 | 344 | 345 | def format_command(cmd: str, args: None | Dict[str, Any] = None) -> str: 346 | """ 347 | Creates a "command string" from a str cmd name, and an optional dict of args. 348 | This is used when constructing a command-based `CompletionItem`. 349 | 350 | @version ST(>=4075) 351 | """ 352 | ... 353 | 354 | 355 | def html_format_command(cmd: str, args: None | Dict[str, Any] = None) -> str: 356 | ... 357 | 358 | 359 | def command_url(cmd: str, args: None | Dict[str, Any] = None) -> str: 360 | """ 361 | Creates a `subl:` protocol URL for executing a command in a minihtml link. 362 | 363 | @version ST(>=4075) 364 | """ 365 | ... 366 | 367 | 368 | def get_clipboard_async(callback: Callable[[str], None], size_limit: int = 16777216) -> None: 369 | """ 370 | Calls `callback` with the contents of the clipboard. For performance reasons 371 | if the size of the clipboard content is bigger than `size_limit`, an empty 372 | string will be returned. 373 | """ 374 | ... 375 | 376 | 377 | def get_clipboard(size_limit: int = 16777216) -> str: 378 | """ 379 | Returns the content of the clipboard. For performance reasons if the size of 380 | the clipboard content is bigger than size_limit, an empty string will be 381 | returned. 382 | 383 | @deprecated Use `get_clipboard_async()` when possible. 384 | """ 385 | ... 386 | 387 | 388 | def set_clipboard(text: str) -> None: 389 | """Sets the contents of the clipboard.""" 390 | ... 391 | 392 | 393 | def log_commands(flag: None | bool = None) -> None: 394 | """ 395 | Controls command logging. If enabled, all commands run from key bindings 396 | and the menu will be logged to the console. 397 | """ 398 | ... 399 | 400 | 401 | def get_log_commands() -> bool: 402 | """ 403 | Returns whether `log_commands()` is enabled or not. 404 | 405 | @version ST(>=4099) 406 | """ 407 | ... 408 | 409 | 410 | def log_input(flag: None | bool = None) -> None: 411 | """ 412 | Enables or disables input logging. 413 | This is useful to find the names of certain keys on the keyboard. 414 | """ 415 | ... 416 | 417 | 418 | def get_log_input() -> bool: 419 | """ 420 | Returns whether `log_input()` is enabled or not. 421 | 422 | @version ST(>=4099) 423 | """ 424 | ... 425 | 426 | 427 | def log_fps(flag: None | bool = None) -> None: 428 | """ 429 | Enables or disables fps logging. 430 | """ 431 | ... 432 | 433 | 434 | def get_log_fps() -> bool: 435 | """ 436 | Returns whether `log_fps()` is enabled or not. 437 | 438 | @version ST(>=4099) 439 | """ 440 | ... 441 | 442 | 443 | def log_result_regex(flag: None | bool = None) -> None: 444 | """ 445 | Enables or disables result regex logging. 446 | This is useful when trying to debug `file_regex` and `line_regex` in build systems. 447 | """ 448 | ... 449 | 450 | 451 | def get_log_result_regex() -> bool: 452 | """ 453 | Returns whether `log_result_regex()` is enabled or not. 454 | 455 | @version ST(>=4099) 456 | """ 457 | ... 458 | 459 | 460 | def log_indexing(flag: None | bool = None) -> None: 461 | ... 462 | 463 | 464 | def get_log_indexing() -> bool: 465 | """ 466 | Returns whether `log_indexing()` is enabled or not. 467 | 468 | @version ST(>=4099) 469 | """ 470 | ... 471 | 472 | 473 | def log_build_systems(flag: None | bool = None) -> None: 474 | ... 475 | 476 | 477 | def get_log_build_systems() -> bool: 478 | """ 479 | Returns whether `log_build_systems()` is enabled or not. 480 | 481 | @version ST(>=4099) 482 | """ 483 | ... 484 | 485 | 486 | def log_control_tree(flag: None | bool = None) -> None: 487 | """ 488 | When enabled, clicking with `Ctrl`+`Alt` will log the control tree under the mouse to the console. 489 | 490 | @version ST(>=4064) 491 | """ 492 | ... 493 | 494 | 495 | def get_log_control_tree() -> bool: 496 | """ 497 | Returns whether `log_control_tree()` is enabled or not. 498 | 499 | @version ST(>=4099) 500 | """ 501 | ... 502 | 503 | 504 | def ui_info() -> Dict[str, Any]: 505 | """Gets the UI information such as theme/color-scheme palette.""" 506 | ... 507 | 508 | 509 | def score_selector(scope_name: str, selector: str) -> int: 510 | """ 511 | Matches the `selector` against the given scope, returning a score. 512 | 513 | A score of `0` means no match, above `0` means a match. 514 | Different selectors may be compared against the same scope: 515 | a higher score means the selector is a better match for the scope. 516 | """ 517 | ... 518 | 519 | 520 | def load_resource(name: str) -> str: 521 | """Loads the given resource. The `name` should be in the format `Packages/Default/Main.sublime-menu`.""" 522 | ... 523 | 524 | 525 | def load_binary_resource(name: str) -> bytes: 526 | """Loads the given resource. The `name` should be in the format `Packages/Default/Main.sublime-menu`.""" 527 | ... 528 | 529 | 530 | def find_resources(pattern: str) -> List[str]: 531 | """Finds resources whose file name matches the given `pattern`.""" 532 | ... 533 | 534 | 535 | def encode_value(val: Any, pretty: bool = ...) -> str: 536 | """ 537 | Encode a JSON compatible value into a string representation. 538 | If `pretty` is set to `True`, the string will include newlines and indentation. 539 | """ 540 | ... 541 | 542 | 543 | def decode_value(data: str) -> Any: 544 | """ 545 | Decodes a JSON string into an object. 546 | If `data` is invalid, a `ValueError` will be thrown. 547 | """ 548 | ... 549 | 550 | 551 | def expand_variables(val: T_ExpandableVar, variables: Dict[str, str]) -> T_ExpandableVar: 552 | """ 553 | Expands any variables in the string `value` using the variables defined in the dictionary 554 | `variables` `value` may also be a `list` or `dict`, in which case the structure will be 555 | recursively expanded. Strings should use snippet syntax, for example: 556 | 557 | ```python 558 | expand_variables("Hello, ${name}", {"name": "Foo"}) 559 | ``` 560 | """ 561 | ... 562 | 563 | 564 | def load_settings(base_name: str) -> Settings: 565 | """ 566 | Loads the named settings. The name should include a file name and extension, 567 | but not a path. The packages will be searched for files matching the 568 | `base_name`, and the results will be collated into the settings object. 569 | 570 | Subsequent calls to `load_settings()` with the `base_name` will return the 571 | same object, and not load the settings from disk again. 572 | """ 573 | ... 574 | 575 | 576 | def save_settings(base_name: str) -> None: 577 | """Flushes any in-memory changes to the named settings object to disk.""" 578 | ... 579 | 580 | 581 | def set_timeout(f: Callback0, timeout_ms: float = 0) -> None: 582 | """ 583 | Schedules a function to be called in the future. Sublime Text will block 584 | while the function is running. 585 | """ 586 | ... 587 | 588 | 589 | def set_timeout_async(f: Callback0, timeout_ms: float = 0) -> None: 590 | """ 591 | Schedules a function to be called in the future. The function will be 592 | called in a worker thread, and Sublime Text will not block while the 593 | function is running. 594 | """ 595 | ... 596 | 597 | 598 | def active_window() -> Window: 599 | """Returns the most recently used window.""" 600 | ... 601 | 602 | 603 | def windows() -> List[Window]: 604 | """Returns a list of all the open windows.""" 605 | ... 606 | 607 | 608 | def get_macro() -> List[CommandArgsDict]: 609 | """ 610 | Returns a list of the commands and args that compromise the currently recorded macro. 611 | Each dict will contain the keys "command" and "args". 612 | """ 613 | ... 614 | 615 | 616 | def project_history() -> List[str]: 617 | """ 618 | Returns paths of recently opened `.sublime-project` / `.sublime-workspace` files. 619 | 620 | @version ST(>=4145) 621 | """ 622 | ... 623 | 624 | 625 | def folder_history() -> List[str]: 626 | """ 627 | Returns paths of recently opened folders. 628 | 629 | @version ST(>=4145) 630 | """ 631 | ... 632 | 633 | 634 | class Window: 635 | """This class represents windows and provides an interface of methods to interact with them.""" 636 | 637 | window_id: int 638 | settings_object: None | Settings 639 | template_settings_object: None | Settings 640 | 641 | def __init__(self, id: int) -> None: 642 | ... 643 | 644 | def __hash__(self) -> int: 645 | ... 646 | 647 | def __eq__(self, other: Any) -> bool: 648 | ... 649 | 650 | def __bool__(self) -> bool: 651 | ... 652 | 653 | def __repr__(self) -> str: 654 | ... 655 | 656 | def id(self) -> int: 657 | """Returns a number that uniquely identifies this window.""" 658 | ... 659 | 660 | def is_valid(self) -> bool: 661 | """ 662 | Returns true if the `Window` is still a valid handle. 663 | Will return False for a closed window, for example. 664 | """ 665 | ... 666 | 667 | def hwnd(self) -> int: 668 | """Platform specific window handle, only returns a meaningful result under Windows OS.""" 669 | ... 670 | 671 | def active_sheet(self) -> None | Sheet: 672 | """Returns the currently focused sheet.""" 673 | ... 674 | 675 | def active_view(self) -> None | View: 676 | """Returns the currently edited view.""" 677 | ... 678 | 679 | def new_html_sheet(self, name: str, contents: str, flags: int = 0, group: int = -1) -> HtmlSheet: 680 | """ 681 | Constructs a sheet with HTML contents rendered using minihtml. 682 | 683 | @version ST(>=4065) 684 | 685 | --- 686 | 687 | - `name`: A unicode string of the sheet name, shown in tab and Open Files 688 | - `contents`: A unicode string of the HTML contents 689 | - `group`: An integer of the group to add the sheet to, -1 for the active group 690 | 691 | The `flags` is a bitwise `OR` combination of: 692 | 693 | - `sublime.TRANSIENT`: If the sheet should be transient 694 | - `sublime.ADD_TO_SELECTION`: Add the file to the currently selected sheets in this group 695 | """ 696 | ... 697 | 698 | def run_command(self, cmd: str, args: None | Dict[str, Any] = ...) -> None: 699 | """ 700 | Runs the named `WindowCommand` with the (optional) given `args`. 701 | This method is able to run any sort of command, dispatching the 702 | command via input focus. 703 | """ 704 | ... 705 | 706 | def new_file(self, flags: int = 0, syntax: str = "") -> View: 707 | """ 708 | Creates a new file, The returned view will be empty, and its 709 | `is_loaded()` method will return `True`. Flags must be either `0` or `TRANSIENT`. 710 | """ 711 | ... 712 | 713 | def open_file(self, fname: str, flags: int = 0, group: int = -1) -> View: 714 | """ 715 | Opens the named file, and returns the corresponding view. If the file is 716 | already opened, it will be brought to the front. Note that as file 717 | loading is asynchronous, operations on the returned view won't be 718 | possible until its `is_loading()` method returns `False`. 719 | 720 | --- 721 | 722 | The optional `flags` parameter is a bitwise combination of: 723 | 724 | - `ENCODED_POSITION`: Indicates the file_name should be searched for a `:row` or `:row:col` suffix 725 | - `TRANSIENT`: Open the file as a preview only: it won't have a tab assigned it until modified 726 | - `FORCE_GROUP`: don't select the file if it's opened in a different group 727 | - `ADD_TO_SELECTION` (4050): Add the file to the currently selected sheets in this group 728 | - `SEMI_TRANSIENT`: open the file in semi-transient mode 729 | - `REPLACE_MRU`: replace the active sheet in the group 730 | - `CLEAR_TO_RIGHT` (4100): unselect all files to the right of the active sheet 731 | 732 | The optional group parameter an a 0-based integer of the group to open the file within. 733 | `-1` specifies the active group. 734 | """ 735 | ... 736 | 737 | def find_open_file(self, fname: str) -> None | View: 738 | """ 739 | Finds the named file in the list of open files, and returns the 740 | corresponding `View`, or `None` if no such file is open. 741 | """ 742 | ... 743 | 744 | def file_history(self) -> List[str]: 745 | """ 746 | Returns a list of paths of recently opened files. 747 | 748 | @version ST(>=4114) 749 | """ 750 | ... 751 | 752 | def num_groups(self) -> int: 753 | """Returns the number of view groups in the window.""" 754 | ... 755 | 756 | def active_group(self) -> int: 757 | """Returns the index of the currently selected group.""" 758 | ... 759 | 760 | def focus_group(self, idx: int) -> None: 761 | """Makes the given group active.""" 762 | ... 763 | 764 | def focus_sheet(self, sheet: Sheet) -> None: 765 | """Switches to the given `sheet`.""" 766 | ... 767 | 768 | def focus_view(self, view: View) -> None: 769 | """Switches to the given `view`.""" 770 | ... 771 | 772 | def select_sheets(self, sheets: Iterable[Sheet]) -> None: 773 | ... 774 | 775 | def bring_to_front(self) -> None: 776 | """ 777 | Brings the window in front of any other windows. 778 | 779 | @version ST(>=4067) 780 | """ 781 | ... 782 | 783 | def get_sheet_index(self, sheet: Sheet) -> Tuple[int, int]: 784 | """ 785 | Returns the group, and index within the group of the `sheet`. 786 | Returns `(-1, -1)` if not found. 787 | """ 788 | ... 789 | 790 | def get_view_index(self, view: View) -> Tuple[int, int]: 791 | """ 792 | Returns the group, and index within the group of the `view`. 793 | Returns `(-1, -1)` if not found. 794 | """ 795 | ... 796 | 797 | def set_sheet_index(self, sheet: Sheet, group: int, idx: int) -> None: 798 | """Moves the `sheet` to the given `group` and index.""" 799 | ... 800 | 801 | def set_view_index(self, view: View, group: int, idx: int) -> None: 802 | """Moves the `view` to the given `group` and index.""" 803 | ... 804 | 805 | def move_sheets_to_group( 806 | self, 807 | sheets: List[Sheet], 808 | group: int, 809 | insertion_idx: int = -1, 810 | select: bool = True, 811 | ) -> bool: 812 | """ 813 | Moves all unique provided sheets to specified group at insertion index provided. 814 | If an index is not provided defaults to last index of the destination group. 815 | 816 | @version ST(>=4123) 817 | 818 | :param sheets: 819 | A List of Sheet objects 820 | 821 | :param group: 822 | An int specifying the destination group 823 | 824 | :param insertion_idx: 825 | An int specifying the insertion index 826 | 827 | :param select: 828 | A bool specifying whether the moved sheets should be selected 829 | """ 830 | ... 831 | 832 | def sheets(self) -> List[Sheet]: 833 | """Returns all open sheets in the window.""" 834 | ... 835 | 836 | def views(self, *, include_transient: bool = False) -> List[View]: 837 | """Returns all open views in the window.""" 838 | ... 839 | 840 | def selected_sheets(self) -> List[Sheet]: 841 | ... 842 | 843 | def selected_sheets_in_group(self, group: int) -> List[Sheet]: 844 | ... 845 | 846 | def active_sheet_in_group(self, group: int) -> None | Sheet: 847 | """Returns the currently focused sheet in the given `group`.""" 848 | ... 849 | 850 | def active_view_in_group(self, group: int) -> None | View: 851 | """Returns the currently edited view in the given `group`.""" 852 | ... 853 | 854 | def sheets_in_group(self, group: int) -> List[Sheet]: 855 | """Returns all open sheets in the given `group`.""" 856 | ... 857 | 858 | def views_in_group(self, group: int) -> List[View]: 859 | """Returns all open views in the given `group`.""" 860 | ... 861 | 862 | def transient_sheet_in_group(self, group: int) -> None | Sheet: 863 | """Returns the transient `Sheet` in the given `group` if any.""" 864 | ... 865 | 866 | def transient_view_in_group(self, group: int) -> None | View: 867 | """Returns the transient `View` in the given `group` if any.""" 868 | ... 869 | 870 | def promote_sheet(self, sheet: Sheet) -> None: 871 | """Promote the `sheet` parameter if semi-transient or transient.""" 872 | ... 873 | 874 | def layout(self) -> Layout: 875 | """Returns the current layout.""" 876 | ... 877 | 878 | def get_layout(self) -> Layout: 879 | """ 880 | @deprecated use `layout()` instead 881 | """ 882 | ... 883 | 884 | def set_layout(self, layout: Layout) -> None: 885 | """Changes the tile-based panel layout of view groups.""" 886 | ... 887 | 888 | def create_output_panel(self, name: str, unlisted: bool = False) -> View: 889 | """ 890 | Returns the view associated with the named output panel, creating it if required 891 | The output panel can be shown by running the `show_panel` window command, 892 | with the panel argument set to the `name` with an "output." prefix. 893 | 894 | The optional `unlisted` parameter is a boolean to control if the 895 | output panel should be listed in the panel switcher. 896 | """ 897 | ... 898 | 899 | def find_output_panel(self, name: str) -> None | View: 900 | """ 901 | Returns the view associated with the named output panel, or `None` if 902 | the output panel does not exist. 903 | """ 904 | ... 905 | 906 | def destroy_output_panel(self, name: str) -> None: 907 | """Destroys the named output panel, hiding it if currently open.""" 908 | ... 909 | 910 | def active_panel(self) -> None | str: 911 | """ 912 | Returns the name of the currently open panel, or `None` if no panel is open. 913 | Will return built-in panel names (e.g. "console", "find", etc) in addition to output panels. 914 | """ 915 | ... 916 | 917 | def panels(self) -> List[str]: 918 | """ 919 | Returns a list of the names of all panels that have not been marked as unlisted. 920 | Includes certain built-in panels in addition to output panels. 921 | """ 922 | ... 923 | 924 | def get_output_panel(self, name: str) -> View: 925 | """ 926 | @deprecated use `create_output_panel()` instead 927 | """ 928 | ... 929 | 930 | def show_input_panel( 931 | self, 932 | caption: str, 933 | initial_text: str, 934 | on_done: None | Callback1[str], 935 | on_change: None | Callback1[str], 936 | on_cancel: None | Callback0, 937 | ) -> View: 938 | """ 939 | Shows the input panel, to collect a line of input from the user 940 | `on_done` and `on_change`, if not `None`, should both be functions 941 | that expect a single string argument 942 | `on_cancel` should be `None` or a function that expects no arguments. 943 | 944 | The view used for the input widget is returned. 945 | """ 946 | ... 947 | 948 | def show_quick_panel( 949 | self, 950 | items: Sequence[QuickPanelItem | str | Sequence[str]], 951 | on_select: Callback1[int], 952 | flags: int = 0, 953 | selected_index: int = -1, 954 | on_highlight: None | Callback1[int] = None, 955 | placeholder: None | str = None, 956 | ) -> None: 957 | """ 958 | Shows a quick panel, to select an item in a list. 959 | 960 | * `items` may be a list of strings, or a list of string lists 961 | In the latter case, each entry in the quick panel will show multiple rows. 962 | 963 | * `on_select` is called when the the quick panel is finished, and should 964 | accept a single integer, specifying which item was selected, or `-1` for 965 | `none`. If flags includes `WANT_EVENT`, `on_select` should accept a second 966 | parameter, which will be a dict with the key "modifier_keys" giving 967 | access to keyboard modifiers pressed when the item was selected.. 968 | 969 | * `flags` is a bitwise OR of `MONOSPACE_FONT`, `KEEP_OPEN_ON_FOCUS_LOST` and `WANT_EVENT` 970 | 971 | * `on_highlighted`, if given, will be called every time the highlighted item in the quick panel is changed 972 | """ 973 | ... 974 | 975 | def is_sidebar_visible(self) -> bool: 976 | """Returns `True` if the sidebar will be shown when contents are available.""" 977 | ... 978 | 979 | def set_sidebar_visible(self, flag: bool) -> None: 980 | """Sets the sidebar to be shown or hidden when contents are available.""" 981 | ... 982 | 983 | def is_minimap_visible(self) -> bool: 984 | """Returns `True` if the minimap is enabled.""" 985 | ... 986 | 987 | def set_minimap_visible(self, flag: bool) -> None: 988 | """Controls the visibility of the minimap.""" 989 | ... 990 | 991 | def is_status_bar_visible(self) -> bool: 992 | """Returns `True` if the status bar will be shown.""" 993 | ... 994 | 995 | def set_status_bar_visible(self, flag: bool) -> None: 996 | """Controls the visibility of the status bar.""" 997 | ... 998 | 999 | def get_tabs_visible(self) -> bool: 1000 | """Returns `True` if tabs will be shown for open files.""" 1001 | ... 1002 | 1003 | def set_tabs_visible(self, flag: bool) -> None: 1004 | """Controls if tabs will be shown for open files.""" 1005 | ... 1006 | 1007 | def is_menu_visible(self) -> bool: 1008 | """Returns `True` if the menu is visible.""" 1009 | ... 1010 | 1011 | def set_menu_visible(self, flag: bool) -> None: 1012 | """Controls if the menu is visible.""" 1013 | ... 1014 | 1015 | def folders(self) -> List[str]: 1016 | """Returns a list of the currently open folders.""" 1017 | ... 1018 | 1019 | def project_file_name(self) -> str: 1020 | """Returns name of the currently opened project file, if any.""" 1021 | ... 1022 | 1023 | def project_data(self) -> None | Dict[str, Any]: 1024 | """ 1025 | Returns the project data associated with the current window. 1026 | The data is in the same format as the contents of a `.sublime-project` file. 1027 | """ 1028 | ... 1029 | 1030 | def set_project_data(self, v: Dict[str, Any]) -> None: 1031 | """ 1032 | Updates the project data associated with the current window. 1033 | If the window is associated with a `.sublime-project` file, the project 1034 | file will be updated on disk, otherwise the window will store the data 1035 | internally. 1036 | """ 1037 | ... 1038 | 1039 | def workspace_file_name(self) -> None | str: 1040 | """ 1041 | Returns the workspace filename of the current `Window` if possible. 1042 | 1043 | @version ST(>=4050) 1044 | """ 1045 | ... 1046 | 1047 | def settings(self) -> Settings: 1048 | """Per-window settings, the contents are persisted in the session""" 1049 | ... 1050 | 1051 | def template_settings(self) -> Settings: 1052 | """Per-window settings that are persisted in the session, and duplicated into new windows.""" 1053 | ... 1054 | 1055 | def symbol_locations( 1056 | self, 1057 | sym: str, 1058 | source: int = SYMBOL_SOURCE_ANY, 1059 | type: int = SYMBOL_TYPE_ANY, 1060 | kind_id: int = KIND_ID_AMBIGUOUS, 1061 | kind_letter: str = "", 1062 | ) -> List[SymbolLocation]: 1063 | """ 1064 | :param sym: 1065 | A unicode string of a symbol name 1066 | 1067 | :param source: 1068 | The source to query for symbols. One of the values: 1069 | - sublime.SYMBOL_SOURCE_ANY 1070 | - sublime.SYMBOL_SOURCE_INDEX 1071 | - sublime.SYMBOL_SOURCE_OPEN_FILES 1072 | 1073 | :param type: 1074 | The type of symbol to return. One of the values: 1075 | - sublime.SYMBOL_TYPE_ANY 1076 | - sublime.SYMBOL_TYPE_DEFINITION 1077 | - sublime.SYMBOL_TYPE_REFERENCE 1078 | 1079 | :param kind_id: 1080 | The kind to filter the list by. One of the values: 1081 | - sublime.KIND_ID_AMBIGUOUS 1082 | - sublime.KIND_ID_KEYWORD 1083 | - sublime.KIND_ID_TYPE 1084 | - sublime.KIND_ID_FUNCTION 1085 | - sublime.KIND_ID_NAMESPACE 1086 | - sublime.KIND_ID_NAVIGATION 1087 | - sublime.KIND_ID_MARKUP 1088 | - sublime.KIND_ID_VARIABLE 1089 | - sublime.KIND_ID_SNIPPET 1090 | 1091 | :param kind_letter: 1092 | A unicode character of the kind letter to filter the list by. 1093 | 1094 | :return: 1095 | A list of sublime.SymbolLocation() objects. 1096 | """ 1097 | ... 1098 | 1099 | def lookup_symbol_in_index(self, sym: str) -> List[Location]: 1100 | """ 1101 | Returns all locations where the symbol `sym` is defined across files in the current project. 1102 | 1103 | @deprecated Use `symbol_locations()` when possible. 1104 | """ 1105 | ... 1106 | 1107 | def lookup_symbol_in_open_files(self, sym: str) -> List[Location]: 1108 | """ 1109 | Returns all locations where the symbol `sym` is defined across open files. 1110 | 1111 | @deprecated Use `symbol_locations()` when possible. 1112 | """ 1113 | ... 1114 | 1115 | def lookup_references_in_index(self, sym: str) -> List[Location]: 1116 | """ 1117 | Returns all files and locations where the symbol `sym` is referenced, 1118 | using the symbol index. 1119 | """ 1120 | ... 1121 | 1122 | def lookup_references_in_open_files(self, sym: str) -> List[Location]: 1123 | """ 1124 | Returns all files and locations where the symbol `sym` is referenced, 1125 | searching through open files. 1126 | """ 1127 | ... 1128 | 1129 | def extract_variables(self) -> Dict[str, str]: 1130 | """ 1131 | Returns a dictionary of strings populated with contextual keys: 1132 | 1133 | - `file_base_name` 1134 | - `file_extension` 1135 | - `file_name` 1136 | - `file_path` 1137 | - `file` 1138 | - `folder` 1139 | - `packages` 1140 | - `platform` 1141 | - `project_base_name` 1142 | - `project_extension`. 1143 | - `project_name` 1144 | - `project_path` 1145 | - `project` 1146 | 1147 | This dict is suitable for passing to `sublime.expand_variables()`. 1148 | """ 1149 | ... 1150 | 1151 | def status_message(self, msg: str) -> None: 1152 | """Show a message in the status bar""" 1153 | ... 1154 | 1155 | 1156 | class Edit: 1157 | """ 1158 | `Edit` objects have no functions, they exist to group buffer modifications. 1159 | 1160 | `Edit` objects are passed to `TextCommands`, and can not be created by the 1161 | user. Using an invalid `Edit` object, or an `Edit` object from a different view, 1162 | will cause the functions that require them to fail. 1163 | """ 1164 | 1165 | edit_token: int 1166 | 1167 | def __init__(self, token: int) -> None: 1168 | ... 1169 | 1170 | def __repr__(self) -> str: 1171 | ... 1172 | 1173 | 1174 | class Region: 1175 | """Represents an area of the buffer. Empty regions, where `a == b` are valid.""" 1176 | 1177 | a: int 1178 | b: int 1179 | xpos: int 1180 | 1181 | def __init__(self, a: int, b: None | int = None, xpos: int = -1) -> None: 1182 | ... 1183 | 1184 | def __iter__(self) -> Iterator[int]: 1185 | ... 1186 | 1187 | def __str__(self) -> str: 1188 | ... 1189 | 1190 | def __repr__(self) -> str: 1191 | ... 1192 | 1193 | def __len__(self) -> int: 1194 | ... 1195 | 1196 | def __eq__(self, rhs: Any) -> bool: 1197 | ... 1198 | 1199 | def __lt__(self, rhs: Region) -> bool: 1200 | ... 1201 | 1202 | def __contains__(self, v: Region | Point) -> bool: 1203 | ... 1204 | 1205 | def to_tuple(self) -> Tuple[Point, Point]: 1206 | """ 1207 | Returns a 2-element tuple of: 1208 | 1209 | - `a`: an `int` 1210 | - `b`: an `int` 1211 | 1212 | Use this to uniquely identify a region in a set or similar. 1213 | Regions can't be used for that directly as they may be mutated. 1214 | 1215 | @version ST(>=4075) 1216 | """ 1217 | ... 1218 | 1219 | def empty(self) -> bool: 1220 | """Returns `True` if `begin() == end()`.""" 1221 | ... 1222 | 1223 | def begin(self) -> int: 1224 | """Returns the minimum of `a` and `b`.""" 1225 | ... 1226 | 1227 | def end(self) -> int: 1228 | """Returns the maximum of `a` and `b`.""" 1229 | ... 1230 | 1231 | def size(self) -> int: 1232 | """Returns the number of characters spanned by the region.""" 1233 | ... 1234 | 1235 | def contains(self, x: Region | Point) -> bool: 1236 | """ 1237 | If `x` is a region, returns `True` if it's a subset. 1238 | If `x` is a point, returns `True` if `begin() <= x <= end()`. 1239 | """ 1240 | ... 1241 | 1242 | def cover(self, rhs: Region) -> Region: 1243 | """Returns a `Region` spanning both this and the given regions.""" 1244 | ... 1245 | 1246 | def intersection(self, rhs: Region) -> Region: 1247 | """Returns the set intersection of the two regions.""" 1248 | ... 1249 | 1250 | def intersects(self, rhs: Region) -> bool: 1251 | """ 1252 | Returns `True` if `self == rhs` or both include one or more 1253 | positions in common. 1254 | """ 1255 | ... 1256 | 1257 | 1258 | class HistoricPosition: 1259 | """ 1260 | Provides a snapshot of the row and column info for a point, before changes were made to a `View`. 1261 | This is primarily useful for replaying changes to a document. 1262 | """ 1263 | 1264 | pt: Point 1265 | row: int 1266 | col: int 1267 | col_utf16: int 1268 | col_utf8: int 1269 | 1270 | def __init__(self, pt: Point, row: int, col: int, col_u16: int, col_u8: int) -> None: 1271 | ... 1272 | 1273 | def __repr__(self) -> str: 1274 | ... 1275 | 1276 | 1277 | class TextChange: 1278 | """ 1279 | Represents a change that occured to the text of a `View`. 1280 | This is primarily useful for replaying changes to a document. 1281 | """ 1282 | 1283 | a: HistoricPosition 1284 | b: HistoricPosition 1285 | len_utf16: int 1286 | len_utf8: int 1287 | str: Str 1288 | 1289 | def __init__(self, pa: HistoricPosition, pb: HistoricPosition, s: Str) -> None: 1290 | ... 1291 | 1292 | def __repr__(self) -> Str: 1293 | ... 1294 | 1295 | 1296 | class Selection(Reversible[Region]): 1297 | """ 1298 | Maintains a set of Regions, ensuring that none overlap. 1299 | The regions are kept in sorted order. 1300 | """ 1301 | 1302 | view_id: int 1303 | 1304 | def __init__(self, id: int) -> None: 1305 | ... 1306 | 1307 | def __iter__(self) -> Iterator[Region]: 1308 | ... 1309 | 1310 | def __len__(self) -> int: 1311 | ... 1312 | 1313 | def __getitem__(self, index: int) -> Region: 1314 | ... 1315 | 1316 | def __delitem__(self, index: int) -> None: 1317 | ... 1318 | 1319 | def __eq__(self, rhs: Any) -> bool: 1320 | ... 1321 | 1322 | def __lt__(self, rhs: Selection) -> bool: 1323 | ... 1324 | 1325 | def __bool__(self) -> bool: 1326 | ... 1327 | 1328 | def __str__(self) -> str: 1329 | ... 1330 | 1331 | def __repr__(self) -> str: 1332 | ... 1333 | 1334 | def __reversed__(self) -> Iterator[Region]: 1335 | ... 1336 | 1337 | def is_valid(self) -> bool: 1338 | """Determines if this `Selection` object is still valid.""" 1339 | ... 1340 | 1341 | def clear(self) -> None: 1342 | """Removes all regions.""" 1343 | ... 1344 | 1345 | def add(self, x: Region | Point) -> None: 1346 | """ 1347 | Adds the given region or point. It will be merged with any intersecting 1348 | regions already contained within the set. 1349 | """ 1350 | ... 1351 | 1352 | def add_all(self, regions: Iterable[Region | Point]) -> None: 1353 | """Adds all `regions` in the given list or tuple.""" 1354 | ... 1355 | 1356 | def subtract(self, region: Region) -> None: 1357 | """Subtracts the `region` from all regions in the set.""" 1358 | ... 1359 | 1360 | def contains(self, region: Region) -> None: 1361 | """ 1362 | Returns `True` if the given `region` is a subset. 1363 | 1364 | @deprecated use the `in` operator instead 1365 | """ 1366 | ... 1367 | 1368 | 1369 | def make_sheet(sheet_id: int) -> Sheet: 1370 | """Create a `Sheet` object with the given ID.""" 1371 | 1372 | 1373 | class Sheet: 1374 | """ 1375 | Represents a content container, i.e. a tab, within a window. 1376 | Sheets may contain a `View`, or an image preview. 1377 | """ 1378 | 1379 | sheet_id: int 1380 | 1381 | def __init__(self, id: int) -> None: 1382 | ... 1383 | 1384 | def __hash__(self) -> int: 1385 | ... 1386 | 1387 | def __eq__(self, other: Any) -> bool: 1388 | ... 1389 | 1390 | def __repr__(self) -> str: 1391 | ... 1392 | 1393 | def id(self) -> int: 1394 | """Returns a number that uniquely identifies this sheet.""" 1395 | ... 1396 | 1397 | def window(self) -> None | Window: 1398 | """ 1399 | Returns the window containing the sheet. 1400 | May be `None` if the sheet has been closed. 1401 | """ 1402 | ... 1403 | 1404 | def view(self) -> None | View: 1405 | """ 1406 | Returns the view contained within the sheet. May be `None` if the 1407 | sheet is an image preview, or the view has been closed. 1408 | """ 1409 | ... 1410 | 1411 | def file_name(self) -> None | str: 1412 | """ 1413 | The full name file the file associated with the buffer, 1414 | or None if it doesn't exist on disk. 1415 | 1416 | @version ST(>=4050) 1417 | """ 1418 | ... 1419 | 1420 | def is_semi_transient(self) -> bool: 1421 | """Determines if this view is semi-transient or not.""" 1422 | ... 1423 | 1424 | def is_transient(self) -> bool: 1425 | """Determines if this view is transient or not.""" 1426 | ... 1427 | 1428 | def group(self) -> int: 1429 | """The (layout) group that the sheet is contained within.""" 1430 | ... 1431 | 1432 | def close(self, on_close: None | Callable[[bool], None] = lambda did_close: None) -> None: 1433 | """Closes the sheet.""" 1434 | ... 1435 | 1436 | 1437 | class TextSheet(Sheet): 1438 | sheet_id: int 1439 | 1440 | def __repr__(self) -> str: 1441 | ... 1442 | 1443 | def set_name(self, name: str) -> None: 1444 | """Sets the name of this `Sheet`.""" 1445 | ... 1446 | 1447 | 1448 | class ImageSheet(Sheet): 1449 | sheet_id: int 1450 | 1451 | def __repr__(self) -> str: 1452 | ... 1453 | 1454 | 1455 | class HtmlSheet(Sheet): 1456 | sheet_id: int 1457 | 1458 | def __repr__(self) -> str: 1459 | ... 1460 | 1461 | def set_name(self, name: str) -> None: 1462 | """Sets the name of this `Sheet`.""" 1463 | ... 1464 | 1465 | def set_contents(self, contents: str) -> None: 1466 | """Sets the content of this `Sheet`.""" 1467 | ... 1468 | 1469 | 1470 | class ContextStackFrame: 1471 | """ 1472 | @version ST(>=4127) 1473 | """ 1474 | 1475 | context_name: str 1476 | source_file: str 1477 | source_location: Tuple[int, int] 1478 | 1479 | def __init__(self, context_name: str, source_file: str, source_location: Tuple[int, int]) -> None: 1480 | ... 1481 | 1482 | def __repr__(self) -> str: 1483 | ... 1484 | 1485 | 1486 | class View: 1487 | """ 1488 | Represents a view into a text buffer. Note that multiple views may refer to 1489 | the same buffer, but they have their own unique selection and geometry 1490 | """ 1491 | 1492 | view_id: int 1493 | selection: Selection 1494 | settings_object: Settings 1495 | 1496 | def __init__(self, id: int) -> None: 1497 | ... 1498 | 1499 | def __len__(self) -> int: 1500 | ... 1501 | 1502 | def __hash__(self) -> int: 1503 | ... 1504 | 1505 | def __eq__(self, other: Any) -> bool: 1506 | ... 1507 | 1508 | def __bool__(self) -> bool: 1509 | ... 1510 | 1511 | def __repr__(self) -> str: 1512 | ... 1513 | 1514 | def id(self) -> int: 1515 | """Returns a number that uniquely identifies this view.""" 1516 | ... 1517 | 1518 | def buffer_id(self) -> int: 1519 | """Returns a number that uniquely identifies the buffer underlying this view.""" 1520 | ... 1521 | 1522 | def buffer(self) -> Buffer: 1523 | """Returns the Buffer object which is associated with this view.""" 1524 | ... 1525 | 1526 | def sheet_id(self) -> int: 1527 | """Returns the sheet ID of this view or `0` if not part of a sheet.""" 1528 | ... 1529 | 1530 | def sheet(self) -> None | Sheet: 1531 | """Returns the sheet for this view, if displayed in a sheet.""" 1532 | ... 1533 | 1534 | def element(self) -> None | str: 1535 | """ 1536 | Returns `None` for normal views, for views that comprise part of the UI, 1537 | a `str` is returned from the following list: 1538 | 1539 | - `"console:input"`: The console input 1540 | - `"goto_anything:input"`: The input for the Goto Anything 1541 | - `"command_palette:input"`: The input for the Command Palette 1542 | - `"find:input"`: The input for the Find panel 1543 | - `"incremental_find:input"`: The input for the Incremental Find panel 1544 | - `"replace:input:find"`: The Find input for the Replace panel 1545 | - `"replace:input:replace"`: The Replace input for the Replace panel 1546 | - `"find_in_files:input:find"`: The Find input for the Find in Files panel 1547 | - `"find_in_files:input:location"`: The Where input for the Find in Files panel 1548 | - `"find_in_files:input:replace"`: The Replace input for the Find in Files panel 1549 | - `"find_in_files:output"`: The output panel for Find in Files (buffer or output panel) 1550 | - `"input:input"`: The input for the Input panel 1551 | - `"exec:output"`: The output for the exec command 1552 | - `"output:output"`: A general output panel 1553 | 1554 | The console output, indexer status output and license input controls are not accessible via the API. 1555 | 1556 | @version ST(>=4050) 1557 | """ 1558 | ... 1559 | 1560 | def is_valid(self) -> bool: 1561 | """ 1562 | Returns true if this View is still a valid handle. 1563 | Will return False for a closed view, for example. 1564 | """ 1565 | ... 1566 | 1567 | def is_primary(self) -> bool: 1568 | """ 1569 | Returns `True` if this view is the primary view into a file. 1570 | Will only be `False` if the user has opened multiple views into a file. 1571 | """ 1572 | ... 1573 | 1574 | def window(self) -> None | Window: 1575 | """ 1576 | Returns a reference to the window containing this view. 1577 | May be `None` if this view has been closed. 1578 | """ 1579 | ... 1580 | 1581 | def clones(self) -> List[View]: 1582 | """Gets a list of all the other views with the same buffer.""" 1583 | ... 1584 | 1585 | def file_name(self) -> None | str: 1586 | """ 1587 | The full name file the file associated with the buffer, or `None` if it 1588 | doesn't exist on disk. 1589 | """ 1590 | ... 1591 | 1592 | def close(self, on_close: None | Callable[[bool], None] = lambda did_close: None) -> bool: 1593 | """Closes this view.""" 1594 | ... 1595 | 1596 | def retarget(self, new_fname: str) -> None: 1597 | """ 1598 | Assigns this view to the file. 1599 | 1600 | You may want to run a `revert` command to reload the file content after that. 1601 | """ 1602 | ... 1603 | 1604 | def name(self) -> str: 1605 | """The name assigned to the buffer, if any.""" 1606 | ... 1607 | 1608 | def set_name(self, name: str) -> None: 1609 | """Assigns a `name` to the buffer.""" 1610 | ... 1611 | 1612 | def reset_reference_document(self) -> None: 1613 | """ 1614 | Clears the state of the incremental diff for this view. 1615 | 1616 | @version ST(>=3190) 1617 | """ 1618 | ... 1619 | 1620 | def set_reference_document(self, reference: str) -> None: 1621 | """ 1622 | Uses the string reference to calculate the initial diff for the incremental diff. 1623 | 1624 | @version ST(>=3186) 1625 | """ 1626 | ... 1627 | 1628 | def is_loading(self) -> bool: 1629 | """Returns `True` if the buffer is still loading from disk, and not ready for use.""" 1630 | ... 1631 | 1632 | def is_dirty(self) -> bool: 1633 | """Returns `True` if there are any unsaved modifications to the buffer.""" 1634 | ... 1635 | 1636 | def is_read_only(self) -> bool: 1637 | """Returns `True` if the buffer may not be modified.""" 1638 | ... 1639 | 1640 | def set_read_only(self, read_only: bool) -> None: 1641 | """Sets the read only property on the buffer.""" 1642 | ... 1643 | 1644 | def is_scratch(self) -> bool: 1645 | """ 1646 | Returns `True` if the buffer is a scratch buffer. Scratch buffers 1647 | never report as being dirty. 1648 | """ 1649 | ... 1650 | 1651 | def set_scratch(self, scratch: bool) -> None: 1652 | """ 1653 | Sets the scratch flag on the text buffer. When a modified scratch buffer 1654 | is closed, it will be closed without prompting to save. 1655 | """ 1656 | ... 1657 | 1658 | def encoding(self) -> str: 1659 | """Returns the encoding currently associated with the file.""" 1660 | ... 1661 | 1662 | def set_encoding(self, encoding_name: str) -> None: 1663 | """Applies a new encoding to the file. This encoding will be used the next time the file is saved.""" 1664 | ... 1665 | 1666 | def line_endings(self) -> str: 1667 | """Returns the line endings used by the current file.""" 1668 | ... 1669 | 1670 | def set_line_endings(self, line_ending_name: str) -> None: 1671 | """Sets the line endings that will be applied when next saving.""" 1672 | ... 1673 | 1674 | def size(self) -> int: 1675 | """Returns the number of character in the file.""" 1676 | ... 1677 | 1678 | def begin_edit(self, edit_token: int, cmd: str, args: None | Dict[str, Any] = None) -> Edit: 1679 | ... 1680 | 1681 | def end_edit(self, edit: Edit) -> None: 1682 | ... 1683 | 1684 | def is_in_edit(self) -> bool: 1685 | ... 1686 | 1687 | def insert(self, edit: Edit, pt: Point, text: str) -> int: 1688 | """ 1689 | Inserts the given string in the buffer at the specified point 1690 | Returns the number of characters inserted, this may be different if 1691 | tabs are being translated into spaces in the current buffer. 1692 | """ 1693 | ... 1694 | 1695 | def erase(self, edit: Edit, r: Region) -> None: 1696 | """Erases the contents of the region from the buffer.""" 1697 | ... 1698 | 1699 | def replace(self, edit: Edit, r: Region, text: str) -> None: 1700 | """Replaces the contents of the region with the given string.""" 1701 | ... 1702 | 1703 | def change_count(self) -> int: 1704 | """ 1705 | Returns the current change count. Each time the buffer is modified, 1706 | the change count is incremented. The change count can be used to 1707 | determine if the buffer has changed since the last it was inspected. 1708 | """ 1709 | ... 1710 | 1711 | def change_id(self) -> Tuple[int, int, int]: 1712 | """ 1713 | Returns a 3-element tuple that can be passed to `transform_region_from()` 1714 | to obtain a region equivalent to a region of the `View` in the past. 1715 | 1716 | This is primarily useful for plugins providing text modification that 1717 | must operate in an asynchronous fashion and must be able to handle the 1718 | view contents changing between the request and response. 1719 | 1720 | @version ST(>=4069) 1721 | """ 1722 | ... 1723 | 1724 | def transform_region_from(self, r: Region, when: Tuple[int, int, int]) -> Region: 1725 | """ 1726 | Transforms a region from a previous point in time to an equivalent 1727 | region in the current state of the `View`. The `when` must have been 1728 | obtained from `change_id()` at the point in time the region is from. 1729 | 1730 | @version ST(>=4069) 1731 | """ 1732 | ... 1733 | 1734 | def run_command(self, cmd: str, args: None | Dict[str, Any] = None) -> None: 1735 | """Runs the named `TextCommand` with the (optional) given `args`.""" 1736 | ... 1737 | 1738 | def sel(self) -> Selection: 1739 | """Returns a reference to the selection""" 1740 | ... 1741 | 1742 | def substr(self, x: Region | Point) -> str: 1743 | """ 1744 | Returns the content of the given region. 1745 | 1746 | - If `x` is a `Region`, returns it's contents as a string. 1747 | - If `x` is a point, returns the character to it's right. 1748 | """ 1749 | ... 1750 | 1751 | def find(self, pattern: str, start_pt: int, flags: int = 0) -> Region: 1752 | """ 1753 | Returns the first region matching the regex `pattern`, starting from 1754 | `start_pt`, or `None` if it can't be found. The optional `flags` 1755 | parameter may be `LITERAL`, `IGNORECASE`, or the two 1756 | ORed together. 1757 | 1758 | If there is no match, `Region(-1, -1)` will be returned. 1759 | """ 1760 | ... 1761 | 1762 | def find_all( 1763 | self, 1764 | pattern: str, 1765 | flags: int = 0, 1766 | fmt: None | str = None, 1767 | extractions: None | Sequence[str] = None, 1768 | ) -> List[Region]: 1769 | """ 1770 | Returns all (non-overlapping) regions matching the regex `pattern`. 1771 | The optional `flags` parameter may be `LITERAL`, 1772 | `IGNORECASE`, or the two ORed together. If a format string is 1773 | given, then all matches will be formatted with the formatted string 1774 | and placed into the `extractions` list. 1775 | """ 1776 | ... 1777 | 1778 | def settings(self) -> Settings: 1779 | """ 1780 | Returns a reference to this view's `Settings` object. Any changes to this 1781 | `Settings` object will be private to this view. 1782 | """ 1783 | ... 1784 | 1785 | def meta_info(self, key: str, pt: Point) -> Dict[str, Any]: 1786 | ... 1787 | 1788 | def extract_tokens_with_scopes(self, r: Region) -> List[Tuple[Vector, str]]: 1789 | """ 1790 | Gets the scope information for the given region. 1791 | 1792 | The returned value is like 1793 | ```python 1794 | [(Region(0, 6), 'source.python meta.statement...'), ...] 1795 | ``` 1796 | """ 1797 | ... 1798 | 1799 | def extract_scope(self, pt: Point) -> Region: 1800 | """ 1801 | Returns the extent of the syntax scope name assigned to the 1802 | character at the given point. 1803 | """ 1804 | ... 1805 | 1806 | def expand_to_scope(self, pt: Point, selector: str) -> None | Region: 1807 | """ 1808 | Expand the point to a region by the selector. 1809 | 1810 | @version ST(>=4130) 1811 | """ 1812 | ... 1813 | 1814 | def scope_name(self, pt: Point) -> str: 1815 | """Returns the syntax scope name assigned to the character at the given point""" 1816 | ... 1817 | 1818 | def context_backtrace(self, pt: Point) -> List[ContextStackFrame]: 1819 | """ 1820 | Returns a list of the contexts on the stack at the specified point. 1821 | 1822 | Very slow but useful for debugging a syntax definition. 1823 | """ 1824 | ... 1825 | 1826 | def match_selector(self, pt: Point, selector: str) -> bool: 1827 | """ 1828 | Checks the `selector` against the scope at the given point 1829 | returning a bool if they match. 1830 | """ 1831 | ... 1832 | 1833 | def score_selector(self, pt: Point, selector: str) -> int: 1834 | """ 1835 | Matches the `selector` against the scope at the given point, returning a score 1836 | A score of 0 means no match, above 0 means a match. Different selectors may 1837 | be compared against the same scope: a higher score means the selector 1838 | is a better match for the scope. 1839 | """ 1840 | ... 1841 | 1842 | def find_by_selector(self, selector: str) -> List[Region]: 1843 | """ 1844 | Finds all regions in the file matching the given `selector`, 1845 | returning them as a list. 1846 | """ 1847 | ... 1848 | 1849 | def style(self) -> Dict[str, str]: 1850 | """ 1851 | Returns a dict of the global style settings for this view 1852 | All colors are normalized to the six character hex form with 1853 | a leading hash, e.g. `#ff0000`. 1854 | 1855 | @version ST(>=3050) 1856 | """ 1857 | ... 1858 | 1859 | def style_for_scope(self, scope: str) -> Dict[str, str]: 1860 | """ 1861 | Accepts a string scope name and returns a `dict` of style information, includes the keys: 1862 | 1863 | - `"foreground"` 1864 | - `"background"` (only if set) 1865 | - `"bold"` 1866 | - `"italic"` 1867 | - `"glow"` (4063) 1868 | - `"underline"` (4075) 1869 | - `"stippled_underline"` (4075) 1870 | - `"squiggly_underline"` (4075) 1871 | - `"source_line"` 1872 | - `"source_column"` 1873 | - `"source_file"` 1874 | 1875 | The foreground and background colors are normalized to the six character hex form 1876 | with a leading hash, e.g. `#ff0000`. 1877 | """ 1878 | ... 1879 | 1880 | def indented_region(self, pt: Point) -> Region: 1881 | """ 1882 | Returns the region that represents consecutive lines which has the same indentation level 1883 | if they are indented. If the point is not indented, returns `sublime.Region(pt, pt)`. 1884 | """ 1885 | ... 1886 | 1887 | def indentation_level(self, pt: Point) -> int: 1888 | """Returns the indentation level of the line which contains the point.""" 1889 | ... 1890 | 1891 | def has_non_empty_selection_region(self) -> bool: 1892 | """Determines if there is a non empty selection region in this view.""" 1893 | ... 1894 | 1895 | def lines(self, r: Region) -> List[Region]: 1896 | """Returns a list of lines (in sorted order) intersecting the region `r`.""" 1897 | ... 1898 | 1899 | def split_by_newlines(self, r: Region) -> List[Region]: 1900 | """Splits the region up such that each region returned exists on exactly one line.""" 1901 | ... 1902 | 1903 | def line(self, x: Region | Point) -> Region: 1904 | """ 1905 | If `x` is a region, returns a modified copy of region such that it 1906 | starts at the beginning of a line, and ends at the end of a line 1907 | Note that it may span several lines. 1908 | 1909 | If `x` is a point, returns the line that contains the point. 1910 | """ 1911 | ... 1912 | 1913 | def full_line(self, x: Region | Point) -> Region: 1914 | """As `line()`, but the region includes the trailing newline character, if any.""" 1915 | ... 1916 | 1917 | def word(self, x: Region | Point) -> Region: 1918 | """ 1919 | If `x` is a region, returns a modified copy of it such that it 1920 | starts at the beginning of a word, and ends at the end of a word. 1921 | Note that it may span several words. 1922 | 1923 | If `x` is a point, returns the word that contains it. 1924 | """ 1925 | ... 1926 | 1927 | def classify(self, pt: Point) -> int: 1928 | """ 1929 | Classifies the point `pt`, returning a bitwise OR of zero or more of these flags: 1930 | 1931 | - `CLASS_WORD_START` 1932 | - `CLASS_WORD_END` 1933 | - `CLASS_PUNCTUATION_START` 1934 | - `CLASS_PUNCTUATION_END` 1935 | - `CLASS_SUB_WORD_START` 1936 | - `CLASS_SUB_WORD_END` 1937 | - `CLASS_LINE_START` 1938 | - `CLASS_LINE_END` 1939 | - `CLASS_EMPTY_LINE` 1940 | """ 1941 | ... 1942 | 1943 | def find_by_class( 1944 | self, 1945 | pt: Point, 1946 | forward: bool, 1947 | classes: int, 1948 | separators: str = "", 1949 | sub_word_separators: str = "", 1950 | ) -> Point: 1951 | """ 1952 | Finds the next location after point that matches the given classes 1953 | If forward is `False`, searches backwards instead of forwards. 1954 | classes is a bitwise OR of the `CLASS_XXX` flags 1955 | `separators` may be passed in, to define what characters should be 1956 | considered to separate words. 1957 | 1958 | - `sub_word_separators` requires ST >= 4130 1959 | """ 1960 | ... 1961 | 1962 | def expand_by_class( 1963 | self, 1964 | x: Region | Point, 1965 | classes: int, 1966 | separators: str = "", 1967 | sub_word_separators: str = "", 1968 | ) -> Region: 1969 | """ 1970 | Expands `x` to the left and right, until each side lands on a location 1971 | that matches `classes`. classes is a bitwise OR of the 1972 | `CLASS_XXX` flags. `separators` may be passed in, to define 1973 | what characters should be considered to separate words. 1974 | 1975 | - `sub_word_separators` requires ST >= 4130 1976 | """ 1977 | ... 1978 | 1979 | def rowcol(self, tp: Point) -> Tuple[int, int]: 1980 | """Calculates the 0-based line and column numbers of the the given point.""" 1981 | ... 1982 | 1983 | def rowcol_utf8(self, tp: Point) -> Tuple[int, int]: 1984 | """ 1985 | (UTF-8) Calculates the 0-based line and column numbers of the the given point. 1986 | 1987 | @version ST(>=4069) 1988 | """ 1989 | ... 1990 | 1991 | def rowcol_utf16(self, tp: Point) -> Tuple[int, int]: 1992 | """ 1993 | (UTF-16) Calculates the 0-based line and column numbers of the the given point. 1994 | 1995 | @version ST(>=4069) 1996 | """ 1997 | ... 1998 | 1999 | def text_point(self, row: int, col: int, *, clamp_column: bool = False) -> int: 2000 | """ 2001 | Converts a row and column into a text point. 2002 | 2003 | --- 2004 | 2005 | - `clamp_column` (4075): A bool, if col should be restricted to valid values for the given row 2006 | """ 2007 | ... 2008 | 2009 | def text_point_utf8(self, row: int, col: int, *, clamp_column: bool = False) -> int: 2010 | """ 2011 | (UTF-8) Converts a row and column into a text point. 2012 | 2013 | @version ST(>=4069) 2014 | 2015 | --- 2016 | 2017 | - `clamp_column` (4075): A bool, if col should be restricted to valid values for the given row 2018 | """ 2019 | ... 2020 | 2021 | def text_point_utf16(self, row: int, col: int, *, clamp_column: bool = False) -> int: 2022 | """ 2023 | (UTF-16) Converts a row and column into a text point. 2024 | 2025 | @version ST(>=4069) 2026 | 2027 | --- 2028 | 2029 | - `clamp_column` (4075): A bool, if col should be restricted to valid values for the given row 2030 | """ 2031 | ... 2032 | 2033 | def visible_region(self) -> Region: 2034 | """Returns the approximate visible region.""" 2035 | ... 2036 | 2037 | def show( 2038 | self, 2039 | x: Selection | Region | Point, 2040 | show_surrounds: bool = True, 2041 | keep_to_left: bool = False, 2042 | animate: bool = True, 2043 | ) -> None: 2044 | """ 2045 | Scrolls this view to reveal x, which may be a Region or point. 2046 | 2047 | --- 2048 | - `x`: A point, Region or Selection to scroll this view to. 2049 | - `show_surrounds`: A bool, scroll this view far enough that surrounding conent is visible also 2050 | - `keep_to_left` (4075): A bool, if this view should be kept to the left, if horizontal scrolling is possible 2051 | - `animate` (4075): A bool, if the scroll should be animated 2052 | """ 2053 | ... 2054 | 2055 | def show_at_center(self, x: Region | Point, animate: bool = True) -> None: 2056 | """ 2057 | Scrolls this view to center on x, which may be a Region or point. 2058 | 2059 | --- 2060 | - `x`: A point, Region to scroll this view to. 2061 | - `animate` (4123): A bool, if the scroll should be animated 2062 | """ 2063 | ... 2064 | 2065 | def viewport_position(self) -> Vector: 2066 | """Returns the (x, y) scroll position of this view in layout coordinates.""" 2067 | ... 2068 | 2069 | def set_viewport_position(self, xy: Vector, animate: bool = True) -> None: 2070 | """Scrolls this view to the given position in layout coordinates.""" 2071 | ... 2072 | 2073 | def viewport_extent(self) -> Vector: 2074 | """Returns the width and height of this viewport, in layout coordinates.""" 2075 | ... 2076 | 2077 | def layout_extent(self) -> Vector: 2078 | """Returns the total height and width of the document, in layout coordinates.""" 2079 | ... 2080 | 2081 | def text_to_layout(self, tp: Point) -> Vector: 2082 | """Converts a text point to layout coordinates.""" 2083 | ... 2084 | 2085 | def text_to_window(self, tp: Point) -> Vector: 2086 | """Converts a text point to window coordinates.""" 2087 | ... 2088 | 2089 | def layout_to_text(self, xy: Vector) -> int: 2090 | """Converts layout coordinates to a text point.""" 2091 | ... 2092 | 2093 | def layout_to_window(self, xy: Vector) -> Vector: 2094 | """Converts layout coordinates to window coordinates.""" 2095 | ... 2096 | 2097 | def window_to_layout(self, xy: Vector) -> Vector: 2098 | """Converts window coordinates to layout coordinates.""" 2099 | ... 2100 | 2101 | def window_to_text(self, xy: Vector) -> int: 2102 | """Converts window coordinates to a text point.""" 2103 | ... 2104 | 2105 | def line_height(self) -> Dip: 2106 | """Returns the height of a line in layout coordinates.""" 2107 | ... 2108 | 2109 | def em_width(self) -> Dip: 2110 | """Returns the em-width of the current font in layout coordinates.""" 2111 | ... 2112 | 2113 | def is_folded(self, sr: Region) -> bool: 2114 | """Determines whether the given region is folded.""" 2115 | ... 2116 | 2117 | def folded_regions(self) -> List[Region]: 2118 | """Gets folded regions in this view.""" 2119 | ... 2120 | 2121 | def fold(self, x: Region | Sequence[Region]) -> bool: 2122 | """Folds the given regions, returning False if they were already folded.""" 2123 | ... 2124 | 2125 | def unfold(self, x: Region | Sequence[Region]) -> List[Region]: 2126 | """Unfolds all text in the region, returning the unfolded regions.""" 2127 | ... 2128 | 2129 | def add_regions( 2130 | self, 2131 | key: str, 2132 | regions: Sequence[Region], 2133 | scope: str = "", 2134 | icon: str = "", 2135 | flags: int = 0, 2136 | annotations: Sequence[str] = [], 2137 | annotation_color: str = "", 2138 | on_navigate: None | Callback1[str] = None, 2139 | on_close: None | Callback0 = None, 2140 | ) -> None: 2141 | """ 2142 | Add a set of `regions` to this view. If a set of regions already exists 2143 | with the given `key`, they will be overwritten. The `scope` is used 2144 | to source a color to draw the regions in, it should be the name of a 2145 | scope, such as "comment" or "string". If the scope is empty, the 2146 | regions won't be drawn. 2147 | 2148 | --- 2149 | 2150 | The optional `icon` name, if given, will draw the named icons in the 2151 | gutter next to each region. The `icon` will be tinted using the color 2152 | associated with the `scope`. Valid icon names are dot, circle and 2153 | bookmark. The `icon` name may also be a full package relative path 2154 | such as _Packages/Theme - Default/dot.png_. 2155 | 2156 | The optional `flags` parameter is a bitwise combination of: 2157 | 2158 | - `DRAW_EMPTY`: Draw empty regions with a vertical bar. By default, they aren't drawn at all. 2159 | - `HIDE_ON_MINIMAP`: Don't show the regions on the minimap. 2160 | - `DRAW_EMPTY_AS_OVERWRITE`: Draw empty regions with a horizontal bar instead of a vertical one. 2161 | - `DRAW_NO_FILL`: Disable filling the regions, leaving only the outline. 2162 | - `DRAW_NO_OUTLINE`: Disable drawing the outline of the regions. 2163 | - `DRAW_SOLID_UNDERLINE`: Draw a solid underline below the regions. 2164 | - `DRAW_STIPPLED_UNDERLINE`: Draw a stippled underline below the regions. 2165 | - `DRAW_SQUIGGLY_UNDERLINE`: Draw a squiggly underline below the regions. 2166 | - `PERSISTENT`: Save the regions in the session. 2167 | - `HIDDEN`: Don't draw the regions. 2168 | 2169 | The underline styles are exclusive, either zero or one of them should be given. 2170 | If using an underline, `DRAW_NO_FILL` and `DRAW_NO_OUTLINE` should generally be passed in. 2171 | 2172 | - `annotations` (4050): An optional collection of unicode strings containing HTML documents 2173 | to display along the right-hand edge of this view. 2174 | There should be the same number of annotations as regions. 2175 | - `annotation_color` (4050): A optional unicode string of the CSS color 2176 | to use when drawing the left border of the annotation. 2177 | - `on_navigate` (4050): A callback that will be passed the href when a link in an annotation is clicked. 2178 | - `on_close` (4050): A callback that will be called when the annotations are closed. 2179 | """ 2180 | ... 2181 | 2182 | def get_regions(self, key: str) -> List[Region]: 2183 | """Return the regions associated with the given `key`, if any.""" 2184 | ... 2185 | 2186 | def erase_regions(self, key: str) -> None: 2187 | """Remove the named regions.""" 2188 | ... 2189 | 2190 | def add_phantom( 2191 | self, 2192 | key: str, 2193 | region: Region, 2194 | content: str, 2195 | layout: int, 2196 | on_navigate: None | Callback1[str] = None, 2197 | ) -> int: 2198 | ... 2199 | 2200 | def erase_phantoms(self, key: str) -> None: 2201 | """Remove the named phantoms.""" 2202 | ... 2203 | 2204 | def erase_phantom_by_id(self, pid: int) -> None: 2205 | """Remove the phantom with the given phantom ID.""" 2206 | ... 2207 | 2208 | def query_phantom(self, pid: int) -> List[Tuple[int, int]]: 2209 | ... 2210 | 2211 | def query_phantoms(self, pids: Sequence[int]) -> List[Tuple[int, int]]: 2212 | ... 2213 | 2214 | def assign_syntax(self, syntax: str | Syntax) -> None: 2215 | """ 2216 | Sets the syntax for this view. 2217 | 2218 | --- 2219 | 2220 | You can use following syntax format: 2221 | 2222 | - The path of a syntax: `"Packages/Python/Python.sublime-syntax"` 2223 | - The top scope of a syntax: `"scope:source.python"` 2224 | - A `Syntax` object, which may come from other APIs. 2225 | """ 2226 | ... 2227 | 2228 | def set_syntax_file(self, syntax: str | Syntax) -> None: 2229 | """ 2230 | @deprecated Use `assign_syntax()` when possible. 2231 | """ 2232 | ... 2233 | 2234 | def syntax(self) -> None | Syntax: 2235 | """Get the syntax used by this view. May be `None`.""" 2236 | ... 2237 | 2238 | def symbols(self) -> List[Tuple[Region, str]]: 2239 | """Extract all the symbols defined in the buffer.""" 2240 | ... 2241 | 2242 | def get_symbols(self) -> List[Tuple[Region, str]]: 2243 | """ 2244 | @deprecated use `symbols()` instead. 2245 | """ 2246 | ... 2247 | 2248 | def indexed_symbols(self) -> List[Tuple[Region, str]]: 2249 | ... 2250 | 2251 | def indexed_references(self) -> List[Tuple[Region, str]]: 2252 | ... 2253 | 2254 | def symbol_regions(self) -> List[SymbolRegion]: 2255 | """Returns a list of sublime.SymbolRegion() objects for the symbols in this view.""" 2256 | ... 2257 | 2258 | def indexed_symbol_regions(self, type: int = SYMBOL_TYPE_ANY) -> List[SymbolRegion]: 2259 | """ 2260 | :param type: 2261 | The type of symbol to return. One of the values: 2262 | 2263 | - sublime.SYMBOL_TYPE_ANY 2264 | - sublime.SYMBOL_TYPE_DEFINITION 2265 | - sublime.SYMBOL_TYPE_REFERENCE 2266 | 2267 | :return: 2268 | A list of sublime.SymbolRegion() objects for the indexed symbols 2269 | in this view. 2270 | """ 2271 | ... 2272 | 2273 | def set_status(self, key: str, value: str) -> None: 2274 | """ 2275 | Adds the status `key` to this view. The value will be displayed in the 2276 | status bar, in a comma separated list of all status values, ordered by key 2277 | Setting the value to the empty string will clear the status. 2278 | """ 2279 | ... 2280 | 2281 | def get_status(self, key: str) -> str: 2282 | """Returns the previously assigned value associated with the `key`, if any.""" 2283 | ... 2284 | 2285 | def erase_status(self, key: str) -> None: 2286 | """Clears the named status.""" 2287 | ... 2288 | 2289 | def extract_completions(self, prefix: str, tp: Point = -1) -> List[str]: 2290 | ... 2291 | 2292 | def find_all_results(self) -> List[Tuple[str, int, int]]: 2293 | ... 2294 | 2295 | def find_all_results_with_text(self) -> List[Tuple[str, int, int, str]]: 2296 | ... 2297 | 2298 | def command_history( 2299 | self, 2300 | delta: int, 2301 | modifying_only: bool = False, 2302 | ) -> Tuple[None | str, None | Dict[str, Any], int]: 2303 | """ 2304 | Returns the command name, command arguments, and repeat count for the 2305 | given history entry, as stored in the undo / redo stack. 2306 | 2307 | Index 0 corresponds to the most recent command, -1 the command before 2308 | that, and so on. Positive values for `delta` indicates to look in the 2309 | redo stack for commands. If the undo / redo history doesn't extend far 2310 | enough, then `(None, None, 0)` will be returned. 2311 | 2312 | Setting `modifying_only` to `True` will only return entries that 2313 | modified the buffer 2314 | """ 2315 | ... 2316 | 2317 | def overwrite_status(self) -> bool: 2318 | """Returns the overwrite status, which the user normally toggles via the insert key.""" 2319 | ... 2320 | 2321 | def set_overwrite_status(self, value: bool) -> None: 2322 | """Sets the overwrite status.""" 2323 | ... 2324 | 2325 | def show_popup_menu(self, items: Sequence[str], on_select: Callback1[int], flags: int = 0) -> None: 2326 | """ 2327 | Shows a pop up menu at the caret, to select an item in a list. `on_done` 2328 | will be called once, with the index of the selected item. If the pop up 2329 | menu was cancelled, `on_done` will be called with an argument of -1. 2330 | 2331 | --- 2332 | 2333 | - `items`: a list of strings. 2334 | - `flags`: currently unused. 2335 | """ 2336 | ... 2337 | 2338 | def show_popup( 2339 | self, 2340 | content: str, 2341 | flags: int = 0, 2342 | location: int = -1, 2343 | max_width: int = 320, 2344 | max_height: int = 240, 2345 | on_navigate: None | Callback1[str] = None, 2346 | on_hide: None | Callback0 = None, 2347 | ) -> None: 2348 | """ 2349 | Shows a popup displaying HTML content. 2350 | 2351 | --- 2352 | 2353 | `flags` is a bitwise combination of the following: 2354 | 2355 | - `COOPERATE_WITH_AUTO_COMPLETE`: Causes the popup to display next to the auto complete menu 2356 | - `HIDE_ON_MOUSE_MOVE`: Causes the popup to hide when the mouse is moved, clicked or scrolled 2357 | - `HIDE_ON_MOUSE_MOVE_AWAY`: Causes the popup to hide when the mouse is moved 2358 | (unless towards the popup), or when clicked or scrolled 2359 | - `KEEP_ON_SELECTION_MODIFIED` (4075): Prevent the popup from hiding when the selection is modified 2360 | - `HIDE_ON_CHARACTER_EVENT` (4075): hide the popup when a character is typed 2361 | 2362 | --- 2363 | 2364 | - `location`: Sets the location of the popup, if -1 (default) will display 2365 | the popup at the cursor, otherwise a text point should be passed. 2366 | - `max_width` and `max_height`: Set the maximum dimensions for the popup, 2367 | after which scroll bars will be displayed. 2368 | - `on_navigate`: A callback that should accept a string contents of the 2369 | href attribute on the link the user clicked. 2370 | - `on_hide`: Called when the popup is hidden 2371 | """ 2372 | ... 2373 | 2374 | def update_popup(self, content: str) -> None: 2375 | """Updates the contents of the currently visible popup.""" 2376 | ... 2377 | 2378 | def is_popup_visible(self) -> bool: 2379 | """Returns if the popup is currently shown.""" 2380 | ... 2381 | 2382 | def hide_popup(self) -> None: 2383 | """Hides the popup""" 2384 | ... 2385 | 2386 | def is_auto_complete_visible(self) -> bool: 2387 | """Returns wether the auto complete menu is currently visible.""" 2388 | ... 2389 | 2390 | def preserve_auto_complete_on_focus_lost(self) -> None: 2391 | """ 2392 | Sets the auto complete popup state to be preserved the next time this View loses focus. 2393 | When this View regains focus, the auto complete window will be re-shown, 2394 | with the previously selected entry pre-selected. 2395 | 2396 | @version ST(>=4073) 2397 | """ 2398 | ... 2399 | 2400 | def export_to_html( 2401 | self, 2402 | regions: None | Region | Sequence[Region] = None, 2403 | minihtml: bool = False, 2404 | enclosing_tags: bool = False, 2405 | font_size: bool = True, 2406 | font_family: bool = True, 2407 | ) -> str: 2408 | """ 2409 | Export this view as HTML. 2410 | 2411 | :param regions: 2412 | The region(s) to export. By default it will export the whole view. 2413 | Can be given either a list of regions or a single region. 2414 | :param minihtml: 2415 | Whether the exported HTML should be compatible with the Sublime Text 2416 | HTML implementation. 2417 | :param enclosing_tags: 2418 | Whether to enclose the exported HTML in a tag with top-level 2419 | styling. 2420 | :param font_size: 2421 | Whether to include the font size in the top level styling. Only 2422 | applies when enclosing_tags=True is provided. 2423 | :param font_family: 2424 | Whether to include the font family in the top level styling. Only 2425 | applies when enclosing_tags=True is provided. 2426 | 2427 | :return: 2428 | A string containing the exported HTML. 2429 | """ 2430 | ... 2431 | 2432 | def clear_undo_stack(self) -> None: 2433 | """ 2434 | Clear the undo stack. 2435 | 2436 | Cannot be used in a `sublime_plugin.TextCommand`, which will modify the undo stack. 2437 | 2438 | @version ST(>=4114) 2439 | """ 2440 | ... 2441 | 2442 | 2443 | def _buffers() -> List[Buffer]: 2444 | """Returns all available Buffer objects""" 2445 | ... 2446 | 2447 | 2448 | class Buffer: 2449 | buffer_id: int 2450 | 2451 | def __init__(self, id: int) -> None: 2452 | ... 2453 | 2454 | def __hash__(self) -> int: 2455 | ... 2456 | 2457 | def __repr__(self) -> str: 2458 | ... 2459 | 2460 | def id(self) -> int: 2461 | """Gets the ID of this buffer""" 2462 | ... 2463 | 2464 | def file_name(self) -> None | str: 2465 | """Gets the file name of this buffer if any, `None` otherwise""" 2466 | ... 2467 | 2468 | def views(self) -> List[View]: 2469 | """Returns all views which are attched to this Buffer""" 2470 | ... 2471 | 2472 | def primary_view(self) -> View: 2473 | """Returns the primary view which is attched to this Buffer""" 2474 | ... 2475 | 2476 | 2477 | class Settings: 2478 | settings_id: int 2479 | 2480 | def __init__(self, id: int) -> None: 2481 | ... 2482 | 2483 | def __getitem__(self, key: str) -> Any: 2484 | # The "Any" annotation should be "StValue" but it will cause annoying errors 2485 | # when casting the returned value. So we probably just use "Any"... 2486 | ... 2487 | 2488 | def __setitem__(self, key: str, value: Any) -> None: 2489 | ... 2490 | 2491 | def __delitem__(self, key: str) -> None: 2492 | ... 2493 | 2494 | def __contains__(self, key: str) -> bool: 2495 | ... 2496 | 2497 | def __repr__(self) -> str: 2498 | ... 2499 | 2500 | def to_dict(self) -> Dict[str, Any]: 2501 | """ 2502 | Return the settings as a dict. This is not very fast. 2503 | 2504 | @version ST(>=4078), Python(3.8) 2505 | """ 2506 | ... 2507 | 2508 | def setdefault(self, key: str, value: Any) -> Any: 2509 | """ 2510 | Returns the value of the item with the specified key. 2511 | 2512 | If the key does not exist, insert the key, with the specified value, see example below. 2513 | """ 2514 | # The "Any" annotation should be "StValue" but it will cause annoying errors 2515 | # when casting the returned value. So we probably just use "Any"... 2516 | ... 2517 | 2518 | def update( 2519 | self, 2520 | pairs: Dict[str, Any] | Mapping[str, Any] | Iterable[Tuple[str, Any]] | HasKeysMethod = tuple(), 2521 | /, 2522 | **kwargs: Any, 2523 | ) -> None: 2524 | """ 2525 | Update the settings from pairs, which may be any of the following: 2526 | 2527 | - A `dict` 2528 | - An implementation of `collections.abc.Mapping` 2529 | - An object that has a `keys()` method 2530 | - An object that provides key/value pairs when iterated 2531 | - Keyword arguments 2532 | 2533 | @version ST(>=4078), Python(3.8) 2534 | """ 2535 | ... 2536 | 2537 | def get(self, key: str, default: None | Any = None) -> Any: 2538 | """ 2539 | Returns the named setting, or `default` if it's not defined. 2540 | If not passed, `default` will have a value of `None`. 2541 | """ 2542 | # The "Any" annotation should be "StValue" but it will cause annoying errors 2543 | # when casting the returned value. So we probably just use "Any"... 2544 | ... 2545 | 2546 | def has(self, key: str) -> bool: 2547 | """Returns `True` if the named option exists in this set of `Settings` or one of its parents.""" 2548 | ... 2549 | 2550 | def set(self, key: str, value: Any) -> None: 2551 | """Sets the named setting. Only primitive types, lists, and dicts are accepted.""" 2552 | ... 2553 | 2554 | def erase(self, key: str) -> None: 2555 | """Removes the named setting. Does not remove it from any parent `Settings`.""" 2556 | ... 2557 | 2558 | def add_on_change(self, tag: str, callback: Callback0) -> None: 2559 | """Register a `callback` to be run whenever a setting in this object is changed.""" 2560 | ... 2561 | 2562 | def clear_on_change(self, tag: str) -> None: 2563 | """Remove all callbacks registered with the given `tag`.""" 2564 | ... 2565 | 2566 | 2567 | class Phantom: 2568 | """ 2569 | Creates a phantom attached to a region 2570 | 2571 | * `content` is HTML to be processed by _minihtml_. 2572 | 2573 | * `layout` must be one of: 2574 | 2575 | - `LAYOUT_INLINE`: Display the phantom in between the region and the point following. 2576 | - `LAYOUT_BELOW`: Display the phantom in space below the current line, 2577 | left-aligned with the region. 2578 | - `LAYOUT_BLOCK`: Display the phantom in space below the current line, 2579 | left-aligned with the beginning of the line. 2580 | 2581 | * `on_navigate` is an optional callback that should accept a single string 2582 | parameter, that is the `href` attribute of the link clicked. 2583 | """ 2584 | 2585 | region: Region 2586 | content: str 2587 | layout: int 2588 | on_navigate: None | Callback1[str] 2589 | id: int 2590 | 2591 | def __init__( 2592 | self, 2593 | region: Region, 2594 | content: str, 2595 | layout: int, 2596 | on_navigate: None | Callback1[str] = None, 2597 | ) -> None: 2598 | ... 2599 | 2600 | def __eq__(self, rhs: Any) -> bool: 2601 | ... 2602 | 2603 | def __repr__(self) -> str: 2604 | ... 2605 | 2606 | def to_tuple(self) -> Tuple[Tuple[int, int], str, int, None | Callback1[str]]: 2607 | """ 2608 | Returns a 4-element tuple of: 2609 | 2610 | - `region`: as a 2-element `tuple` 2611 | - `content`: a `str` 2612 | - `layout`: an `int` 2613 | - `on_navigate`: a `callback` or `None` 2614 | 2615 | Use this to uniquely identify a phantom in a set or similar. 2616 | Phantoms can't be used for that directly as they may be mutated. 2617 | 2618 | The phantom's range will also be returned as a tuple. 2619 | 2620 | @version ST(>=4075) 2621 | """ 2622 | ... 2623 | 2624 | 2625 | class PhantomSet: 2626 | """ 2627 | A collection that manages Phantoms and the process of adding them, 2628 | updating them and removing them from the View. 2629 | """ 2630 | 2631 | view: View 2632 | key: str 2633 | phantoms: List[Phantom] 2634 | 2635 | def __init__(self, view: View, key: str = "") -> None: 2636 | ... 2637 | 2638 | def __del__(self) -> None: 2639 | ... 2640 | 2641 | def __repr__(self) -> str: 2642 | ... 2643 | 2644 | def update(self, new_phantoms: Sequence[Phantom]) -> None: 2645 | """ 2646 | phantoms should be a sequence of phantoms. 2647 | 2648 | The `region` attribute of each existing phantom in the set will be updated. 2649 | New phantoms will be added to the view and phantoms not in phantoms list will be deleted. 2650 | """ 2651 | ... 2652 | 2653 | 2654 | class Html: 2655 | data: Any 2656 | 2657 | def __init__(self, data: Any) -> None: 2658 | ... 2659 | 2660 | def __repr__(self) -> str: 2661 | ... 2662 | 2663 | 2664 | class CompletionList: 2665 | """ 2666 | Represents a list of completions, 2667 | some of which may be in the process of being asynchronously fetched. 2668 | 2669 | @version ST(>=4050) 2670 | """ 2671 | 2672 | target: None | Any 2673 | completions: List[Completion] 2674 | flags: int 2675 | 2676 | def __init__(self, completions: None | Sequence[Completion] = None, flags: int = 0) -> None: 2677 | """ 2678 | --- 2679 | 2680 | - `completions`: An optional list of completion values. 2681 | If None is passed, the method `set_completions()` must be called 2682 | before the completions will be displayed to the user. 2683 | 2684 | The parameter `flags` may be a bitwise `OR` of: 2685 | 2686 | - `sublime.INHIBIT_WORD_COMPLETIONS`: 2687 | prevent Sublime Text from showing completions based on the contents of the view 2688 | - `sublime.INHIBIT_EXPLICIT_COMPLETIONS`: 2689 | prevent Sublime Text from showing completions based on .sublime-completions files 2690 | - `sublime.DYNAMIC_COMPLETIONS` (4057): 2691 | if completions should be re-queried as the user types 2692 | - `sublime.INHIBIT_REORDER` (4074): 2693 | prevent Sublime Text from changing the completion order 2694 | """ 2695 | ... 2696 | 2697 | def __repr__(self) -> str: 2698 | ... 2699 | 2700 | def _set_target(self, target: None | Any) -> None: 2701 | ... 2702 | 2703 | def set_completions(self, completions: Sequence[Completion], flags: int = 0) -> None: 2704 | """ 2705 | Sets the list of completions, allowing the list to be displayed to the user. 2706 | 2707 | --- 2708 | 2709 | The parameter `flags` may be a bitwise `OR` of: 2710 | 2711 | - `sublime.INHIBIT_WORD_COMPLETIONS`: 2712 | prevent Sublime Text from showing completions based on the contents of the view 2713 | - `sublime.INHIBIT_EXPLICIT_COMPLETIONS`: 2714 | prevent Sublime Text from showing completions based on `.sublime-completions` files 2715 | - `sublime.DYNAMIC_COMPLETIONS` (4057): 2716 | if completions should be re-queried as the user types 2717 | - `sublime.INHIBIT_REORDER` (4074): 2718 | prevent Sublime Text from changing the completion order 2719 | """ 2720 | ... 2721 | 2722 | 2723 | class CompletionItem: 2724 | """ 2725 | Represents an available auto-completion item. 2726 | 2727 | @version ST(>=4050) 2728 | """ 2729 | 2730 | trigger: str 2731 | annotation: str 2732 | completion: Completion 2733 | completion_format: int 2734 | kind: CompletionKind 2735 | details: str 2736 | flags: int 2737 | 2738 | def __init__( 2739 | self, 2740 | trigger: str, 2741 | annotation: str = "", 2742 | completion: Completion = "", 2743 | completion_format: int = COMPLETION_FORMAT_TEXT, 2744 | kind: CompletionKind = KIND_AMBIGUOUS, 2745 | details: str = "", 2746 | ) -> None: 2747 | ... 2748 | 2749 | def __eq__(self, rhs: Any) -> bool: 2750 | ... 2751 | 2752 | def __repr__(self) -> str: 2753 | ... 2754 | 2755 | @classmethod 2756 | def snippet_completion( 2757 | cls, 2758 | trigger: str, 2759 | snippet: str, 2760 | annotation: str = "", 2761 | kind: CompletionKind = KIND_SNIPPET, 2762 | details: str = "", 2763 | ) -> CompletionItem: 2764 | """ 2765 | --- 2766 | 2767 | - `trigger`: A unicode string of the text to match against the user's input. 2768 | - `snippet`: The snippet text to insert if the item is selected. 2769 | - `annotation`: An optional unicode string of a hint to draw to the right-hand side of the trigger. 2770 | - `kind`: An optional `completion_kind` tuple that controls the presentation 2771 | in the auto-complete window (defaults to `sublime.KIND_SNIPPET`). 2772 | - `details` (4073): An optional HTML description of the completion, 2773 | shown in the detail pane at the bottom of the auto complete window. 2774 | Only supports limited inline HTML, including the tags: 2775 | ``, ``, ``, ``, ``, ``, ``, `` 2776 | """ 2777 | ... 2778 | 2779 | @classmethod 2780 | def command_completion( 2781 | cls, 2782 | trigger: str, 2783 | command: str, 2784 | args: Dict[str, Any] = {}, 2785 | annotation: str = "", 2786 | kind: CompletionKind = KIND_AMBIGUOUS, 2787 | details: str = "", 2788 | ) -> CompletionItem: 2789 | """ 2790 | --- 2791 | 2792 | - `trigger`: A unicode string of the text to match against the user's input. 2793 | - `command`: A unicode string of the command to execute 2794 | - `args`: An optional dict of args to pass to the command 2795 | - `annotation`: An optional unicode string of a hint to draw to the right-hand side of the trigger. 2796 | - `kind`: An optional completion_kind tuple that controls the presentation 2797 | in the auto-complete window - defaults to sublime.KIND_AMBIGUOUS. 2798 | - `details` (4073): An optional HTML description of the completion, 2799 | shown in the detail pane at the bottom of the auto complete window. 2800 | Only supports limited inline HTML, including the tags: 2801 | ``, ``, ``, ``, ``, ``, ``, `` 2802 | """ 2803 | ... 2804 | 2805 | 2806 | def list_syntaxes() -> List[Syntax]: 2807 | """ 2808 | Returns a list of Syntaxes for all known syntaxes. 2809 | 2810 | @version ST(>=4050) 2811 | """ 2812 | ... 2813 | 2814 | 2815 | def syntax_from_path(path: str) -> None | Syntax: 2816 | """ 2817 | Get the syntax for a specific path. 2818 | 2819 | @version ST(>=4050) 2820 | """ 2821 | ... 2822 | 2823 | 2824 | def find_syntax_by_name(name: str) -> List[Syntax]: 2825 | """ 2826 | Find syntaxes with the specified name. Name must match exactly. 2827 | 2828 | @version ST(>=4050) 2829 | """ 2830 | ... 2831 | 2832 | 2833 | def find_syntax_by_scope(scope: str) -> List[Syntax]: 2834 | """ 2835 | Find syntaxes with the specified scope. Scope must match exactly. 2836 | 2837 | @version ST(>=4050) 2838 | """ 2839 | ... 2840 | 2841 | 2842 | def find_syntax_for_file(path: str, first_line: str = "") -> None | Syntax: 2843 | """ 2844 | Returns the path to the syntax that will be used when opening a file with the name fname. 2845 | The `first_line` of file contents may also be provided if available. 2846 | 2847 | @version ST(>=4050) 2848 | """ 2849 | ... 2850 | 2851 | 2852 | class Syntax: 2853 | path: str 2854 | name: str 2855 | hidden: bool 2856 | scope: str 2857 | 2858 | def __init__(self, path: str, name: str, hidden: bool, scope: str) -> None: 2859 | ... 2860 | 2861 | def __eq__(self, other: Any) -> bool: 2862 | ... 2863 | 2864 | def __hash__(self) -> int: 2865 | ... 2866 | 2867 | def __repr__(self) -> str: 2868 | ... 2869 | 2870 | 2871 | class QuickPanelItem: 2872 | trigger: str 2873 | details: str | Sequence[str] 2874 | annotation: str 2875 | kind: CompletionKind 2876 | 2877 | def __init__( 2878 | self, 2879 | trigger: str, 2880 | details: str | Sequence[str] = "", 2881 | annotation: str = "", 2882 | kind: CompletionKind = KIND_AMBIGUOUS, 2883 | ) -> None: 2884 | ... 2885 | 2886 | def __repr__(self) -> str: 2887 | ... 2888 | 2889 | 2890 | class SymbolRegion: 2891 | name: str 2892 | region: Region 2893 | syntax: Syntax 2894 | type: int 2895 | kind: CompletionKind 2896 | 2897 | def __init__( 2898 | self, 2899 | name: str, 2900 | region: Region, 2901 | syntax: Syntax, 2902 | type: int, 2903 | kind: CompletionKind, 2904 | ) -> None: 2905 | ... 2906 | 2907 | def __repr__(self) -> str: 2908 | ... 2909 | 2910 | 2911 | class ListInputItem(Generic[T]): 2912 | text: str 2913 | value: T 2914 | details: str 2915 | annotation: str 2916 | kind: CompletionKind 2917 | 2918 | def __init__( 2919 | self, 2920 | text: str, 2921 | value: T, 2922 | details: str = "", 2923 | annotation: str = "", 2924 | kind: CompletionKind = KIND_AMBIGUOUS, 2925 | ) -> None: 2926 | ... 2927 | 2928 | def __repr__(self) -> str: 2929 | ... 2930 | 2931 | 2932 | class SymbolLocation: 2933 | path: str 2934 | display_name: str 2935 | row: int 2936 | col: int 2937 | syntax: Syntax 2938 | type: int 2939 | kind: CompletionKind 2940 | 2941 | def __init__( 2942 | self, 2943 | path: str, 2944 | display_name: str, 2945 | row: int, 2946 | col: int, 2947 | syntax: Syntax, 2948 | type: int, 2949 | kind: CompletionKind, 2950 | ) -> None: 2951 | ... 2952 | 2953 | def __repr__(self) -> str: 2954 | ... 2955 | 2956 | def path_encoded_position(self) -> str: 2957 | """ 2958 | :return: 2959 | A unicode string of the file path, with the row and col appended 2960 | using :row:col, which works with window.open_file() using the 2961 | sublime.ENCODED_POSITION flag. 2962 | """ 2963 | ... 2964 | --------------------------------------------------------------------------------