-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
Open Glow output in the same window as input buffer or split #120
base: main
Are you sure you want to change the base?
Conversation
The option `in_place` determines if the output from Glow has to be displayed in the same window as the input buffer or instead of in a preview window like it was before this commit. The ability to manage multiple windows with different markdown buffers was incidentally implemented. The `in_place_state` table is a map where: - a key represent a certain window - its value contains both the input buffer and the output buffer (the one created by *glow.nvim* holding the content of Glow). ```lua in_place_state = { [WIN_1] = { BUFFER_BEFORE, BUFFER_CREATED }, ... } ``` So to the steps now are: - Check if the config flag is enabled - If it is save the state to retrieve BUFFER_BEFORE when needed - Replace the buffer in WIN_1 with BUFFER_CREATED - When "closing the window" reset the BUFFER_BEFORE in the WIN_1 and set in_place_state[WIN_1] to NIL Line 346 had to be changed as well or: - `Glow|Glow!|Glow` wouldn't have been possible (e.g. use command multiple times) - `Glow|Glow` printed an error: ```lua (current_win == win and not glow.config.in_place) -- keep previous behaviour or in_place_state[current_win] -- Window is managed by Glow and needs to be considered as a `glowpreview` buffer (e.g. closed or not bothered) ``` This is because before `current_win == win` always meant we were on the preview window which now isn't the case anymore.
06dc810
to
c0eafd9
Compare
If I open a render with Is the preview window supposed to be able to get the background buffer with |
Sorry for the late reply @drjaska.
I don't know if I understood properly but since before my PR you can close the rendered view with vim.keymap.set("n", "q", close_window, keymaps_opts)
vim.keymap.set("n", "<Esc>", close_window, keymaps_opts) so perhaps you should use that instead of reopening buffer with
The render buffer is wiped from the buffer list when it is no longer displayed in a window ( I usually used preview as such: If you would like to have the original buffer in the preview window I can work on it. Maybe we can have a keymap that in every render windows toggles to the original markdown file. I'll see what I can do, I think it would actually be a different feature so maybe a future PR. Hope I was clear |
There are now 3 main possible window configuration (`types` table): - `preview`: the default one, opens a preview window, as it was until commit ellisonleao/glow.nvim@a3f24fd - `keep`: keeps the same window as input buffer for the output from Glow - `split`: opens a split and puts the output there The user can configure his preferred behaviour with `glow.config.default_type` which can be "preview|keep|split". The split direction can be configured with `glow.config.split_dir` to either be "split|vsplit". The user can also override the default window type via the `Glow` user command, by providing the type: - `Glow <file>` opens <file> with `glow.config.default_type` - `Glow <type>` opens current file with <type> - `Glow <file> <type>` opens <file> with <type> - `Glow <type> <file>` opens <file> with <type> The order is not required by the user, we internally order the args to be file first and type second.
In every type of window (keep, split, preview) you can now press P to toggle between the input and output buffers. The plugin doesn't wipe original buffer local keymaps and restores them when closing Glow
closing the window and toggling between Glow/input is now customizable
Would be great to have this merged. I just tried @lnc3l0t branch and it works great :) |
The branch has two commits with detailed explanations in the commit message.
Commit 8327f2a adds a global configuration option to allow for the output to be rendered in_place. When in a markdown buffer
:Glow<CR>
renders the output in the same window as the buffer, andq
,<Esc>
and:Glow!<cr>
restore the original buffer in the window.Commit 06dc810 goes a step further than just adding the "split" functionality (which similarly to before allows the output to be in a new split. It also make the usercommand
Glow
accept a second argument (identified as type for window type) that overrides the config option and opens the output in the specified window (current, split, preview).Both commit allow to have multiple markdown buffers be rendered and then closed which wasn't possible before because issuing
:Glow<CR>
twice would override the globalwin
variable and closing it wouldn't be possible, try::Glow<cr>
-><C-w><C-w>
-> open fileB.md ->:Glow<cr>
->q
-> fileB output closes<c-w><c-w>
until back on the initial preview window and pressq
the error pops up