Skip to content

Deep Learning Based Syntax Detection

This feature is experimental and disabled by default.

Overview

It uses Google's Magika library to detect the file syntax.

Prerequisites

  1. If you are using MacOS, MacOS 11 (Big Sur) or later is required. You can run $ sw_vers in terminal to check the OS version.
  2. If you are using Linux, GLIBC 2.27 or later is required. You can run $ ldd --version in terminal to check the GLIBC version on your system.

  3. Install dependencies.

    Run AutoSetSyntax: Download Dependencies from the command palette. The dependencies is about 15~25 MB in size, so it may take a while. When it's done, there will be a popup dialogue.

    If your machine has no access to GitHub...

    You can download the dependencies on GitHub basing on your machine's OS and CPU architecture by any means. If you don't know which one to download, run the following command in Sublime Text's console:

    import AutoSetSyntax; AutoSetSyntax.plugin.constants.PLUGIN_PY_LIBS_URL
    

    Decompress the downloaded .tar.xz file into Package Storage/AutoSetSyntax/ so that the directory structure looks like the following:

    Package Storage
    └─ AutoSetSyntax
       └─ libs-py38@linux_x64
          ├── click
          ├── click-8.1.7.dist-info
          ├── colorama
          ├── colorama-0.4.6.dist-info
          ├── coloredlogs
          ├── coloredlogs.pth
          ├── coloredlogs-15.0.1.dist-info
          ...
    

    You can open Package Storage/AutoSetSyntax/ directory by running the following Python code in Sublime Text's console:

    import AutoSetSyntax; (d := AutoSetSyntax.plugin.constants.PLUGIN_STORAGE_DIR).mkdir(parents=True, exist_ok=True); window.run_command("open_dir", {"dir": str(d)})
    
  4. Enable the feature.

    Set "magika.enabled" to true in AutoSetSyntax's settings.

After finishing all steps above, it should just work without restarting Sublime Text. You may go here to copy some Rust codes and paste them into Sublime Text to test whether this feature works.

Demo