Skip to content

Keys, commands and context menus

The core binds few keys: : (the command line), ? (help), i (the composer), Esc and Ctrl-c. The rest — vim-style moves, the Space leader, readline keys — are the default flavor’s (omfp://docs/flavor), bound from the user’s init file; omfp://keymap lists both and the commands.

Every key runs a command: a built-in (omfp://keymap), one a widget registers with useCommand (while it is shown) or one a window module registers with omfp.command (omfp://docs/window-modules). So a widget can ship a command and the init file the key that runs it.

ctx.keys.bind("spc T", "ws.tests"); // normal mode
ctx.keys.bind("g l", "view.switch", "logs"); // args go to the command's run(args)
ctx.keys.bindIn("insert", "Ctrl-t", "ws.tests"); // another mode
ctx.keys.bind("spc x", ""); // "" removes a binding
  • Modes: normal (the default: Threads and View mode both), threads (nothing focused or the left column), view (the focus in the view, outside a text field), insert (a text field), cmdline (the : line). A threads or view binding wins over a normal one with the same keys.
  • Keys are tokens separated by spaces: a printable key is its character (j, G, :), other keys their name (Space/spc, Esc, Enter, Tab), with Ctrl-, Alt-, Meta- prefixes (g g, Space t, Ctrl-k).
  • Order: the core’s keys, then the user’s init file (daemon-wide; the flavor’s keys come from there), :set keymap.<keys>=<command> (until restart), the workspace’s init file, then window modules’ bind, each layer winning over the ones before it. A later binding of the same mode and keys replaces the earlier one.
  • Leader: Space alone opens the which-key menu; a started sequence shows it after 300 ms with each completing key and the title of its command. Bind yours under a free letter (Space T, groups like Space o a); binding a group’s own keys (Space h) replaces the group.

:describe-key shows what a key runs and where it was bound; :describe-command <name> a command’s names, keys and who registered it.

useCommand({
id: "ws.tests",
title: "Run the tests", // shown by which-key, :help and menus: keep it short
description: "Runs the test suite in the tests widget.",
aliases: ["tests"], // typed after ":" (:tests)
run: (args) => job.restart(),
});

{ id, title, description?, aliases?, scope?, args?, enabled?, run(args, element?) }: args(before) completes the argument being typed; enabled(args?) returning false hides it; with scope, it answers only while the focus is inside an element carrying SCOPE_ATTRIBUTE with that scope, before a global command of the same id.

  • Ids are dotted <area>.<action> like the built-ins (thread.archive, view.switch). Name a workspace’s commands ws.<action> and the user’s own my.<action> so they never clash.
  • A command whose id equals a built-in’s replaces it while registered (keys bound to that id run yours); the built-in comes back when it goes away.
  • An alias another command already answers to keeps answering to that older command: pick unique ones.

A right click (Shift-F10 or the menu key on the focused item, a long press on touch) on a message, a file reference or a thread row opens omfp’s menu. Each item runs a registered command with the target as its one argument:

on The argument Built-in items
message its index in the thread’s transcript ("2") Fork from here (thread.fork), Copy (thread.copy)
file its path, <path>:<line> when it points at a line Open (file.open), Copy path (file.copyPath)
thread the thread’s id Archive/Unarchive, Copy conversation (thread.copy), Export (thread.export)

Add items with useContextMenu({ on, items }) in a widget (while shown) or omfp.contextMenu in a window module: items are command ids or aliases, or { command, title }. An item whose command is not registered, or whose enabled(args) is false for that target, is left out. run(args, element) gets the target’s element too.

useContextMenu({ on: "file", items: [{ command: "ws.review", title: "Review" }] });

A widget makes its own elements targets with data-omfp-path (and data-omfp-line), data-omfp-thread or data-omfp-message; the innermost under the pointer wins. A widget handling onContextMenu itself (with preventDefault()) keeps its own menu; text fields and selected text keep the browser’s.