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

mini.files errors when combined with mini.starter #485

Closed
3 tasks done
skoch13 opened this issue Sep 21, 2023 · 8 comments
Closed
3 tasks done

mini.files errors when combined with mini.starter #485

skoch13 opened this issue Sep 21, 2023 · 8 comments
Labels
mini.files question Further information is requested

Comments

@skoch13
Copy link

skoch13 commented Sep 21, 2023

Contributing guidelines

Module(s)

mini.starter, mini.files

Description

Thank you for your work! I'm a huge fan of mini.files, but the only place where it doesn't work for me is for the special Starter file. I want to be able to browse the project files on the starting screen without opening Telescope or similar plugins.

Neovim version

0.9.2

Steps to reproduce

  1. Use mini.files and mini.starter in your config
  2. Open nvim which triggers mini.starter
  3. Start mini.files

Expected behavior

No response

Actual behavior

E5108: Error executing lua: (mini.files) `path` is not a valid path ("/Users/%USER%/.dotfiles/Starter")
stack traceback:

@skoch13 skoch13 added the bug Something isn't working label Sep 21, 2023
@echasnovski echasnovski added question Further information is requested mini.files and removed bug Something isn't working labels Sep 21, 2023
@echasnovski
Copy link
Owner

Hi! Thanks for kind words!

This is working as intended. You seem to start 'mini.files' with something like this which opens inside a directory of current file. But Starter buffer is not associated with any file. Try plain :lua MiniFiles.open() instead.

@skoch13
Copy link
Author

skoch13 commented Sep 21, 2023

When I tried to open it as you suggested, I received the following error:

Error  20:15:42 msg_show.lua_error   MiniFiles.open() E5108: Error executing lua [string ":lua"]:1: attempt to index global 'MiniFiles' (a nil value)
stack traceback:
	[string ":lua"]:1: in main chunk

@echasnovski
Copy link
Owner

When I tried to open it as you suggested, I received the following error:

Error  20:15:42 msg_show.lua_error   MiniFiles.open() E5108: Error executing lua [string ":lua"]:1: attempt to index global 'MiniFiles' (a nil value)
stack traceback:
	[string ":lua"]:1: in main chunk

It assumes that you ran require('mini.files').setup() (which creates global MiniFiles variable).

Try :lua require('mini.files').open() instead then.

@skoch13
Copy link
Author

skoch13 commented Sep 21, 2023

That works, indeed. I appreciate your help!

@akijakya
Copy link

akijakya commented Sep 9, 2024

I put together this function which toggles mini.files, assigned to a key combination:

function()
  local miniFiles = require("mini.files")
  if not miniFiles.close() then
    -- open file explorer if current buffer is not on disk, e.g. Starter
    if vim.fn.getreg("%") ~= "" then
      miniFiles.open()
    else
      -- open file explorer at current file
      miniFiles.open(vim.api.nvim_buf_get_name(0))
    end
  end
end

@echasnovski
Copy link
Owner

@akijakya, this will do more closely what is described in the comments (assuming require('mini.files').setup() was called prior; which it probably should):

function()
  -- Close explorer if it is opened
  if MiniFiles.close() then return end
  -- Compute whether current buffer is for file on disk.
  -- If yes - use it to open explorer; otherwise use cwd.
  local buf_path = vim.api.nvim_buf_get_name(0)
  local path = vim.loop.fs_stat(buf_path) ~= nil and buf_path or vim.fn.getcwd()
  MiniFiles.open(path)
end

@akijakya
Copy link

akijakya commented Sep 9, 2024

@echasnovski thanks a lot, that is much better! Sorry for the half-baked attempt (would have made sense (only) for the Starter buffer with this condition vim.fn.getreg("%") == "Starter" though)...

@echasnovski
Copy link
Owner

@echasnovski thanks a lot, that is much better! Sorry for the half-baked attempt (would have made sense (only) for the Starter buffer with this condition vim.fn.getreg("%") == "Starter" though)...

No worries.

Usually the better way to tell if the buffer is for a certain plugin is to test its filetype. So here it could be vim.bo.filetyep == 'ministarter'. Also the vim.fn.getreg("%") is the same as vim.api.nvim_buf_get_name(0) (as far as documentation describes), so it would make sense to use one consistently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mini.files question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants