Hi.

I like to have blank lines beetwen import sentences of different group
of packages (if such a concept does exist). I wrote a small function
to do this (It also remove the blank lines but one beetwen the package
sentence and the first import). Users of both
'jde-import-sort-imports' or 'jde-sort-imports' can use this function
(it requires the imports to be sorted) easily.

That is the function:

(defun jde-import-space-lines()
  "Put blank lines between import sentences of different group of
packages"
  (interactive)
  (save-excursion
    (goto-char (point-min))
        ;; First clean the extra blank lines
    (search-forward-regexp "^import.*;")
    (forward-line -1)
    (newline)
    (delete-blank-lines)    
        ;; Now put the required blank lines
    (while (search-forward-regexp "^import \\w*")
      (let ((imp-package (match-string 0)))
        (while
            (and 
             (search-forward-regexp "^import \\w*")
             (if (not (equal imp-package (match-string 0)))
              (progn
                (beginning-of-line)
                (newline)
                nil)
            t)
            ))))))

And this is an example of the results:

 > import JGra.tipos.TipoContenido;
 > import JGra.ventana.VentDialog;
 > 
 > import Util.Mascara;
 > 
 > import java.awt.Color;
 > import java.awt.Dimension;
 > import java.util.Enumeration;
 > import java.util.StringTokenizer;
 > import java.util.Vector;
 > 
 > import javax.swing.JComponent;
 > import javax.swing.JPanel;

Comments are welcomed.

--
Leon

Reply via email to