notesy::commands
A plugin's commands: in the palette, the keybindings and, when it likes,
the editor's / menu. Its script adds them as it runs, and takes them
away when they stop making sense: "Sign in" while signed out, "Sign out"
after. Takes the commands permission.
rustuse notesy::{accounts, commands};
pub fn ready() {
if accounts::signed_in("github") { sign_out_command(); } else { sign_in_command(); }
}
fn sign_in_command() {
commands::add("sign-in", #{ title: "Sign in to GitHub", shortcut: "Ctrl+Alt+L" }, |command| {
command.remove();
accounts::sign_in("github", |result| {
match result {
Ok(_) => sign_out_command(),
Err(_) => sign_in_command(),
}
});
});
}
fn sign_out_command() {
commands::add("sign-out", "Sign out of GitHub", |command| {
command.remove();
accounts::sign_out("github");
sign_in_command();
});
}
#commands::add(key, options, run)
Adds a command, or changes the one it added with that key, and returns
it. run(command) runs it, from the palette, its shortcut, the / menu, a
status item, a sidebar item or a view; command is the command itself, so
it can take itself away.
key names the command for good: lowercase letters, digits, -, _ and
., starting with a letter. notesy keeps the shortcut the user gave it by
its key, so keep it the same from one version to the next.
options is its title, or an object:
| Option | What it is |
|---|---|
title |
What the palette calls it. |
shortcut |
Its shortcut until the user picks another, like Ctrl+Alt+L. A key that's bound already stays with what has it, and this one starts without. |
category |
The group it's in, like Insert; the plugin's name unless set. |
slash |
A line for it in the editor's / menu, saying what it does. |
icon |
Its icon in the / menu, by name. |
keywords |
More words the / menu finds it by. |
snippet |
What it types, for a command that only types something: notesy types it at the caret itself, at once, with {date} and {time} filled in and the caret at its first $0 ("> [!tip] $0"). Its run isn't called: give it |command| (). Takes the editor permission. |
block |
true: its snippet is a block, so typed mid-line it starts a line of its own. |
A shortcut notesy can't read leaves the command without one, and the plugin's log says why.
Picked in the / menu, a command's /query comes out first, then it
runs where that was. What its script types straight after
(editor::insert, replace or insert_snippet, notesy::editor)
undoes in one step with it, as notesy's own do.
#A command
| Method | What it does |
|---|---|
command.id() |
Its full id, plugin.<plugin id>.<key>: what command fields in views, status items and section items take, and what the command.ran event says. |
command.remove() |
Takes it out of the palette, the keybindings and the / menu. Adding it again with its key brings it back. |
#commands::run(id)
Runs a command by its full id: notesy's own (toggle_sidebar, new_note
…; the Keybindings page shows each one's), or one of its own. notesy's
that change the note in front, the editor's own (delete_line, bold,
undo …) and the ones that only type something, take the editor
permission too. Another plugin's command is never run; what isn't allowed
is refused, and its log says why.
Whatever a script added goes when it stops: when it's turned off, reloaded, or fails too often.
Every page
- Overview
- plugin.toml: Every field of plugin.toml
- Permissions: What a plugin can ask for, when notesy asks, and what changes it
- Scripts: How a script runs: its lifecycle, events, limits and errors
- Packing and installing: Making, checking, signing, packing and installing
- notesy::log: Lines for its log on the Plugins page
- notesy::events: Hearing what happens, and every event
- notesy::commands: Adding commands, and running notesy's
- notesy::store: Keeping its own data
- notesy::settings: Reading its settings
- notesy::secrets: Keys and tokens, in the system keychain
- notesy::notes: Reading and changing the vault's notes
- notesy::editor: The note in front
- notesy::files: A folder of its own
- notesy::links: Opening pages in the browser
- notesy::clipboard: Copying and pasting
- notesy::view: What panels, tabs and sections show
- notesy::panels and notesy::views: Adding side panels and tabs
- notesy::sections: Sidebar sections
- notesy::menus: Items in notesy's right-click menus
- notesy::status: Status bar items
- notesy::notices: Notices
- notesy::dialogs: Asking in a dialog, notesy's kinds or its own
- notesy::cards: Its part of the tree's hover cards
- notesy::boards: Boards' cards and arrows, and kinds of card of its own
- notesy::blocks: Drawing its fenced blocks
- notesy::icons: Drawing its own icons
- notesy::net: Requests to the sites it names
- notesy::accounts: Signing in to a service
- notesy::json: Reading and writing JSON
- notesy::toml: Reading and writing TOML
- notesy::yaml: Reading and writing YAML, and a note's front matter
- notesy::time: Now, written in the user's time zone, dates read, how long ago
- notesy::math: Trigonometry and the like, for drawing
- Names: Icon, Color, Tone, Side, Method, Command, Menu, Sidebar, Event: Notesy's names as enums
- notesy::preview: Its own screens for notesy preview
- notesy::perf: Timing its own work
- notesy::tex: Math macros for every note's formulas