-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


(defun jde-import-expand-imports()
  "Search a java buffer for duplicate explicit imports and replace them with a
package import.

Example:

If you have following source:

import org.jdom.Document;
import org.jdom.Element;

It will be replace with

import org.jdom.*;
"
  (interactive)

  (save-excursion
    (beginning-of-buffer)

    (let((case-fold-search nil)
         package)
    
      (while (re-search-forward "^import 
\\(\\([a-z0-9_]+\\.?\\)*\\)\\([A-Z][a-z]+\\)*" nil t)

        ;;keep searching forward for this package and replace it.

        (setq package (match-string 1))

        ;;trim the tailing . off the package

        (setq package (substring package 0 (1- (length package))))

        ;;replace the text with a new package import

        (let(start end)

          (setq start (match-beginning 0))

          (end-of-line)

          (setq end (point))

          (delete-region start end))
        
        (insert (concat "import " package ".*;"))

        (save-excursion

          (while(re-search-forward (concat "^import " package) nil t)

            (let(start end)

              (setq start (match-beginning 0))

              (end-of-line)

              (setq end (1+ (point)))
            
              (delete-region start end))))))))


- -- 
Kevin A. Burton ( [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED] )
        Cell: 408-910-6145 URL: http://relativity.yi.org ICQ: 73488596 

Evolution has an IQ only slightly greater than 0 which is enough to beat
entropy and create wonderful designs given enough time.  -- Ray Kurzweil



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: Get my public key at: http://relativity.yi.org/pgpkey.txt

iD8DBQE7YdtjAwM6xb2dfE0RAvjJAJ0XcmFTLJL/oUMgVg66FRl85aQVuACeJz8X
IEYyl/QdeXqdki6R1mmLr00=
=41xA
-----END PGP SIGNATURE-----

Reply via email to