Skip to content

TreeOpen event not fired when opening at startup in directory #1993

Closed
@dave-kennedy

Description

@dave-kennedy

Description

I followed the instructions to open the tree at startup when the argument is a directory.

I've been trying to clear the status line in the tree window. It seems the way to do this is to subscribe to the TreeOpen event. This works when toggling the tree window with a key binding but not at startup.

I wonder if it's because it isn't attached to the event right away.

Neovim version

NVIM v0.8.3
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

Operating system and version

Ubuntu 22.04

nvim-tree version

36e29c3

Minimal config

local api = require('nvim-tree.api')

require('nvim-tree').setup()

api.events.subscribe(api.events.Event.TreeOpen, function ()
    print('TreeOpen happened')
end)

vim.api.nvim_create_autocmd('VimEnter', {
    group = vim.api.nvim_create_augroup('nvim_tree_open', {}),
    callback = function (ctx)
        print('VimEnter happened')
        if vim.fn.isdirectory(ctx.file) == 1 then
            api.tree.open({path = ctx.file})
        end
    end
})

Steps to reproduce

  1. Start nvim with a directory argument, e.g. nvim ~.
  2. Check output of :messages

Expected behavior

VimEnter and TreeOpen messages should appear in the log.

Actual behavior

Only VimEnter message appears in the log.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions