Next: , Previous: , Up: API  


1.17 (heks-linux prelude)

1.17.1 Procedures

Procedure: G_ msg

Translate msg using the current text domain.

(G_ "Hello")
Procedure: ensure-directory-tree! dir

Create dir and every missing parent directory leading to it.

Unlike a bare mkdir, this also works for nested targets such as ~/.config/systemd/user on a machine where ~/.config/systemd does not exist yet.

(ensure-directory-tree! "~/.config/systemd/user")
Procedure: fill-template template substitutions

Replace every @token@ in template from substitutions.

substitutions is a list of (token . value) pairs; a token with no value is left in place. Pages and stylesheets that carry a dozen palette colours are written this way rather than as positional format arguments, where a missing value silently shifts every colour after it.

Procedure: flatten-list xs

Recursively flatten a nested list structure xs into a single flat list.

(flatten-list '(1 (2 (3 4)) 5))
⇒ (1 2 3 4 5)
Procedure: install-config-file! KEY: #:name #:dir #:contents #:perms

Write contents to a file named name inside directory dir. If dir (or any of its parents) does not exist, it is created automatically. perms is applied to the written file with chmod; the default #o644 is readable by everyone, while executable scripts pass #o755 (493).

The file is written beside the target and renamed into place, so it is either the old file or the new one and never half of one. That matters for the generated scripts: re-rendering one of them from inside itself - which is what a palette switch does - must not pull the file out from under a running interpreter. A path that is a symlink is written through, so a dotfile linked into a repository stays linked.

(install-config-file! #:name "config.toml"
                      #:dir "/etc/myapp"
                      #:contents "[settings]
port = 8080")
Procedure: load-local-overrides module-name profile-name

Dynamically load a machine-specific configuration file within a target module.

Look for an optional configuration file at the path $XDG_CONFIG_HOME/heks-linux/profile-name.scm, defaulting to ~/.config/heks-linux/profile-name.scm if XDG_CONFIG_HOME is not set or empty. If the file exists, temporarily switch the active module context to module-name using save-module-excursion before executing load.

This ensures that the localized configuration script evaluates within the namespace where the module’s parameters and internal definitions are bound, preventing unbound variable errors.

(load-local-overrides '(heks-linux waybar) 'waybar-settings)
Procedure: mk-css-conf-lines pairs

Format an association list of pairs into a CSS ruleset string.

(mk-css-conf-lines '((body (color . "black") (margin . 0))))
⇒ "body {
  color: black;
  margin: 0;
}
"
Procedure: mk-kv-conf-lines pairs KEY: #:template

Format an association list of pairs into configuration lines using template.

(mk-kv-conf-lines '((host . "localhost") (port . 80)))
⇒ "host=localhost
port=80
"
Procedure: mk-lines items

Join a list of items into a single string, appending a newline to each item.

(mk-lines '("foo" "bar"))
⇒ "foo
bar
"
Procedure: mk-rec-kv-conf-lines pairs KEY: #:template

Recursively format nested configuration pairs into a string using template. This handles both top-level key-values and nested blocks as INI-style sections.

(mk-rec-kv-conf-lines '((settings (port . 8080))) #:template "~a=~a
")
⇒ "
[settings]
port=8080
"
Procedure: nix-profile-install x

Install the Nix package specified by the attribute path x via system call.

(nix-profile-install "nixpkgs.tmux")
Procedure: serialize-rec-conf-item template item

Serialize a single configuration item using template to the current output port. If the item’s value is a list, it formats the key as an INI-style section header.

(with-output-to-string
  (lambda () (serialize-rec-conf-item "~a=~a
" '(port . 80))))
⇒ "port=80
"
Procedure: setup-i18n

Initialize internationalization (i18n) locales and text domains for the application. Safely catches and logs errors if initialization fails.

Procedure: syscall cmd KEY: #:silent?

Execute the system command cmd via an input pipe and return its stdout. If silent? is true, the output is also printed to the current output port.

(syscall "echo 'hello'")
⇒ "hello
"
Procedure: template-leftovers document

Return the @token@s left in document.

A leftover means a value was never supplied and the browser would show the placeholder, so a renderer’s spec can assert the document is complete instead of trusting the argument list.

1.17.2 Variables

Variable: css-conf-pair
"  ~a: ~a;\n"
Variable: equal-conf-pair
"~a=~a\n"
Variable: equal-conf-quote-value-pair
"~a=\"~a\"\n"
Variable: spaced-conf-pair
"~a ~a\n"
Variable: spaced-equal-conf-pair
"~a = ~a\n"

Next: (heks-linux rmpc), Previous: (heks-linux palette), Up: API