Skip to content

Instantly share code, notes, and snippets.

View OdatNurd's full-sized avatar

Terence Martin OdatNurd

View GitHub Profile
@OdatNurd
OdatNurd / region_sample.py
Created May 19, 2021 05:55
Sample of using regions in Sublime Text plugins
import sublime
import sublime_plugin
_types = {
"IDII": 7,
"SEDOL": 7,
"DATE": 7,
"TYPE": 1
}
@OdatNurd
OdatNurd / hover_bookmark_toggle.py
Created March 10, 2021 23:34
Sublime Text 3 bookmark hover toggle
import sublime
import sublime_plugin
class BookmarkEventListener(sublime_plugin.EventListener):
def toggle_bookmarks(self, view, point):
# Get existing bookmarks and create a region for the new one
bookmarks = view.get_regions("bookmarks")
new = sublime.Region(point)
@OdatNurd
OdatNurd / Default (PLATFORM).sublime-keymap
Created March 4, 2021 23:16
Closing a Terminus view and pane at the same time
[
// If you use the Chain of Command package, use this binding to chain
// the two required commands together.
{ "keys": ["ctrl+shift+h"], "command": "chain",
"args": {
"commands": [
["terminus_close"],
["destroy_pane", {"direction": "self"}]
]
},
@OdatNurd
OdatNurd / snippet_folder.py
Created February 15, 2021 09:30
Sublime Text 4 plugin to expand snippets and automatically fold parts of them up
import sublime
import sublime_plugin
class ExpandAndFoldSnippetCommand(sublime_plugin.TextCommand):
def run(self, edit, name, folds):
self.view.run_command("insert_snippet", {"name": name})
for _ in range(folds):
self.view.run_command("fold")
@OdatNurd
OdatNurd / Default.sublime-commands
Created January 20, 2021 05:16
Easily open the Sublime Plugin API files
[
{ "caption": "Developer: Open API Files", "command": "open_api_files" },
]
@OdatNurd
OdatNurd / selection_test.py
Created January 18, 2021 04:36
Plugin 101 Lesson 21 examples
import sublime
import sublime_plugin
class ReverseSelectAllCommand(sublime_plugin.TextCommand):
def run(self, edit):
span = sublime.Region(len(self.view), 0)
self.view.sel().add(span)
@OdatNurd
OdatNurd / do_find.py
Created December 28, 2020 17:31
Plugin 101 Lesson 20 examples
import sublime
import sublime_plugin
class DoFindReplaceCommand(sublime_plugin.TextCommand):
"""
Find all instances of the search text and replace it with the replacement
text provided. The arguments allow you to decide if the command should be a
regular expression (the default) or just plain text, and whether or not
case should be ignored or not (by default it is not).
@OdatNurd
OdatNurd / edit_examples.py
Created December 21, 2020 07:28
Sample plugin showing how to edit, replace and erase text in a Sublime Text plugoin
import sublime
import sublime_plugin
class ExampleCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.insert(edit, 0, "Hello, World!")
class SecondExampleCommand(sublime_plugin.TextCommand):
@OdatNurd
OdatNurd / view_tests.py
Created December 14, 2020 07:59
Plugin example: How to work with Points and Regions in Sublime Text
import sublime
import sublime_plugin
class RegionExampleCommand(sublime_plugin.TextCommand):
def run(self, edit, example):
if example == "1": region = sublime.Region(0, 10)
elif example == "2": region = sublime.Region(10, 20)
elif example == "3": region = sublime.Region(5)
elif example == "4": region = self.view.word(5)
@OdatNurd
OdatNurd / key_context_example.py
Created November 19, 2020 19:00
Defining a custom settings key context for Sublime Text that can compare any setting and not just booleans
import sublime
import sublime_plugin
class CustomContextEventListener(sublime_plugin.EventListener):
"""
This event is raised when Sublime sees a key binding context key it does not
recognize.
"""
def on_query_context(self, view, key, operator, operand, match_all):