Skip to content

Instantly share code, notes, and snippets.

@dangh
Last active July 9, 2021 05:33
Show Gist options
  • Save dangh/ffe9a735f441451f6e0c20f7e1e7c8f9 to your computer and use it in GitHub Desktop.
Save dangh/ffe9a735f441451f6e0c20f7e1e7c8f9 to your computer and use it in GitHub Desktop.
Prevent Sublime Text 3 close window on Command+W

Installation for ST3

curl -L https://gist.github.com/dangh/ffe9a735f441451f6e0c20f7e1e7c8f9/raw/group_has_transient_sheet.py -o "$HOME/Library/Application Support/Sublime Text 3/Packages/User/group_has_transient_sheet.py"

Usage

Add key binding to your .sublime-keymap

//prevent close empty window
{ "keys": ["super+w"], "command": "noop", "context":
  [{ "key": "group_has_transient_sheet", "operator": "equal", "operand": true }]
},

This key binding works in ST4 without this plugin as group_has_transient_sheet key is already provided out of the box.

import sublime
import sublime_plugin
class GroupHasTransientSheetEventListener(sublime_plugin.ViewEventListener):
def on_query_context(self, key, operator, operand, match_all):
if key == 'group_has_transient_sheet':
group_has_transient_sheet = len(sublime.active_window().views()) == 0
if operator == sublime.OP_EQUAL:
return group_has_transient_sheet == operand
elif operator == sublime.OP_NOT_EQUAL:
return group_has_transient_sheet != operand
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment