ThePrimeagen / harpoon

MIT License
7.07k stars 378 forks source link

vim.opt_local in ftplugin is not set correctly when opening files using harpoon #626

Open chenxin-yan opened 3 months ago

chenxin-yan commented 3 months ago

I use ftpluign/markdown.md to set text wrap to true when opening a markdown file. It works as expected. However, when openning markdown file for the first time on startup using harpoon, text wrap is not set to true.

-- Text wrap
vim.opt_local.wrap = true -- Wrap text
vim.opt_local.linebreak = true -- Line break on whole words

here is my config

GusJelly commented 2 months ago

This happens with any code that you write that is specific to filetypes. Even when I use autocmds for filetypes, navigating to a file using harpoon (either with the gui or list:select()) makes it so neovim does not use filetype specific code. I think this is only happening on filetypes, since using an autocmd with BufEnter makes it so that it works normally.

chenxin-yan commented 2 months ago

I see, Is there any way arround this, such as specify a callback function when switching files using Harpoon?

GusJelly commented 2 months ago

I see, Is there any way around this, such as specify a callback function when switching files using Harpoon?

I couldn't find a way around it. I went back to old harpoon since it doesn't have this issue.

dhzip commented 1 month ago

If you don't mind a band-aid job, you can have an autocmd source your ftplugin files without much pain.

vim.api.nvim_create_autocmd({ "BufEnter" }, {
  desc     = "Source ftplugin/$1.lua to override Issue #626",
  group    = vim.api.nvim_create_augroup("Harpoon_Optlocal", { clear = true }),
  callback = function()
    local ft = vim.bo.filetype
    vim.cmd("silent! source $XDG_CONFIG_HOME/nvim/after/ftplugin/" .. ft .. ".lua")
  end,
})
GusJelly commented 1 month ago

If you don't mind a band-aid job, you can have an autocmd source your ftplugin files without much pain.

vim.api.nvim_create_autocmd({ "BufEnter" }, {
  desc     = "Source ftplugin/$1.lua to override Issue #626",
  group    = vim.api.nvim_create_augroup("Harpoon_Optlocal", { clear = true }),
  callback = function()
    local ft = vim.bo.filetype
    vim.cmd("silent! source $XDG_CONFIG_HOME/nvim/after/ftplugin/" .. ft .. ".lua")
  end,
})

I tried using it, unfortunately this does not work for me. I will make a minimal repro config with harpoon only to make sure it's some weirdness with my hacky config.

NycRat commented 1 month ago

I tried using it, unfortunately this does not work for me. I will make a minimal repro config with harpoon only to make sure it's some weirdness with my hacky config.

One possible issue, which I came across is that $XDG_CONFIG_HOME is not defined for my specific environment on macos. Once I explicitly wrote the config path into the code snippet, it works as expected. Have you tried to check that the path of the file is correct?

Here's the snippet of my config with the fixed path:

vim.api.nvim_create_autocmd({ "BufEnter" }, {
  desc     = "Source ftplugin/$1.lua to override Issue #626",
  group    = vim.api.nvim_create_augroup("Harpoon_Optlocal", { clear = true }),
  callback = function()
    local ft = vim.bo.filetype
    vim.cmd("silent! source ~/.config/nvim/after/ftplugin/" .. ft .. ".lua")
  end,
})