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

Buffer does not revert or update instantly after formatting buffer #88

Open
NathanLovato opened this issue Sep 3, 2020 · 3 comments
Open
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@NathanLovato
Copy link
Collaborator

Running gdscript-format-buffer, once the formatting operation completed, does not revert the buffer instantly, letting you type characters that can get lost. That is unlike gdscript-format-region, that locks Emacs until the formatter finished its work (which takes a split second now).

@NathanLovato NathanLovato added bug Something isn't working good first issue Good for newcomers labels Sep 3, 2020
@rileyrg
Copy link
Contributor

rileyrg commented Sep 9, 2020

When using gdscript-format-buffer from "current buffer" then the comint stuff seems overkill. A possibly naive, but functional fix is

(defun gdscript-format-buffer()
  "Format the current buffer using `gdformat'."
  (interactive)
  (save-mark-and-excursion
    (mark-whole-buffer)
    (gdscript-format-region))
  (when (buffer-modified-p)
    (save-buffer)))

It's not saving the point for some reason but it's a start.

(ps I dont think it should auto save - if I was to PR this I would suggest we remove the buffer-modified-p check - I like to save the buffer myself )

@NathanLovato
Copy link
Collaborator Author

gdscript-format--save-buffer saves the buffer before running gdformat, which is necessary: if you run gdformat on a file with unsaved changes, you'll lose your work.

There are some improvements that comint brought that were a pain before, like gdformat inserting ['-'] at the start of the file. It makes error handling consistent in the package.

Sure, it was more work, but @VlachJosef did it and did it well. This issue is just a detail: you can type a few characters while gdformat is running in the background and have the buffer revert after a second, which doesn't feel great.

Note: instead of save-mark-and-excursion, I'd recommend using buffer-end, which returns a position without changing the state of point.

@rileyrg
Copy link
Contributor

rileyrg commented Sep 10, 2020

Sure, my observation is not about gdscript-format--save-buffer - just the interactive call to gdscript-format-buffer running on a buffer and not a file. I'll have a look at buffer-end, thanks for the pointer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants