Mini Micro code editor

From MiniScript Wiki
Revision as of 21:17, 3 July 2023 by JoeStrout (talk | contribs)
Jump to navigation Jump to search

Mini Micro comes with a built-in code editor, accessed with the edit command.

General Usage

The code editor is invoked with the edit command. This replaces the standard Mini Micro display with a graphical (GUI) code editor, as shown below.

Screen shot of the Mini Micro code editor.

The code editor is meant to be used with a keyboard and mouse, like any desktop text editor. Select text by clicking and dragging with the mouse, by shift-clicking, or by holding Shift while using the arrow keys. Type to replace the selected text. If your keyboard has Page Up/Down and Home/End keys, these may be used to navigate in addition to the scrollbar.

If any line of code in the current program is wider than the screen, a horizontal scrollbar will appear at the bottom of the screen.

The code editor can only edit one program at a time, specifically, the program currently in memory (see load and reset). Changes made in the code editor always affect the current program in memory, but will not change the program on disk unless Auto-Save is checked or you save manually.

Toolbar

At the top of the screen is the toolbar, containing various buttons and menus as follows:

Code editor toolbar, with widgets labeled.
  • Close (keyboard shortcut: Control-W): closes the code editor, returning you to the MiniScript prompt. If Auto-Save is checked, and there is a File path shown, the contents of the editor will also be saved to that file.
  • Save (control-S): saves the contents of the editor to the path shown in File path. If there currently is no path set, or if you hold the Alt or Option key while clicking this button or pressing control-S, then you will be prompted for a path (relative to the current directory) in which to save.
  • Revert: replaces the contents of the editor with a fresh reload of the file shown in File path.
  • Run (control-R or F5): closes the editor and executes the run command to run the edited source code. If Auto-Save is checked, and there is a File path shown, the contents of the editor will also be saved to that file.
  • Undo (control-Z) and Redo (shift-control-Z): undoes and redoes the last editing action.
  • Cut (control-X), Copy (control-C), Paste (control-V): standard text cut/copy/paste operations common to all text editors.
  • Find/Replace (control-F): opens/closes the Find/Replace dialog on the bottom portion of the screen.
  • Navigate: a menu containing a "Jump to line..." command, as well as any functions found in your source file; selecting any function name jumps to the start of that function in the code.
  • Code: a menu containing Comment/Uncomment Line, Insert Color, and a variety of code snippets (for loops, etc.). Code snippets are loaded from /sys/data/codeSnippets.txt, and /usr/data/codeSnippets.txt (if that exists).
  • File path: shows the path of the file currently being edited, if any. This area is blank if you are editing a program in memory that is not yet associated with any disk file.
  • Auto-save checkbox: if checked, then the contents of the editor are automatically saved whenever the editor is closed. If not, then any code changes are in memory only; you may run and test them, but they will not be written to disk unless you manually do a save.
  • Help: opens the web browser on your host machine to the Mini Micro section of this wiki.


Search & Replace

Customization

As of Mini Micro version 1.2, you can customize the colors used by the code editor by creating a map of color names to colors, and assigning this to env.editorColors. The following example shows how to use this to create a "dark mode" color theme.

// Set up a dark theme for the editor.
m = {}
m.codeBackground = "#333333"
m.noCodeBackground = "#000000"
m.lineNumber = "#666666"
m.caret = "#CCCCCCCC"
m.toolbarTint = "#CCCCFF"  // (keep light for best results)

m.text = {}
m.text.default = "#BBBBBB"
m.text.operator = "#AAAADD"
m.text.string = "#DDAAAA"
m.text.openString = "#FF0000"
m.text.identifier = "#BBBBBB"
m.text.comment = "#FFFFCC"
m.text.number = "#88FF88"
m.text.keyword = "#FF99FF"
m.text.colon = color.fuchsia
m.text.paren = ["#00FFFF", "#FF8800", "#CC44FF", "#00FF00"]
m.text.bracket = m.text.paren

env.editorColors = m

The above example shows all the supported color keys. Note that text.paren and text.bracket are lists of colors, rotated through to indicate deeper levels of nested parentheses or square brackets. These lists may be as long or short as you like.


This article is a stub. You can help the MiniScript Wiki by expanding it.