Re: Bugs introduced that affected jde-import-all (patch to jde-import.el)

"Jeff Peck" <[email protected]>
Newsgroups gmane.emacs.jdee.devel
Message-ID <A0C156C3C65E4902988E3FB6E5B08860@blue>
Upon reading the docstring for jde-import-get-insertion-point, 
we see that it is expected to add new-lines when inserting the first import
between package and class; so that is back in the code.
This patch from 202, with the code cleaned up, consolidates the save-excursions, etc.

Unless someone finds additional bugs, i'll stop now.  :)

[Eric, i'llcontact you off-list to learn more about semantic reparse]

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev

_______________________________________________
jdee-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jdee-devel
jde-import-insertion.patch (application/octet-stream, 4.1 KB)
Index: lisp/jde-import.el
===================================================================
--- lisp/jde-import.el	(revision 202)
+++ lisp/jde-import.el	(working copy)
@@ -213,7 +213,7 @@
 	    (throw 'found import))))))
 
 (defun jde-import-get-import-insertion-point ()
-   "Determine where to insert an import statement.
+  "Determine where to insert an import statement.
 If the buffer contains an import statement, return
 the beginning of the next line; otherwise, if
 the buffer contains a package statement, insert
@@ -222,36 +222,37 @@
 contains a class definition, return the beginning
 of the line before the class definition; otherwise,
 return the beginning of the buffer."
-   (let* ((tags (semantic-fetch-tags))
-	  (import-tag
-	   (car (last (semantic-brute-find-tag-by-class
-		       'include tags))))
-	  (package-tag (car (semantic-brute-find-tag-by-class
-			     'package tags)))
-	  (class-tag (car (semantic-brute-find-tag-by-class
-			   'type tags)))
-	  insertion-point)
-     (cond (import-tag
-	    (setq insertion-point (+ (semantic-tag-end import-tag) 1)))
-	   (package-tag
-	    (save-excursion
-	      (goto-char (semantic-tag-end package-tag))
-	      (forward-line)
-	      (insert "\n")
-	      (setq insertion-point (point))))
-	   (class-tag
-	    (setq insertion-point
-		  (let ((comment-token (semantic-documentation-for-tag
-					class-tag 'lex)))
-		    (if comment-token
-			(semantic-lex-token-start comment-token)
-		      (semantic-tag-start class-tag)))))
-	   (t
-	    (setq insertion-point 1)))
-     (save-excursion
-       (goto-char insertion-point)
-       (unless (and (bolp) (eolp)) (insert "\n")))
-     insertion-point))
+  (flet ((insertion-point-after (tag-end)
+	  (goto-char tag-end)
+	  (if (eolp) (forward-char 1)(forward-line 1)) ;skip comment
+	  (point)
+	  ))
+    (let* ((tags (semantic-fetch-tags)) ;(xx (message "tags = %s" tags))
+	   (import-tag (car
+			(last (semantic-brute-find-tag-by-class
+			       'include tags))))
+	   (package-tag (car (semantic-brute-find-tag-by-class
+			      'package tags)))
+	   (class-tag (car (semantic-brute-find-tag-by-class
+			    'type tags)))
+	   )
+      (save-excursion
+	(cond (import-tag
+	       (insertion-point-after (semantic-tag-end import-tag)))
+	      (package-tag
+	       (insertion-point-after (semantic-tag-end package-tag))
+	       (insert "\n")		;empty line before new imports
+	       (unless (eolp)		;empty line after new imports
+		 (save-excursion (insert "\n")))
+	       (point))
+	      (class-tag
+	       (let ((comment-token (semantic-documentation-for-tag
+				     class-tag 'lex)))
+		 (if comment-token
+		     (semantic-lex-token-start comment-token)
+		   (semantic-tag-start class-tag))))
+	      (t 1)))
+      )))
 
 (defun jde-import-import (class)
   "*Insert an import statement for a class in the current buffer.
@@ -402,20 +403,22 @@
 (defun jde-import-insert-imports-into-buffer (new-imports &optional exclude)
   "Inserts imports into the correct place in the buffer."
   (save-excursion
-    (goto-char (jde-import-get-import-insertion-point))
+    (goto-char (jde-import-get-import-insertion-point)) ;
     (if (not jde-xemacsp) (deactivate-mark))
     (if exclude
       (setq new-imports (jde-import-exclude-imports new-imports)))
     (loop for new-import in new-imports do
-	  (when (> (length new-import) 0) ;; added to avoid insert empty import statements.
-	    (insert
-	     (concat "import " new-import ";\n"))
+	  (when (> (length new-import) 0) ; added to avoid insert empty import statements.
+	    (insert (concat "import " new-import ";\n"))
 	    (message "Imported %s" new-import)))
     (if jde-import-auto-collapse-imports
-	(let (jde-import-auto-collapse-imports) ;; setting this to avoid infinite recursion
+	(let (jde-import-auto-collapse-imports) ; setting this to avoid infinite recursion
 	  (jde-import-collapse-imports)))
     (if jde-import-auto-sort
-	(funcall jde-import-auto-sort-function))))
+	(funcall jde-import-auto-sort-function))
+    (semantic-fetch-tags)
+    (semantic-parse-changes)
+    ))
 
 
 (defun jde-import-already-imports-class (class-name existing-imports)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.