-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Fix: Treat REPL buffer filetype as filetype for repl #390
base: master
Are you sure you want to change the base?
Fix: Treat REPL buffer filetype as filetype for repl #390
Conversation
…r code buffer, by taking repl ft as buffer ft
I think it would be handy to have a user provided function in configuration instead of hard coding the filetype this way. In the referenced comment the person mentioned using Maybe the config could look something like this: {
config = {
repl_filetype = function(repl_ft)
-- ...
end
}
} In this way, iron can define a default implementation return value (like |
I think that might make the goal to get hide and focus working stable regardles of the current cursor more complicated. Also what is the help of having a filetype iron? How do you work with it? I think it's quite logical to treat a window with a python interpreter as type python. If you set it to iron-python, how do you use that? But I am not aware of the plans and ideas for this plugin. Only think I notice is thats a horrible user experience currently. But it seems there is not much activity here anyway. |
In my case I am using the filetype "iron" so that I can integrate iron repl buffers with edgy.
I disagree and here's why:
Thus, from a substitution perspective, I think it is illogical to treat the windows the same. The structure and meaning of the two are different. My whole point of recommending a user extensible hook to the set the filetype is to avoid exactly this sort of unproductive discussion. 😄 By having a hook
Everyone wins! |
I am really not experienced with lua and nvim plugins. So my solution might not be the best. And I am totally open to it getting rejected. My only strong opinion on this topic is that the main commands, like focus, hide, restart and so on should simply work, no matter if the curso is in the repl or in a buffer with the filetype. |
I definitely agree! I am not a pro lua/neovim hacker either, but I think a configuration hook is relatively easy to pull off in this case. First, we need to extend configuration table here with a default implementation of {
repl_filetype = function (bufnr, ft)
-- Returning `nil` because that is consistent with the current behavior
-- making this a non-breaking change.
return nil
end
} In new_repl.create_on_new_window = function(ft)
-- ...
-- Set the filetype if configured by the user.
local filetype = config.repl_filetype(bufnr, ft)
if filetype ~= nil then
vim.api.nvim_set_option_value("filetype", filetype, { buf = bufnr })
end
return meta
end And that's it! In my configuration, I now have: {
repl_filetype = function(bufnr, ft)
return "iron"
end,
} Your configuration (and I tested this) would look like: {
repl_filetype = function(bufnr, ft)
return ft
end,
} Try it out! You'll notice that the hide/show commands do, in fact, work as you'd like them to. 😄 Feel free to consider this a collaboration and use the code for your patch. 👍 |
Setting rhe filetype on buffer creation is indeed maybe more flexible. In the moment I don't really want to work on that. First I want to see if there is any feedback from any maintainer in the end. |
I think there are actually two problems here.
The patch I have proposed above address the first problem directly and I think it's worthy as a standalone patch for the reasons I've laid out. The second problem, can be solved via my proposal but only if the My suggestion would be to use the code I've suggested here to solve the filetype issue or I can open a separate PR (and name you as a collaborator in the commit message so you get credit). A separate ticket/patch should be opened for your actual problem. |
I am fine with that. I only recently started to use Iron and directly noted some bugs or for me missing features. Only after I made my few contributions I read that this project was short before being archived. At the moment my fork works for me, but I hope there will be some activity here again. |
Currently many commands only work if the cursor is on the repl buffer or on a code buffer with fitting filetype.
This is inconvenient, because one can't call IronHide, if focus is on repl and one can't call IronFocus, if cursor is on repl etc.
This fix checks if the current buffer is a repl buffer and returns the filetype that the repl was created for.
See also #323 (comment) for example.