Sublime Forum

Sublime_lib, a utility library for Sublime Text — Version 1.2

#1

I am pleased to announce the initial public release of sublime_lib, a new Package Control dependency providing a variety of convenience features for other packages to use.

sublime_lib makes it easier for packages to work with a variety of built-in Sublime Text features. If you’re a package developer, take a look at the API reference to see if sublime_lib can make your life easier.

Current release

1.2, released December 17 2018.

Summary of features

  • SettingsDict — Wrapper for sublime.Settings with a dict-like interface.
  • NamedSettingsDictSettingsDict for a sublime-settings file.
  • ViewStream — Read/write stream encapsulating a View object.
  • OutputPanelViewStream wrapping an output panel.
  • ResourcePathpathlib[-inspired representation of a Sublime Text resource path.
  • new_view() — Open a new View with a variety of convenient options.
  • close_view() — Close a View, discarding unsaved changes or raising an exception.
  • new_window() – Open a new window and return the Window object.
  • close_window() — Close a Window, discarding unsaved changes or raising an exception.
  • show_selection_panel() — Open a quick panel to select an item from a list.
  • list_syntaxes() — List all loaded syntax definitions.
  • get_syntax_for_scope() — Get the syntax definition for a given scope.
  • sublime_lib.encodings — Translate between Sublime and standard encoding names.
  • sublime_lib.flags — Enumerations for built-in flags.
11 Likes

Sublime_lib 1.4 — ActivityIndicator, more enums, and better performance
#2

Is this an official plugin?

I’d recommend fixing Sublime Text Settings Object.

It doesn’t support inheritance… IE if you have a table in the default settings file and you want to change a single key - right now you have to copy the entire table over just to edit a single value. This is a bad design.

Second, If you use settings.get( ‘key’, settings.get( ‘key’, settings.get( ‘key’, settings.get( ‘key’, _default ) ) ) ) you end up with a LOT of lag. It is really expensive to do - even if the settings objects are loaded in, and if each ‘settings’ var in this example is something else.,

I use 5 or so settings files for my plugin and I do this - ultimately at the end it looks in the default sublime preferences for ‘acms_’ + _key or _default… But it checks runtime, definitions, mapping, plugin, and another settings file and I do this to keep this organized.

I’ve also had to use some ugly formatting tricks to not use tables ‘blah->x’, etc… And I’m now having to use the direct settings object for each settings file, which I was getting to, but for a system that’s supposed to be O( 1 ), it’s quite costly…

So since this is in SublimeText official repo directory, I’m guessing you can fix some of these issues so I don’t have to reinvent the wheel?

0 Likes

#3

The SublimeText GitHub organization is a collection of community-made packages. It is not run by Sublime HQ.

sublime_lib is implemented using the existing Sublime API. We can’t change Sublime itself.

I’d recommend fixing Sublime Text Settings Object.

It doesn’t support inheritance… IE if you have a table in the default settings file and you want to change a single key - right now you have to copy the entire table over just to edit a single value. This is a bad design.

I’m not sure what you mean. What is a “table”? All of the data in the underlying Settings? A single value that happens to be large?

Second, If you use settings.get( ‘key’, settings.get( ‘key’, settings.get( ‘key’, settings.get( ‘key’, _default ) ) ) ) you end up with a LOT of lag. It is really expensive to do - even if the settings objects are loaded in, and if each ‘settings’ var in this example is something else.,

I use 5 or so settings files for my plugin and I do this - ultimately at the end it looks in the default sublime preferences for ‘acms_’ + _key or _default… But it checks runtime, definitions, mapping, plugin, and another settings file and I do this to keep this organized.

If you have several SettingsDict objects, you can user itertools.chain to combine them into one dict.

0 Likes

#4

Version 1.2 has been released with a number of new features and bug fixes.

Enhancements

  • Added ResourcePath, a pathlib-inspired representation of a Sublime Text resource path.
  • Added new_window and close_window functions.
  • Added show_selection_panel, a convenient wrapper for sublime.show_quick_panel.
  • ViewStream.seek now accepts any integer offset for any value of whence.
  • Added ViewStream.show_cursor and the ViewStream(follow_cursor) argument.
  • Added new_view(line_endings) argument and LineEnding enum.
  • All enums in sublime_lib can be constructed from a member name. Flag enums can be constructed using multiple arguments.

Bug Fixes

  • Significantly improved list_syntaxes and find_syntax_by_scope:
    • Correctly observe resource loading order.
    • Ignore tmLanguage and hidden-tmLanguage files that are “shadowed” by sublime-syntax files. (#73)
    • Support hidden-tmLanguage files. (#76)

Documentation Changes

  • New single-page design for API reference.
  • Many improvements to individual docstrings.

Internal Changes

  • 100% test coverage.
  • Simplified documentation build process.
  • Moved non-exported utility functionality to _util submodule.
  • Vendored pathlib.
0 Likes

#5

Wow, new_window and close_window are pretty big ones. I thlught we were hardcoded out of that.

0 Likes

#6

sublime_lib 1.3

Enhancements

  • New Panel class for use with panels other than output panels, such as the console.
  • Several new methods of ResourcePath:
    • copy and copytree.
    • relative_to.
    • add_suffix and remove_suffix.
  • The flags argument of show_selection_panel accepts more values.

Bug Fixes

  • sublime_lib.encodings.to_sublime and from_sublime explicitly handle lookup errors.

Documentation Changes

  • Minor improvements to docs layout. (#102)

Internal Changes

  • Use MyPy type checking.
0 Likes

#7

Wow, new_window and close_window are pretty big ones. I thlught we were hardcoded out of that.

Internally, sublime_lib uses the new_window and close_window commands, plus extra code to make sure that they work as expected.

0 Likes