Sublime Forum

Saving the kill ring between sessions: a settings() question

#1

I want to add an option to save the emacs kill ring in the Emacs Pro Essentials plugin.

What I’d really like is a hook for when the editor is going to exit, so I can save the kill ring then, but no such hook exists.

But maybe settings() are saved automatically on exit, and I have just been overthinking this? My experience with settings, however, is that they are saved every time you add or remove something from the settings object. (You get a log message in the console when you do that - I am using settings to keep the isearch history …)

It seems like settings in views are saved automatically by sublime, so I thought, Maybe I can create an invisible view (is there such a thing?) and store the kill ring on that view’s settings, and then it would be saved automatically on exit then.

I admit I am being lazy. I can write tests on all these things but I am hoping somebody out there in plugin land has some advice.

0 Likes

#2

@canoeberry Make use of plugin_unloaded()? It won’t catch crashes, though…


Compare code below which also checks against package_control events:

#!/usr/bin/env python
# coding: utf-8


PACKAGE_NAME = 'your_package_name'


def status_msg(msg):
    import sublime

    sublime.status_message(PACKAGE_NAME + ': ' + msg)


def plugin_loaded():
    from package_control import events

    if events.install(PACKAGE_NAME):
        status_msg('Installed %s' % events.install(PACKAGE_NAME))
    elif events.post_upgrade(PACKAGE_NAME):
        status_msg('Upgraded to %s' % events.post_upgrade(PACKAGE_NAME))


def plugin_unloaded():
    from package_control import events

    if events.pre_upgrade(PACKAGE_NAME):
        status_msg('Upgrading from %s' % events.pre_upgrade(PACKAGE_NAME))
    elif events.remove(PACKAGE_NAME):
        status_msg('Removing %s' % events.remove(PACKAGE_NAME))
0 Likes

#3

I don’t think this catches quits, either.

0 Likes