     (simulate-input-expression (concat ":sw " filename))))
 
 (defun sw::file-to-specware-unit-id (filename)
-  (when (eq (elt filename 1) ?:)
-    (setq filename (substring filename 2)))
   (let ((len (length filename)))
     (when (equal ".sw" (substring filename (- len 3)))
       (setq filename (substring filename 0 (- len 3))))
     (setq filename (sw::normalize-filename filename))
-    (name-relative-to-swpath filename)))
+    (setq filename (name-relative-to-swpath filename))
+    (when (eq (elt filename 1) ?:)
+      (setq filename (substring filename 2)))
+    filename))
 
 (defun sw::normalize-filename (filename)
   (setq filename (replace-in-string filename "\\\\" "/"))

(defun name-relative-to-swpath (filename)
  (let ((swpath (get-swpath)))
    (loop for dir in swpath
	  do (if (string-equal dir (substring filename 0 (min (length dir)
							      (length filename))))
		 (let ((rel-filename (substring filename (length dir))))
		   (return (if (eq (elt rel-filename 0) ?/)
			       rel-filename
			     (concat "/" rel-filename)))))
	  finally (let ((oldpath (sw:eval-in-lisp "(specware::getenv \"SWPATH\")")))
		    (simulate-input-expression
		     (concat ":swpath " oldpath

      ["Process Unit" sw:process-unit t]
      ["Generate Lisp" sw:generate-lisp t]
      ["Generate & Load Lisp" (sw:generate-lisp t) t]
      ["Generate Local Lisp"  sw:gcl-current-file t]
      ["Evaluate Region (:swe)" sw:evaluate-region (mark)]
      ["Set :swe Spec" sw:set-swe-spec t]
      [":cd to this directory" cd-current-directory t] 
