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

Easier way to set local options #155

Closed
lopi-py opened this issue Feb 25, 2022 · 5 comments
Closed

Easier way to set local options #155

lopi-py opened this issue Feb 25, 2022 · 5 comments
Labels
enhancement New feature or request how-to

Comments

@lopi-py
Copy link
Contributor

lopi-py commented Feb 25, 2022

I have signcolumn setted to 2, but in file explorer I don't want the signcolumn, looks weird, or is there an option to this?

@cseickel
Copy link
Contributor

The short answer is that the neo-tree buffer has a filetype of "neo-tree", and you can use autocmd events to set options based on that. For a pure lua solution, you can use neo-tree's own event system. See #104 for an example.

@lopi-py
Copy link
Contributor Author

lopi-py commented Feb 25, 2022

Thanks!, I think it's a hacky solution but works, I wonder if can be setted at buffer creation

@cseickel cseickel changed the title set signcolumn=no when open neo-tree buffer Easier way to set local options Feb 26, 2022
@cseickel cseickel added the enhancement New feature or request label Feb 26, 2022
@cseickel
Copy link
Contributor

I could certainly create another way for you to add set local options for neo-tree buffers. I'm hesitant because there are already so many options... I can think of three options, in order of most generic to most specific:

  1. Add another event type that is specific to "neo-tree-buffer-enter", just so you don't need to do the filetype check yourself.
  2. Add a root level config option which is a function that fires on the above event:
require("neo-tree").setup({
  buffer_enter = function()
    vim.cmd("setlocal signcolumn=2")
  end
})
  1. Add a root level config option which is a table of local options to be set, like this: https://github.com/MunifTanjim/nui.nvim/tree/main/lua/nui/popup#win_options

For your specific use case, 3 is the ideal solution, but 1 and 2 can be reused for other things and will allow conditional logic, like having different settings for a float vs sidebar vs split.

@lopi-py
Copy link
Contributor Author

lopi-py commented Feb 26, 2022

Yeah, the 3 looks good, but you can tree make a combination of 2 and 3, something like this

require("neo-tree").setup({
  buffer_options = { SETTINGS HERE } | function()
    -- allow buffer_options to be a table or function
  end
})

@cseickel
Copy link
Contributor

I ended up going with the event solution, just to keep the number of config strategies down. There are now 4 new events that can be used to set/unset options that should apply to the neo-tree buffers:

"neo_tree_buffer_enter"~
Fired after entering a neo-tree buffer. It is also right after neo-tree applies
it's own settings, so it's the ideal place to apply any local settings you would
like to have.

"neo_tree_buffer_leave"~
Fired after a neo-tree buffer was exited. Technically it fires when entering a
buffer that is not neo-tree, when the last buffer enter event was neo-tree.

"neo_tree_popup_buffer_enter"~
Fired after entering a neo-tree popup buffer. This includes things such as file
rename prompts and filter inputs. It runs right after neo-tree applies it's own
settings, so it's the ideal place to apply any local settings you would like to
have.

"neo_tree_popup_buffer_leave"~
Fired after leaving a neo-tree popup buffer.

For example, to use them to hide the cursor in a neo-tree window, you could do something like this:

  require('neo-tree').setup({
    event_handlers = {
      {
        event = "neo_tree_buffer_enter",
        handler = function()
          vim.cmd 'highlight! Cursor blend=100'
        end
      },
      {
        event = "neo_tree_buffer_leave",
        handler = function()
          vim.cmd 'highlight! Cursor guibg=#5f87af blend=0'
        end
      }
    },
  })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request how-to
Projects
None yet
Development

No branches or pull requests

2 participants