derekwyatt / vim-scala

My work on integration of Scala into Vim - not a ton here, but useful for me.
http://derekwyatt.org
Apache License 2.0
1.09k stars 144 forks source link

plugin: save scala files after sorting imports #140

Closed fsareshwala closed 6 years ago

fsareshwala commented 7 years ago

The SortScalaImports command sorts scala imports but leaves the file thinking it has been modified. This breaks down when you simply want to look at a file and close it quickly after. Because Vim thinks the file has been modified, you are required to either use :q! or :wq to actually exit the file rather than the standard :q.

This change updates SortScalaImports to write the file out after sorting inputs.

derekwyatt commented 7 years ago

I'm not sure what you're talking about. Do you automatically run SortScalaImports when you read a file?

On Mon, Apr 24, 2017, 5:25 PM Faraaz Sareshwala, notifications@github.com wrote:

The SortScalaImports command sorts scala imports but leaves the file thinking it has been modified. This breaks down when you simply want to look at a file and close it quickly after. Because Vim thinks the file has been modified, you are required to either use :q! or :wq to actually exit the file rather than the standard :q.

This change updates SortScalaImports to write the file out after sorting inputs.

You can view, comment on, or merge this pull request online at:

https://github.com/derekwyatt/vim-scala/pull/140 Commit Summary

  • plugin: save scala files after sorting imports

File Changes

Patch Links:

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/derekwyatt/vim-scala/pull/140, or mute the thread https://github.com/notifications/unsubscribe-auth/AADzdMULHRrTa-T9MOqjepfAnYm6viFBks5rzRM6gaJpZM4NGu26 .

fsareshwala commented 7 years ago

I do but this also seems to be the case when I run :SortScalaImports on a file I've opened without using autocmd FileType scala SortScalaImport. Let me know if that doesn't help and I can try and provide a better reproducer.

Faraaz

On Mon, Apr 24, 2017 at 2:40 PM, Derek Wyatt notifications@github.com wrote:

I'm not sure what you're talking about. Do you automatically run SortScalaImports when you read a file?

On Mon, Apr 24, 2017, 5:25 PM Faraaz Sareshwala, <notifications@github.com

wrote:

The SortScalaImports command sorts scala imports but leaves the file thinking it has been modified. This breaks down when you simply want to look at a file and close it quickly after. Because Vim thinks the file has been modified, you are required to either use :q! or :wq to actually exit the file rather than the standard :q.

This change updates SortScalaImports to write the file out after sorting inputs.

You can view, comment on, or merge this pull request online at:

https://github.com/derekwyatt/vim-scala/pull/140 Commit Summary

  • plugin: save scala files after sorting imports

File Changes

Patch Links:

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/derekwyatt/vim-scala/pull/140, or mute the thread https://github.com/notifications/unsubscribe-auth/AADzdMULHRrTa- T9MOqjepfAnYm6viFBks5rzRM6gaJpZM4NGu26 .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/derekwyatt/vim-scala/pull/140#issuecomment-296830096, or mute the thread https://github.com/notifications/unsubscribe-auth/AAM_gBLHZCganPRPBUrFZXXlF1aCNe8lks5rzRawgaJpZM4NGu26 .

derekwyatt commented 7 years ago

Running :SortScalaImports doesn't do an automatic write so if you run it then it's possibly going to leave you with a modified buffer. If you have a custom autocommand that does it when you open a file then you'll probably want to modify your autocommand to write it. Or make a PreWrite trigger that will run :SortScalaImports before writing.

But I'm not willing to make this change because you're assuming that the buffer is a) backed by a file, b) that the file us writable, c) the user wants this to happen.

On Mon, Apr 24, 2017, 6:05 PM Faraaz Sareshwala, notifications@github.com wrote:

I do but this also seems to be the case when I run :SortScalaImports on a file I've opened without using autocmd FileType scala SortScalaImport. Let me know if that doesn't help and I can try and provide a better reproducer.

Faraaz

On Mon, Apr 24, 2017 at 2:40 PM, Derek Wyatt notifications@github.com wrote:

I'm not sure what you're talking about. Do you automatically run SortScalaImports when you read a file?

On Mon, Apr 24, 2017, 5:25 PM Faraaz Sareshwala, < notifications@github.com

wrote:

The SortScalaImports command sorts scala imports but leaves the file thinking it has been modified. This breaks down when you simply want to look at a file and close it quickly after. Because Vim thinks the file has been modified, you are required to either use :q! or :wq to actually exit the file rather than the standard :q.

This change updates SortScalaImports to write the file out after sorting inputs.

You can view, comment on, or merge this pull request online at:

https://github.com/derekwyatt/vim-scala/pull/140 Commit Summary

  • plugin: save scala files after sorting imports

File Changes

Patch Links:

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/derekwyatt/vim-scala/pull/140, or mute the thread https://github.com/notifications/unsubscribe-auth/AADzdMULHRrTa- T9MOqjepfAnYm6viFBks5rzRM6gaJpZM4NGu26 .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <https://github.com/derekwyatt/vim-scala/pull/140#issuecomment-296830096 , or mute the thread < https://github.com/notifications/unsubscribe-auth/AAM_gBLHZCganPRPBUrFZXXlF1aCNe8lks5rzRawgaJpZM4NGu26

.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/derekwyatt/vim-scala/pull/140#issuecomment-296835375, or mute the thread https://github.com/notifications/unsubscribe-auth/AADzdNpCllGh1BxJDjp3Q2aMQH2KMvbVks5rzRypgaJpZM4NGu26 .

fsareshwala commented 7 years ago

No problem. Those are good points that I didn't think of. I'm a Scala newbie and a vim plugin newbie as well so I really need that kind of advice. For my understanding, under what situation would Scala code not be backed by a file? The code may not be writable if the code is owned by another user perhaps?

Let's kill this pull request for now. I have another one coming up soon for you :).

derekwyatt commented 7 years ago

I often use vim to write up a code snippet that I paste into a browser or hip chat or something. In those cases there is no file.

Also, when I used to have to work with perforce files would be read only until checked out. This would make the automatic writing od files a serious pain.

I can't close it right now but will get to it eventually :)

On Mon, Apr 24, 2017, 7:11 PM Faraaz Sareshwala, notifications@github.com wrote:

No problem. Those are good points that I didn't think of. I'm a Scala newbie and a vim plugin newbie as well so I really need that kind of advice. For my understanding, under what situation would Scala code not be backed by a file? The code may not be writable if the code is owned by another user perhaps?

Let's kill this pull request for now. I have another one coming up soon for you :).

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/derekwyatt/vim-scala/pull/140#issuecomment-296847153, or mute the thread https://github.com/notifications/unsubscribe-auth/AADzdEa45c6xA_Hl4BdPsxuIahV4j9CIks5rzSwrgaJpZM4NGu26 .