 	       (message "Refactoring succeeded!")))))))
 
 
+
 (defun erl-refactor-rename-mod (node name)
   "Rename the current module name."
   (interactive (list (erl-target-node)

		     nil))))
	       (message "Refactoring succeeded!")))))))

(defun create-new-file-p (name)
  (let  ((filename (expand-file-name (concat name ".erl") (file-name-directory (buffer-file-name)))))
         (if (file-exists-p filename) t
	     (yes-or-no-p "The specified module does not exist, do you want to create one? "))))

 
;; redefined get-file-buffer to handle the difference between

		       nil)))))
            (message "Refactoring succeeded!"))))))

(defun erl-refactor-register-pid(node name start end)
  "Introduce a new function to represent an user-selected expression/expression sequence."
  (interactive (list (erl-target-node)
		     (read-string "process name: ")
		     (region-beginning)
		     (region-end)
		     ))
  (let ((current-file-name (buffer-file-name))
	(buffer (current-buffer))
	(start-line-no (line-no-pos start))
	(start-col-no  (current-column-pos start))
	(end-line-no   (line-no-pos end))
	(end-col-no    (current-column-pos end)))     
    (erl-spawn
      (erl-send-rpc node 'wrangler_distel 'register_pid
		    (list current-file-name start-line-no start-col-no end-line-no (- end-col-no 1) name erlang-refac-search-paths))
      (erl-receive (buffer node 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]]
	    (message "Refactoring failed: %s" rsn))
	   (['rex ['registered pars]]
	    (if (yes-or-no-p "Do you want to continue the refactoring?")
		(erl-spawn
		  (erl-send-rpc node 'wrangler_distel 'register_pid
				(list current-file-name start-line-no start-col-no end-line-no (- end-col-no 1) name erlang-refac-search-paths))
		  (erl-receive (buffer)
		      ((['rex ['badrpc rsn]]
			(message "Refactoring failed: %S" rsn))
		       (['rex ['error rsn]]
			(message "Refactoring failed: %s" rsn))
		       (['rex ['ok modified]]
			(with-current-buffer buffer (revert-buffer nil t t))
			(message "Refactoring succeeded!")))))
	      (message "Refactoring aborted!")))	      
	   (['rex ['ok modified]]
	    (with-current-buffer buffer
	      (dolist (f modified)
		(let ((buffer (get-file-buffer f)))
		  (if buffer (with-current-buffer buffer (revert-buffer nil t t))
		    ;;(message-box (format "modified unopened file: %s" f))))))
		    nil))))
	    (message "Refactoring succeeded!")))))))
	  
(defun erl-refactor-move-fun (node name)
  "Move a function definition from one module to another."
  (interactive (list (erl-target-node)
