summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Cervin <albert@acervin.com>2023-11-19 20:00:22 +0100
committerAlbert Cervin <albert@acervin.com>2023-11-19 20:00:22 +0100
commitc87888f10dfb54590c5aae8311b7aff887193d9a (patch)
tree7fb52e36cd3e09aa9de7550335aac3a7087201c4
parent8b4c8bbd6db2b712fb069d3e773d70159979ab97 (diff)
downloaddged-c87888f10dfb54590c5aae8311b7aff887193d9a.tar.gz
dged-c87888f10dfb54590c5aae8311b7aff887193d9a.tar.xz
dged-c87888f10dfb54590c5aae8311b7aff887193d9a.zip
Make goto line a bit more intelligent
Now handles negative line numbers to mean "from the end".
-rw-r--r--src/main/cmds.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/main/cmds.c b/src/main/cmds.c
index 26e2628..5991f4a 100644
--- a/src/main/cmds.c
+++ b/src/main/cmds.c
@@ -580,9 +580,17 @@ static int32_t goto_line(struct command_ctx ctx, int argc, const char *argv[]) {
return minibuffer_prompt(ctx, "line: ");
}
- uint32_t line = atoi(argv[0]);
- buffer_view_goto(window_buffer_view(ctx.active_window),
- (struct location){.line = line, .col = 0});
+ struct buffer_view *v = window_buffer_view(ctx.active_window);
+
+ int32_t line = atoi(argv[0]);
+ if (line < 0) {
+ uint32_t nlines = buffer_num_lines(v->buffer);
+ line = -line;
+ line = line >= nlines ? 0 : nlines - line;
+ } else if (line > 0) {
+ line = line - 1;
+ }
+ buffer_view_goto(v, (struct location){.line = line, .col = 0});
}
void register_buffer_commands(struct commands *commands) {