 	(end-col-no    (current-column-pos end)))
     (let* ((n (buffer-name buffer)) (n1 (substring n 0 1)))
       (if (and (not (or (string= " " n1) (string= "*" n1))) (buffer-modified-p buffer))
-	  (message-box "The current buffer has been changed")
+	  (message-box "The current buffer has been changed, please save it first.")
 	(erl-spawn
 	  (erl-send-rpc wrangler-erl-node 'wrangler_distel 'new_macro
 			(list current-file-name start-line-no start-col-no end-line-no (- end-col-no 1) name wrangler-search-paths tab-width))
-	  (erl-receive (buffer start-line-no start-col-no)
+	  (erl-receive (start-line-no start-col-no current-file-name)
 	      ((['rex ['badrpc rsn]]
 		(message "Refactoring failed: %S" rsn))
 	       (['rex ['error rsn]]
 		(message "Refactoring failed: %s" rsn))
-	       (['rex ['ok str]]
-		(with-current-buffer buffer (progn (revert-buffer nil t t)
-						   (goto-line start-line-no)
-						   (goto-column start-col-no)))
-						  ;; (goto-char (get-position start-line-no start-col-no))))
-		(message "Refactoring succeeded!")))))))))
-
+	       (['rex ['ok modified]]
+		(if (yes-or-no-p "Do you want to preview the changes to be performed?")
+		    (ediff current-file-name (concat current-file-name ".swp"))
+		  (commit-or-abort))
+		(with-current-buffer (get-file-buffer current-file-name)
+		  (goto-line start-line-no)
+		  (goto-column start-col-no))))))))))
+	
 (defun erl-refactor-fold-against-macro()
   "Fold expression(s)/patterns(s) against a macro definition."
   (interactive)

	(let* ((n (buffer-name b)) (n1 (substring n 0 1)))
	  (if (and (not (or (string= " " n1) (string= "*" n1))) (buffer-modified-p b))
	      (setq changed (cons (buffer-name b) changed)))))
      (if changed (message-box (format "there are modified buffers: %s" changed))
	(erl-spawn
	  (erl-send-rpc wrangler-erl-node 'wrangler_distel 'register_pid
			(list current-file-name start-line-no start-col-no end-line-no (- end-col-no 1) name wrangler-search-paths tab-width))
	  (erl-receive (buffer current-file-name start-line-no start-col-no end-line-no end-col-no name)
	      ((['rex ['badrpc rsn]]
		(message "Refactoring failed: %S" rsn))
	       (['rex ['error rsn]]

	(let* ((n (buffer-name b)) (n1 (substring n 0 1)))
	  (if (and (not (or (string= " " n1) (string= "*" n1))) (buffer-modified-p b))
	      (setq changed (cons (buffer-name b) changed)))))
      (if changed (message-box (format "there are modified buffers: %s, please save these buffers first." changed))
    (erl-spawn
      (erl-send-rpc wrangler-erl-node 'wrangler_distel 'move_fun
		    (list current-file-name line-no column-no name create-new-file wrangler-search-paths tab-width))
      (erl-receive (line-no column-no current-file-name)
	  ((['rex ['badrpc rsn]]
	    (message "Refactoring failed: %S" rsn))
	   (['rex ['error rsn]]
	    (message "Refactoring failed: %s" rsn))
	   (['rex ['ok modified]]
	    (progn
	      (if (yes-or-no-p "Do you want to preview the changes to be performd?")
		  (progn
		    (setq modified-files (cdr modified))
		    (ediff current-file-name (concat current-file-name ".swp")))
		(commit-or-abort))
	      (with-current-buffer (get-file-buffer current-file-name)
		(goto-line line-no)
		(goto-column column-no))))
	   )))))))
	    

(defun create-new-file-p (filename wrangler-search-paths)
  (if (equal (locate-file filename (cons (file-name-directory filename) nil) '("" ".erl")) nil)
