From d6b960094f0b30f70b1f7cda110d56edbc4e92cd Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sun, 30 Apr 2017 20:53:34 -0400 Subject: [PATCH] Added GoTo tag to mirror ctrl+g functionality --- TODO.md | 1 - docs/xedit.1 | 4 ++++ docs/xedit.1.md | 2 ++ xedit.c | 19 ++++++++++++------- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/TODO.md b/TODO.md index 0aea04e..a8a93d3 100644 --- a/TODO.md +++ b/TODO.md @@ -3,7 +3,6 @@ Up Next: * refactor x11.c and win.c -* Add a GoTo tag for ctags lookup and line number jump (or right click magic?) * Add keyboard shortcut to highlight the thing under the cursor * Make Fn keys execute nth command in the tags buffer * Run commands in the background and don't block the main thread. diff --git a/docs/xedit.1 b/docs/xedit.1 index 030f337..dfb531e 100644 --- a/docs/xedit.1 +++ b/docs/xedit.1 @@ -232,6 +232,10 @@ Toggle the line\-ending style for the buffers contents between LF and CRLF Find the next occurrence of the selected text\. . .TP +\fBGoTo [arg]\fR +Jump to a specific line number or symbol\. +. +.TP \fBIndent\fR Toggle the autoindent feature on or off\. . diff --git a/docs/xedit.1.md b/docs/xedit.1.md index 52fc42f..c0548f9 100644 --- a/docs/xedit.1.md +++ b/docs/xedit.1.md @@ -219,6 +219,8 @@ search operation to be applied in the opposite direction of the previous. Toggle the line-ending style for the buffers contents between LF and CRLF * `Find [term]`: Find the next occurrence of the selected text. +* `GoTo [arg]`: + Jump to a specific line number or symbol. * `Indent`: Toggle the autoindent feature on or off. * `Paste`: diff --git a/xedit.c b/xedit.c index 17ccab1..c0dafa6 100644 --- a/xedit.c +++ b/xedit.c @@ -287,7 +287,7 @@ static void redo(void) { view_redo(win_view(FOCUSED)); } -static void tag_save(char* arg) { +static void saveas(char* arg) { if (arg) { char* path = win_buf(EDIT)->path; win_buf(EDIT)->path = stringdup(arg); @@ -381,17 +381,21 @@ static void complete(void) { free(PickTagCmd[3]); } -static void goto_ctag(void) { - char* str = view_getctx(win_view(FOCUSED)); - if (str) { - size_t line = strtoul(str, NULL, 0); +static void jump_to(char* arg) { + if (arg) { + size_t line = strtoul(arg, NULL, 0); if (line) { view_setln(win_view(EDIT), line); win_setregion(EDIT); } else { - pick_symbol(str); + pick_symbol(arg); } } +} + +static void goto_ctag(void) { + char* str = view_getctx(win_view(FOCUSED)); + jump_to(str); free(str); } @@ -446,13 +450,14 @@ static void newline(void) { static Tag Builtins[] = { { .tag = "Quit", .action.noarg = quit }, { .tag = "Save", .action.noarg = save }, - { .tag = "SaveAs", .action.arg = tag_save }, + { .tag = "SaveAs", .action.arg = saveas }, { .tag = "Cut", .action.noarg = cut }, { .tag = "Copy", .action.noarg = copy }, { .tag = "Paste", .action.noarg = paste }, { .tag = "Undo", .action.noarg = tag_undo }, { .tag = "Redo", .action.noarg = tag_redo }, { .tag = "Find", .action.arg = find }, + { .tag = "GoTo", .action.arg = jump_to }, { .tag = "Tabs", .action.noarg = tabs }, { .tag = "Indent", .action.noarg = indent }, { .tag = "Eol", .action.noarg = eol_mode }, -- 2.51.0