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

rust-enable-format-on-save + compile = annoying jump to end of buffer #256

Closed
Dushistov opened this issue Dec 13, 2017 · 14 comments
Closed
Labels

Comments

@Dushistov
Copy link

This is bug is similar to #231, but instead of begin of buffer,
at now it jumps to the end of buffer with rust code.
I have applied fix from #251

Steps to reproduce:

  1. Split window by two and run compile command in the second one:
    C-x 2 C-x O M-x compile choose and run compilation command
  2. Return back to code window and choose code at the middle of buffer and change it's
    formating in so way that rustfmt should modify it (Do not save buffer)
  3. Jump to compilation window C-x O and press g

as result the position of cursor in buffer with rust code will change to the end of buffer.

/cc @brotzeit

@brotzeit
Copy link
Contributor

Can you do me a favor and try this with my fork. I have added a custom process and it's possible that this issue doesn't occur with it. If the problem still exists I will try to fix it.

@Dushistov
Copy link
Author

@brotzeit

I tried. For real project is does not work at all.

error[E0583]: file not found for module `cpp_code`
 --> /home/evgeniy/projects/rust-infra/swig/macroslib/src/cpp/mod.rs:1:5
  |
1 | mod cpp_code;
  |     ^^^^^^^^
  |
  = help: name the file either cpp_code.rs or cpp_code/mod.rs inside the directory "/tmp"

looks like it copy just one file into '/tmp' and run rustfmt for it?

But for dummy test project created with cargo --new bin it looks like work.

I wonder how scheme with copying will work for real projects, with tree of modules,
plus part of code is generated by build.rs and lay in target and included via include!?

@brotzeit
Copy link
Contributor

brotzeit commented Dec 16, 2017

Thanks for taking a look at it!
Actually you wouldn't even get this kind of error with the current solution in rust-mode, because it is ignored when running rustfmt with stdin. I've tried it with a temp file as there are several issues with stdin, but I didn't think of this error.

What do you think would be the best solution. Switch to stdin again, try to ignore this error with the current solution or create a temp file in the project directory ?
I don't like the solution with the temp file, but I think stdin is currently not really usable.

@Dushistov
Copy link
Author

Dushistov commented Dec 16, 2017

@brotzeit

What do you think would be the best solution. Switch to stdin again, try to ignore this >error with the current solution or create a temp file in the project directory ?
I don't like the solution with the temp file, but I think stdin is currently not really usable.

If I edit foo.rs why not just run rustfmt against foo.rs without stdin/temp etc?

emacs reload changed on disk file without problems and it saves position of cursor.
The only problem is time of reload, I think default timeout is something like 5 seconds or so,
so may be force reload of current buffer after run of rustfmt.

@brotzeit
Copy link
Contributor

I wouldn't have a problem with that. The best way would be reverting I guess, but I will check if this is practicable.

But probably there will be complaints about it as it changes the user experience.

@Dushistov
Copy link
Author

@brotzeit

May be time to ask emacs-devel for general infrastructure for that? gofmt/clang-format-buffer and so on all of them win from that too.

@brotzeit
Copy link
Contributor

Maybe, but I don't think it would change anything for this issue. rustfmt just isn't ready.

And even if they would add something we could use it in 5 ? years.

@brotzeit
Copy link
Contributor

It should work, but I just fixed it for now.

@Dushistov
Copy link
Author

Maybe, but I don't think it would change anything for this issue. rustfmt just isn't ready.
And even if they would add something we could use it in 5 ? years.

Looks like function already exists in emacs 26: emacs-lsp/lsp-mode#258 (comment) , also in lsp-mode#258 was implemented some work around for emacs 25.

@apiraino
Copy link
Contributor

Hi,

not sure if relevant: I experience a slight variation of this issue: when I save the code is formatted and the cursor goes to the lower part of the buffer (as if running executing command recenter-top-bottom i.e. C-l).

Example:
https://asciinema.org/a/kDrKAA9n6OFkDKYEa4xSfYBbH

I'm using Emacs 25.2.2 on Linux and rust-mode 20180215.210

@apiraino
Copy link
Contributor

@Dushistov @brotzeit I didn't clearly understand at what level the fix should be applied, whether in the Emacs world or in rustfmtand if there's a working temporary workaround.

Can you kindly help me understanding here? I'm still experiencing this, it's a bit annoying (especially when pair-programming or in live coding sessions).

thank you!

@zippy
Copy link

zippy commented Jul 5, 2018

Bump: anybody find a workaround? I've had to disable auto-fmt because it's so bad. (rust-mode 20180626.1512, GNU Emacs 24.5.1)

@apiraino
Copy link
Contributor

apiraino commented Jul 5, 2018

Hi @zippy, I've opened a pull request #269 (no feedback so far) but it works for me (© 2018). Could you try it and see if it works for you, too?

@brotzeit
Copy link
Contributor

I added save-excursion to the function so it should work now(if it didn't already before).

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

No branches or pull requests

4 participants