I've tweaked the update imports code and incorporated a few suggestions -
thought I'd post it for comments.

* Fix jde-compile-finish-update-imports and modify jde-compile so that
imports are correctly updated upon finishing a compile.
* Don't update the list of imports if they haven't changed; instead, display
a message so that the user knows this.
* Add variable jde-import-update-organize-method which allows the user to
choose between normal sorting and partitioning of packages *or* using
jde-import-group-function to organize imports.
* Fix existing function jde-import-organize to use delete-region rather than
kill-region so that the kill ring is not clobbered.

Regards,
/Nick

> -----Original Message-----
> From: Nick Sieger [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, April 26, 2001 11:21 PM
> To: [EMAIL PROTECTED]
> Subject: Enhancement: smart clean/update imports
>
>
> I've been working on an enhancement based on previous discussions about
> cleaning up imports.  Sandip ([EMAIL PROTECTED]), a while back,
> posted some code that uses BCEL (http://bcel.sourceforge.net) to
> generate a
> clean import list for a source file based on the compiled class file for
> that source.  I took his code, extended it, wrote some elisp wrappers for
> it, and the result is attached.  First off, I realize that I'm introducing
> another dependency for the JDE by submitting this for inclusion, but I've
> tried where possible to make the use of BCEL optional, so that it need not
> be part of the main JDE distribution.  Only if the user might wish to use
> the `jde-import-update-buffer-imports' command that I've written will they
> need to install BCEL.  Note that BCEL is dual MPL/LGPL licensed code, so I
> hope its license is viewed as compatible with the JDE's GPL.
>
> Attached are source files that JDE developers can use to rebuild
> jde.jar, as
> well as the modified elisp sources.  Note that this requires BCEL.jar
> (ftp://bcel.sourceforge.net/pub/bcel/BCEL.jar).  I can make a binary patch
> if anyone is interested; email me and I'll get it to you to try out.
>
> Usage:
>
> `jde-import-update-buffer-imports' is the main function.  M-x
> jde-import-update-buffer-imports will cause the list of imports to be
> regenerated from the class file.  Existing imports will be deleted.
> Invoking with a prefix arg causes existing imports to be commented out
> instead (like `jde-import-kill-extra-imports').
>
> There are several customizable variables which affect the
> formatting of the
> resulting list of imports.  The default values for all results in
> an import
> list that looks like this:
>
> --- begin import source
> import com.sun.j3d.utils.applet.MainFrame;
>
> import com.sun.j3d.utils.geometry.ColorCube;
>
> import com.sun.j3d.utils.universe.SimpleUniverse;
> import com.sun.j3d.utils.universe.ViewingPlatform;
>
> import java.applet.Applet;
>
> import java.awt.BorderLayout;
> import java.awt.Container;
>
> import javax.media.j3d.BranchGroup;
> import javax.media.j3d.Canvas3D;
> import javax.media.j3d.Group;
> import javax.media.j3d.Transform3D;
> import javax.media.j3d.TransformGroup;
> --- end import source
>
> The customization variables are as follows.
> * jde-import-begin-imports-marker: String to be inserted at the
> front of the
> imports list.  Default is empty.
> * jde-import-end-imports-marker: String to be inserted at the end of the
> imports list.  Default is empty.
> * jde-import-package-begin-format: Format string to be inserted at the
> beginning of each package block.  Default is "\n".
> * jde-import-package-end-format:  Format string to be inserted at
> the end of
> each package block.  Default is empty.
> * jde-import-update-package-sort-function:  Function to be used as a sort
> predicate to control the order of appearance of each of the
> package blocks.
> Default is `string-lessp'.  An alternative is
> `jde-import-package-sort-java-first', which will place java.* and javax.*
> packages first.
>
> As an example, here is part of the previous block of imports annotated to
> show where stuff will be inserted:
>
> --- begin import source
> // (jde-import-begin-imports-marker inserted here)
> // (jde-import-package-begin-format formatted and inserted here)
> import com.sun.j3d.utils.applet.MainFrame;
> // (jde-import-package-end-format formatted and inserted here)
> // (jde-import-package-begin-format formatted and inserted here)
> import com.sun.j3d.utils.geometry.ColorCube;
>
> // ...
>
> import javax.media.j3d.TransformGroup;
> // (jde-import-package-end-format formatted and inserted here)
> // (jde-import-end-imports-marker inserted here)
> --- end import source
>
> There is also a utility function
> `jde-compile-finish-update-imports' that is
> suitable for inclusion in `jde-compile-finish-hook' so that imports are
> updated automatically.
>
> Any questions or suggestions, please let me know.  Again, also, if you
> aren't set up to build the JDE let me know and I can send you a modified
> jde.jar plus the changed elisp sources instead.  Note:  This enhancement
> should only be applied on top of the latest JDE, version 2.2.7beta10.

jde-clean-imports-2.tar.gz

Reply via email to