Package Control for Sublime Text

repository·master·Indexed 26 days ago

https://github.com/sublimehq/package_control

The official package manager for Sublime Text, used to find, install, and manage extensions and plugins. It provides tools for installing packages via the Command Palette or Python console, managing package channels and repositories, and programmatically enabling, disabling, or listing installed packages through a set of CLI commands and API methods.

Tokens
4.9K
Snippets
14
Records
39
Agent score
89%

What's inside Package Control

  1. Install Package Control using the Sublime Text Installer Tool

    master

    The easiest way to install Package Control is through the Sublime Text Command Palette.

    1. Open the Command Palette using Ctrl+Shift+P or via Tools → Command Palette....
    2. Select Install Package Control.
    3. Press Enter.

    Note on Upgrading: After installation, run Package Control: Upgrade/Overwrite All or restart Sublime Text to ensure you are updated to Package Control 4.

    Troubleshooting: If you are using an older version (Package Control 3.4.1) on a modern OS and encounter loading failures due to missing OpenSSL 1.1.1 libraries, use the Manual Install method instead.

    Ctrl+Shift+P
  2. Install a package using Package Control

    master

    All primary features of Package Control are accessed through the Command Palette.

    To install a new package:

    1. Open the Command Palette using Ctrl+Shift+P or via Tools → Command Palette....
    2. Choose Package Control: Install Package.
    3. Select the desired package from the list and press Enter.
    Ctrl+Shift+P
  3. Manually install Package Control via the Sublime Text console

    master

    If the automated installer fails (e.g., due to missing OpenSSL 1.1.1 libraries on modern operating systems), you can manually install the .sublime-package file by running a script in the Sublime Text console.

    1. Open the Sublime Text console.
    2. Paste and run the following Python script:
    from urllib.request import urlretrieve; urlretrieve(url="https://download.sublimetext.com/Package%20Control.sublime-package", filename=sublime.installed_packages_path() + '/Package Control.sublime-package')
  4. Upgrade packages via UpgradePackagesCommand

    master

    The upgrade_packages command allows you to upgrade a specific list of packages or prompt the user for a comma-separated list of package names. It runs the upgrade process in a background thread to avoid blocking the editor.

    Arguments

    • packages (list, optional): A list of strings representing the names of the packages to upgrade. If not provided, the command will prompt the user via an input panel.
    • unattended (bool, optional): If set to True, error dialogs will be suppressed during the upgrade process.
    sublime.run_command(
        "upgrade_packages",
        {
            "packages": ["Package 1", "Package 2"],
            "unattended": False
        }
    )
  5. Install multiple packages via install_packages command

    master

    Use the install_packages command to install a list of packages programmatically. You can provide a list of package names and an option to suppress error dialogs.

    If the packages argument is not provided, the command will prompt the user with an input panel to enter package names as a comma-separated list.

    sublime.run_command(
        "install_packages",
        {
            "packages": ["Package 1", "Package 2"],
            "unattended": False  # if True, suppress error dialogs
        }
    )
  6. Clear the Sublime Text cache directory via `clear_package_cache` command

    master

    The clear_package_cache command clears out the Sublime Text Cache directory to reset all packages to a freshly installed state.

    This command can be invoked via the Sublime Text Python API. It accepts an unattended option:

    • unattended (bool): If True, the command suppresses error dialogs and confirmation dialogs. If False (default), it will prompt the user with a confirmation dialog before proceeding.

    Note: You may need to restart Sublime Text for changes to take effect after clearing the cache.

    sublime.run_command(
        "clear_package_cache",
        {
            "unattended": False  # if True, suppress error dialogs
        }
    )
  7. List unmanaged packages

    master

    The ListUnmanagedPackagesCommand identifies packages that are currently installed in Sublime Text but are not managed by Package Control. A package is considered 'unmanaged' if it is not present in the installed_packages setting.

    When executing this command, the following packages are automatically excluded from the resulting list:

    • Any package listed in the unmanaged_packages_ignore setting.
    • Any package listed in the installed_packages setting.

    The resulting list is returned as a sorted list of package names (case-insensitive) intended for display in a quick panel.

  8. Retrieve readme information with ReadmeClient.readme_info()

    master

    Use the readme_info(url) method to retrieve the contents and metadata of a README file. The method supports standard URLs and specifically optimizes for GitHub-based READMEs by attempting to fetch cached content via the GitHub API before falling back to a direct download.

    Returns: A dictionary containing:

    • filename: The basename of the URL.
    • format: The detected format (markdown, textile, creole, rst, or txt).
    • contents: The file contents as a string.

    Exceptions:

    • DownloaderException: Raised if there is an error downloading the readme.
    • ClientException: Raised if there is an error parsing the response.
  9. Disable packages via the `disable_packages` command

    master

    You can disable a specific list of packages programmatically using the disable_packages command. This command accepts a dictionary containing a packages key, which must be a list of package names.

    Note that the command automatically filters out protected packages: Binary, Default, Package Control, Text, and User cannot be disabled via this command.

    sublime.run_command("disable_packages", {"packages": ["Package 1", "Package 2"]})
  10. Revert an installed package to a previous version

    master

    The RevertPackageCommand provides a way to revert a user-installed package to a previous version. When executed, it presents a quick panel list of installed packages.

    Note that this command only targets packages that are installed by the user and are not part of the predefined or default built-in packages. If no eligible packages are found, it returns the error: "There are no built-in package overrides that can be reverted".