Skip to content

bt-types

[module] bt-types

Hooks

Hooks are procedures that are registered to be called at specific moments during program execution. Hooks are organized in hook sets.

Bintracker defines various hook sets for different tasks, including application start-up (on-startup-hooks, see bintracker-core), and file operations (after-load-file-hooks, on-close-file-hooks, on-save-file-hooks; see bt-gui). Plug-ins, config/config.scm, and other user code may extend and modify these sets. For details, see documentation for the make-hooks procedure below.

[procedure] (make-hooks . HOOKS)

Create a set of hooks. HOOKS must be key-value pairs, where keys are identifier and values are procedures. You can call the resulting hook set HS as follows:

(HS 'execute [ARGS ...])

Execute the hooks in order. Each hook is called with ARGS ... as the procedure arguments.

(HS 'add ID HOOK [WHERE [OTHER-HOOK]])

Append ID . HOOK to the set of hooks. You can control the execution order with the optional WHERE and OTHER-HOOK arguments. WHERE must be either 'before, 'after or 'instead-of, and OTHER-HOOK may be the identifier of an already existing hook. In this case, HOOK is inserted before, after, or instead of OTHER-HOOK. If WHERE is 'before or 'after and OTHER-HOOK is omitted, then the new hook will be added in first resp. last position. Note that the latter has the same result as calling (HS 'add ID HOOK) with no additional arguments.

(HS 'remove ID)

Remove the hook with the identifier ID.

(HS 'list)

Returns the list of hook identifiers.

Application State

[record] app-journal

[constructor] (make-app-journal #!key (UNDO-STACK (make-stack)) (REDO-STACK (make-stack)) (UNDO-STACK-DEPTH 0))
[predicate] app-journal?
implementation: defstruct

field getter setter default type
undo-stack app-journal-undo-stack app-journal-undo-stack-set! (make-stack) (struct stack)
redo-stack app-journal-redo-stack app-journal-redo-stack-set! (make-stack) (struct stack)
undo-stack-depth app-journal-undo-stack-depth app-journal-undo-stack-depth-set! 0 fixnum

Undo/Redo stack wrapper Undo stack depth is limited to stack-limit. For performance reasons, undo stack depth is tracked manually. Redo stack size does not need to be tracked since it cannot grow beyond the undo stack depth.

[record] app-state

[constructor] (make-app-state #!key UI MENU (FONT-HEIGHT-CACHED 10))
[predicate] app-state?
implementation: defstruct

field getter setter default type
ui app-state-ui app-state-ui-set!
menu app-state-menu app-state-menu-set!
font-height-cached app-state-font-height-cached app-state-font-height-cached-set! 10 fixnum

Record type that wraps application state variables

[record] app-keys

[constructor] (make-app-keys #!key (GLOBAL '()) (CONSOLE '()) (EDIT '()) (NOTE-ENTRY '()) (PLUGINS '()))
[predicate] app-keys?
implementation: defstruct

field getter setter default
global app-keys-global app-keys-global-set! '()
console app-keys-console app-keys-console-set! '()
edit app-keys-edit app-keys-edit-set! '()
note-entry app-keys-note-entry app-keys-note-entry-set! '()
plugins app-keys-plugins app-keys-plugins-set! '()

[variable] settings

default:

(let ((s `((keymap . ,(apply make-app-keys
                 (cdr (call-with-input-file
                      "config/keymaps/en.keymap"
                    read))))
           (number-base . 16)
           (mdal-mdef-dir . "mdef/")
           (theme-generator . default-theme-generator)
           (startup-layout .
        ((welcome #t 5 <ui-welcome-buffer>)
         (repl #t 2 <ui-repl> setup
               "For help, type \"(info)\" at the prompt.\n")))
           (text-to-speech . #f)
           (show-menu . #t)
           (show-toolbars . #t)
           (show-modelines . #t)
           (font-mono . "Courier")
           (font-size . 10)
           (line-spacing . 1)
           (enable-row-play . #t)
           (default-edit-step . 1)
           (default-base-octave . 4)
           (default-major-row-highlight . 2)
           (default-minor-row-highlight . 4)
           (default-block-length . 16)
           (journal-limit . 100)
           (dwim-module-edit . #t))))
      (lambda args
    (cond
     ((null? args) s)
     ((= 1 (length args)) (alist-ref (car args) s))
     ((= 2 (length args)) (set! s (alist-update (car args) (cadr args) s)))
     (else (error 'settings "Wrong number of arguments")))))

The global application settings registry. Use as follows:

  • (settings) - Return the complete list of settings.
  • (settings PARAM) - Return the value of the setting with the ID PARAM.
  • (settings PARAM VALUE) - Set a new VALUE for the setting PARAM. If PARAM does not exist, create a new entry for it.