summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/next-editor.md8
-rw-r--r--src/CHANGELOG.md5
-rw-r--r--src/edit.zig7
-rw-r--r--test/lib/editor.zig25
4 files changed, 39 insertions, 6 deletions
diff --git a/docs/next-editor.md b/docs/next-editor.md
index af0ee537..fdb656cb 100644
--- a/docs/next-editor.md
+++ b/docs/next-editor.md
@@ -42,8 +42,10 @@ history for Alt-i to go back by (the page allocator: it holds nothing of
the code that made it). With it, Alt-o, Alt-i, Alt-n, Alt-p, Alt-a,
Alt-I, Alt-e, Alt-b and `]f` and kin are the text's and run in the
library on pardes's own nodeSelect and objectJump, and `mif` and kin find
-the `Language`'s `textobjects`; with no `lang` they do nothing, as in a
-text without a grammar. Without `syn` they come back as actions (`mif`
+the `Language`'s `textobjects`, and Enter, `o` and `O` take a new line's
+indent from its `indents` as a file's does (edit.treeIndent: without one,
+the plain indent, a level more after `(`, `[`, `{` or `)`); with no `lang`
+they do nothing, as in a text without a grammar. Without `syn` they come back as actions (`mif`
does nothing). An argument, not a field of the value: the tree holds
pointers into the grammar's code, and an argument is the least code
(the context of the call carries it, `Editor.syntax`; no interface).
@@ -125,8 +127,6 @@ terminals, replicas, dumps. Macros and `.`: their log is keys.zig's (the
core's dispatcher) and recording replays through it; keeping them meant
moving it, more code than leaving them out. `n`/`N`: pardes decides
between the look ring, a query's places and the register, the core's.
-Tree indents: they read the file's tree through `fileTree`, not
-`nodeTree`; a new line's indent in the library is the plain one.
Alt-o's history across calls lives in the `Syntax`, so a caller that
makes one per call (a sketch's `update` sees only State) has Alt-i go to
the first child instead, as helix does with no history.
diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md
index 6d51311b..764b9815 100644
--- a/src/CHANGELOG.md
+++ b/src/CHANGELOG.md
@@ -19,7 +19,10 @@
in the library on pardes's own functions, Alt-i going back the way
Alt-o came; `replace` rewrites a byte range as one step to undo, the
ranges following, and a drag that rewrites a number every frame can
- join its frames into one.
+ join its frames into one. A new line's indent comes from that parse
+ where its grammar has an indent query (a `Language`'s `indents`), as a
+ file's does from its own, so a language whose lines end in `)` is not
+ pushed a level in at every line.
- The terminal is a module of its own (`src/term/`: the emulator, its
screen state for replicas, kitty images, the pager's parse), which never
imports the core and is reached through one table of plain-data
diff --git a/src/edit.zig b/src/edit.zig
index 32943c19..fe644541 100644
--- a/src/edit.zig
+++ b/src/edit.zig
@@ -762,8 +762,13 @@ pub fn retireEditText(e: Editor, new: []u8) void {
}
/// helix's indent for a line opened after byte `at` of `row` (indent.zig),
-/// from the file's tree, where its grammar has an indent query.
+/// from the file's tree, where its grammar has an indent query; in the
+/// library, from the parse handed in (normal.nodeTree), its `Language`'s.
fn treeIndent(e: Editor, t: *Text, text: []const u8, row: usize, at: usize) Error!?[]const u8 {
+ if (comptime Editor.lib) {
+ const tree = normal.nodeTree(e, t, text) orelse return null;
+ return indents.forNewline(e.scratch, indents.lang(tree.path) orelse return null, tree.root, text, row, at);
+ }
const f = bodyFile(t) orelse return null;
const l = indents.lang(f.path) orelse return null;
const tree = normal.fileTree(e.p, f) orelse return null;
diff --git a/test/lib/editor.zig b/test/lib/editor.zig
index 2784b176..22690915 100644
--- a/test/lib/editor.zig
+++ b/test/lib/editor.zig
@@ -214,3 +214,28 @@ test "a byte range replaced is one step to undo, the ranges following it; a drag
try std.testing.expectEqual(pe.Outcome{ .refused = .text_full }, ed.replace(a, 0, 1, &ys, false));
try std.testing.expectEqualSlices(u8, std.mem.asBytes(kept), std.mem.asBytes(ed));
}
+
+test "a new line's indent comes from the parse handed in, where its language has an indent query; else the plain one" {
+ const gpa = std.testing.allocator;
+ pe.syntax.start(gpa);
+ defer pe.syntax.stop();
+ var buf: [4096]u8 = undefined;
+ // the plain indent is a level more after `)`: what a language whose
+ // lines are calls does not want, and says by an indent query
+ for ([_]struct { ?pe.Language, []const u8 }{
+ .{ null, "f(1)\n y" },
+ .{ .{ .name = "mine", .ext = ".mine", .ts = tree_sitter_c() }, "f(1)\n y" },
+ .{ .{ .name = "mine", .ext = ".mine", .ts = tree_sitter_c(), .indents = "(compound_statement) @indent \"}\" @outdent" }, "f(1)\ny" },
+ }) |case| {
+ const ed = try gpa.create(Ed);
+ defer gpa.destroy(ed);
+ ed.* = .{};
+ var syn: pe.Syntax = .{ .lang = case[0] };
+ defer syn.forget();
+ try ed.load("f(1)");
+ var arena = std.heap.ArenaAllocator.init(gpa);
+ defer arena.deinit();
+ for ([_]pe.Key{ .{ .cp = 'A', .text = "A" }, .{ .cp = pe.Key.enter }, .{ .cp = 'y', .text = "y" }, .{ .cp = pe.Key.escape } }) |k| _ = ed.key(arena.allocator(), &syn, k);
+ try std.testing.expectEqualStrings(case[1], text(ed, &buf));
+ }
+}