Scintilla library for Gerbil Scheme
  • Scheme 98.3%
  • Makefile 1.7%
Find a file
Jaime Fournier ee426bc785 build.ss: link libc++ on macOS, libstdc++ on Linux
Lexilla's LexCPP uses std::regex; on macOS (clang/libc++) those symbols live in
libc++, so a hardcoded -lstdc++ fails to link the FFI (Undefined symbols:
std::__1::regex_error for arm64). Branch on uname, matching gemacs's build.ss.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 21:01:56 -06:00
.gitignore Working Scintilla 2026-02-10 17:45:39 -07:00
autocomplete.ss updates 2026-02-10 16:59:36 -07:00
build.ss build.ss: link libc++ on macOS, libstdc++ on Linux 2026-06-02 21:01:56 -06:00
constants.ss Add word navigation and mouse dwell Scintilla constants 2026-02-23 12:18:09 -07:00
ffi.ss fix: correct SCI_SETILEXER_MSG from 4030 to 4033 2026-02-15 18:01:52 -07:00
folding.ss updates 2026-02-10 16:59:36 -07:00
gerbil.pkg updates 2026-02-10 16:59:36 -07:00
lexer.ss Working Scintilla 2026-02-10 17:45:39 -07:00
Makefile Working Scintilla 2026-02-10 17:45:39 -07:00
manifest.ss Add word navigation and mouse dwell Scintilla constants 2026-02-23 12:18:09 -07:00
markers.ss updates 2026-02-10 16:59:36 -07:00
README.md first commit 2026-02-10 16:59:25 -07:00
scintilla-test.ss Working Scintilla 2026-02-10 17:45:39 -07:00
scintilla.ss Working Scintilla 2026-02-10 17:45:39 -07:00
search.ss updates 2026-02-10 16:59:36 -07:00
style.ss updates 2026-02-10 16:59:36 -07:00
tui.ss updates 2026-02-10 18:14:34 -07:00

gerbil-scintilla

Gerbil Scheme bindings for the Scintilla text editor component library.

Overview

gerbil-scintilla provides a layered API for controlling Scintilla text editor widgets from Gerbil Scheme:

  • constants — Complete set of Scintilla message IDs, notification codes, and flag constants
  • ffi — Low-level FFI bindings for direct Scintilla message passing
  • scintilla — High-level editor interface (text, selection, undo, clipboard, view settings)
  • lexer — Syntax highlighting and lexer configuration
  • style — Text styling (colors, fonts, attributes) and caret/selection appearance
  • search — Find/replace with regex support and target-based operations
  • folding — Code folding, line visibility, and fold level management
  • autocomplete — Autocompletion lists and call tips
  • markers — Line markers (bookmarks, breakpoints) and margin configuration

Dependencies

System libraries:

# Debian/Ubuntu
sudo apt install libscintilla-dev libgtk-3-dev

# macOS
brew install scintilla

Gerbil v0.19+

Build

make          # build all modules
make test     # run test suite
make install  # install to ~/.gerbil
make clean    # remove build artifacts

To install to a different prefix:

make install PREFIX=/path/to/gerbil

Usage

(import :gerbil-scintilla/scintilla
        :gerbil-scintilla/constants
        :gerbil-scintilla/lexer
        :gerbil-scintilla/style
        :gerbil-scintilla/search
        :gerbil-scintilla/folding
        :gerbil-scintilla/autocomplete
        :gerbil-scintilla/markers)

;; Wrap a Scintilla widget (obtained from your GUI toolkit)
(def editor (create-scintilla-editor widget))

;; Set text content
(editor-set-text editor "Hello, Scintilla!")

;; Configure for C++ editing
(editor-set-lexer editor SCLEX_CPP)
(editor-set-keywords editor 0 "int void return if else while for")

;; Style the default text
(editor-style-set-font editor STYLE_DEFAULT "Monospace")
(editor-style-set-size editor STYLE_DEFAULT 12)
(editor-style-set-foreground editor STYLE_DEFAULT (rgb->scintilla 0 0 0))
(editor-style-set-background editor STYLE_DEFAULT (rgb->scintilla 255 255 255))
(editor-style-clear-all editor)

;; Enable line numbers
(editor-margin-set-type editor 0 SC_MARGIN_NUMBER)
(editor-margin-set-width editor 0 40)

;; Configure folding
(editor-set-automatic-fold editor
  (bitwise-ior SC_AUTOMATICFOLD_SHOW SC_AUTOMATICFOLD_CLICK SC_AUTOMATICFOLD_CHANGE))

