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

Allow formatter using 'filepath on a modified buffer #110

Merged
merged 3 commits into from
Aug 14, 2022

Conversation

andersk
Copy link
Contributor

@andersk andersk commented Jul 5, 2022

Fixes #109.

andersk added 2 commits July 4, 2022 18:31
'filepath is supposed to indicate that the formatter doesn’t actually
read from the named file, meaning it’s safe to use on a modified
buffer.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Fixes radian-software#109.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
@andersk andersk force-pushed the filepath-modified branch from 0be4131 to e050722 Compare July 5, 2022 01:45
@elken elken requested a review from raxod502 July 17, 2022 20:35
@mohkale
Copy link
Contributor

mohkale commented Aug 9, 2022

I don't think this is a good idea. The restriction from formatting when the buffer is modified is because it assumes the formatter is formatting the file, not the buffer, and then when we try to apply the changes atop the buffer because it doesn't match what was there before formatting there could be some discrepencies. That said I'm also not a big fan of the current state of this. It might be better to add an option to auto-save the buffer before running the formatter or add a new field (aside from filepath) which indicates to apheleia "yes, this uses the filepath, but it still formats through stdin".

@andersk
Copy link
Contributor Author

andersk commented Aug 9, 2022

filepath is the option that indicates to apheleia “yes, this uses the filepath, but still formats through stdin”. If you want to avoid indicating that, you use file instead of filepath. See this existing comment:

apheleia/apheleia.el

Lines 959 to 961 in 12804a5

it. (Use `filepath' instead of `file' if you need the filename of
the current buffer, but you still want its contents to be passed
on stdin.)

Also, I consider it very important that formatting a buffer does not save it. For me, formatting is as integral to the editing experience as pressing the space bar, and I would never want an editor that auto-saved every time I pressed the space bar.

@elken
Copy link
Contributor

elken commented Aug 14, 2022

I can see this argument and I'm kinda in favour of it.

The thought of making the formatting run more transparently during typing is an interesting one.

@raxod502
Copy link
Member

You're right. There is no need to block formatting on a modified buffer for filepath, only for file.

Copy link
Member

@raxod502 raxod502 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raxod502 raxod502 merged commit 0c5e40e into radian-software:main Aug 14, 2022
@andersk andersk deleted the filepath-modified branch August 14, 2022 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Can’t run Prettier on modified buffer via M-x apheleia-format-buffer
4 participants