Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Plugin path #1

Open
orhnk opened this issue Sep 21, 2023 · 2 comments
Open

Custom Plugin path #1

orhnk opened this issue Sep 21, 2023 · 2 comments

Comments

@orhnk
Copy link

orhnk commented Sep 21, 2023

Not everyone probably wants a new file for each plugin they install.

Also there is no path variable for the location we want to put config in.

{
  "roobert/tabtree.nvim",
  config = function(_, opts)
    require("tabtree").setup(opts)
  end,
  opts = {
    path = [[lua/plugins/configs/]],
    config_path = [[lua/plugins/init.lua]],
    add_to_config = true, -- will append to a file (not create one)
  },
}

(e.g this is my file-tree)

.
├── core
│   ├── bootstrap.lua
│   ├── default_config.lua
│   ├── init.lua
│   ├── mappings.lua
│   └── utils.lua
└── plugins
    ├── configs
    │   ├── cmp.lua
    │   ├── lazy_nvim.lua
    │   ├── lspconfig.lua
    │   ├── mason.lua
    │   ├── nvimtree.lua
    │   ├── others.lua
    │   ├── telescope.lua
    │   └── treesitter.lua
    ├── init.lua
    └── venn_nvim.lua
@roobert
Copy link
Owner

roobert commented Sep 21, 2023

Not everyone probably wants a new file for each plugin they install.

I think this would be too difficult to implement because it's not practical to parse and update source code in a simple, reliable, programmatic way.

Also there is no path variable for the location we want to put config in.

Agree that this should be configurable, I'll try to add this soon!

{
  "roobert/tabtree.nvim",
  config = function(_, opts)
    require("tabtree").setup(opts)
  end,
  opts = {
    path = [[lua/plugins/configs/]],
    config_path = [[lua/plugins/init.lua]],
    add_to_config = true, -- will append to a file (not create one)
  },
}

(e.g this is my file-tree)

.
├── core
│   ├── bootstrap.lua
│   ├── default_config.lua
│   ├── init.lua
│   ├── mappings.lua
│   └── utils.lua
└── plugins
    ├── configs
    │   ├── cmp.lua
    │   ├── lazy_nvim.lua
    │   ├── lspconfig.lua
    │   ├── mason.lua
    │   ├── nvimtree.lua
    │   ├── others.lua
    │   ├── telescope.lua
    │   └── treesitter.lua
    ├── init.lua
    └── venn_nvim.lua

@orhnk
Copy link
Author

orhnk commented Sep 21, 2023

I think this would be too difficult to implement because it's not practical to parse and update source code in a simple, reliable, programmatic way.

You don't need to write a parser from scratch for lua. (I agree that it is a hard task)
But there are other ways to solve this problem:

  • Using tree-sitter nvim

  • Config option as line number in config file (below snippet)

  • Taking a regex Query in config (and adding to the capture's end position):

    {
      "roobert/tabtree.nvim",
      config = function(_, opts)
        require("tabtree").setup(opts)
      end,
      opts = {
        path = [[lua/plugins/configs/]],
        config_path = [[lua/plugins/init.lua]],
        add_to_config = true, -- will append to a file (not create one)
        -- position = 300 -- file position as line nr
        position = [[local\splugins\s=\s\{(.)\}]]
        -- NOTE:
        -- The regexp above will catch the following:
        -- local plugins = { -- <- Anything between these brace pairs
        --     { "UTFeight/vim-case-change" } -- THIS
        --     --> plugins should insert HERE <--
        -- }
      },
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants