Bug 22742 - Add an "Automatically format source before save" option
Summary: Add an "Automatically format source before save" option
Status: RESOLVED DUPLICATE of bug 6749
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 2.0   Edit
Hardware: All All
: P3 enhancement with 17 votes (vote)
Target Milestone: 3.3 M3   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 26275 28804 49080 70045 80757 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-08-22 15:44 EDT by Gary Gregory CLA
Modified: 2006-10-26 12:23 EDT (History)
26 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gary Gregory CLA 2002-08-22 15:44:29 EDT
I usually do an source "Format" before a file save. The only reason I do not do 
it all the time is that it is a pain to right-click and go through the menus.
Comment 1 Gary Gregory CLA 2002-09-12 16:10:33 EDT
Same comment with Organize Imports.
Comment 2 Dirk Baeumer CLA 2002-11-20 08:52:01 EST
*** Bug 26275 has been marked as a duplicate of this bug. ***
Comment 3 Alex Blewitt CLA 2003-02-20 21:35:15 EST
If doing both format and organise imports, then IMHO they should be done in this order:

o Organise Imports
o Format
o Save

Organise imports can insert extra lines in the package list, and the code format
has an option to remove blank lines, so in order for the latter option to be
preserved it should be done after the imports are organised.
Comment 4 Gary Gregory CLA 2003-07-16 09:20:21 EDT
You could add Sort to the list of options BUT Sort breaks code sometimes IF
variable initialization depend on each other and Sort reorders them.
Comment 5 Alex Blewitt CLA 2003-07-17 18:00:33 EDT
Comment #4 is valid, but should not necessarily associated with this bug. The sort ordering may be 
being addressed to be more intelligent to avoid this problem in the future.

Combinations of organise imports/format/sort/save should probably be options which can be 
enabled/disabled to avoid some of these problems.
Comment 6 Dani Megert CLA 2003-12-18 11:06:19 EST
*** Bug 49080 has been marked as a duplicate of this bug. ***
Comment 7 Sebastian Davids CLA 2004-01-08 11:42:24 EST
dup of bug 6749
Comment 8 Dani Megert CLA 2004-01-08 11:44:41 EST
I like this one better because it contains exactly one request. The other one
contains various requests in one PR.
Comment 9 Mohamed ZERGAOUI CLA 2004-06-04 05:29:05 EDT
Now we have a nice formatter very useful with plenty of options and that now
handle wery well "Imports" so it will not interfer with "Organize imports"
I still think this kind of automation could be nice to have
Indeed, it will become a useful trick for a lot of other automation (Organize
imports on save, Organize imports on format, organize imports on save, etc...)
I could moreother be done with AspectJ
Is this to be handled for 3.0 or may be 3.1 ?
Comment 10 Dani Megert CLA 2004-07-19 06:17:52 EDT
*** Bug 70045 has been marked as a duplicate of this bug. ***
Comment 12 Gunnar Wagenknecht CLA 2004-10-29 13:23:01 EDT
There might be a general hook for loading and saving files. This can be used 
with team policies to format a file on open to the developer's preferences and 
format it on save to the team's preferences (allowing an easy diff and merge).
Comment 13 Marcus Beyer CLA 2004-10-30 03:21:59 EDT
Gunnar Wagenknecht wrote:

> There might be a general hook for loading and saving files. This can be used 
> with team policies to format a file on open to the developer's preferences and 
> format it on save to the team's preferences (allowing an easy diff and merge).

Wow, that feature would be a very cool one!
Comment 14 Ilja Preuss CLA 2004-11-01 03:59:30 EST
With the only drawback that it would probably confuse the quick diff feature.
Comment 15 Dani Megert CLA 2004-12-12 12:23:06 EST
*** Bug 80757 has been marked as a duplicate of this bug. ***
Comment 16 David Newcomb CLA 2005-09-12 05:13:46 EDT
What is happening with this one? Are there any plans to implement it?
Comment 17 Dani Megert CLA 2005-09-16 11:30:57 EDT
>What is happening with this one? Are there any plans to implement it?
Not for 3.2.
Comment 18 Sébastien Vauclair CLA 2005-09-23 05:04:33 EDT
While we wait for this to be integrated into Eclipse, I made a simple plugin
that automatically formats and organizes imports when saving a Java editor.

It is compatible with Eclipse 3.1 and 3.2M1 and can be downloaded at
http://sourceforge.net/project/showfiles.php?group_id=47272&package_id=164404
Comment 19 Dani Megert CLA 2006-01-10 04:03:40 EST
*** Bug 28804 has been marked as a duplicate of this bug. ***
Comment 20 Dani Megert CLA 2006-10-26 12:23:45 EDT

*** This bug has been marked as a duplicate of 6749 ***