emacs-gdscript-mode icon indicating copy to clipboard operation
emacs-gdscript-mode copied to clipboard

Buffer does not revert or update instantly after formatting buffer

Open NathanLovato opened this issue 5 years ago • 3 comments

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 avatar Sep 03 '20 19:09 NathanLovato

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 )

rileyrg avatar Sep 09 '20 21:09 rileyrg

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.

NathanLovato avatar Sep 10 '20 02:09 NathanLovato

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.

rileyrg avatar Sep 10 '20 05:09 rileyrg