Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion docs/utilities/ace-modes.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ const editorLanguages = acode.require("editorLanguages");

## Methods

### `register(name, extensions, caption?, loader?)`
### `register(name, extensions, caption?, loader?, options?)`

Registers a language mode.

- `name`: Internal mode name.
- `extensions`: String or string array (without `.`), for example `"mymode"` or `["mymode", "mym"]`.
- `caption` (optional): Label shown in UI.
- `loader` (optional): Function returning a CodeMirror extension (or a Promise resolving to one).
- `options` (optional):
- `aliases`: other names that resolve to this mode.
- `filenameMatchers`: `RegExp[]` matched against file names.
- `formatAs`: name of a mode whose formatter this mode reuses. See [Formatting](#formatting).

```javascript
const editorLanguages = acode.require("editorLanguages");
Expand All @@ -43,6 +47,29 @@ const editorLanguages = acode.require("editorLanguages");
editorLanguages.unregister("myMode");
```

## Formatting

A new mode has no formatter, and the built-in Prettier doesn't know its name. If your language is a variant of an existing one, set `formatAs` to reuse that mode's formatter:

```javascript
editorLanguages.register(
"json-bedrock",
["jsonbe"],
"JSON (Bedrock)",
loadBedrockLanguage,
{ formatAs: "json" }, // [!code focus]
);
```

When the user formats a `json-bedrock` file:

- Acode uses the formatter chosen for `json-bedrock` in **Settings → Formatter**, or the one chosen for `json` if there is none.
- Prettier formats it with the `json` parser.

In **Settings → Formatter**, the "JSON (Bedrock)" row shows the inherited formatter, for example "Prettier (JSON)", and its picker also lists the formatters available for `json`. Picking one there overrides the inherited choice. This works with any formatter, not only Prettier.

Older Acode versions ignore `formatAs`, so passing it is safe; the mode just has no formatter there.

## Apply A Mode To Active File

```javascript
Expand Down
Loading