Giter Club home page Giter Club logo

harpoon-relative-marks's Introduction

Harpoon Relative Marks

This extension for ThePrimeagen/harpoon is an extremely hacky way to display marks relative to your current file.

I currently use it with my fork of harpoon, although I don't think that is required as I have overriden the implementation here anyways.

This is my harpoon config:

local find_project_root = function()
    local current_dir = vim.loop.cwd()
    local marker_files = { ".git", "package.json", ".sln" }

    -- Check each parent directory for the existence of a marker file or directory
    while current_dir ~= "/" do
        for _, marker in ipairs(marker_files) do
            local marker_path = current_dir .. "/" .. marker
            if vim.fn.isdirectory(marker_path) == 1 or vim.fn.filereadable(marker_path) == 1 then
                return current_dir
            end
        end
        current_dir = vim.fn.resolve(current_dir .. "/..")
    end
    -- If no marker file or directory is found, return the original directory
    return vim.loop.cwd()
end

return {
    -- "ThePrimeagen/harpoon",
    -- branch = "harpoon2",
    "maxrzaw/harpoon",
    branch = "harpoon3",
    lazy = false,
    dependencies = {
        "nvim-lua/plenary.nvim",
        {
            "maxrzaw/harpoon-relative-marks",
            dependencies = { "pysan3/pathlib.nvim" },
        },
    },
    config = function()
        local Harpoon = require("harpoon")
        local relative_marks = require("harpoon-relative-marks")

        Harpoon:setup({
            settings = {
                save_on_toggle = true,
                sync_on_ui_close = true,
                key = function()
                    -- return vim.uv.cwd() -- This is the default
                    return find_project_root()
                end,
            },
            default = {
                display = relative_marks.display,
                create_list_item = relative_marks.create_list_item,
            },
        })

        relative_marks.setup({
            key = function()
                return find_project_root()
            end,
        })

        vim.keymap.set("n", "<leader>m", function()
            Harpoon:list():add()
        end)
        vim.keymap.set("n", "<leader>h", function()
            Harpoon.ui:toggle_quick_menu(Harpoon:list(), {
                border = "rounded",
                title_pos = "center",
                title = " >-> Harpoon <-< ",
                ui_max_width = 80,
            })
        end)
    end,
}

TODO

  • There was a wierd bug when I went to a mark outside of the cwd as well.
  • Need to properly expand ~/

harpoon-relative-marks's People

Contributors

maxrzaw avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.