Go Locate Import

This forum allows you to share scripts with other Zeus users. Please do not post bug reports, feature requests or questions to this forum, but rather use it exclusively for posting scripts or for the discussion of scripts that have been posted.
Post Reply
jussij
Site Admin
Posts: 2511
Joined: Fri Aug 13, 2004 5:10 pm

Go Locate Import

Post by jussij » Tue Oct 25, 2016 5:38 am

This macro will try to locate the folder location of the Go import found on the current line.

Just place the cursor on the line containing the import and run the macro.

Code: Select all

--
--        Name: Go Locate Import Macro
--
--    Language: Lua Macro
--
-- Description: This macro will try to locate the folder of the import
--              found on the current.
--

function file_import(gopath, import)
    local file_name =  gopath .. "\\src\\" ..import

    -- clean the string
    file_name = string.gsub(file_name, "/", "\\")
    file_name = string.gsub(file_name, "\\\\", "\\")
    file_name = string.gsub(file_name, "\\\\", "\\")

    return find_drives_item(file_name)
end

function key_macro()
    -- get a copy of the current line
    local text = get_line_text()

    if string.len(text) > 0 then
        local import = string.match(text, '^%s+\"([%a%./]+)\"')

        if import == nil then
            import = string.match(text, '^import%s+\"([%a%./]+)\"')
        end

        if import ~= nil then
            local result = file_import(os.getenv("GOPATH"), import)

            if result == 0 then
                result = file_import("c:\\Go", import)
            end

            if result == 0 then
                result = file_import("d:\\Go", import)
            end

            if result == 0 then
                message("Import not found: '" .. import .. "'")
                beep()
            else
                -- return the focus to the active document
                ActivateDocument()
            end
        else
            message("No import details found on current line. Place the cursor on a line containing a Go import.")
        end
    else
        message("Place the cursor on a line containing a Go import.")
    end
end

key_macro() -- run the macro

Post Reply
kuchnie warszawa opinie

Who is online

Users browsing this forum: No registered users and 2 guests