-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
File tree integration with nvim-tree and NERDTree #179
Changes from 3 commits
4eaed97
60d409a
014d905
1ee6574
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -480,6 +480,19 @@ function AutoSession.RestoreSessionFromFile(session_file) | |
AutoSession.RestoreSession(string.format(AutoSession.get_root_dir() .. "%s.vim", session_file:gsub("/", "%%"))) | ||
end | ||
|
||
-- | ||
-- Refresh syntax highlighting and file trees | ||
local function post_restore_refresh() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what fixes the syntax highlighting. I moved it to after the restore session, so that it's always triggered. Although, I'm not sure if the problem exists other than in during the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting, I hadn't noticed problems with this. But this should be fine anyway 👍 |
||
-- refresh sytax highlighting | ||
for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do | ||
if vim.api.nvim_buf_is_loaded(bufnr) then | ||
vim.api.nvim_buf_call(bufnr, function() | ||
vim.cmd 'filetype detect' | ||
end) | ||
end | ||
end | ||
end | ||
|
||
-- TODO: make this more readable! | ||
---Restores the session by sourcing the session file if it exists/is readable. | ||
---This function is intended to be called by the user but it is also called by `AutoRestoreSession` | ||
|
@@ -513,6 +526,8 @@ function AutoSession.RestoreSession(sessions_dir_or_file) | |
|
||
local post_cmds = AutoSession.get_cmds "post_restore" | ||
run_hook_cmds(post_cmds, "post-restore") | ||
|
||
vim.defer_fn(post_restore_refresh, 0) | ||
end | ||
|
||
-- I still don't like reading this chunk, please cleanup | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach was causing an infinite loop. From the docs:
By triggering
Autosession.AutoRestoreSession
asynchronously, it caused an infinite loop where the opened buffer could change the global directory (somehow) after opening. So, I moved the asynchronous part to after the session was restored. It then runsfiletype detect
on all the open buffers which fixes the syntax highlighting error.