sigildocs

Editor Setup

Sigil provides first-class Emacs support with syntax highlighting, REPL integration, and project commands. Other editors can use the nREPL protocol for basic integration.

Emacs

The sigil.el package provides a complete development environment:

  • sigil-mode — Major mode for .sgl files
  • sigil-nrepl — Network REPL client for interactive development
  • sigil-transient — Menu for CLI commands

Installation

Add the Sigil editor directory to your load path:

(add-to-list 'load-path "/path/to/sigil/editor/emacs")
(require 'sigil)

Or with use-package:

(use-package sigil
  :load-path "/path/to/sigil/editor/emacs"
  :mode ("\\.sgl\\'" . sigil-mode)
  :commands (run-sigil sigil-transient-menu)
  :bind (:map sigil-mode-map
         ("C-c C-z" . sigil-switch-to-repl)
         ("C-c C-p" . sigil-transient-menu)))

[DW] Show an example with the Emacs version that supports package-vc-install in use-package? Was that Emacs 29 or 30?

Key Bindings

Source Buffers

KeyCommandDescription
C-c C-zsigil-switch-to-replSwitch to REPL buffer
C-c C-csigil-send-definitionSend current definition to REPL
C-c C-rsigil-send-regionSend selected region to REPL
C-c C-bsigil-send-bufferSend entire buffer to REPL
C-c C-lsigil-load-fileLoad current file in REPL
C-c C-ksigil-compile-fileCompile current file
C-c C-psigil-transient-menuOpen project command menu
C-c C-d dsigil-describe-symbolDescribe symbol at point

REPL Buffer

KeyCommandDescription
RETSend inputEvaluate expression
C-c C-cInterruptCancel current evaluation
M-p / M-nHistoryNavigate command history

Starting the REPL

Use M-x run-sigil to start a Sigil REPL with nREPL support:

  1. Starts sigil repl --nrepl subprocess
  2. Connects to the nREPL server
  3. Opens the REPL buffer

With prefix argument (C-u M-x run-sigil), prompts for port number.

Project Commands

The transient menu (C-c C-p) provides quick access to CLI commands:

┌─────────────────────────────────────┐
│ Sigil                               │
├─────────────────────────────────────┤
│ Project                             │
│   b  Build                          │
│   t  Test                           │
│   r  Run task                       │
├─────────────────────────────────────┤
│ Code                                │
│   f  Format file                    │
│   F  Format buffer                  │
├─────────────────────────────────────┤
│ REPL                                │
│   i  Start REPL                     │
│   z  Switch to REPL                 │
└─────────────────────────────────────┘

Completion

Symbol completion works automatically via the nREPL connection. Type part of a symbol and use your completion framework (company-mode, corfu, etc.):

;; With company-mode
(add-hook 'sigil-mode-hook #'company-mode)

;; With corfu
(add-hook 'sigil-mode-hook #'corfu-mode)

Completion queries the running REPL for available symbols in the current module context.

Multiple Projects

When working with multiple Sigil projects, each source buffer automatically associates with the REPL for its project (based on package.sgl location).

Customization

(setq sigil-program "/path/to/sigil")  ; Sigil executable path
(setq sigil-nrepl-default-port 7888)   ; Default nREPL port

nREPL Protocol

Start the server:

sigil repl --nrepl 7888

The protocol uses length-prefixed S-expression messages:

<length:u32-be><sexp>

Request Types

;; Evaluate code
(request :id "1" :op eval :code "(+ 1 2)")

;; Complete symbol
(request :id "2" :op complete :prefix "str")

;; Get documentation
(request :id "3" :op doc :symbol "map")

;; Describe symbol
(request :id "4" :op describe :symbol "cons")

;; Expand macro
(request :id "5" :op macroexpand :code "(when test body)")

;; List modules
(request :id "6" :op modules)

;; Ping
(request :id "7" :op ping)

Response Types

;; Success
(response :id "1" :status ok :value "3")
(response :id "2" :status ok :completions ("string?" "string-ref" ...))

;; Error
(response :id "1" :status error :message "unbound variable: x")

Terminal REPL

For editors without nREPL support, use the standard REPL in a terminal:

sigil repl

Send code via terminal integration features.

Vim/Neovim

Basic setup with Scheme syntax:

" In .vimrc or init.vim
autocmd BufRead,BufNewFile *.sgl set filetype=scheme

For REPL integration, consider using a terminal multiplexer (tmux) or a plugin like vim-slime to send code to a running sigil repl.

Configuration Files

Sigil uses package.sgl as the project configuration file. Editors should recognize this for project root detection:

;; Emacs - already built into sigil.el
(defun sigil-project-root ()
  (locate-dominating-file default-directory "package.sgl"))