-- jumptag - Jump to any function, class or heading with F4. Go, Python, C... -- Copyright 2020-2022 Tero Karvinen http://TeroKarvinen.com -- https://github.com/terokarvinen/micro-jump -- MIT license local config = import("micro/config") local shell = import("micro/shell") local micro = import("micro") local buffer = import("micro/buffer") function init() config.MakeCommand("jumptag", jumptagCommand, config.NoComplete) config.TryBindKey("F4", "command:jumptag", true) config.AddRuntimeFile("jump", config.RTHelp, "help/jump.md") end function extractDetails(line) local firstWord = line:match("^%S+") local filePath = line:match("\t(.-)\t") local lineNumber = line:match("line:(%d+)") return firstWord, filePath, lineNumber end function jumptagCommand(bp) -- bp BufPane local filename = bp.Buf.Path -- local cmd = string.format("bash -c \"ctags -f - --sort=no --fields=n '%s'|fzf --layout=reverse|tr ':' '\n'|tail -1\"", filename) local cmd = string.format("bash -c \"git ls-files | ctags --quiet=yes -L - -f - --fields=n | fzf --layout=reverse \"") local out = shell.RunInteractiveShell(cmd, false, true) local firstWord, filePath, lineNumber = extractDetails(out) if filePath ~= nil and firstWord ~= "" then local buf, err = buffer.NewBufferFromFile(filePath) if err == nil then bp:OpenBuffer(buf) end else micro.InfoBar():Message("Jump cancelled.") return end local linenum = tonumber(lineNumber)-1 bp.Cursor.Y = linenum micro.InfoBar():Message(string.format("Jumped to %s on line %s in file %s", firstWord, lineNumber, filePath)) end