Skip to content

Instantly share code, notes, and snippets.

View OdatNurd's full-sized avatar

Terence Martin OdatNurd

View GitHub Profile
@OdatNurd
OdatNurd / Language.sublime-syntax
Created February 22, 2017 04:20
Goto Definition and symbols containing a period
%YAML 1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
file_extensions:
- lang
scope: source.lang
contexts:
main:
- match: '//'
scope: punctuation.definition.comment.lang
@OdatNurd
OdatNurd / report_on_update.py
Last active March 15, 2021 12:54
Triggering report generation after package update
import sublime
watcher = None
class SettingsWatcher():
def __init__(self):
self.removed = set()
self.settings = sublime.load_settings("Preferences.sublime-settings")
self.cached_ignored = set(self.settings.get("ignored_packages", []))
@OdatNurd
OdatNurd / useless_cmd.py
Created September 18, 2017 23:37
A contrived example of code in another thread communicating back to the main thread in a Sublime plugin
import sublime
import sublime_plugin
from threading import Thread
def background_work(target, value):
# We're in some anonymous thread; if we care, this makes sure that we
# execute the callback in the main thread.
sublime.set_timeout(target.result_of_operation(value), 1)
class UselessCommand(sublime_plugin.WindowCommand):
@OdatNurd
OdatNurd / Main.sublime-menu
Created September 28, 2017 21:42
An example of adding a settings item to the Preferences menu in ST3 (recent builds)
[
{
"caption": "Preferences",
"mnemonic": "n",
"id": "preferences",
"children":
[
{
"caption": "Package Settings",
"mnemonic": "P",
@OdatNurd
OdatNurd / CustomC.sublime-build
Last active March 15, 2021 12:50
Sample of a subclass of ExecCommand that allows arbitrary build options
{
"target": "my_exec",
"shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\"",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"exe_path": "something.exe",
"variants":
@OdatNurd
OdatNurd / font_size_limit.py
Created January 10, 2018 22:01
Sublime Text font size limiting on "zoom"
import sublime
import sublime_plugin
# This is a modified version of the Default/font.py file that ships with
# sublime, which includes versions of the increase and decrease font size
# commands that limit the size the font can be at each extreme.
# This includes an event listener that catches any attempt to use the
# "standard" font commands and rewrites the command to use these ones instead.
@OdatNurd
OdatNurd / exec.py
Created March 2, 2018 06:43
The exec.py plugin from Sublime Text 2.0.2 modified to use incremental decoding
import sublime, sublime_plugin
import os, sys, codecs
import thread
import subprocess
import functools
import time
# This is the exec.py file taken from the Default package in Sublime Text 2.0.2
# which has been modified to use incremental decoding of build system output
# the way it's done in Sublime Text 3.
@OdatNurd
OdatNurd / folding_listener.py
Last active March 7, 2018 23:23
Fold all newly loaded files and all files loaded from the session file at Sublime startup
import sublime
import sublime_plugin
def fold(view):
view.run_command("fold_by_level", {"level": 2})
def plugin_loaded():
for window in sublime.windows():
for view in window.views():
fold(view)
@OdatNurd
OdatNurd / snippet_override.py
Created March 29, 2018 17:51
Allows placement of Sublime snippet overrides in the User folder, automatically creating empty overrides to mask the packaged version
import sublime
import sublime_plugin
import os
import textwrap
# Related Reading:
# https://forum.sublimetext.com/t/overriding-default-latex-snippet-in-user-folder-not-working/35900
@OdatNurd
OdatNurd / rsubl_listener.py
Created April 18, 2018 17:26
Detecting when a file is opened via rsubl in Sublime (from Stack Overflow)
import sublime
import sublime_plugin
# From the Stack Overflow Question:
# https://stackoverflow.com/questions/49897187/sublime-text-3-simple-plug-in-that-changes-color-theme-depending-on-remote-host
class ExampleCommand(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view