;; Search with regex
(editor-set-search-flags editor (make-search-flags regexp: #t match-case: #t))
(editor-target-whole-document editor)
(editor-search-in-target editor "def\\s+\\w+")

;; Group operations for single undo
(with-undo-action editor
  (editor-insert-text editor 0 "// Header\n")
  (editor-append-text editor "\n// Footer"))

API Reference

scintilla — Core Editor

Function Description
(create-scintilla-editor widget) Wrap a native Scintilla widget
(editor-set-text editor text) Set entire document content
(editor-get-text editor) Get entire document content
(editor-get-text-length editor) Get text length in bytes
(editor-add-text editor text) Add text at cursor
(editor-insert-text editor pos text) Insert text at position
(editor-append-text editor text) Append text to end
(editor-clear-all editor) Clear all content
(editor-delete-range editor start len) Delete range
(editor-get-current-pos editor) Get caret position
(editor-set-current-pos editor pos) Set caret position
(editor-set-selection editor anchor caret) Set selection range
(editor-get-selection-text editor) Get selected text
(editor-select-all editor) Select all
(editor-goto-pos editor pos) Go to position
(editor-goto-line editor line) Go to line
(editor-get-line editor line) Get line text
(editor-get-line-count editor) Get line count
(editor-undo editor) Undo
(editor-redo editor) Redo
(with-undo-action editor body ...) Group operations for single undo
(editor-cut editor) Cut to clipboard
(editor-copy editor) Copy to clipboard
(editor-paste editor) Paste from clipboard
(editor-set-tab-width editor n) Set tab width
(editor-set-eol-mode editor mode) Set EOL: 'crlf, 'cr, 'lf
(editor-set-wrap-mode editor mode) Set wrap: 'none, 'word, 'char
(editor-set-read-only editor bool) Set read-only mode
(editor-zoom-in editor) Zoom in
(editor-zoom-out editor) Zoom out

lexer — Syntax Highlighting

Function Description
(editor-set-lexer editor id) Set lexer by SCLEX_* constant
(editor-set-lexer-language editor name) Set lexer by name string
(editor-set-keywords editor set words) Set keyword list (0-8)
(editor-colourise editor start end) Trigger colorisation
(editor-set-property editor key val) Set lexer property
(symbol->lexer-id sym) Map symbol to SCLEX_* ID
(lexer-id->symbol id) Map SCLEX_* ID to symbol

Supported language symbols: python, cpp, c, html, xml, perl, sql, ruby, lua, css, yaml, bash, shell, rust, json, markdown, scheme, lisp, haskell, ocaml, julia, nim, fsharp, gdscript, and more.

style — Text Appearance

Function Description
(editor-style-set-foreground editor style color) Set text color
(editor-style-set-background editor style color) Set background color
(editor-style-set-bold editor style bool) Set bold
(editor-style-set-italic editor style bool) Set italic
(editor-style-set-size editor style pts) Set font size
(editor-style-set-font editor style name) Set font face
(editor-style-set-underline editor style bool) Set underline
(editor-style-set-weight editor style w) Set font weight
(editor-style-clear-all editor) Reset all styles
(editor-set-caret-foreground editor color) Set caret color
(editor-set-caret-line-visible editor bool) Highlight caret line
(editor-set-selection-background editor use? color) Set selection color

search — Find and Replace

Function Description
(editor-search-anchor editor) Set search start
(editor-search-next editor flags text) Search forward
(editor-search-prev editor flags text) Search backward
(editor-set-target-range editor start end) Set search range
(editor-target-whole-document editor) Search entire document
(editor-search-in-target editor text) Find in range
(editor-replace-target editor text) Replace found text
(editor-replace-target-re editor text) Regex replace
(make-search-flags ...) Build flags from keywords

make-search-flags keywords: match-case:, whole-word:, word-start:, regexp:, posix:, cxx11-regex:

folding — Code Folding

Function Description
(editor-toggle-fold editor line) Toggle fold at line
(editor-fold-line editor line action) Fold/unfold: 'contract, 'expand, 'toggle
(editor-fold-all editor action) Fold/unfold all
(editor-show-lines editor start end) Show line range
(editor-hide-lines editor start end) Hide line range
(editor-ensure-visible editor line) Expand folds to show line
(editor-set-automatic-fold editor flags) Set auto-fold behavior

autocomplete — Completion and Calltips

Function Description
(editor-autocomplete-show editor len items) Show completion list
(editor-autocomplete-cancel editor) Hide completions
(editor-autocomplete-complete editor) Accept selection
(editor-autocomplete-set-ignore-case editor bool) Case sensitivity
(editor-autocomplete-set-order editor mode) 'presorted, 'perform-sort, 'custom
(editor-calltip-show editor pos text) Show call tip
(editor-calltip-cancel editor) Hide call tip
(editor-calltip-set-highlight editor start end) Highlight parameter

markers — Markers and Margins

Function Description
(editor-marker-define editor num symbol) Define marker appearance
(editor-marker-add editor line num) Add marker to line
(editor-marker-delete editor line num) Remove marker
(editor-marker-delete-all editor num) Remove all of type
(editor-marker-next editor start mask) Find next marked line
(editor-margin-set-type editor n type) Set margin type
(editor-margin-set-width editor n px) Set margin width
(editor-margin-set-sensitive editor n bool) Enable margin clicks
(editor-brace-highlight editor a b) Highlight matching braces
(editor-brace-match editor pos) Find matching brace

constants — Color Helpers

Function Description
(rgb->scintilla r g b) Convert RGB to Scintilla BGR format
(scintilla->rgb color) Convert BGR back to RGB (returns 3 values)

Architecture

Application Code
       ↓
  ┌─────────────────────────────────────────┐
  │  lexer / style / search / folding /     │
  │  autocomplete / markers                 │
  └──────────────────┬──────────────────────┘
                     ↓
  ┌──────────────────────────────────────────┐
  │  scintilla.ss  (high-level editor API)   │
  │  constants.ss  (message IDs & flags)     │
  └──────────────────┬───────────────────────┘
                     ↓
  ┌──────────────────────────────────────────┐
  │  ffi.ss  (C FFI — direct function path)  │
  └──────────────────┬───────────────────────┘
                     ↓
            libscintilla (C)

License

See LICENSE file.

gerbil-scintilla