Skip to content

Instantly share code, notes, and snippets.

@lewisl
Created August 13, 2023 16:22
Show Gist options
  • Save lewisl/5b92ee1722ce250c07fbd8b43d749bed to your computer and use it in GitHub Desktop.
Save lewisl/5b92ee1722ce250c07fbd8b43d749bed to your computer and use it in GitHub Desktop.
Using Sublime Text with Gambit Scheme

An effective alternative to Emacs for developing in Scheme is Sublime Text. It provides excellent syntax highlighting and formatting, easy-to-use integration with Gambit's REPL and is very fast.

These brief instructions assume you are familiar with Sublime Text and have installed its package manager. Setup for Gambit development only involves plugins that are installed with Sublime Text's package manager. These instructions use menu commands, but there are equivalent key mappings if you are already a Sublime Text user. The Package Manager relies on an internet connection to download packages.

  1. First, install Scheme language support. Choose Tools / Command Palette... Type Pkg and you will see a list of commands for the Package Manager. Use down arrow to highlight Package Control: Install Package. Begin typing Scheme--very quickly the package for Scheme Syntax will be listed. Down-arrow to highlight it and press enter. It will be installed.

  2. Second, install Sublimerepl. Choose Tools / Command Palette... Use down arrow to highlight Package Control: Install Package. Begin typing Sublimerepl and the extension will be listed. Down arrow to highlight it and press enter. It will be installed.

SublimeRepl comes with templates for dozens of languages including 3 schemes and 7 common lisps. Many of these work immediately, but Gambit is not one of the pre-configured Schemes. We can easily modify (or copy) the configuration for Gauche scheme to support Gambit. This requires editing 2 files in the config/Scheme directory of the SublimeREPL package:

  1. Access the SublimeREPL configuration file, which is a JSON file like most of Sublime Text's configurations.
  • On MacOS, use SublimeText to open: ~/Library/Application Support/Sublime Text/Packages/SublimeREPL/config/Scheme/Default.sublime-commands
    • in the section for Gauche:
      • change the entry for "caption" to: "caption": "SublimeREPL: Gambit"
      • change the entry for "id" to: "id": "repl_gambit"
      • and save this file.
  • Also open ~/Library/Application Support/Sublime Text/Packages/SublimeREPL/config/Scheme/Main.sublime-menu
    • in the section for Gauche, change these entries:

      • "caption" to "caption": "Gambit"

      • "id" to "id": "repl_gambit"

      • within "cmd" set "osx": ["gsi", "-i"]

      • and save this file.

Now, you can open the Command Palette and type repl and you will see lots of choices for SublimeREPL: . Move the highlight to SublimeREPL: Gambit and press enter. The familiar Gambit repl will start in a new tab. Use the View menu to split the Sublime Text window into panes and drag the repl tab to a different pane to use split screen (like tmux). If the repl doesn't open then gsi was not in your current path.

To use the Gambit repl within Sublime Text, open or create a Gambit file with extension .scm. It should appear with syntax Scheme in the status bar at the lower right of the window. You can select an s-expression, like a define for a function. Then choose the menu command Tools / SublimeREPL / Eval in REPL / Selection. The S-expression will be evaluated though only the output will appear. Or, you can choose Tools / SublimeREPL / Transfer to REPL / Selection. The S-expression will be copied to the REPL (and evaluated if your selection included the final new-line). The key mappings show up next to the menu commands.

On Windows the config changes for SublimeREPL are identical except the 2 files are:

  • %APPDATA%\Sublime Text\Packages\SublimeREPL\config\Scheme\Default.sublime-commands
  • %APPDATA%\Sublime Text\Packages\SublimeREPL\config\Scheme\Main.sublime-menu

Note: A more convenient way to access the directory containing the SublimeREPL package config files is to select Sublime Text / Settings / Browse Packages... on MacOS or Preferences / Browse Packages... on Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment