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

[Feature Request] Shortcut for Reloading Buffers #53

Open
kevinmatthes opened this issue Jul 19, 2022 · 5 comments
Open

[Feature Request] Shortcut for Reloading Buffers #53

kevinmatthes opened this issue Jul 19, 2022 · 5 comments

Comments

@kevinmatthes
Copy link
Contributor

When working with Zee, it is useful to have a second terminal to do the Git operations there, for instance committing the latest progress, run tests and so on. Sometimes, one needs to restore a previous state of a single file from the Git history. Then, Zee needs to be restarted -- at least in case that the affected file was edited in an opened window -- in order to mirror the changes there.

As a starting point, I would like to suggest to check whether it would be possible to bind the scanning of the current directory of the focused window to a shortcut. The Midnight Commander (mc) uses [CTRl] + [R] therefore but maybe this binding is already reserved for an earlier feature request.

@iainh
Copy link
Contributor

iainh commented Jul 19, 2022

I wonder if there would be value in adding a file watcher in addition to the key binding suggested to look at the mtime of the current file and update the buffer if it changed. My use case for this is similar to yours where I'd like to run an external application, say rustfmt, to format the file and see the results in zee. This could also be used to get us part way to format on save since zee could kick off the external process to format the file on save and then receive the change event once complete.

@kevinmatthes
Copy link
Contributor Author

That sounds like a really good idea! Maybe this would also fix the whitespace cropping bug which can break the application, see #42.

Do you have a certain starting point in mind, for instance a crate you would like to use for the implementation?

@iainh
Copy link
Contributor

iainh commented Jul 20, 2022

I was thinking perhaps of using the notify crate and looking at xi-editor's usage as a starting point. https://github.com/xi-editor/xi-editor/blob/master/rust/core-lib/src/watcher.rs .

@mcobzarenco What do you think of this idea? Something you want to see in zee or would you rather it be done another way?

@mcobzarenco
Copy link
Collaborator

mcobzarenco commented Jul 23, 2022

👍 Agreed, reloading the files automatically is a must imo. I'm thinking the following behaviour (similar to emacs):

  • The contents of the buffer is automatically updated if there are no unsaved changes. A new undo point is created, so undoing would revert the buffer to the previous state.
  • If there are unsaved changes present, the buffer will not be automatically updates. Instead, on save, there'd be an interactive prompt saying the file has changed on disk in the meantime. The options would be to 1. overwrite the changes or 2. reload the buffer, reverting the unsaved changes or 3. cancel the save.

EDIT: I still there's value in providing a shortcut to reload the buffer, if nothing else, as a stop gap solution. This would also be much easier to implement.

@iainh
Copy link
Contributor

iainh commented Jul 30, 2022

I've done a rough port of the watcher module from xi-editor I mentioned above and put it up here: iainh@a123b8a. The code is far enough from done that I didn't even want to make it a draft PR but I think it could be interesting as a proof of concept. The basics, refreshing the content of saved files after an external change, work surprisingly well for a quick Friday hack.

I'll be travelling for the next week or so and won't be able to work more on this until after that but my next step will be to get it cleaned up enough to turn it into a PR and implement the behaviour mentioned above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants