Files
YesNt-Interpreter/docs/editor.md
T

56 lines
2.6 KiB
Markdown

# YesNt Code Editor
`YesNt.CodeEditor` is a terminal editor for writing, formatting, running, and debugging YesNt scripts.
## Start the editor
```bash
yesntcode [optional-path-to-file.ynt]
```
If you pass a file path, it is loaded on startup.
## Modes
- **Command mode:** enter editor commands in the `>>>` prompt.
- **Edit mode:** direct text editing with keyboard navigation.
- **Debug mode:** script output/debug information while running.
## Command mode commands
| Command | Description |
| --------------------- | ------------------------------------------------------------------- |
| `edit` | Switch to edit mode |
| `line <n>` | Jump to line `n` and switch to edit mode |
| `save [path]` | Save to current path or a new path |
| `load <path>` | Load a file |
| `new` | Create new file |
| `format` | Auto-format indentation |
| `run [path]` | Save then run script (runs unsaved buffer if no path is set) |
| `debug [path] [step]` | Save then run in debug mode (`step` enables step-by-step execution) |
| `exit` | Close the editor |
## Edit mode controls
- Arrow keys: move cursor
- Enter: split line
- Backspace/Delete: remove characters/merge lines
- **Alt+C:** return to command mode
- **Alt+T:** jump to top
- **Alt+B:** jump to bottom
- **Alt+S:** jump to start of line
- **Alt+E:** jump to end of line
- **Alt+R:** run script
- **Alt+D:** run debug mode
- **Alt+F:** format current file
## Formatter behavior (quick summary)
- Indents `func`, `if`, `else`, and `while` blocks.
- Dedents on `end_func`, `end_if`, and `end_while`.
- `return` / `return <value>` are regular body statements and stay indented with the block they are in.
- `exit` / `throw` / `error` close active non-function blocks for following lines.
- Comment lines (`# ...`) are kept unindented.
- Single empty lines are preserved, runs of empty lines are collapsed to one, and leading/trailing blank lines are removed.
- A blank line is inserted before each block opener (`func` / `if` / `while`) that is not nested directly under another opener, and after each block closer (`end_func` / `end_if` / `end_while`), separating sibling blocks. `else:` stays attached to its `if` block.