From fe937359e10a82856007fcb3abcb261bb285c6ed Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sat, 3 Dec 2016 10:08:52 -0500 Subject: [PATCH] added shortcut to fuzzy find a ctag symbol --- xedit.c | 43 +++++++++++++++++++++++++------------------ xtagpick | 13 +++++++++++-- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/xedit.c b/xedit.c index df10da7..81abc1c 100644 --- a/xedit.c +++ b/xedit.c @@ -49,6 +49,7 @@ static void search(void); static void execute(void); static void find(char* arg); static void open_file(void); +static void pick_ctag(void); static void goto_ctag(void); // Tag/Cmd Execution @@ -146,7 +147,7 @@ static KeyBinding Bindings[] = { { ModCtrl, 'f', search }, { ModCtrl, 'd', execute }, { ModCtrl, 'o', open_file }, - //{ ModCtrl, 'p', pick_ctag }, + { ModCtrl, 'p', pick_ctag }, { ModCtrl, 'g', goto_ctag }, }; @@ -513,28 +514,34 @@ static void open_file(void) { free(file); } -static void goto_ctag(void) { - char* str = view_getctx(currview()); - if (str) { - size_t line = strtoul(str, NULL, 0); - if (line) { - view_setln(getview(EDIT), line); +static void pick_symbol(char* symbol) { + PickTagCmd[2] = symbol; + char* pick = cmdread(PickTagCmd, NULL); + if (pick) { + Buf* buf = getbuf(EDIT); + if (buf->path && 0 == strncmp(buf->path, pick, strlen(buf->path))) { + view_setln(getview(EDIT), strtoul(strrchr(pick, ':')+1, NULL, 0)); Focused = EDIT; } else { - PickTagCmd[2] = str; - char* pick = cmdread(PickTagCmd, NULL); - if (pick) { - Buf* buf = getbuf(EDIT); - if (0 == strncmp(buf->path, pick, strlen(buf->path))) { - view_setln(getview(EDIT), strtoul(strrchr(pick, ':')+1, NULL, 0)); - Focused = EDIT; - } else { - OpenCmd[1] = pick; - cmdrun(OpenCmd, NULL); - } + if (!buf->path && !buf->modified) { + view_init(getview(EDIT), pick); + } else { + OpenCmd[1] = chomp(pick); + cmdrun(OpenCmd, NULL); } } } +} + +static void pick_ctag(void) { + pick_symbol(NULL); +} + +static void goto_ctag(void) { + char* str = view_getctx(currview()); + if (str) { + pick_symbol(str); + } free(str); } diff --git a/xtagpick b/xtagpick index 15c4d06..712bff8 100755 --- a/xtagpick +++ b/xtagpick @@ -2,9 +2,18 @@ TAGFILE="$1" TAG="$2" -if [ "" == "$TAG" ] || [ "" == "$TAGFILE" ]; then - echo "Usage: $0 TAGFILE TAG" +usage(){ + echo "Usage: $0 TAGFILE [TAG]" exit 1 +} + +if [ "" == "$TAGFILE" ]; then + usage +fi + +if [ "" == "$TAG" ]; then + TAG=$(cat tags | grep -v '^!' | cut -f1 | uniq | xpick) + [ "" == "$TAG" ] && exit fi awk -v TAG="$TAG" ' -- 2.49.0